Let's say I have a simple table with two columns - C1, and C2. C1 is indexed, while C2 is not. If I were to write a stamenet like this:
select C1, C2 from table WHERE C1 = "A" and C2 = "B"
Would it be any different if I write it like this:
select C1, C2 from table WHERE C2 = "B" and C1 = "A"
I theory, since C1 is indexed, the first statement would execute faster. The second condition (C2 = "B" should not even be evaluated in cases where C1 = "A" is false.
Now, my question is:
Does the order of conditions in the WHERE clause matter?
Or, is the server "smart" enough to know which fields are indexed and will perform those comparisons first (and not do other comparisons where applicable)?
Or, will the server perform ALL of the comparisons in the where clause, regardless of their order and whether they are indexed or not?
I'm using Sybase ASE 11, but I'm also interested in how this works in other systems.
select C1, C2 from table WHERE C1 = "A" and C2 = "B"
Would it be any different if I write it like this:
select C1, C2 from table WHERE C2 = "B" and C1 = "A"
I theory, since C1 is indexed, the first statement would execute faster. The second condition (C2 = "B" should not even be evaluated in cases where C1 = "A" is false.
Now, my question is:
Does the order of conditions in the WHERE clause matter?
Or, is the server "smart" enough to know which fields are indexed and will perform those comparisons first (and not do other comparisons where applicable)?
Or, will the server perform ALL of the comparisons in the where clause, regardless of their order and whether they are indexed or not?
I'm using Sybase ASE 11, but I'm also interested in how this works in other systems.