o_orderdate我已經在屬性上安裝了一個 b-tree 索引。
我有這個查詢:
explain select
o_orderpriority,
count(*) as order_count
from
orders
where
o_orderdate>='01/07/1993'
and
o_orderdate<'01/10/1993'
and
exists (select * from commitdate_before_receiptdate_view) -- mat view
GROUP by
o_orderpriority
ORDER by
o_orderpriority
這給了我:
"Finalize GroupAggregate (cost=734229.48..734230.75 rows=5 width=24)"
" Group Key: orders.o_orderpriority"
" InitPlan 1 (returns $0)"
" -> Seq Scan on commitdate_before_receiptdate_view (cost=0.00..1714549.24 rows=33184824 width=0)"
" -> Gather Merge (cost=734229.43..734230.60 rows=10 width=24)"
" Workers Planned: 2"
" Params Evaluated: $0"
" -> Sort (cost=733229.41..733229.42 rows=5 width=24)"
" Sort Key: orders.o_orderpriority"
" -> Partial HashAggregate (cost=733229.30..733229.35 rows=5 width=24)"
" Group Key: orders.o_orderpriority"
" -> Result (cost=0.00..732048.00 rows=236260 width=16)"
" One-Time Filter: $0"
" -> Parallel Seq Scan on orders (cost=0.00..732048.00 rows=236260 width=16)"
" Filter: ((o_orderdate >= '1993-07-01'::date) AND (o_orderdate < '1993-10-01'::date))"
如何檢查我的查詢是否使用了我在o_orderdate屬性上安裝的索引?
根據這篇文章,優化器已經確定并行查詢是最快的解決方案,創建一個Gather節點。所以它沒有使用 B 索引o_orderdate?
uj5u.com熱心網友回復:
它沒有使用索引,但“并行”并沒有向我們展示這一點,因為索引掃描也可以并行完成。'seq scan' 的存在和 '[parallel] [bitmap] index [only] scan' 的缺失告訴了我們這一點。一個簡單的 EXPLAIN 足以告訴我們它不使用索引,但不能告訴我們它為什么選擇不使用索引,我認為這就是你想要得到的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/446067.html
標籤:sql PostgreSQL 索引
