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
VACUUM
SET
CREATE INDEX
QUERY PLAN
GroupAggregate (cost=0.12..8.17 rows=1 width=28)
  Group Key: date(received_at), location_id, purpose_id
  -> Index Scan using "inquiries_DATE_index" on inquiries (cost=0.12..8.15 rows=1 width=28)
        Index Cond: ((date(received_at) >= '2023-11-01'::date) AND (date(received_at) <= '2023-12-01'::date))
EXPLAIN
DROP INDEX
CREATE INDEX
QUERY PLAN
GroupAggregate (cost=0.12..8.17 rows=1 width=28)
  Group Key: (date(received_at)), location_id, purpose_id
  -> Index Only Scan using inquiries_date_plus_idx on inquiries (cost=0.12..8.15 rows=1 width=28)
        Index Cond: (((date(received_at)) >= '2023-11-01'::date) AND ((date(received_at)) <= '2023-12-01'::date))
EXPLAIN
DROP INDEX
CREATE INDEX
QUERY PLAN
GroupAggregate (cost=8.16..8.18 rows=1 width=28)
  Group Key: ((received_at)::date), location_id, purpose_id
  -> Sort (cost=8.16..8.16 rows=1 width=28)
        Sort Key: ((received_at)::date), location_id, purpose_id, identity_id
        -> Index Only Scan using inquiries_received_at_plus_idx on inquiries (cost=0.12..8.15 rows=1 width=28)
              Index Cond: ((received_at >= '2023-11-01'::date) AND (received_at < '2023-12-01'::date))
EXPLAIN
QUERY PLAN
GroupAggregate (cost=8.16..8.20 rows=1 width=28)
  Group Key: ((inquiries.received_at)::date), inquiries.location_id, inquiries.purpose_id
  -> Unique (cost=8.16..8.17 rows=1 width=28)
        -> Sort (cost=8.16..8.16 rows=1 width=28)
              Sort Key: ((inquiries.received_at)::date), inquiries.location_id, inquiries.purpose_id, inquiries.identity_id
              -> Index Only Scan using inquiries_received_at_plus_idx on inquiries (cost=0.12..8.15 rows=1 width=28)
                    Index Cond: ((received_at >= '2023-11-01'::date) AND (received_at < '2023-12-01'::date))
EXPLAIN