Skip to content

Instantly share code, notes, and snippets.

@rapimo
Created January 22, 2016 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rapimo/995570f8cd8734e7f01c to your computer and use it in GitHub Desktop.
Save rapimo/995570f8cd8734e7f01c to your computer and use it in GitHub Desktop.
istore beats case
\timing
CREATE EXTENSION istore;
CREATE TABLE foo AS SELECT i%10 as id, i FROM generate_series(1,1e7::int) i;
SELECT CASE
WHEN id = 1 THEN 10 WHEN id = 2 THEN 20 WHEN id = 3 THEN 30 WHEN id = 4 THEN 40 WHEN id = 5 THEN 50
WHEN id = 6 THEN 60 WHEN id = 7 THEN 70 WHEN id = 8 THEN 80 WHEN id = 9 THEN 90
ELSE 0 END,
SUM(i)
FROM foo GROUP BY 1;
SELECT COALESCE('1=>10,2=>20,3=>30,4=>40,5=>50,6=>60,7=>70,8=>80'::istore -> id,0),
SUM(i)
FROM foo GROUP BY 1;
SELECT CASE
WHEN id = 1 THEN 10 WHEN id = 2 THEN 20
ELSE 0 END,
SUM(i)
FROM foo GROUP BY 1;
SELECT COALESCE('1=>10,2=>20'::istore -> id,0),
SUM(i)
FROM foo GROUP BY 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment