使用 ANALYZE 检查我的查询是否在属性上使用索引
Check whether my query is using index on attribute using ANALYZE
我在 o_orderdate
属性上安装了一个 b 树索引。
我有这个查询:
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 [=11=])"
" -> 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: [=11=]"
" -> 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: [=11=]"
" -> 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
属性上安装的索引?
根据 this article,优化器确定并行查询是最快的解决方案,创建了 Gather
节点。所以它没有在 o_orderdate?
上使用 B 索引
它没有使用索引,但是'parallel'并没有告诉我们这一点,因为索引扫描也可以并行完成。 'seq scan' 的存在和“[parallel] [bitmap] index [only] scan” 的存在告诉我们这一点。一个简单的 EXPLAIN 足以告诉我们它不使用索引,但不能告诉我们很多关于 为什么 它选择不使用的信息,我认为这就是你想要的到达。
我在 o_orderdate
属性上安装了一个 b 树索引。
我有这个查询:
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 [=11=])"
" -> 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: [=11=]"
" -> 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: [=11=]"
" -> 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
属性上安装的索引?
根据 this article,优化器确定并行查询是最快的解决方案,创建了 Gather
节点。所以它没有在 o_orderdate?
它没有使用索引,但是'parallel'并没有告诉我们这一点,因为索引扫描也可以并行完成。 'seq scan' 的存在和“[parallel] [bitmap] index [only] scan” 的存在告诉我们这一点。一个简单的 EXPLAIN 足以告诉我们它不使用索引,但不能告诉我们很多关于 为什么 它选择不使用的信息,我认为这就是你想要的到达。