Grouping columns the right way
Some people might wonder what is meant by the title of this section. Does it make a difference which order columns are aligned in? This might be a bit surprising, but it does. Even if a table contains the same data, its size on the disk might vary depending on the order of columns. Here is an example:
test=# CREATE TABLE t_test ( i1 int, i2 int, i3 int, v1 varchar(100), v2 varchar(100), v3 varchar(100) ); CREATE TABLE test=# INSERT INTO t_test SELECT 10, 20, 30, 'abcd', 'abcd', 'abcd' FROM generate_series(1, 10000000); INSERT 0 10000000
A table with three columns has been created. First of all, there are three integer columns. Then some varchar
columns are added. In the second statement, 10 million rows are added. The generate_series
command is a nice way to generate a list of numbers. In this example, the output of generate_series
is not used. I am just utilizing the function...