Unworkable plan above certain row count

2022-04-27 Thread André Hänsel
I noticed an issue in a simple query with WHERE NOT IN (SELECT ...). I am aware that anti-joins with NOT IN are currently not optimized and should be rewritten as WHERE NOT EXISTS (SELECT ...), so if this is irrelevant please just ignore it. Here is a setup that works: CREATE TABLE a ( a_

Why is there a Sort after an Index Only Scan?

2022-05-04 Thread André Hänsel
Quick(?) question... why is there a Sort node after an Index Only Scan? Shouldn't the index already spit out sorted tuples? CREATE INDEX ON orders_test(shipping_date, order_id); EXPLAIN ANALYZE SELECT FROM orders_test WHERE TRUE AND shipping_date >= '2022-05-01' AND shipping_date <= '2022-05-01'

RE: Why is there a Sort after an Index Only Scan?

2022-05-04 Thread André Hänsel
> They are sorted by order_id only within sets of the same shipping_date, which > is not good enough. Ah yes, that totally makes sense for the general case. > so maybe you can just tweak that application to test if the start and end > dates are the same and use equality when they are. I defi