indexing - PostgreSQL manualy change query execution plan to force using sort and sequential access instead of full scan -
i have simple query this:
select * t1 f1 > 42 , f2 = 'foo' , f3 = 'bar' order f4 desc limit 10 offset 100; i have index field f4 (for other queries). condition "f1 > 42 , f2 = 'foo' , f3 = 'bar'" not representative , corresponds 70% of records in table t1. it's 2 000 000 records in table , growing every day. query plan explanation query shows using of seq scan entire table , performing ordering , limitation.
is possible postgres perform query way:
- iterate through reverse ordered rows using index on field f4.
- for each row comparison condition f1 > 42 , f2 = 'foo' , f3 = 'bar' , take if corresponded.
- if result set size greater limit stop iterate.
here configurations query planner. can manipulate them change query plan (for case can simple set enable_seqscan = off; query).
but before change planner configuration - check if statistics on table correct , collect them again if needed.
Comments
Post a Comment