Oracle SQL - 为什么此查询具有全表扫描?

时间:2014-07-01 10:53:00

标签: sql oracle sql-execution-plan

我对此查询有疑问:

SELECT *
  FROM customer_table PARTITION (p25062014)
 WHERE (   customer_table.username NOT IN ('user1','user2','user3')
        OR customer_table.username IS NULL
       )
   AND (customer_table.ip NOT IN ('ip1','ip2','ip3') OR customer_table.ip IS NULL
       )
   AND (   customer_table."ACCOUNT DEVICE ID" NOT IN ('deviceId1','deviceId2','deviceId3')
        OR customer_table."ACCOUNT DEVICE ID" IS NULL
       )

即使我在这个表上为这些字段创建了索引,我在桌面上也有一个“Table Access Full”:

CREATE INDEX customer_table_USERNAME ON customer_table
(USERNAME)

CREATE INDEX customer_table_DEVICE_ID ON customer_table
("ACCOUNT DEVICE ID")

CREATE INDEX customer_table_IP ON customer_table
(IP)
Plan
SELECT STATEMENT  ALL_ROWSCost: 2  Bytes: 965  Cardinality: 1       
    2 PARTITION RANGE SINGLE  Cost: 2  Bytes: 965  Cardinality: 1  Partition #: 1  Partitions accessed #21  
        1 TABLE ACCESS FULL TABLE customer_table Cost: 2  Bytes: 965  Cardinality: 1  Partition #: 2  Partitions accessed #21

我该如何解决? 感谢。

1 个答案:

答案 0 :(得分:1)

NOT IN where子句通常不使用索引,因为从索引中获取的内容不多。阅读详细信息here。虽然该博客解释了为什么索引在“not eqals”比较中被忽略,但同样适用于NOT IN