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?.
CREATE TABLE
INSERT 0 16
INSERT 0 128000
VACUUM
CREATE FUNCTION
QUERY PLAN
Sort (cost=12045.82..12046.82 rows=400 width=28) (actual rows=64008 loops=1)
  Sort Key: (min(tmp.date))
  Sort Method: external merge Disk: 2640kB
  -> HashAggregate (cost=12024.53..12028.53 rows=400 width=28) (actual rows=64008 loops=1)
        Group Key: tmp.id_type, count((((lag(tmp.id_type) OVER (?) <> tmp.id_type)) OR NULL::boolean)) OVER (?)
        Batches: 5 Memory Usage: 4145kB Disk Usage: 3680kB
        -> WindowAgg (cost=0.29..9464.21 rows=128016 width=20) (actual rows=128016 loops=1)
              -> WindowAgg (cost=0.29..6263.81 rows=128016 width=13) (actual rows=128016 loops=1)
                    -> Index Scan using tmp_date_key on tmp (cost=0.29..4023.53 rows=128016 width=12) (actual rows=128016 loops=1)
Planning Time: 0.536 ms
Execution Time: 540.065 ms
EXPLAIN
QUERY PLAN
Sort (cost=36213.06..36214.06 rows=400 width=28) (actual rows=64008 loops=1)
  Sort Key: (min(tmp.date))
  Sort Method: external merge Disk: 2640kB
  -> HashAggregate (cost=36191.77..36195.77 rows=400 width=28) (actual rows=64008 loops=1)
        Group Key: tmp.id_type, (row_number() OVER (?) - (row_number() OVER (?)))
        Batches: 5 Memory Usage: 4401kB Disk Usage: 3664kB
        -> WindowAgg (cost=31071.13..33631.45 rows=128016 width=20) (actual rows=128016 loops=1)
              -> Sort (cost=31071.13..31391.17 rows=128016 width=20) (actual rows=128016 loops=1)
                    Sort Key: tmp.date
                    Sort Method: external merge Disk: 4264kB
                    -> WindowAgg (cost=15022.73..17583.05 rows=128016 width=20) (actual rows=128016 loops=1)
                          -> Sort (cost=15022.73..15342.77 rows=128016 width=12) (actual rows=128016 loops=1)
                                Sort Key: tmp.id_type, tmp.date
                                Sort Method: external merge Disk: 2768kB
                                -> Seq Scan on tmp (cost=0.00..1972.16 rows=128016 width=12) (actual rows=128016 loops=1)
Planning Time: 0.207 ms
Execution Time: 441.764 ms
EXPLAIN
QUERY PLAN
Function Scan on f_tmp_groups (cost=0.25..10.25 rows=1000 width=20) (actual rows=64008 loops=1)
Planning Time: 0.039 ms
Execution Time: 123.466 ms
EXPLAIN