我遇到过这样的情况:Pg 总是更喜欢对具有大约 70M 行的表进行顺序扫描。(索引扫描非常适合该查询,我已经通过设置enable_seq_scan = off确认了这一点,速度提高了200倍)
所以,为了帮助 Pg 更好地理解我的数据,我执行了这个
ALTER TABLE tablename ALTER COLUMN columnname SET STATISTICS 1000;
不幸的是,这需要更新独占锁来锁定整个表(锁太多)。
postgresql postgresql-performance
postgresql ×1
postgresql-performance ×1