Table size with page layout

前端 未结 1 1101
醉话见心
醉话见心 2021-01-03 10:53

I\'m using PostgreSQL 9.2 on Oracle Linux Server release 6.3.

According to the storage layout documentation, a page layout holds:

  • PageHeaderData(24 byt
相关标签:
1条回答
  • 2021-01-03 11:08

    Your calculation is off at several points.

    • Storage size of varchar, text (and character!) is, quoting the manual):

    The storage requirement for a short string (up to 126 bytes) is 1 byte plus the actual string, which includes the space padding in the case of character. Longer strings have 4 bytes of overhead instead of 1. Long strings are compressed by the system automatically, so the physical requirement on disk might be less.

    Bold emphasis mine to address question in comment.

    • The HeapTupleHeader occupies 23 bytes. But each tuple ("item" - row or index entry) has an item identifier at the start of the data page to it, totaling at the mentioned 27 bytes. The distinction is relevant as actual user data begins at a multiple of MAXALIGN from the start of each item, and the item identifier does not count against this offset - as well as the actual "tuple size".

    • 1 byte of padding due to data alignment (multiple of 8), which is used for the NULL bitmap in this case.

    • No padding for type varchar (but the additional byte mentioned above)

    So, the actual calculation (with all columns filled to the maximum) is:

        23    -- heaptupleheader
     +   1    -- NULL bitmap (or padding if row has NO null values)
     +   9    -- columns ...
     + 101 
     +   2 
     + 101 
     +   4 
     +  11
    -------------
       252 bytes
    
     +   4    -- item identifier at page start

    Related:

    • Does not using NULL in PostgreSQL still use a NULL bitmap in the header?
    • Calculating and saving space in PostgreSQL

    You'll find many more in the link list to the right of these answers.

    0 讨论(0)
提交回复
热议问题