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?.
version
PostgreSQL 12.8 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 8.4.1 20200928 (Red Hat 8.4.1-1), 64-bit
1 rows affected
n m
3 5
1000 rows affected
xi
1
2
3
3
2
1
1
2
3
3
2
1
1
2
3
3
2
1
1
2
3
3
2
1
1
2
3
3
2
1
n m i i i xi
3 5 0 0 0 4
3 5 1 0 0 3
3 5 2 0 0 2
3 5 3 0 0 1
3 5 0 1 0 0
3 5 1 1 0 1
3 5 2 1 0 2
3 5 3 1 0 3
3 5 0 2 0 4
3 5 1 2 0 3
3 5 2 2 0 2
3 5 3 2 0 1
3 5 0 0 1 4
3 5 1 0 1 3
3 5 2 0 1 2
3 5 3 0 1 1
3 5 0 1 1 0
3 5 1 1 1 1
3 5 2 1 1 2
3 5 3 1 1 3
3 5 0 2 1 4
3 5 1 2 1 3
3 5 2 2 1 2
3 5 3 2 1 1
3 5 0 0 2 4
3 5 1 0 2 3
3 5 2 0 2 2
3 5 3 0 2 1
3 5 0 1 2 0
3 5 1 1 2 1
3 5 2 1 2 2
3 5 3 1 2 3
3 5 0 2 2 4
3 5 1 2 2 3
3 5 2 2 2 2
3 5 3 2 2 1
3 5 0 0 3 4
3 5 1 0 3 3
3 5 2 0 3 2
3 5 3 0 3 1
3 5 0 1 3 0
3 5 1 1 3 1
3 5 2 1 3 2
3 5 3 1 3 3
3 5 0 2 3 4
3 5 1 2 3 3
3 5 2 2 3 2
3 5 3 2 3 1
3 5 0 0 4 4
3 5 1 0 4 3
3 5 2 0 4 2
3 5 3 0 4 1
3 5 0 1 4 0
3 5 1 1 4 1
3 5 2 1 4 2
3 5 3 1 4 3
3 5 0 2 4 4
3 5 1 2 4 3
3 5 2 2 4 2
3 5 3 2 4 1
3 5 0 0 5 4
3 5 1 0 5 3
3 5 2 0 5 2
3 5 3 0 5 1
3 5 0 1 5 0
3 5 1 1 5 1
3 5 2 1 5 2
3 5 3 1 5 3
3 5 0 2 5 4
3 5 1 2 5 3
3 5 2 2 5 2
3 5 3 2 5 1
QUERY PLAN
Sort (cost=473756301482.78..477226107732.78 rows=1387922500000 width=16) (actual time=0.093..0.095 rows=30 loops=1)
  Output: (CASE WHEN (g2.i = 1) THEN gn.i ELSE ((p.n + 1) - gn.i) END), gm.i, g2.i, gn.i
  Sort Key: gm.i, g2.i, gn.i
  Sort Method: quicksort Memory: 26kB
  Buffers: shared hit=16
  -> Nested Loop (cost=15.43..27803995845.52 rows=1387922500000 width=16) (actual time=0.056..0.078 rows=30 loops=1)
        Output: CASE WHEN (g2.i = 1) THEN gn.i ELSE ((p.n + 1) - gn.i) END, gm.i, g2.i, gn.i
        Buffers: shared hit=16
        -> Nested Loop (cost=0.56..45545807.90 rows=1632850000 width=12) (actual time=0.047..0.058 rows=15 loops=1)
              Output: p.n, gn.i, gm.i
              Buffers: shared hit=13
              -> Nested Loop (cost=0.28..53552.90 rows=1921000 width=12) (actual time=0.039..0.041 rows=3 loops=1)
                    Output: p.n, p.m, gn.i
                    Buffers: shared hit=4
                    -> Seq Scan on public.parameters p (cost=0.00..32.60 rows=2260 width=8) (actual time=0.011..0.011 rows=1 loops=1)
                          Output: p.n, p.m
                          Buffers: shared hit=1
                    -> Index Only Scan using numbers_pkey on public.numbers gn (cost=0.28..15.18 rows=850 width=4) (actual time=0.023..0.024 rows=3 loops=1)
                          Output: gn.i
                          Index Cond: (gn.i <= p.n)
                          Heap Fetches: 3
                          Buffers: shared hit=3
              -> Index Only Scan using numbers_pkey on public.numbers gm (cost=0.28..15.18 rows=850 width=4) (actual time=0.003..0.004 rows=5 loops=3)
                    Output: gm.i
                    Index Cond: (gm.i <= p.m)
                    Heap Fetches: 15
                    Buffers: shared hit=9
        -> Materialize (cost=14.87..39.74 rows=850 width=4) (actual time=0.001..0.001 rows=2 loops=15)
              Output: g2.i
              Buffers: shared hit=3
              -> Bitmap Heap Scan on public.numbers g2 (cost=14.87..35.49 rows=850 width=4) (actual time=0.006..0.006 rows=2 loops=1)
                    Output: g2.i
                    Recheck Cond: (g2.i <= 2)
                    Heap Blocks: exact=1
                    Buffers: shared hit=3
                    -> Bitmap Index Scan on numbers_pkey (cost=0.00..14.65 rows=850 width=0) (actual time=0.003..0.003 rows=2 loops=1)
                          Index Cond: (g2.i <= 2)
                          Buffers: shared hit=2
Planning Time: 0.204 ms
Execution Time: 0.145 ms