sql - 为什么我的 pg_hint_plan 前导提示没有被使用?

标签 sql database postgresql hint yugabytedb

我使用 Leading(b a) 定义了连接顺序,但 PostgreSQL 或 YugabyteDB 等兼容数据库仍然从 a 连接到 b:

yugabyte=# explain (costs off, timing off)
          /*+ Leading( b a ) */ 
          select * from table_a a join table_b b using(id);

                    QUERY PLAN
--------------------------------------------------
 Nested Loop
   ->  Seq Scan on table_a a
   ->  Index Scan using table_b_pkey on table_b b
         Index Cond: (id = a.id)

最佳答案

前导提示有两种语法。只需按照查询规划器应考虑的顺序列出表,例如 Leading ( b a ),将交换内表和外表的选择权留给优化器。另一个定义每个连接对,并带有额外的括号,如 Leading( (b a) ) ,其中左/右项是(外部 内部)。对于第三个表,它将是 Leading( ( (b a) c ) )Leading( ( c (b a) ) )

通常,修复执行计划需要第二种语法,加上每个连接的连接方法提示以及每个表的访问方法提示。

示例:https://dev.to/yugabyte/predictable-plans-with-pghintplan-full-hinting-1do3

关于sql - 为什么我的 pg_hint_plan 前导提示没有被使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72557184/

相关文章:

php - mysql 内连接查询优化

postgresql - Postgres 从 JSON 转换为 UUID

postgresql - 解决 Postgres.app 中的 "Binaries not found"错误

mongodb - 没有打开的连接时 mongod run with nohup 退出

mysql - MySQL 中的 `UPDATE ... SET ... LIMIT`

node.js - 由于使用sequelize.js 的 UUID 外键而尝试将行插入表时出错

sql - 使用 REST API 的 Linq to SQL?

mysql - 如何更改对 phpmyadmin SQL/SQL 服务器的语法 SQL 访问

python - Django 按最频繁值排序

php - 这个 PHP 类是否针对 mysql 数据库访问进行了优化?