Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. CREATE TABLE t (
  2. refid BIGINT NOT NULL,
  3. created TIMESTAMPTZ NOT NULL
  4. );
  5. CREATE INDEX t_refid_created ON t (refid, created);
  6.  
  7. -- index only scan t_refid_created_desc_idx
  8. SELECT DISTINCT ON (refid) * FROM t
  9. ORDER BY refid, created DESC;
  10.  
  11. -- index scan t_refid_created_idx
  12. SELECT refid, max(created) FROM t GROUP BY refid;
  13.  
  14. CREATE index t_refid_created_desc_idx ON t (refid, created DESC);
  15.  
  16. Unique (cost=0.56..850119.78 rows=291 width=16)
  17. -> Index Only Scan using t_refid_created_desc_idx on t (cost=0.56..808518.47 rows=16640527 width=16)
  18.  
  19. Finalize GroupAggregate (cost=599925.13..599932.41 rows=291 width=16)
  20. Group Key: refid
  21. -> Sort (cost=599925.13..599926.59 rows=582 width=16)
  22. Sort Key: refid
  23. -> Gather (cost=599837.29..599898.40 rows=582 width=16)
  24. Workers Planned: 2
  25. -> Partial HashAggregate (cost=598837.29..598840.20 rows=291 width=16)
  26. Group Key: refid
  27. -> Parallel Seq Scan on t (cost=0.00..564169.53 rows=6933553 width=16)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement