Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2004
    Location
    India
    Posts
    3

    Unanswered: Order for conditions to be processed

    what is order in which conditions are processed for sql query i.e for
    select * from table1, table2 where cond1 and cond2 and cond3 which condition will be processed first (i.e. for optimination purpose condition cutting down max no. of row shud be placed first or last?)

  2. #2
    Join Date
    Jan 2003
    Location
    India
    Posts
    523

    Re: Order for conditions to be processed

    Originally posted by kiranghag
    what is order in which conditions are processed for sql query i.e for
    select * from table1, table2 where cond1 and cond2 and cond3 which condition will be processed first (i.e. for optimination purpose condition cutting down max no. of row shud be placed first or last?)

    If all the conditions are AND'ed then the order will be left to right, if the first condition is false the entire thing will be false so the remaining conditions would not be processed.
    And if the conditions are OR'ed then if the first condition is true then all the conditions are true.
    Also adding parenthesis decides which conditions are processesed when.

    Regards,
    Harshal.

  3. #3
    Join Date
    Feb 2004
    Posts
    492

    Re: Order for conditions to be processed

    Originally posted by kiranghag
    what is order in which conditions are processed for sql query i.e for
    select * from table1, table2 where cond1 and cond2 and cond3 which condition will be processed first (i.e. for optimination purpose condition cutting down max no. of row shud be placed first or last?)
    sql has an internal parser which reorders the conditions depending on clustered/indexes and such (keys for example). Conditions that refer to the c/indexes are processed prior to the non-c/indexes.

    Besides that, the order in which the other conditions are processed might get reversed, which ever suit sql best.

  4. #4
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Kaiowas, I think you're talking about the order in which the records are retrieved in the case of SELECT, or UPDATEed/DELETEed respectively.

    harshal's statement pretty much summarizes what the optimizer does and how to control it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •