我有大表ir_data(150GB),其中包含不同日期的數據(列val_date)。我需要知道在我的應用程序中的各個點上ir_data是否有給定的日期。索引掃描令人費解的性能。爲什麼掃描索引變慢,即使結果集很小並編入索引
select distinct(val_date) from ir_data
我下面的實驗ir_data包含val_date的29個不同的值。
SETUP 1
我預期ir_data(val_date,KEY_ID,other_colum),以幫助快速找到29個值的指數。事實上這需要超過5分鐘:
查詢1的1,行寫着:29,經過時間(秒) - 合計:343.96, SQL查詢:343.958,閱讀效果:0.002
我總是期望索引是一個樹,其中的節點存儲在樹形結構中,例如像這樣
val_date -> key_id -> other_column -> data-nodes
1.1.2017 -> 0-50 -> A -> (1.1.2017, 0, Automobile), (1.1.2017, 2, Amsterdam)
-> B-E -> (1.1.2017, 12, Batman)
-> 51-100 -> A -> ...
X
-> 666-1000 -> A
-> B-C
-> E
2.1.2017 -> ...
根據這個結構得到29個不同的val_dates應該很快。
問題:爲什麼需要這麼長時間?
子問題:有沒有辦法解決這個問題而不創建另一個表?
SETUP 2
我創建僅包含val_date另一個索引。這需要大致相同的時間。
查詢的計劃:
The type of query is SELECT.
2 operator(s) under root
|ROOT:EMIT Operator (VA = 2)
|
| |GROUP SORTED Operator (VA = 1)
| |Distinct
| |
| | |SCAN Operator (VA = 0)
| | | FROM TABLE
| | | ir_data
| | | Index : ir_data_idx1 <-- this is the index containing only val_date.
| | | Forward Scan.
| | | Positioning at index start.
| | | Index contains all needed columns. Base table will not be read.
| | | Using I/O Size 16 Kbytes for index leaf pages.
| | | With MRU Buffer Replacement Strategy for index leaf pages.
您的查詢是什麼? –
@OfirWinegarten是的,我應該提到這一點。添加。 – Beginner