[Answer]-Variant data type in DB

1đź‘Ť

You are implementing something called an entity-attribute-value (EAV) model. You’ve described it pretty well, in case you don’t know what it is.

In terms of the data structure, string types occupy little space when they have NULL values. But other types do occupy space, so you will have wasted space. You could store everything as a string — numbers as numbers, dates as YYYY-MM-DD, and make do with a single string. You do lose some of the flexibility of a native data type though.

In general, EAV models are computationally expensive. 600 Mbytes per month is a respectable amount of data. Pouring through gigabytes of data to bring records back together can be painful in MySQL (which has poor performance for group by). I generally recommend a hybrid EAV model, where a “regular” record stores commonly used attributes and the EAV piece is only there for the uncommon attributes.

👤Gordon Linoff

Leave a comment