博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Parameterized Path 的例子
阅读量:7193 次
发布时间:2019-06-29

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

Improve the planner's ability to use nested loops with inner index scans (Tom Lane)The new "parameterized path" mechanism allows inner index scans to use values from relations that are more than one join level up from the scan. This can greatly improve performance in situations where semantic restrictions (such as outer joins) limit the allowed join orderings.

数据准备:

postgres=# create table tst01(id integer);CREATE TABLEpostgres=# postgres=# insert into tst01 values(generate_series(1,100000));INSERT 0 100000postgres=# postgres=# create index idx_tst01_id on tst01(id);CREATE INDEXpostgres=#

运行:

postgres=# prepare s(int) as select * from tst01 t where id < $1;PREPAREpostgres=# explain execute s(2);                                   QUERY PLAN                                    --------------------------------------------------------------------------------- Index Only Scan using idx_tst01_id on tst01 t  (cost=0.00..8.38 rows=1 width=4)   Index Cond: (id < 2)(2 rows)postgres=# explain execute s(10000);                                      QUERY PLAN                                       --------------------------------------------------------------------------------------- Index Only Scan using idx_tst01_id on tst01 t  (cost=0.00..337.64 rows=10130 width=4)   Index Cond: (id < 10000)(2 rows)postgres=# explain execute s(1000000);                          QUERY PLAN                           --------------------------------------------------------------- Seq Scan on tst01 t  (cost=0.00..1693.00 rows=100000 width=4)   Filter: (id < 1000000)(2 rows)postgres=# explain execute s(100000);                          QUERY PLAN                           --------------------------------------------------------------- Seq Scan on tst01 t  (cost=0.00..1693.00 rows=100000 width=4)   Filter: (id < 100000)(2 rows)postgres=#

这是一个小例子,而且还是一个有些特殊的例子。

对比一下在PostgreSQL9.1.0中的表现:

postgres=# create table tst01(id integer);CREATE TABLEpostgres=# insert into tst01 values(generate_series(1,100000));INSERT 0 100000postgres=# create index idx_tst01_id on tst01(id);CREATE INDEXpostgres=# prepare s(int) as select * from tst01 t where id < $1;PREPAREpostgres=# explain execute s(2);                                   QUERY PLAN                                    --------------------------------------------------------------------------------- Bitmap Heap Scan on tst01 t  (cost=626.59..1486.25 rows=33333 width=4)   Recheck Cond: (id < $1)   ->  Bitmap Index Scan on idx_tst01_id  (cost=0.00..618.26 rows=33333 width=0)         Index Cond: (id < $1)(4 rows)postgres=# explain execute s(10000);                                   QUERY PLAN                                    --------------------------------------------------------------------------------- Bitmap Heap Scan on tst01 t  (cost=626.59..1486.25 rows=33333 width=4)   Recheck Cond: (id < $1)   ->  Bitmap Index Scan on idx_tst01_id  (cost=0.00..618.26 rows=33333 width=0)         Index Cond: (id < $1)(4 rows)postgres=#

可以看到,在9.1里,是不区分状况,执行计划固定。

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

你可能感兴趣的文章
Gradle Build速度加快终极方法(android studio)
查看>>
CentOS6.8安装360 pika
查看>>
scu oj 4442 Party(2015年四川省acm程序设计竞赛)
查看>>
hdu1133 Buy the Ticket (卡兰特数应用+java大数)
查看>>
Servlet -- 中文乱码解决
查看>>
【案例实战】餐饮企业分店財务数据分析系统解决方式:系统功能开发
查看>>
POJ 3154 Graveyard【多解,数论,贪心】
查看>>
C++ Primer 学习笔记与思考_7 void和void*指针的使用方法
查看>>
&lt;!DOCTYPE&gt;奇葩的问题
查看>>
使用Gitolite搭建Gitserver
查看>>
【Maven】Snapshot和Release版本的区别
查看>>
FZU1920 Left Mouse Button(dfs)
查看>>
迭代器模式
查看>>
poj 1979 dfs
查看>>
(转)论python工厂函数与内建函数
查看>>
HDU1212 Big Number 【同余定理】
查看>>
HDU1069(还是dp基础)
查看>>
用RotateDrawable实现网易云音乐唱片机效果
查看>>
Mac OS X各版本号的历史费用和升级关系
查看>>
Android -- AsyncTask源码解析
查看>>