tags:

views:

74

answers:

1

This question was inspired by a previous question posted on SO, "Does the order of the WHERE clause make a differnece?". Would it improve a SELECT statement's performance if the the columns used in the WHERE section are placed at the begining of the SELECT statement?

example:

    SELECT customer.id, 
           transaction.id, 
           transaction.efective_date, 
           transaction.a,
           [...]
      FROM customer, transaction 
     WHERE customer.id = transaction.id;

I do know that limiting the list of columns to only the needed ones in a SELECT statement improves performance as opposed to using SELECT * because the current list is smaller.

+7  A: 

For Oracle and Informix and any other self-respecting DBMS, the order of the columns should have no impact on performance. Similarly, it should be the case that the query engine finds the optimal order to process the Where clause so the order should not matter all things being equal (i.e., looking past constructs which might force an execution order).

Thomas
@Thomas- OK, anyway I have a habit of putting them in the same order as the columns in my WHERE section because it makes it easier for me to visualize and update the statement if need be. I also put only the needed columns, thinking that the optimizer will create a smaller current list vs. a current list with the entire row set.
Frank Computer
@Frank: there's absolutely no harm in your self-imposed discipline, but it is not going to alter the performance of the query.
Jonathan Leffler
The rule based optimizer did use ordering of the where clause, but not the CBO. (See http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1857060700346051220)
Paul James
The leading hint makes the CBO use the ordering of the where clause, but in the opposite direction to the RBO!
Mark Bannister