Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE t (
- refid BIGINT NOT NULL,
- created TIMESTAMPTZ NOT NULL
- );
- CREATE INDEX t_refid_created ON t (refid, created);
- -- index only scan t_refid_created_desc_idx
- SELECT DISTINCT ON (refid) * FROM t
- ORDER BY refid, created DESC;
- -- index scan t_refid_created_idx
- SELECT refid, max(created) FROM t GROUP BY refid;
- CREATE index t_refid_created_desc_idx ON t (refid, created DESC);
- Unique (cost=0.56..850119.78 rows=291 width=16)
- -> Index Only Scan using t_refid_created_desc_idx on t (cost=0.56..808518.47 rows=16640527 width=16)
- Finalize GroupAggregate (cost=599925.13..599932.41 rows=291 width=16)
- Group Key: refid
- -> Sort (cost=599925.13..599926.59 rows=582 width=16)
- Sort Key: refid
- -> Gather (cost=599837.29..599898.40 rows=582 width=16)
- Workers Planned: 2
- -> Partial HashAggregate (cost=598837.29..598840.20 rows=291 width=16)
- Group Key: refid
- -> Parallel Seq Scan on t (cost=0.00..564169.53 rows=6933553 width=16)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement