对PostgreSQL的 ctid 的初步认识

开始

ctid 和 物理存储有关,指的是 一条记录位于哪个数据块的哪个位移上面。

postgres=# select ctid, * from gaotab;
  ctid   | id  |  name  | deptno | age 
---------+-----+--------+--------+-----
 (0,1)   |   1 | gao    |     10 |  30
 (0,2)   |   2 | jian   |     11 |  35
 (0,3)   |   3 | tom    |     11 |  30
 (0,4)   |   4 | nam04  |     12 |  25
 (0,5)   |   5 | nam05  |     13 |  40
 (0,6)   |   6 | nam06  |     12 |  32
 (0,7)   |   7 | nam07  |     13 |  30
 (0,8)   |   8 | nam08  |     14 |  35
 (0,9)   |   9 | nam09  |     14 |  30
 (0,10)  |  10 | nam10  |     14 |  25
 (0,11)  |  11 | nam11  |     12 |  40
 (0,12)  |  12 | nam12  |     13 |  32
 (0,13)  |  13 | nam13  |     12 |  30
 (0,14)  |  14 | nam14  |     13 |  35
 (0,15)  |  15 | nam15  |     14 |  30
 (0,16)  |  16 | nam16  |     14 |  25
--More--

执行计划

[作者:技术者高健@博客园  mail: luckyjackgao@gmail.com ]

postgres=# explain select * from gaotab where ctid='(0,10)';
                      QUERY PLAN                       
-------------------------------------------------------
 Seq Scan on gaotab  (cost=0.00..2.25 rows=1 width=17)
   Filter: (ctid = '(0,10)'::tid)
(2 rows)

postgres=# 
postgres=# explain select oid from pg_proc where ctid='(0,1)';
                      QUERY PLAN                       
-------------------------------------------------------
 Tid Scan on pg_proc  (cost=0.00..4.01 rows=1 width=4)
   TID Cond: (ctid = '(0,1)'::tid)
(2 rows)

虽然据说涉及到 ctid 的时候, Tid Scan 因为物理上的原因,可能会很快。但是有的时候还是没有 sequential 来的快。

postgres=# 
postgres=# explain select name from gaotab where ctid='(0,1)';
                      QUERY PLAN                      
------------------------------------------------------
 Tid Scan on gaotab  (cost=0.00..4.01 rows=1 width=5)
   TID Cond: (ctid = '(0,1)'::tid)
(2 rows)

postgres=# set session enable_seqscan=true;
SET
postgres=# explain select name from gaotab where ctid='(0,1)';
                      QUERY PLAN                      
------------------------------------------------------
 Seq Scan on gaotab  (cost=0.00..2.25 rows=1 width=5)
   Filter: (ctid = '(0,1)'::tid)
(2 rows)

postgres=# 

 

[作者:技术者高健@博客园  mail: luckyjackgao@gmail.com ] 

结束

转载于:https://www.cnblogs.com/gaojian/archive/2012/11/07/2758658.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值