Where clause ordering
From: Jonathan Lewis <Jonathan_at_jlcomp.demon.co.uk>
Date: 1995/08/23
Message-ID: <809212818snz_at_jlcomp.demon.co.uk>#1/1
Date: 1995/08/23
Message-ID: <809212818snz_at_jlcomp.demon.co.uk>#1/1
select count(*) from lookups where class = 123 and to_number(value) = 0;
could in theory run faster than:
select count(*) from lookups where to_number(value) = 0; and class = 123
depending on which column satisfies the condition least often, and whereabouts in the table the columns are.
In practice, I have never found any real difference in performance even when rigging the data in an extreme fashion, but today I actually ran a statement of the above type: surprise, surprise, the top one would _not_ run (Oracle error: invalid number) whilst the bottom one would.
The reason, if you haven't already guessed it: CLASS = 123 guaranteed that the varchar2 VALUE was really numeric in form so the to-number() was always valid, whereas lots of other rows in the table had VALUE of a non-numeric form.
Oracle: 7.1.6, on Sequent, SQL*Plus 3.1.3
-- Jonathan LewisReceived on Wed Aug 23 1995 - 00:00:00 CEST