Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: prepare statement within DBI

by mpeppler (Vicar)
on Aug 26, 2004 at 07:07 UTC ( [id://385926]=note: print w/replies, xml ) Need Help??


in reply to Re^2: prepare statement within DBI
in thread prepare statement within DBI

A select count(*) usually has to traverse at least an index tree to find the actual number of rows currently in the table. A quick test on Sybase on a fairly busy server shows that it can take up to 3 seconds to count the rows in a 4+ million row table, with a lot of the time spent fetching data pages into cache. Keep in mind that the database engine has to be able to run the select count(*) where somecondition as well, for which no real short-cut is available, unless an appropriate index exists that can satisfy the WHERE clause.

Michael

Replies are listed 'Best First'.
Re^4: prepare statement within DBI
by dragonchild (Archbishop) on Aug 26, 2004 at 12:06 UTC
    From what I understood in my MySQL course a few months back, MyISAM tables actually keep the number of rows in the table stored somewhere. I'm not sure why it does this, but it does. So, select count(*) from table1; is actually special-cased in the MySQL code.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://385926]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-25 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found