add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
Help with an interesting Postgres question: Why isn't an Index Only Scan used on a partition accessed via the parent table?.
5000 rows affected
1 rows affected
174721 rows affected
QUERY PLAN
Limit (cost=0.42..201.70 rows=1 width=65) (actual time=26.414..26.414 rows=1 loops=1)
  -> Index Scan Backward using btr_orders_pkey on btr_orders (cost=0.42..11876.08 rows=59 width=65) (actual time=26.412..26.412 rows=1 loops=1)
        Filter: ((NOT temporary) AND (user_id = 40000000) AND ((active_since IS NULL) OR (active_since <= now())) AND ((premium_until > now()) OR (intermediate_premium_until > now())))
        Rows Removed by Filter: 96062
Planning time: 0.150 ms
Execution time: 26.433 ms
QUERY PLAN
Limit (cost=0.29..19.15 rows=1 width=65) (actual time=9.681..9.681 rows=1 loops=1)
  -> Index Scan Backward using quite_simple_idx on btr_orders (cost=0.29..1546.49 rows=82 width=65) (actual time=9.679..9.679 rows=1 loops=1)
        Index Cond: (user_id = 40000000)
        Filter: (((active_since IS NULL) OR (active_since <= now())) AND ((premium_until > now()) OR (intermediate_premium_until > now())))
        Rows Removed by Filter: 23963
Planning time: 0.179 ms
Execution time: 9.700 ms