Tutorial

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):

Entity:

product_id

Attribute:

attribute_id

product_id

attribute_name

Value:

attribute_id

product_id

attribute_value

Sample data are as below:

Entity:

product_id (1)

Attribute:

attribute_id (1)                                                attribute_id (2)

product_id (1)                                                  product_id (1)

attribute_name (color)                                  attribute_name (price)

Value:

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.

Shares:
  • […] This post was mentioned on Twitter by Avinash Zala, Avi. Avi said: What is EAV model in Magento?: EAV stands for Entity Attribute Value Model. EAV also known as object attribute val… http://bit.ly/d3YjmE […]

    Reply
  • […] because of the EAV database structure. To more about the EAV database structure see my post on EAV database structure in Magento. But EAV database model is not much faster in terms of the performance. This is because we need […]

    Reply
  • Ferry Ardhana
    August 21, 2011 at 1:20 am

    Yeah.. Magento have very high scalability. And because of that have problem on loading process.
    Maybe there is one of reason why is recomended to enable catalog flat table and always keep index is up to date on magento backend.
    Because when index process is running, they are collecting summary data from entity into only one table (catalog_product_flat_). CMIIW. :)

    Reply
    • Avinash
      August 21, 2011 at 2:05 am

      Hi Ferry,

      Thanks for sharing this information.

      Reply
  • kiran
    kiran
    November 11, 2011 at 6:55 pm

    Very nice and useful article. Thank you very much

    Reply
  • Iqbal
    Iqbal
    April 10, 2012 at 6:36 pm

    I am new to magento and found that good understanding of EAV model of magento is a key to good grasp on magento.

    Reply
  • Bokin
    April 24, 2012 at 7:28 pm

    In your article, I realized that why the magento was slow. Thanks :)

    Reply
  • […] Article on Magento after very long time. Last article which I have posted about magento is about Magento EAV Database structure. In that article I have explained the reason for the flexibility […]

    Reply
  • Anusha E
    Anusha E
    September 20, 2014 at 6:11 pm

    thanks ,the information is very helpful :)

    Reply
  • Asraful Haque
    Asraful Haque
    December 30, 2014 at 12:23 am

    Thanks this is very useful content.

    Reply
  • Banvari Lal
    Banvari Lal
    January 14, 2018 at 11:46 pm

    very good explaination

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *