MySQL performance question
| From: | Lars Olsson | Date: | Sun, 04 Aug 2002 20:27:35 +0000 |
| Subject: | MySQL performance question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-111089@lists.php.net to get a copy of this message | ||
Hi all!
Sorry for being slightly off topic, but this list seems to have it's fair share of MySQL gurus... :-) Anyway, here's my question:
Suppose I create a table (called table1) which has a field with only unique values (called id). Now suppose this table has some rows and that I want to select ONE of them. I usually do this:
"SELECT * FROM table1 WHERE id=somevalue"
Since id is a unique value this can only return (at most) 1 row. Now let's try this:
"SELECT * FROM table1 WHERE id=somevalue LIMIT 1"
This query will produce exactly the same result as the first query. But which one (if any) of the two queries are the most efficient? Is it
a) The first one, since it's a less complicated SQL query (less time to parse)
b) The second one, since it will restrict MySQL from searching further whenever a row is found
Any opinions?
/lasso (lasso@lassoweb.nu)