带 in 子句的 SQL 索引

标签 sql oracle indexing oracle10g in-clause

我们的应用程序在其中一个环境中突然变慢了。我所做的唯一更改是更改了 SQL。发布之前,SQL是这样的

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

发布后SQL为

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

该表的索引是employee_state_id_index (Dept,record_state,EmployeeTypeId) 索引没有改变。这个索引对新的SQL没有帮助吗?新的SQL是否扫描整个表?我不知道索引如何与 in 子句一起使用。感谢您的帮助和评论

查询的解释计划是

| 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')

最佳答案

我们面临的问题的解决方案是重新索引表。该表有 1000 万条记录,我们最近清理了表中的数据(当我们意识到有重复记录时),并将其减少到之前记录数量的近一半。所以我们认为我们会尝试重新索引,因为无论如何它都需要它。这很有帮助:)

关于带 in 子句的 SQL 索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14955077/

相关文章:

SQL 检查列中的所有值

python - 使用 numpy 获取查找表索引的最快方法

整数字段的 MySQL WHERE 条件返回不正确的值

java - SQL不将文件内容添加到表中

html - 松散搜索,例如这样 "htlm"就会找到 "html5"

sql - Insert Into 使用 WITH 子句 (CTE) 导致 ORA-00928

mysql - SQL:每个 id 最常见的值

.net - 多个oracle查询问题

Mysql select on indexed column llowed on large tables

jquery - 如何使用 jQuery 获取表列索引?