index 設計
更新時間 2025-02-14 10:22:11
最近更新時間: 2025-02-14 10:22:11
分享文章
本頁介紹天翼云TeleDB數據庫的Index設計規范。
TeleDB提供的index類型:B-tree,Hash,GiST (Generalized Search Tree),SP-GiST (space-partitioned GiST),GIN (Generalized Inverted Index),BRIN (Block Range Index),目前不建議使用Hash,通常情況下使用B-tree。
建議create或drop index時,加CONCURRENTLY參數,達到與寫入數據并發的效果。
建議對于頻繁update, delete的包含于index定義中的column的table, 用create index CONCURRENTLY,drop index CONCURRENTLY的方式進行維護其對應index。
建議用unique index代替unique constraints,便于后續維護。
建議對where中帶多個字段and條件的高頻query,參考數據分布情況,建多個字段的聯合index。
建議對固定條件的(一般有特定業務含義)且選擇時數據占比低的query,建議帶 where的Partial Indexes。
select * from test where status=1 and col=?; -- 其中status=1為固定的條件 create index on test (col) where status=1;建議對經常使用表達式作為查詢條件的query,可以使用表達式或函數索引加速 query。
select * from test where exp(xxx); create index on test ( exp(xxx) );建議不要建過多index,一般不要超過6個,核心table(產品,訂單)可適當增加 index個數。