【问题标题】:Showing sequential scan result instead of the index [duplicate]显示顺序扫描结果而不是索引 [重复]
【发布时间】:2021-08-18 03:09:17
【问题描述】:

当我分析我的 Postgres SQL 查询时,它给了我一个问题,它总是给出顺序扫描结果而不是索引,我们已经增加了 Postgres 数据库的内存并对其进行清理,但我们在这里没有得到任何积极的结果是我们执行的查询和我们得到的结果 查询

EXPLAIN ANALYZE SELECT *
FROM "Geography".regions where "type" ='City'
Result:
Seq Scan on regions  (cost=0.00..25934.28 rows=84979 width=1099) (actual time=0.010..38.759 rows=85245 loops=1)
  Filter: ((type)::text = 'City'::text)
  Rows Removed by Filter: 8217
Planning Time: 0.103 ms
Execution Time: 42.257 ms

【问题讨论】:

  • 您的查询返回表中几乎所有的行。 Seq Scan 是最快的方法。
  • 与您的问题无关,但是:您应该真正避免使用那些可怕的带引号的标识符。他们的麻烦比他们的价值要多得多。 wiki.postgresql.org/wiki/…

标签: sql postgresql performance indexing sequential


【解决方案1】:

好吧,执行计划显示只有 8% 的行被您的条件过滤掉,这意味着该表中 92% 的行将被返回,因此当大多数行应该被返回时,Seq Scan 会快得多回来 , 这就是为什么优化器从不费心扫描索引的原因

【讨论】:

    猜你喜欢
    • 2021-08-12
    • 1970-01-01
    • 2021-03-19
    • 2022-01-15
    • 2018-04-08
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    相关资源
    最近更新 更多