postgresql - PostrgeSQL storage using 2^n-1 for char and varchar -
there rule once heard when assigning storage size char , varchar instead of doing regular 4, 8, 16, 32 rule want use 3,7,15, 31. apparently has optimizing space in stored.
know if there validity statement or there better way of assigning size char , varchar in postgresql? rule postgresql or keep in mind in of sql languages?
you're mis-remembering applies @ lower level.
strings in "c" language terminated zero-byte. so: "hello" traditionally take 6 bytes. of course, when assumed single character fit neatly single byte. not case more.
the other (main) way store strings have length stored @ front, , have characters following. happens postgresql does, , believe has optimisation length doesn't take space short strings.
there separate issues memory access cheaper/easier @ 2/4/8 byte boundaries (depending on age of machine) , memory allocation can more efficient in powers of 2 (1024, 2048, 4096 bytes).
for postgresql (or of major scripting languages / java) worry representing data accurately. 99% of time fiddly low-level optimisation irrelevant. actually, if writing in "c", don't worry there until need to.
Comments
Post a Comment