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.

http://www.postgresql.org/docs/current/static/release-9-2.html

数据准备:

postgres=# create table tst01(id integer);
CREATE TABLE
postgres=# postgres=# insert into tst01 values(generate_series(,));
INSERT
postgres=# postgres=# create index idx_tst01_id on tst01(id);
CREATE INDEX
postgres=#

运行:

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

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

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

postgres=# create table tst01(id integer);
CREATE TABLE
postgres=# insert into tst01 values(generate_series(1,100000));
INSERT 0 100000
postgres=# create index idx_tst01_id on tst01(id);
CREATE INDEX
postgres=# prepare s(int) as select * from tst01 t where id < $1;
PREPARE
postgres=# 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里,是不区分状况,执行计划固定。

Parameterized Path 的例子的更多相关文章

  1. 像画笔一样慢慢画出Path的三种方法(补充第四种)

    今天大家在群里大家非常热闹的讨论像画笔一样慢慢画出Path的这种效果该如何实现. 北京-LGL 博客号@ligl007发起了这个话题.然后各路高手踊跃发表意见.最后雷叔 上海-雷蒙 博客号@雷蒙之星 ...

  2. Raphael path 拖动实现

    让 Raphael 的 Path 动起来 Raphaël 是一个很实用的线上矢量图操作 Javascript 库.使用简单,一个值得一提的卖点是通过抽象出共同的接口屏蔽了 SVG 和 VML 之间的差 ...

  3. d3.js path路径

    转自:http://www.d3js.cn/?p=68 svg的path标签被称为”可以组成任何形状的形状” SVG Path可以绘制任何形状的图形,包括矩形,圆形,椭圆,折线,多边形,直线,曲线等. ...

  4. 学ant(2)——path

    1.path是ant内置的一种datatype,作用是声明路径之类的东西,在官方的manual中也叫做Path-like Structures,一般是这样声明的 <pathelement loc ...

  5. PostgreSQL的prepare 和 execute 动作背后

    我给PostgreSQL的源代码加入了调试信息以后,会有如下表现: 我执行Prepare: postgres=# prepare s(; PREPARE postgres=# 背后的反应: ** In ...

  6. python对文件的操作

    一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法. 1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 2.返回指定目录下的所有文件 ...

  7. requirejs:模块加载(require)及定义(define)时的路径小结

    原文地址:http://www.tuicool.com/articles/7JBnmy 接触过requirejs的童鞋可能都知道,无论是通过define来定义模块,还是通过require来加载模块,模 ...

  8. docker好文收藏

    深入浅出Docker(一):Docker核心技术预览 2. 核心技术预览 Docker核心是一个操作系统级虚拟化方法, 理解起来可能并不像VM那样直观.我们从虚拟化方法的四个方面:隔离性.可配额/可度 ...

  9. requirejs:让人迷惑的路径解析

    接触过requirejs的童鞋可能都知道,无论是通过define来定义模块,还是通过require来加载模块,模块依赖声明都是很重要的一步.而其中涉及到的模块路径解析,对于新手来说,有的时候会让人觉得 ...

随机推荐

  1. OS.ENVIRON()详解

    OS.ENVIRON()详解

  2. ↗☻【HTML5秘籍 #BOOK#】第1章 HTML5简介

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  3. Weblogic11g安装

    我们在64位的服务器上为提高性能要安装64位的weblogic.经常在网上看到有人问,weblogic有64位的么?weblogic需要破解么? weblogic有专门的64位版本,这里安装的是web ...

  4. PostgreSql与sqlserver对比杂记

    PostgreSql与MSSqlServer区别 增删查改没有语法一样. 排序Group Having 聚集函数使用一样 联结查询 ON 子句是最常见的连接条件的类型:它接收一个和 WHERE 子句相 ...

  5. Java多线程同步——生产者消费者问题

    这是马士兵老师的Java视频教程里的一个生产者消费者问题的模型 public class ProduceConsumer{ public static void main(String[] args) ...

  6. visual studio 2012 update3

    http://www.microsoft.com/zh-cn/download/confirmation.aspx?id=39305

  7. WEB开发总结(持续更新。。。)

    近期开始搞搞web的东西,觉得有必要把遇到的问题总结一下,就在这里当做个笔记本吧. 1.用maven建立的web工程,在运行的时候,右键找不到“Run on server”菜单: 可以在命令提示行中, ...

  8. Solution for Latex error: "Cannot determine size of graphic"

    I'm trying to include graphics in my Latex-file, which I compiled with latex+dvipdf on OS X. Latex h ...

  9. OpenCV中的常用函数

    1.cvLoadImage:将图像文件加载至内存: 2.cvNamedWindow:在屏幕上创建一个窗口: 3.cvShowImage:在一个已创建好的窗口中显示图像: 4.cvWaitKey:使程序 ...

  10. HDU-4605 Magic Ball Game 树状数组+离散+dfs

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4605 题意:给一颗树,每个节点有个权值w[u],每个节点只有两个儿子或者没有儿子,从根节点放下一个小球 ...