Skip to content
Advertisement

Oracle Selecting Index Optimisation

I need to optimise this query by using indexing. I tried to index some of the columns, but it is not helping. Is there anyone have thoughts?

The query I need to optimise:

I tried to created the following indexes: ”’create index wine_vid_idx on wine(vid); create index wine_cid_idx on wine(cid); create index wine_grade_idx on wine(grade);“`

My execution plan for the original query is:

Advertisement

Answer

To start with: you are using an old join syntax (of the 1980s actually). This is how we would write the query today:

Here a mere glimpse at the WHERE clause suffices to see that you are looking for wines matching a class and grade. So, have an index on the two columns. Order may matter, so provide two indexes. Extend this with the vineyard ID, so as to get quickly to the vineyard table.

As to class and vineyard, you should already have indexes on their IDs. You may want to add the one column for each table you are selecting, so the DBMS can get the values directly from the index.

Use the execution plan to detect indexes that are not used (the query will only use either idx01 or idx02 or even none of these, not both) and drop them.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement