本页介绍天翼云TeleDB数据库的Index设计规范。 1. TeleDB提供的index类型:Btree,Hash,GiST (Generalized Search Tree),SPGiST (spacepartitioned GiST),GIN (Generalized Inverted Index),BRIN (Block Range Index),目前不建议使用Hash,通常情况下使用Btree。 2. 建议create或drop index时,加CONCURRENTLY参数,达到与写入数据并发的效果。 3. 建议对于频繁update, delete的包含于index定义中的column的table, 用create index CONCURRENTLY,drop index CONCURRENTLY的方式进行维护其对应index。 4. 建议用unique index代替unique constraints,便于后续维护。 5. 建议对where中带多个字段and条件的高频query,参考数据分布情况,建多个字段的联合index。 6. 建议对固定条件的(一般有特定业务含义)且选择时数据占比低的query,建议带 where的Partial Indexes。 plaintext select from test where status1 and col?; 其中status1为固定的条件 create index on test (col) where status1; 7. 建议对经常使用表达式作为查询条件的query,可以使用表达式或函数索引加速 query。 plaintext select from test where exp(xxx); create index on test ( exp(xxx) ); 8. 建议不要建过多index,一般不要超过6个,核心table(产品,订单)可适当增加 index个数。
本页介绍天翼云TeleDB数据库的Index设计规范。 1. TeleDB提供的index类型:Btree,Hash,GiST (Generalized Search Tree),SPGiST (spacepartitioned GiST),GIN (Generalized Inverted Index),BRIN (Block Range Index),目前不建议使用Hash,通常情况下使用Btree。 2. 建议create或drop index时,加CONCURRENTLY参数,达到与写入数据并发的效果。 3. 建议对于频繁update, delete的包含于index定义中的column的table, 用create index CONCURRENTLY,drop index CONCURRENTLY的方式进行维护其对应index。 4. 建议用unique index代替unique constraints,便于后续维护。 5. 建议对where中带多个字段and条件的高频query,参考数据分布情况,建多个字段的联合index。 6. 建议对固定条件的(一般有特定业务含义)且选择时数据占比低的query,建议带 where的Partial Indexes。 select from test where status1 and col?; 其中status1为固定的条件 create index on test (col) where status1; 7. 建议对经常使用表达式作为查询条件的query,可以使用表达式或函数索引加速 query。 select from test where exp(xxx); create index on test ( exp(xxx) ); 8. 建议不要建过多index,一般不要超过6个,核心table(产品,订单)可适当增加 index个数。