--查詢索引
select * from pg_indexes where tablename='tab1';
--創建索引(查詢用到哪幾列,就對哪幾個字段創建索引)
CREATE INDEX index_moni_gk_city_day ON moni_gk_city_day USING btree (datatime, citycode);
CREATE INDEX index_moni_gk_city_hour ON moni_gk_city_hour USING btree (datatime, citycode);
CREATE INDEX index_moni_gk_site_day ON moni_gk_site_day USING btree (datatime, stationcode);
CREATE INDEX index_moni_gk_site_hour ON moni_gk_site_hour USING btree (datatime, stationcode);
--刪除索引
drop index tab1_bill_code_index ;
注意:
雖然索引的目的在於提高數據庫的性能,但這里有幾個情況需要避免使用索引。
使用索引時,需要考慮下列准則:
- 索引不應該使用在較小的表上。
- 索引不應該使用在有頻繁的大批量的更新或插入操作的表上。
- 索引不應該使用在含有大量的 NULL 值的列上。
- 索引不應該使用在頻繁操作的列上。