簡體   English   中英

Oracle SQL-為什么此查詢具有全表掃描?

[英]Oracle SQL - Why this query has full table scan?

我對此查詢有疑問:

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
       )

即使我已經在這些表上為這些字段創建了索引,我在表上仍然有一個“表訪問已滿”:

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

我該如何解決? 謝謝。

NOT IN where子句通常不使用索引,因為從索引中獲得的收益不多。 此處閱讀詳細信息。 盡管該博客解釋了為什么對“非等式”比較而言索引被忽略,但對NOT IN也是有效的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM