[英]Postgresql index and seq scan
I'm realised that one interesting thing.我意识到一件有趣的事情。 I have a table with multiple column index.
我有一个带有多列索引的表。
CREATE INDEX transaction_idx ON transaction USING btree (period_id, day_id, value_type, indicator_id);
when I run query like :当我运行查询时:
select *
from transaction
where period_id = '202104'
and day_id = 30
and value_type = 1
and indicator_id = 2
DB will go seq scan. DB 将进行 seq 扫描。
But if I just change the day_id value to 20, then DB will go Index Scan.但是如果我只是将 day_id 值更改为 20,那么 DB 将进行索引扫描。 Go index Scan
去索引扫描
Go Seq Scan去 Seq 扫描
I'm appreciate that if someone can share the root reason to me about it .
我很感激,如果有人可以与我分享根本原因。
Thank you !谢谢 !
好的,我已经更新了 random_page_cost 值,查询按我的预期运行。
alter database db set random_page_cost=0.7;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.