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?.
setseed
SELECT 1
CREATE TABLE
CREATE TABLE
CREATE TABLE
INSERT 0 2000
INSERT 0 40000
INSERT 0 20000
PREPARE
QUERY PLAN
Sort (cost=386.22..386.72 rows=200 width=40) (actual time=11.252..11.255 rows=5 loops=1)
  Output: r.acceptance_status, (count(*))
  Sort Key: r.acceptance_status, (count(*))
  Sort Method: quicksort Memory: 25kB
  -> HashAggregate (cost=376.57..378.57 rows=200 width=40) (actual time=11.203..11.207 rows=5 loops=1)
        Output: r.acceptance_status, count(*)
        Group Key: r.acceptance_status
        Batches: 1 Memory Usage: 40kB
        -> Hash Join (cost=346.93..375.57 rows=200 width=32) (actual time=9.918..10.710 rows=2000 loops=1)
              Output: r.acceptance_status
              Inner Unique: true
              Hash Cond: (r.route_id = rts.route_id)
              -> Seq Scan on public.route r (cost=0.00..24.97 rows=1397 width=36) (actual time=0.021..0.288 rows=2000 loops=1)
                    Output: r.route_id, r.acceptance_status
              -> Hash (cost=344.43..344.43 rows=200 width=4) (actual time=9.877..9.878 rows=2000 loops=1)
                    Output: rts.route_id
                    Buckets: 2048 (originally 1024) Batches: 1 (originally 1) Memory Usage: 87kB
                    -> Subquery Scan on rts (cost=340.43..344.43 rows=200 width=4) (actual time=8.776..9.477 rows=2000 loops=1)
                          Output: rts.route_id
                          -> HashAggregate (cost=340.43..342.43 rows=200 width=36) (actual time=8.775..9.193 rows=2000 loops=1)
                                Output: rts_1.route_id, NULL::integer[]
                                Group Key: rts_1.route_id
                                Batches: 1 Memory Usage: 257kB
                                -> Seq Scan on public.route_to_shipment rts_1 (cost=0.00..290.14 rows=20114 width=4) (actual time=0.017..3.269 rows=20000 loops=1)
                                      Output: rts_1.shipment_id, rts_1.route_id
Planning Time: 0.903 ms
Execution Time: 11.356 ms
EXPLAIN
acceptance_status count
accepted 502
pending 468
prep 254
rejected 270
sent 506
SELECT 5