zoukankan      html  css  js  c++  java
  • 对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 ] 

    结束

  • 相关阅读:
    516. Longest Palindromic Subsequence
    31. Next Permutation
    572. Subtree of Another Tree
    vue中无法监听到子组件的事件的问题
    vue中注意watch的执行顺序
    vue中路由懒加载浅析
    关于typescript 报错问题
    深入理解Typescript中文版
    vue中的高阶组件
    vue中的mixins
  • 原文地址:https://www.cnblogs.com/gaojian/p/2758658.html
Copyright © 2011-2022 走看看