PostgreSQL ignoring index on timestamp column

后端 未结 1 1067
死守一世寂寞
死守一世寂寞 2021-01-18 19:12

I have the following table and index created:

CREATE TABLE cdc_auth_user
(
  cdc_auth_user_id bigint NOT NULL DEFAULT nextval(\'cdc_auth_user_id_seq\'::regcl         


        
相关标签:
1条回答
  • 2021-01-18 20:02

    If there are a lot of results, the btree can be slower than just doing a table scan. btree indices are really not designed for this kind of "range-selection" kind of query you're doing here; the entries are placed in a big unsorted file and the index is built against that unsorted group, so every result potentially requires a disk seek after it is found in the btree. Sure, the btree can be easily read in order but the results still need to get pulled from the disk.

    Clustered indices solve this problem by ordering the actual database records according to what's in the btree, so they actually are helpful for ranged queries like this. Consider using a clustered index instead and see how it works.

    0 讨论(0)
提交回复
热议问题