博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在PostgreSQL中,如何模拟Oracle的hint效果
阅读量:5823 次
发布时间:2019-06-18

本文共 2831 字,大约阅读时间需要 9 分钟。

Oracle 的SQL文,可以强制指定各种 hint。

但是在PostgreSQL中是不支持的。

其wiki 是这样说的:

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.

但是可以通过如下的postgresql.conf参数来调节:

# - Planner Method Configuration -#enable_bitmapscan = on#enable_hashagg = onenable_hashjoin = on#enable_indexscan = on#enable_indexonlyscan = on#enable_material = onenable_mergejoin = onenable_nestloop = on#enable_seqscan = on#enable_sort = on#enable_tidscan = on

对于我的查询:

explain select  dept.no_emps,emp.age from dept,emp where emp.name = dept.mgr and dept.dept_name = 'shoe';

如果 enable_hashjoin = on,其他也为on,则执行计划是:

postgres=# explain select dept.no_emps,emp.age from dept,emp where emp.name = dept.mgr and dept.dept_name = 'shoe';                            QUERY PLAN                            ------------------------------------------------------------------ Hash Join  (cost=19.30..45.07 rows=23 width=8)   Hash Cond: ((emp.name)::text = (dept.mgr)::text)   ->  Seq Scan on emp  (cost=0.00..21.30 rows=1130 width=42)   ->  Hash  (cost=19.25..19.25 rows=4 width=42)         ->  Seq Scan on dept  (cost=0.00..19.25 rows=4 width=42)               Filter: ((dept_name)::text = 'shoe'::text)(6 rows)postgres=#

如果 enable_hashjoin=off,其他为on,则执行计划是:

postgres=# explain select dept.no_emps,emp.age from dept,emp where emp.name = dept.mgr and dept.dept_name = 'shoe';                             QUERY PLAN                             -------------------------------------------------------------------- Merge Join  (cost=97.89..103.79 rows=23 width=8)   Merge Cond: ((dept.mgr)::text = (emp.name)::text)   ->  Sort  (cost=19.29..19.30 rows=4 width=42)         Sort Key: dept.mgr         ->  Seq Scan on dept  (cost=0.00..19.25 rows=4 width=42)               Filter: ((dept_name)::text = 'shoe'::text)   ->  Sort  (cost=78.60..81.43 rows=1130 width=42)         Sort Key: emp.name         ->  Seq Scan on emp  (cost=0.00..21.30 rows=1130 width=42)(9 rows)postgres=#

如果enable_hashjoin 为 off,而 enable_mergejoin也为 off,则执行计划为:

postgres=# explain select dept.no_emps,emp.age from dept,emp where emp.name = dept.mgr and dept.dept_name = 'shoe';                            QUERY PLAN                            ------------------------------------------------------------------ Nested Loop  (cost=0.00..108.36 rows=23 width=8)   Join Filter: ((dept.mgr)::text = (emp.name)::text)   ->  Seq Scan on emp  (cost=0.00..21.30 rows=1130 width=42)   ->  Materialize  (cost=0.00..19.27 rows=4 width=42)         ->  Seq Scan on dept  (cost=0.00..19.25 rows=4 width=42)               Filter: ((dept_name)::text = 'shoe'::text)(6 rows)postgres=#

转载地址:http://zvddx.baihongyu.com/

你可能感兴趣的文章
Android图片添加水印图片并把图片保存到文件存储
查看>>
BigDecimal 舍入模式(Rounding mode)介绍
查看>>
开源 免费 java CMS - FreeCMS1.2-标签 infoSign
查看>>
开源 免费 java CMS - FreeCMS1.9 移动APP生成栏目列表数据
查看>>
Squid 反向代理服务器配置
查看>>
Java I/O操作
查看>>
Tomcat性能调优
查看>>
Android自学--一篇文章基本掌握所有的常用View组件
查看>>
灰度图像和彩色图像
查看>>
TCP segmentation offload
查看>>
FreeMarker-Built-ins for strings
查看>>
argparse - 命令行选项与参数解析(转)
查看>>
修改上一篇文章的node.js代码,支持默认页及支持中文
查看>>
Php实现版本比较接口
查看>>
删除设备和驱动器中软件图标
查看>>
第四章 TCP粘包/拆包问题的解决之道---4.1---
查看>>
html语言
查看>>
从源码看集合ArrayList
查看>>
spring-boot支持websocket
查看>>
菜鸟笔记(一) - Java常见的乱码问题
查看>>