Answer the question
In order to leave comments, you need to log in
How to make a proper complex index?
There is a rather large table (200M+) that has three columns of interest:
update_date timestamptz
num_status int
n_flag int
n_flag can be 0..5
num_status 0..20
update_date is when the record was updated.
We need to find the oldest record, where n_flag=0 and num_status>=10.
Query
select * from table1 where n_flag=0 and num_status>=10 order by update_date asc limit 1;
Very long time.
select * from table1 where num_status>=10 order by update_date asc limit 1; - quickly
select * from table1 where n_flag=0 order by update_date asc limit 1; - fast
All three fields have an index.
How to do it right?
Answer the question
In order to leave comments, you need to log in
We need to find the oldest record, where n_flag=0 and num_status>=10.
btree(update_date) where n_flag=0 and num_status>=10
n_flag can be 0..5
num_status 0..20
...
entry where n_flag=0 and num_status>=10.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question