Parameterized Path 的例子
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 的例子的更多相关文章
- 像画笔一样慢慢画出Path的三种方法(补充第四种)
今天大家在群里大家非常热闹的讨论像画笔一样慢慢画出Path的这种效果该如何实现. 北京-LGL 博客号@ligl007发起了这个话题.然后各路高手踊跃发表意见.最后雷叔 上海-雷蒙 博客号@雷蒙之星 ...
- Raphael path 拖动实现
让 Raphael 的 Path 动起来 Raphaël 是一个很实用的线上矢量图操作 Javascript 库.使用简单,一个值得一提的卖点是通过抽象出共同的接口屏蔽了 SVG 和 VML 之间的差 ...
- d3.js path路径
转自:http://www.d3js.cn/?p=68 svg的path标签被称为”可以组成任何形状的形状” SVG Path可以绘制任何形状的图形,包括矩形,圆形,椭圆,折线,多边形,直线,曲线等. ...
- 学ant(2)——path
1.path是ant内置的一种datatype,作用是声明路径之类的东西,在官方的manual中也叫做Path-like Structures,一般是这样声明的 <pathelement loc ...
- PostgreSQL的prepare 和 execute 动作背后
我给PostgreSQL的源代码加入了调试信息以后,会有如下表现: 我执行Prepare: postgres=# prepare s(; PREPARE postgres=# 背后的反应: ** In ...
- python对文件的操作
一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法. 1.得到当前工作目录,即当前Python脚本工作的目录路径: os.getcwd() 2.返回指定目录下的所有文件 ...
- requirejs:模块加载(require)及定义(define)时的路径小结
原文地址:http://www.tuicool.com/articles/7JBnmy 接触过requirejs的童鞋可能都知道,无论是通过define来定义模块,还是通过require来加载模块,模 ...
- docker好文收藏
深入浅出Docker(一):Docker核心技术预览 2. 核心技术预览 Docker核心是一个操作系统级虚拟化方法, 理解起来可能并不像VM那样直观.我们从虚拟化方法的四个方面:隔离性.可配额/可度 ...
- requirejs:让人迷惑的路径解析
接触过requirejs的童鞋可能都知道,无论是通过define来定义模块,还是通过require来加载模块,模块依赖声明都是很重要的一步.而其中涉及到的模块路径解析,对于新手来说,有的时候会让人觉得 ...
随机推荐
- Maven、gradle、Ant、Eclipse IDE
Maven.gradle.Ant.Eclipse IDE之间的关系 http://wenku.baidu.com/view/d33208810912a21615792910.html?from=sea ...
- UVa 10539 (筛素数、二分查找) Almost Prime Numbers
题意: 求正整数L和U之间有多少个整数x满足形如x=pk 这种形式,其中p为素数,k>1 分析: 首先筛出1e6内的素数,枚举每个素数求出1e12内所有满足条件的数,然后排序. 对于L和U,二分 ...
- UVa 1395 (最小生成树) Slim Span
题意: 规定一棵生成树的苗条度为:最大权值与最小权值之差.给出一个n个顶点m条边的图,求苗条度最小的生成树. 分析: 按照边的权值排序,枚举边集的连续区间[L, R]的左边界L,如果这些区间刚好满足一 ...
- Java [leetcode 34]Search for a Range
题目描述: Given a sorted array of integers, find the starting and ending position of a given target valu ...
- MYSQL学习心得
我的MYSQL学习心得(一) 简单语法 我的MYSQL学习心得(二) 数据类型宽度 我的MYSQL学习心得(三) 查看字段长度 我的MYSQL学习心得(四) 数据类型 我的MYSQL学习心得(五) 运 ...
- 实现sqrt()函数
求一个正数N的开方, 并且可以指定精度, 要求不能用库函数sqrt 方法一:如下所示,先求sqrt(N)的整数部分,再求小数点后1位,2位 ... ... 方法二:牛顿迭代法,根据公式 Ai+1 = ...
- LINQ之路系列
Life a Poem http://www.cnblogs.com/lifepoem/archive/2011/11/22/2258830.html
- Linux Add a Swap File
http://www.cyberciti.biz/faq/linux-add-a-swap-file-howto/ Procedure To Add a Swap File Under Linux Y ...
- C# 检测机器是否有声卡设备
有时候我们的程序需要进行音频的播放,则我们首先需要判断机器是否有声卡能够进行音频的播放.在网上找了一下没有发现太多关于如何检机器是否有声卡的例子.我在看了一些文档后自己写了一个小测试程序,如果机器装有 ...
- unity3d自己写角色移动脚本
废话没有,直接上代码: using UnityEngine; using System.Collections; public class SuperWalk : MonoBehaviour { pu ...