full全表扫描

最近更新时间: 2025-02-18 16:02:00

示例:/*+full(table_name) */强制选择全表扫描

创建表并插入数据,对比使用hint全表扫描前后执行计划差异。

  • 复制
    复制成功
postgres=# create table hint_t1(f1 integer,f2 integer) ;
CREATE TABLE
postgres=# create index hint_t1_f1_idx on hint_t1(f1);
CREATE INDEX
postgres=# insert into hint_t1 select t as f1,t as f2 from generate_series(1,10000) as t;
INSERT 0 10000
postgres=# explain select /*+SeqScan(hint_t1) */ * from hint_t1 where f1=1;   
                               QUERY PLAN                                
-------------------------------------------------------------------------
 Remote Subquery Scan on all (dn001)  (cost=0.00..205.00 rows=1 width=8)
   ->  Seq Scan on hint_t1  (cost=0.00..205.00 rows=1 width=8)
         Filter: (f1 = 1)
(4 rows)
postgres=#  explain select  * from hint_t1 where f1=1;                       
                                     QUERY PLAN                                     
------------------------------------------------------------------------------------
 Remote Subquery Scan on all (dn001)  (cost=0.16..4.18 rows=1 width=8)
   ->  Index Scan using hint_t1_f1_idx on hint_t1  (cost=0.16..4.18 rows=1 width=8)
         Index Cond: (f1 = 1)
(3 rows) 
postgres=# explain select /*+full(hint_t1) */ * from hint_t1 where f1=1; 
                               QUERY PLAN                                
-------------------------------------------------------------------------
 Remote Subquery Scan on all (dn001)  (cost=0.00..205.00 rows=1 width=8)
   ->  Seq Scan on hint_t1  (cost=0.00..205.00 rows=1 width=8)
         Filter: (f1 = 1)
(3 rows)