Hello All,
I have a problem with my database having lots of 'stale' slow_queries. I think the problem may be because of the following code:
$numresults=mysql_query("select * from links where catagory=".$catagory." order by linknum");$numrows=mysql_num_rows($numresults);
I believe this sql statement is doing a full table scan; is this correct?
Would there be anything to gain from coding the sql like this:
select count(*) from links where ...
I've just realised that catagory (i know it's spelt incorrectly...) isn't an index... the links table is the biggest table - do you think this could be a problem?
Also I don't close the db connection - I'm reading conflicting messages about how good/bad this can be... most of my pages select a subset of data then have links where you can get the next/previous batch which work via post - i'm not sure how a close of each db connection will behave. Any ideas on the best approach?
My db is not very big. It only has six tables and 70k entries in the biggest table...
My index in the biggest table isn't contiguous because entries get deleted - is this a problem?
Lots of questions! Hope you can help - you've probably realised that I'm new to this! ...I've just created the database to do what I need and didn't really do any 'design' as such.
Many thanks, p.
I have a problem with my database having lots of 'stale' slow_queries. I think the problem may be because of the following code:
$numresults=mysql_query("select * from links where catagory=".$catagory." order by linknum");$numrows=mysql_num_rows($numresults);
I believe this sql statement is doing a full table scan; is this correct?
Would there be anything to gain from coding the sql like this:
select count(*) from links where ...
I've just realised that catagory (i know it's spelt incorrectly...) isn't an index... the links table is the biggest table - do you think this could be a problem?
Also I don't close the db connection - I'm reading conflicting messages about how good/bad this can be... most of my pages select a subset of data then have links where you can get the next/previous batch which work via post - i'm not sure how a close of each db connection will behave. Any ideas on the best approach?
My db is not very big. It only has six tables and 70k entries in the biggest table...
My index in the biggest table isn't contiguous because entries get deleted - is this a problem?
Lots of questions! Hope you can help - you've probably realised that I'm new to this! ...I've just created the database to do what I need and didn't really do any 'design' as such.
Many thanks, p.
Comment