Switch to: V12V11V10V9V8V7V6V5

VarChar Technical Notes

Since a VarChar field can store strings of a variable length, the internal implementation of a VarChar file is based on pages. The size of a page is 4096 bytes.

Each string uses on a page: (length of the string + 4) bytes, as well as 4 bytes in the Table column.

Note that if the value of VarChar is empty then 8 bytes are used:

  • 4 bytes in the Table and
  • 4 bytes in a page file

i.e. VarChar has 8 bytes overhead per empty/null string.

The default maximal length for VarChar field is

  • 2044 characters for UTF-16 strings, i.e. 4088 bytes.
  • 4088 characters for single byte encodings, i.e. also 4088 bytes.

They are default because they are the maximal numbers that allow us to use one page of VarChar file. Really: (4088 + 4) + 4 = 4096

You can specify lower values for maximal length (e.g., 20), but 4K pages still will be used. The only advantage is that you will truncate longer strings to 20 bytes.

On the left picture you can see structure of PageFile that Valentina uses to keep VarChar values (as well as field indexes). On the right picture you can see that varchar field internally uses 2 files: first to keep ULONG values - references to pages, second is page file.