Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the order of parameters in the where clause affect whether a table uses an index?

Tags:

sql

rdbms

So I am wondering if there is a definitive answer to this question.
Also, does it matter if the index is clustered vs. non-clustered. Is it the same in all RDBMS implementations or is the exact behavior going to be proprietary?

like image 261
Daniel Honig Avatar asked Nov 11 '08 05:11

Daniel Honig


2 Answers

SQL is a declarative language, not a procedural one. Each SQL implementation is going to have its own quirks about implementation details like which indexes get used, how the optimizer decides which indexes to use, what the SQL programmer can do to affect the choice, and so on.

like image 131
Ned Batchelder Avatar answered Oct 12 '22 23:10

Ned Batchelder


Use of indexes is not a part of the SQL standard, but rather an implementation detail of the particular DBMS.

Ideally, it shouldn't affect it, since it doesn't affect the actual rows that are returned.

But I've seen queries on an unnamed DBMS that does change index use based on the SQL query order.

like image 21
paxdiablo Avatar answered Oct 12 '22 23:10

paxdiablo