Thursday 3 September 2015

What is EAV model in Magento?

EAV stands for Entity Attribute Value Model.
EAV also known as object attribute value model and open schema.
Entity (E): Entity actually refers to data item. For example we can consider it as customer, category or product.
Attribute (A): Attribute refers to the different attributes of the Entity. Like for example product have different attributes like color, size, price, etc.
Value (V): Value refers to the actual value of the attribute of the entity. Like color has value red, price has value $25, etc.
Below is the basic structure of the EAV (Considering product as an example):






Sample data are as below:


product_id (1)


attribute_id (1)                                                attribute_id (2)
product_id (1)                                                  product_id (1)
attribute_name (color)                                  attribute_name (price)


attribute_id (1)                                                     attribute_id (2)
product_id (1)                                                       product_id (1)
attribute_value (red)                                           attribute_value (290)
As per the above table structure, magento stores entry in three tables (actually more than three, but for this point it’s three). When you enter product in magento you have to insert different attributes of the product. So when you insert one product it will make one main entry in entity table. Then after with the reference of that entity id it will insert the various attributes (only name) of entity. At last with reference of entity id and attribute ids it will insert the actual value of the different attributes.
This is the basic structure of EAV which magento use. There may be (actually there are) some more complex structure of the EAV available but the main concept will remain same.

Why to use EAV?

EAV used because of scalability. We can insert anything without changing its structure. This is the main benefit of this structure.
Main problem with EAV structure is that, it is much slower than custom made solution because of SQL query complexity.
You need to make few join to retrieve just a single entity and in opposite in custom made solution we just have to make one simple select query to retrieve single entity.
Magento uses EAV structure because its designed to be scalable, regardless of speed problem.


Post a Comment

Subscribe to Post Comments [Atom]

<< Home