Unnecessary scan from non-overlapping range predicates

Поиск
Список
Период
Сортировка
От Ajit Awekar
Тема Unnecessary scan from non-overlapping range predicates
Дата
Msg-id CAER375MzJRka+WEo--jKAoqbP8E2rSrj5Ko7sW9pH8xKDzdf4A@mail.gmail.com
обсуждение исходный текст
Ответы Re: Unnecessary scan from non-overlapping range predicates
Список pgsql-hackers
Hi Team,

Please find below an observation regarding query planning  that leads to unnecessary table scan when the WHERE clause contains non-overlapping conditions.


EXPLAIN (costs off)
select * from products where price < 100 AND price > 300;
Seq Scan on products
  Filter: ((price < '100'::numeric) AND (price > '300'::numeric))

Since this condition is false and result will always be empty. Despite this, we still perform unnecessary sequential scan over the table.

Can we  detect such contradictory predicates during planning and optimize them away using a Result node with One-Time Filter: false. This would avoid scanning large tables unnecessarily and improve performance.

Similarly below non-overlapping ranges in query also lead to unnecessary scan without any result.

select * from products where (price between 3 and 100) and (price between 900 and 1000);


Thanks
Ajit

В списке pgsql-hackers по дате отправления: