Skip to content

Instantly share code, notes, and snippets.

@rapimo
Created November 1, 2013 10:49
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/7263779 to your computer and use it in GitHub Desktop.
Save rapimo/7263779 to your computer and use it in GitHub Desktop.
postgres order of columns matters
CREATE TABLE small (
a smallint,
b smallint,
c integer,
d integer,
e date
)
CREATE TABLE big (
c integer,
a smallint,
e date,
b smallint,
d integer
)
INSERT INTO small (a,b,c,d,e)
SELECT i%32000, i%15000, i+1000,i+3000,current_date + i
FROM generate_series(1,1E6::integer) i
INSERT INTO big (a,b,c,d,e)
SELECT i%32000, i%15000, i+1000,i+3000,current_date + i
FROM generate_series(1,1E6::integer) i
SELECT pg_size_pretty(pg_total_relation_size('small'));
pg_size_pretty
----------------
42 MB
(1 row)
SELECT pg_size_pretty(pg_total_relation_size('big'));
pg_size_pretty
----------------
50 MB
(1 row)
@rapimo
Copy link
Author

rapimo commented Nov 1, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment