条件索引
 
                  更新时间 2025-02-14 10:21:45
                 
 
                    最近更新时间: 2025-02-14 10:21:45
                  
 本文为您介绍如何使用条件索引。
 teledb=# create table t_sex(id int,sex text) ;
CREATE TABLE
teledb=# 
teledb=# create index t_sex_sex_idx on t_sex (sex);
CREATE INDEX
teledb=# insert into t_sex select t,'男' from generate_series(1,1000000) as t;
INSERT 0 1000000
teledb=# insert into t_sex select t,'女' from generate_series(1,100) as t; 
INSERT 0 100
teledb=# analyze t_sex ;
ANALYZE
teledb=# explain  select * from t_sex where sex ='女'; 
QUERY PLAN                                    
----------------------------------------------------------------------------------
Remote Fast Query Execution  (cost=0.00..0.00 rows=0 width=0)
Node/s: dn01, dn02
->  Index Scan using t_sex_sex_idx on t_sex  (cost=0.42..9.30 rows=50 width=8)
Index Cond: (sex = '女'::text)
(4 rows)