Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding an Index degraded execution time
    primarykey
    data
    text
    <p>I have a table like this:</p> <pre><code>myTable (id, group_id, run_date, table2_id, description) </code></pre> <p>I also have a index like this:</p> <pre><code>index myTable_grp_i on myTable (group_id) </code></pre> <p>I used to run a query like this:</p> <pre><code>select * from myTable t where t.group_id=3 and t.run_date='20120512'; </code></pre> <p>and it worked fine and everyone was happy. Until I added another index:</p> <pre><code>index myTable_tab2_i on myTable (table2_id) </code></pre> <p>My life became miserable... it's taking almost as 5 times longer to run !!! execution plan looks the same (with or without the new index):</p> <pre><code>-------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 220 | 17019 |* 1 | TABLE ACCESS BY INDEX ROWID| MYTABLE | 1 | 220 | 17019 |* 2 | INDEX RANGE SCAN | MYTABLE_GRP_I | 17056 | | 61 -------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("T"."RUN_DATE"='20120512') 2 - access("T"."GROUP_ID"=3) </code></pre> <p>I have almost no hair left on my head, why should another index which is not used, on a column which is not in the where clause make a difference ... </p> <hr> <p>I will update the things I checked:<br> a. I removed the new index and it run faster<br> b. I added the new index in 2 more different environments and the same thing happen<br> c. I changed MYTABLE_GRP_I to be on columns run_date and group_id - this made it run fast as a lightning !!</p> <p>But still why does it happen ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload