Domanda

Our application has suddenly gone slow in one of the env. The only change I have done is changed the SQL. Before release, the SQL was something like this

Select EmployeeId 
From Employee 
Where Dept='CS' 
  and record_state='ACTIVE' 
  and EmployeeTypeId ='1' 

After release SQL is

Select EmployeeId 
From Employee Where Dept='CS' 
 and record_state='ACTIVE' 
 and EmployeeTypeId IN ('1','2')

The index on this table is employee_state_id_index (Dept,record_state,EmployeeTypeId ) The index has not been changed. Does this index not help the new SQL? does the new SQL scan the whole table? I have no idea how indexes work with in clause. Appreciate your help and comments

The explain plan for the query is

| Id  | Operation         | Name                     | Rows  | Bytes | Cost (%CPU)|

|   0 | DELETE STATEMENT  |                          |     1 |    57 |     4   (0)|
|   1 |  DELETE           | Employee                 |       |       |            |
|*  2 |   INDEX RANGE SCAN| employee_state_id_index  |     1 |    57 |     4   (0)|
--------------------------------------------------------------------------------

Predicate Information (identified by operation id):


PLAN_TABLE_OUTPUT


   2 - access("C"."Dept"='CS' AND
              "C"."RECORD_STATE"='ACTIVE')
       filter("C"."EmployeeTypeId"='1' OR
              "C"."EmployeeTypeId"='2')
È stato utile?

Soluzione

The solution to the problem we faced, was reindexing the table. The table had a 10 million records and we recently cleaned up the data in the table (when we realized that we had duplicate records) and that reduced it to almost half of the amount of records it previously had. So we thought we will give a try with reindexing, since anyway it needed it. And that helped :)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top