PostgreSQL:指定要使用的索引

标签 postgresql

<分区>

如果我在 postgres 的同一列上有几个索引,我可以通过什么方式指定在给定查询中使用哪个索引?主要用于测试,而不是生产目的。 换句话说,我需要使用 MySQL 替代 USE INDEX 甚至 FORCE INDEX。 不,这不是重复项,因为那是关于强制 postgres 使用索引扫描而不是普通扫描,这不是主题。

最佳答案

恐怕 Postgres 中没有这样的东西:

参见 http://wiki.postgresql.org/wiki/OptimizerHintsDiscussion

Many people over the years have requested that the PostgreSQL project implement "optimizer hints" or "query hints" as they are implemented in other RDBMSes such as Oracle and MySQL. The official current stance from the community is this:

We are not interested in implementing hints in the exact ways they are commonly implemented on other databases. Proposals based on "because they've got them" will not be welcomed. If you have an idea that avoids the problems that have been observed with other hint systems, that could lead to valuable discussion.

Wiki 列出了一些替代提示的方法 here ,但是这些建议都不等同于您正在寻找的内容。

但是,您可以按照 14.3. Controlling the Planner with Explicit JOIN Clauses 中所述强制加入顺序,具体取决于 from_collapse_limitjoin_collapse_limit 的值(您可以即时设置/重置它们)。这会间接影响使用哪些索引,但同样没有明确选择索引。

关于PostgreSQL:指定要使用的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25245709/

相关文章:

java - 执行 postgresql 模式脚本 Spring DatabasePopulator 提示 Unterminated dollar quote started at position

json - 如何使用 jsonb_path_query 以文本形式获取 jsonb 对象的值

postgresql - 重启aws ec2实例后如何重启postgres数据库?

hibernate - 在 hibernate createSQLQuery 中转义冒号

sql - 选择 A 列字符串中的任何单词与 B 列字符串中的任何单词匹配的位置

sql - 排序后只获取最后一行

SQL - 如果数组包含特定项目则过滤行

sql - 如何使用 SQL 查找用户 session 事件之间的时间

postgresql - 查找 Postgres 过程的用法

postgresql - 根据监控,我们是否需要为使用 60 IOPS 的 RDS 实例预配置 IOPS?