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 13.4 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
i xi
1 1
2 2
3 3
4 3
5 2
6 1
xi i
1 1
2 2
3 3
3 4
2 5
1 6
1 1
2 2
3 3
3 4
2 5
1 6
1 1
2 2
3 3
3 4
2 5
1 6
1 1
2 2
3 3
3 4
2 5
1 6
1 1
2 2
3 3
3 4
2 5
1 6
generate_up_down_series
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
QUERY PLAN
Gather Merge (cost=456638946.01..896114073.03 rows=3766666666 width=12) (actual time=12.687..12.997 rows=30 loops=1)
  Output: "*SELECT* 2".xi, "*SELECT* 2"."?column?", x.j
  Workers Planned: 2
  Params Evaluated: $0
  Workers Launched: 2
  Buffers: shared hit=121
  InitPlan 1 (returns $0)
    -> Seq Scan on public.param param_2 (cost=0.00..32.60 rows=2260 width=4) (actual time=0.036..0.037 rows=1 loops=1)
          Output: param_2.m
          Buffers: shared hit=1
  -> Sort (cost=456637913.38..461346246.72 rows=1883333333 width=12) (actual time=0.124..0.127 rows=10 loops=3)
        Output: "*SELECT* 2".xi, "*SELECT* 2"."?column?", x.j
        Sort Key: x.j, "*SELECT* 2"."?column?"
        Sort Method: quicksort Memory: 26kB
        Buffers: shared hit=120
        Worker 0: actual time=0.138..0.139 rows=0 loops=1
          Sort Method: quicksort Memory: 25kB
          Buffers: shared hit=59
        Worker 1: actual time=0.145..0.146 rows=0 loops=1
          Sort Method: quicksort Memory: 25kB
          Buffers: shared hit=59
        -> Nested Loop (cost=0.01..37760879.27 rows=1883333333 width=12) (actual time=0.011..0.023 rows=10 loops=3)
              Output: "*SELECT* 2".xi, "*SELECT* 2"."?column?", x.j
              Buffers: shared hit=2
              Worker 0: actual time=0.002..0.003 rows=0 loops=1
              Worker 1: actual time=0.002..0.003 rows=0 loops=1
              -> Parallel Append (cost=0.00..94199.27 rows=1883334 width=8) (actual time=0.008..0.017 rows=2 loops=3)
                    Buffers: shared hit=2
                    Worker 0: actual time=0.001..0.002 rows=0 loops=1
                    Worker 1: actual time=0.001..0.002 rows=0 loops=1
                    -> Subquery Scan on "*SELECT* 2" (cost=0.00..84782.60 rows=2260000 width=8) (actual time=0.017..0.020 rows=3 loops=1)
                          Output: "*SELECT* 2".xi, "*SELECT* 2"."?column?"
                          Buffers: shared hit=1
                          -> Nested Loop (cost=0.00..62182.60 rows=2260000 width=8) (actual time=0.017..0.019 rows=3 loops=1)
                                Output: (x_1.i + param.n), ((param.n + 1) - x_1.i)
                                Buffers: shared hit=1
                                -> Seq Scan on public.param (cost=0.00..32.60 rows=2260 width=4) (actual time=0.005..0.005 rows=1 loops=1)
                                      Output: param.n, param.m
                                      Buffers: shared hit=1
                                -> Function Scan on pg_catalog.generate_series x_1 (cost=0.00..10.00 rows=1000 width=4) (actual time=0.010..0.010 rows=3 loops=1)
                                      Output: x_1.i
                                      Function Call: generate_series(1, param.n)
                    -> Subquery Scan on "*SELECT* 1" (cost=0.00..67832.60 rows=2260000 width=8) (actual time=0.022..0.025 rows=3 loops=1)
                          Output: "*SELECT* 1".xi, "*SELECT* 1".i
                          Buffers: shared hit=1
                          -> Nested Loop (cost=0.00..45232.60 rows=2260000 width=8) (actual time=0.021..0.023 rows=3 loops=1)
                                Output: x_2.i, x_2.i
                                Buffers: shared hit=1
                                -> Seq Scan on public.param param_1 (cost=0.00..32.60 rows=2260 width=4) (actual time=0.006..0.007 rows=1 loops=1)
                                      Output: param_1.n, param_1.m
                                      Buffers: shared hit=1
                                -> Function Scan on pg_catalog.generate_series x_2 (cost=0.00..10.00 rows=1000 width=4) (actual time=0.011..0.012 rows=3 loops=1)
                                      Output: x_2.i
                                      Function Call: generate_series(1, param_1.n)
              -> Function Scan on pg_catalog.generate_series x (cost=0.00..10.00 rows=1000 width=4) (actual time=0.001..0.001 rows=5 loops=6)
                    Output: x.j
                    Function Call: generate_series(1, $0)
Planning Time: 0.190 ms
Execution Time: 13.086 ms
QUERY PLAN
ProjectSet (cost=0.00..5.27 rows=1000 width=4) (actual time=0.034..0.038 rows=30 loops=1)
  Output: generate_up_down_series(3, 5)
  -> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.001..0.001 rows=1 loops=1)
Planning Time: 0.021 ms
Execution Time: 0.050 ms