Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: SQL Tuning
Greg Moore wrote:
>
> That's a great SQL tuning presentation, but I don't follow what he says in
> slide #91:
>
> -------------------------------------------
> "No WHERE clause with an ORDER BY"
> Often a screen will return rows with a predefined order, e.g., ORDER BY
> NAME. The user is expected to enter a NAME or part of a name, NAME=SMI. If
> the user presses Enter for the query without entering a name, all table rows
> must be sorted. So always have a WHERE NAME > CHR(1).
> --------------------------------------------
>
> What does the extra WHERE clause do for you?
>
I have not checked the detail of the presentation but this is an old trick with the rule based optimizer. When using the RBO Oracle will not use an index if the indexed column is not referenced in the WHERE clause (no fast full scan, which you are likely to get with the CBO and a relatively recent Oracle release). By asking for values greater than something known to be smaller than all entries, Oracle will use the (sorted) index and avoid the cost of a sort.
-- Regards, Stephane Faroult Oriole Corporation Voice: +44 (0) 7050-696-269 Fax: +44 (0) 7050-696-449 Performance Tools & Free Scripts -------------------------------------------------------------- http://www.oriole.com, designed by Oracle DBAs for Oracle DBAs -------------------------------------------------------------- -- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Stephane Faroult INET: sfaroult_at_oriole.com Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Tue Nov 20 2001 - 17:12:32 CST