Re: Optimizing a SQL statement

From: Andy Sayer <>
Date: Fri, 6 Dec 2019 10:12:17 +0000
Message-ID: <>


As I explained before, you’d need every single one of those like filtered columns in your index to allow it to be used to filter rows. Not a single one of the filters can be applied on its own because they are OR’ed together. By the time you’ve added all the columns to the same index, you’ll most likely hit the index key size (which is less than half the block size) or you’ll have an index which is essentially the table and will always need (fast) full scanning.

One other plan that comes to mind is if OR expansion were to occur. If all columns were individually indexed then this would be possible, but Oracle is still likely to cost that fairly expensively with the bind predicates as there could be leading wildcards. Depending on how the predicates are actually used, this might be okay. If more than one or two include a leading wildcard, you’re probably going to do more work than one full tablescan would.

I stick with best to start by thinking about rewriting the ORs.


On Fri, 6 Dec 2019 at 08:10, Stefan Koehler <> wrote:

> Hello Amir,
> unfortunately one of the most important information (access/filter
> predicates and column projections) is missing in your case but let's do a
> little bit of guess work here.
> > Almost all of the columns in the statement are indexed. Tables PRODUCT
> and PLACE have 4,576,690 and 1,892,243 rows respectively.
> Your statement is CPU driven which is possibly caused by the amount of
> LIOs which are mainly driven by the PRODUCT table access (4.570.888). Your
> index access/filter predicates are almost returning all rows (4.578.439)
> which are then additionally filtered down to 1 by one of the predicates by
> PRODUCT table access.
> So the question is - how does the access/filter predicates and column
> projections look like - if you can avoid the PRODUCT table access at all
> (or filter more early in the index) it should be way faster :)
> Best Regards
> Stefan Koehler
> Independent Oracle performance consultant and researcher
> Website:
> Twitter: _at_OracleSK
> > "Hameed, Amir" <> hat am 4. Dezember 2019 um 18:05
> geschrieben:
> >
> >
> > Hi,
> >
> >
> > The following statement does over 4.5 million LIOs per execution. It
> runs at an average of 3-4 times per minute. Almost all of the columns in
> the statement are indexed. Tables PRODUCT and PLACE have 4,576,690 and
> 1,892,243 rows respectively. The only way I have been able to optimize it
> is to add a hint to scan the PRODUCT table in PARALLEL, which does help
> with the elapsed time and the statement finishes within 10 seconds.
> However, because the statement runs quite frequently, I don’t believe using
> the parallel hint would be a good idea. What would be a good approach I
> should look into to help optimize it. The DB version is
> >
> >
> > Thanks
> --

Received on Fri Dec 06 2019 - 11:12:17 CET

Original text of this message