no_index全表扫描

最近更新时间: 2025-10-11 18:10:00

示例:/+no_index(table_name)/强制SQL不走特定索引的方法

postgres=# create table hint_t7(f1 integer,f2 integer) ;
CREATE TABLE
postgres=# insert into hint_t7 select t as f1,t as f2 from generate_series(1,10000) as t; 
INSERT 0 10000
postgres=# create index hint_t7_f1_idx on hint_t7(f1);      
CREATE INDEX
postgres=# vacuum ANALYZE hint_t7;
VACUUM 
postgres=# explain select /*+no_index(hint_t7) */ * from hint_t7 where f1=1 ;
                               QUERY PLAN                                
-------------------------------------------------------------------------
 Remote Subquery Scan on all (dn001)  (cost=0.00..200.00 rows=1 width=8)
   ->  Seq Scan on hint_t7  (cost=0.00..200.00 rows=1 width=8)
         Filter: (f1 = 1)
(3 rows) 
postgres=# explain select  * from hint_t7 where f1=1 ;                       
                                     QUERY PLAN                                     
------------------------------------------------------------------------------------
 Remote Subquery Scan on all (dn001)  (cost=0.16..4.18 rows=1 width=8)
   ->  Index Scan using hint_t7_f1_idx on hint_t7  (cost=0.16..4.18 rows=1 width=8)
         Index Cond: (f1 = 1)
(3 rows) 
postgres=#