gpt4 book ai didi

postgresql - 按不使用索引的查询分组

转载 作者:行者123 更新时间:2023-11-29 13:39:22 25 4
gpt4 key购买 nike

这是我的查询 -

select bill, render, count (*)
from dx
group by bill, render

这是我为它创建的索引——

CREATE INDEX bill_render ON dx (bill, render);

为什么我的查询不使用带计数 (*) 和不带计数 (*) 的索引?

"Finalize GroupAggregate  (cost=70441673.89..89334654.09 
rows=61437331 width=27)"
" Group Key: bill, render"
" -> Gather Merge (cost=70441673.89..87798720.82 rows=122874662 width=27)"
" Workers Planned: 2"
" -> Partial GroupAggregate
(cost=70440673.86..73614935.97 rows=61437331 width=27)"
" Group Key: bill, render"
" -> Sort (cost=70440673.86..71080646.06 rows=255988880 width=19)"
" Sort Key: bill, render"
" -> Parallel Seq Scan on dx (cost=0.00..18940581.80 rows=255988880 width=19)"

最佳答案

原因是它不能执行仅索引扫描,而普通索引扫描(必须获取表行以检查可见性)会比顺序扫描慢。

如果您想在 PostgreSQL 中进行仅索引扫描,您必须确保大多数表 block 在可见性映射中标记为“全部可见”。然后 PostgreSQL 可以跳过昂贵的堆获取。

可见性 map 由 VACUUM 维护,因此在表上运行它以提高性能。

关于postgresql - 按不使用索引的查询分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57698332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com