条件索引 本文为您介绍如何使用条件索引。 plaintext teledb create table tsex(id int,sex text) ; CREATE TABLE teledb teledb create index tsexsexidx on tsex (sex); CREATE INDEX teledb insert into tsex select t,'男' from generateseries(1,1000000) as t; INSERT 0 1000000 teledb insert into tsex select t,'女' from generateseries(1,100) as t; INSERT 0 100 teledb analyze tsex ; ANALYZE teledb explain select from tsex where sex '女'; QUERY PLAN Remote Fast Query Execution (cost0.00..0.00 rows0 width0) Node/s: dn01, dn02 > Index Scan using tsexsexidx on tsex (cost0.42..9.30 rows50 width8) Index Cond: (sex '女'::text) (4 rows) 索引对于条件在性别为男的情况下无效。 plaintext teledb explain select from tsex where sex '男'; QUERY PLAN Remote Fast Query Execution (cost0.00..0.00 rows0 width0) Node/s: dn01, dn02 > Seq Scan on tsex (cost0.00..9966.58 rows500556 width8) Filter: (sex '男'::text) (4 rows) 连接DN 节点查看索引占用空间大,而且度数也高。 plaintext teledb di+ tsexsexidx List of relations Schema Name Type Owner Table Size Allocated Size Description +++++++ public tsexsexidx index teledb tsex 14 MB 14 MB (1 row) teledb q [teledb@localhost bin]$ ./telesql p 11111 U teledb d teledb Password for user teledb: telesql (TeleDB V6) Type "help" for help. teledb