Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgres Performance: Static row length?

Mysql behaves in a special (presumably more performant) manner when a table has no variable-width columns

Does postgres have similar behavior? Does adding a single variable-width column to a table make any major difference?

like image 950
Frank Farmer Avatar asked Mar 25 '11 19:03

Frank Farmer


1 Answers

The general advice given in the postgres docs (read the tip) is that variable length fields often perform better because it results in less data so the table fits in less disk blocks and takes up less space in cache memory. Modern CPU's are so much faster then the memory and disks that the overhead of variable length field is worth the reduction in IO.

Notice that postgresql stores NULL values in a bitmap at the beginning of the row and omits the field if the value is NULL. So any nullable column has basically a variable width. The way postgresql stores it data (Database page layout) suggests that retrieving the last column would be slower then the first column. But this will probably only have a noticable impact if you have many columns and the data was mostly in cache to start with. Otherwise the disk io will be the dominant factor.

like image 131
Eelke Avatar answered Nov 15 '22 06:11

Eelke