text: ## PostgreSQL tid range scan - 行号范围扫描   
                                                      
  ### 作者                                                    
  digoal                                                    
                                                      
  ### 日期                                                    
  2019-09-01                                                  
                                                      
  ### 标签                                                    
  PostgreSQL , tid scan , tid range scan    
                                                      
  ----                                                    
                                                      
  ## 背景     
  这个功能用于返回指定行号范围的内容，例如，如下SQL返回heap page block_id 0到99号数据块的内容。  
    
  ```  
  select ctid,* from t1 where ctid >= '(0,0)' and ctid <'(100,0)';  
  ```  
    
  不需要进行全表扫描，只会扫描对应的数据块。  
    
  https://www.postgresql.org/message-id/flat/CAMyN-kB-nFTkF=VA_JPwFNo08S0d-Yk0F741S2B7LDmYAi8eyA@mail.gmail.com  
    
  在此之前，会执行全表扫描    
    
  ```  
  postgres=# explain select count(*) from a where ctid >= '(0,0)' and ctid <'(100,0)';e  
                                QUERY PLAN                                
  ----------------------------------------------------------------------  
   Aggregate  (cost=41676.39..41676.40 rows=1 width=8)  
     ->  Seq Scan on a  (cost=0.00..41667.01 rows=3749 width=0)  
           Filter: ((ctid >= '(0,0)'::tid) AND (ctid < '(100,0)'::tid))  
  (3 rows)  
  ```  
    
  ## 参考  
  https://www.postgresql.org/message-id/flat/CAMyN-kB-nFTkF=VA_JPwFNo08S0d-Yk0F741S2B7LDmYAi8eyA@mail.gmail.com  
      
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
  #### [PostgreSQL 许愿链接](https://github.com/digoal/blog/issues/76 "269ac3d1c492e938c0191101c7238216")
  您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议，奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等，奖品丰富，快来许愿。[开不开森](https://github.com/digoal/blog/issues/76 "269ac3d1c492e938c0191101c7238216").  
    
    
  #### [9.9元购买3个月阿里云RDS PostgreSQL实例](https://www.aliyun.com/database/postgresqlactivity "57258f76c37864c6e6d23383d05714ea")
    
    
  #### [PostgreSQL 解决方案集合](https://yq.aliyun.com/topic/118 "40cff096e9ed7122c512b35d8561d9c8")
    
    
  #### [德哥 / digoal's github - 公益是一辈子的事.](https://github.com/digoal/blog/blob/master/README.md "22709685feb7cab07d30f30387f0a9ae")
    
    
  ![digoal's wechat](../pic/digoal_weixin.jpg "f7ad92eeba24523fd47a6e1a0e691b59")
    
  