Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database Design: to EAV or not to EAV?

Say I have an entity that will have many attributes, some I know about now and others will be user defined. What's the best way to model this?

1) Do I have a main table and relate it to a secondary name-value pair table? All the attributes go in the secondary EAV table.

  • OR -

2) Do I put the most common attributes (not all users will need them, so I expect a lot of NULL entries) in the main table and have the secondary EAV table for the user defined attributes?

  • OR -

3) Some other approach I have not thought of?

like image 489
StackOverflowNewbie Avatar asked Apr 09 '11 23:04

StackOverflowNewbie


People also ask

What is EAV design?

Entity–attribute–value model (EAV) is a data model to encode, in a space-efficient manner, entities where the number of attributes (properties, parameters) that can be used to describe them is potentially vast, but the number that will actually apply to a given entity is relatively modest.

What is EAV database?

EAV database model, as well known as 'open schema' or 'vertical model', describe entities where the number of all attributes in unknown and potentially significant, however number of attributes for a particular entity is small.

Is EAV an Antipattern?

The Entity-Attribute-Value (EAV) [ ] data model has appeared in many different guises over the years, and comes under a variety of names, such as Object-Attribute-Value Model and Open Schema.

What is EAV in magento2?

EAV (Entity-attribute-value) is a model of storing the values of entity attributes in a certain data storage. As a data storage, Magento 2 supports MySQL-compatible databases (like MySQL, MySQL NDB Cluster, MariaDB, Percona and others).


1 Answers

You may use solution two for efficiency reason, in particular if you need to select often on these quantities. These values may be "cache" of the EAV table, if you want. You introduce duplication but speed up lookup.

EAV is a good solution for this problem unless you have to perform joins at the db level. An alternative is to move away from the relational model and move to a RDF based model.

like image 190
Stefano Borini Avatar answered Oct 17 '22 05:10

Stefano Borini