-
Which Is Faster?
A query like:
SELECT * FROM table
Or:
SELECT * FROM table WHERE id = 1 OR id = 2 OR id = 3 OR id = 4 OR id = 5
Assuming that the table was pretty huge?
Thanks.
-
If there is an index on ID, and you have more than just those five IDs in there...
It depends.
We need more information than just that, including the table schema, indexes (if any), what you are trying to do, etc.
-
What a question... query 2 of course. Try this instead:
SELECT * FROM table WHERE id IN (1,2,3,4,5)
You are comparing selecting everything and selecting only 5.
-
Ramiro: If there is no index on ID, or if {1,2,3,4,5} is a superset of the actual data in the table, it should take approximately the same time.
There is more to this issue than simply the existance of predicates in the where clause.
-
I agree Im talking about a simple MySQL table with an index on the Id column.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks