smallest storage of integer array in mysql? -


i have table of user entries, , every entry have array of (2-byte) integers store (15-25, sporadically more). array elements written , read @ same time, never needed update or access them individually. order matters. makes sense think of array object.

i have many millions of these user entries , want store minimum possible amount of disk space. i'm struggling mysql's lack of array datatype.

i've been considering following options.

  • do mysql way. make table my_data columns user_id, data_id , data_int. make efficient, 1 needs index on user_id, totalling on 10 bytes per integer.
  • store array in text format. takes ~6.5 bytes per integer.
  • making 35-40 columns ("enough") , having -32768 'empty' (since value cannot occur in data). takes 3.5-4 bytes per integer, ugly (as have impose strict limit on number of elements in array).

is there better way in mysql? know mysql has efficient varchar type, ideally i'd store 2-byte integers 2-byte chars in varchar (or similar approach blob), i'm not sure how that. possible? how should done?

you store them separate smallint null columns.

in myisam this uses 2 bytes of data + 1 bit of null indicator each value.

in innodb, null indicators encoded column's field start offset, don't take space, , null values not stored in row data. if rows small enough offsets 1 byte, uses 3 bytes every existing value (1 byte offset, 2 bytes data), , 1 byte every nonexistent value.

either of these better using int special value indicate doesn't exist, since 4 bytes of data every value.

see null in mysql (performance & storage)


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -