SlideShare a Scribd company logo
Entity - Attribute - Value (EAV) Data Model in Magento  @Pờ Đình Tâm
What is EAV EAV can be thought of as “vertical” modeling instead of “horizontal” modeling of columns in a database table. Instead of a table consisting of a number of columns, denoting attributes of a conceptual piece of data, the attributes are stored in one column of a separate table.
Traditional User Table table: user_entity
EAV Style Tables
Structure of an EAV table The entity: Objects are entities (in Magento. Entities are: product, customer, order,…) The attribute: object properties are attributes The value: The value of the attribute
Update SQL: UPDATE `eav_attribute` SET `attribute_id` = ?, `entity_type_id` = ?, `attribute_code` = ?, `attribute_model` = ?, `backend_model` = ?, `backend_type` = ?, `backend_table` = ?, `frontend_model` = ?, `frontend_input` = ?, `frontend_input_renderer` = ?, `frontend_label` = ?, `frontend_class` = ?, `source_model` = ?, `is_global` = ?, `is_visible` = ?, `is_required` = ?, `is_user_defined` = ?, `default_value` = ?, `is_searchable` = ?, `is_filterable` = ?, `is_comparable` = ?, `is_visible_on_front` = ?, `is_html_allowed_on_front` = ?, `is_unique` = ?, `is_used_for_price_rules` = ?, `is_filterable_in_search` = ?, `used_in_product_listing` = ?, `used_for_sort_by` = ?, `is_configurable` = ?, `apply_to` = ?, `position` = ?, `note` = ?, `is_visible_in_advanced_search` = ? WHERE (attribute_id='498') BIND: Array ( [0] => 498 [1] => 4 [2] => sp_test [3] =>  [4] =>  [5] => varchar [6] =>  [7] =>  [8] => text [9] =>  [10] => sp test [11] =>  [12] =>  [13] => 0 [14] => 1 [15] => 0 [16] => 1 [17] =>  [18] => 1 [19] => 0 [20] => 1 [21] => 0 [22] => 1 [23] => 0 [24] => 0 [25] => 0 [26] => 0 [27] => 0 [28] => 0 [29] =>  [30] => 0 [31] =>  [32] => 1 )
Delete SQL: DELETE FROM `eav_attribute` WHERE (attribute_id='498')
Read SQL:  SELECT COUNT(DISTINCT e.entity_id)  FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_category_product_index` AS `cat_index`  ON cat_index.product_id=e.entity_id  AND cat_index.store_id='1'  AND cat_index.visibility  IN(3, 4)  AND cat_index.category_id='2'  WHERE    (   e.entity_id in    (   SELECT `t1`.`entity_id` FROM `catalog_product_entity_varchar` AS `t1`   LEFT JOIN `catalog_product_entity_varchar` AS `t2`    ON t1.entity_id = t2.entity_id    AND t1.attribute_id = t2.attribute_id    AND t2.store_id='1'    WHERE (t1.store_id = 0)    AND (t1.attribute_id = 498)    AND (IFNULL(t2.value, t1.value) LIKE :attribute_498)    AND    (   t1.entity_id IN   (   SELECT `t1`.`entity_id` FROM `catalog_product_entity_int` AS `t1`   LEFT JOIN `catalog_product_entity_int` AS `t2`    ON t1.entity_id = t2.entity_id    AND t1.attribute_id = t2.attribute_id    AND t2.store_id='1'    WHERE (t1.store_id = 0)    AND (t1.attribute_id = 497)    AND (IFNULL(t2.value, t1.value) IN ('0', '1'))    AND    (   t1.entity_id IN   (   SELECT `t1`.`entity_id`    FROM `catalog_product_entity_int` AS `t1`   LEFT JOIN `catalog_product_entity_int` AS `t2`    ON t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id    AND t2.store_id='1'    WHERE (t1.store_id = 0) AND (t1.attribute_id = 496) AND (IFNULL(t2.value, t1.value) IN ('0', '1'))   )   )   )   )   )   ) BIND: Array ( [attribute_498] => %ten% )
Read(2)
Read(3) Relation database: SELECT *  FROM Employee  WHERE Name = ‘John’  AND Nationality = ‘English
Read(4) Self Join:  SELECT  t1.ID as 'ID' t1.Value AS ‘Name’,  t2.Value AS ‘Nationality’ t3.Value AS Birthday FROM EAV_Data t1 LEFT JOIN EAV_Data t2 ON t1.ID = t2.ID LEFT JOIN EAV_Data t3 ON t1.ID = t3.ID WHERE t1.Attribute = ‘Name’ AND t1.Value = ‘John’ AND t2.Attribute = ‘Nationality’ AND t2.Value = ‘English’ AND t3.Attribute = ‘Birthday
Good Provides a flexible mechanism to record the attributes associated with any entity. This EAV design requires almost no consideration of the nature of the applicable hierarchical data and requires very little time to implement  The database schema does not change when the model changes
Bad The EAV table doesn't provide a mechanism to create relationships between entities of different sub-types. The EAV table does nothing to provide a grouping of related entity types. The EAV table uses a VARCHAR column for all attribute values regardless if Dates, timestamps, integers, numerics or booleans would be more appropriate Inefficient queries. Where you would execute a simple query returning 20 columns from a single table, you end up with 20 self-joins, one for each column
Solution Take a look at Magento Database Diagram
EAV table with Pivot (3) Pivot SELECT * FROM ( SELECT ID , [100] AS Name , [101] AS Birthday , [102] AS Nationality FROM  ( SELECT ID, EntityID, AttributeID, Value FROM EAV_Table ) p PIVOT ( MAX (Value) FOR AttributeID IN ([100], [101], [102]) ) AS pvt ) WHERE Name = 'John' AND Nationality = 'English'
When Recommend from Amazon SimpleDB:  Principally utilize index and query functions rather than more complex relational database functions Don’t want any administrative burden at all in managing their structured data Want a service that scales automatically up or down in response to demand, without user intervention Require the highest availability and can’t tolerate downtime for data backup or software maintenance
Thanks for your attention

More Related Content

PPTX
EAV Sytem- Magento EAV Model
PPT
STL ALGORITHMS
PPTX
Sql comandos
PDF
Ejercicios resueltos de_pl-sql
PDF
Nested Queries Lecture
PDF
JAVA - VTU - Object oriented Concepts - 18CS45 - Module I
DOCX
C# Unit 1 notes
PPTX
2. Classes | Object Oriented Programming in JavaScript | ES6 | JavaScript
EAV Sytem- Magento EAV Model
STL ALGORITHMS
Sql comandos
Ejercicios resueltos de_pl-sql
Nested Queries Lecture
JAVA - VTU - Object oriented Concepts - 18CS45 - Module I
C# Unit 1 notes
2. Classes | Object Oriented Programming in JavaScript | ES6 | JavaScript

What's hot (20)

PDF
Basics of Model/View Qt programming
 
PPT
Generics in java
DOCX
Entenda o ciclo de vida das entidades jpa
PDF
Flask Basics
PPTX
Input devices
PPT
Memory allocation in c
PPTX
Lab2 ddl commands
PPT
Java Serialization
PDF
In-Depth Model/View with QML
 
PDF
Java+8-New+Features.pdf
PPT
vb.net Constructor and destructor
PDF
QThreads: Are You Using Them Wrong?
 
PPTX
Operators in java presentation
PDF
Triggers and active database
PDF
9 Curso de POO en java - variables, constantes y objetos
PPTX
Java Foundations: Objects and Classes
PPT
Generic programming in java
PPTX
C# Generics
PDF
Implicit parameters, when to use them (or not)!
PPT
Introduction to ADO.NET
Basics of Model/View Qt programming
 
Generics in java
Entenda o ciclo de vida das entidades jpa
Flask Basics
Input devices
Memory allocation in c
Lab2 ddl commands
Java Serialization
In-Depth Model/View with QML
 
Java+8-New+Features.pdf
vb.net Constructor and destructor
QThreads: Are You Using Them Wrong?
 
Operators in java presentation
Triggers and active database
9 Curso de POO en java - variables, constantes y objetos
Java Foundations: Objects and Classes
Generic programming in java
C# Generics
Implicit parameters, when to use them (or not)!
Introduction to ADO.NET
Ad

Similar to Entity Attribute Value (Eav) (20)

PPT
EAV in Magento
PDF
Eav Data Model Concepts
PDF
20. Magento Austria meetup - EAV Principles
KEY
MongoDB and Ecommerce : A perfect combination
PDF
Dare to build vertical design with relational data (Entity-Attribute-Value)
PDF
Database.pdf
PPTX
38. Magento Meetup Austria: Ivan Cuk - From Core to Custom. A Deep Dive into ...
PDF
Magento 2.1 ee content staging
DOCX
Database design guide
DOC
Create table dimcustomer ( customerid int/tutorialoutlet
DOCX
Running Head PROJECT DELIVERABLE 31PROJECT DELIVERABLE 310.docx
PDF
Inventory management system
DOCX
Inventory aging report using oracle discoverer desktop
PPTX
Subquery & view
PPT
Data Warehousing
PPT
Datawarehosuing
DOCX
Database Management Systems Project Report
PDF
Unit 2-Data Modeling.pdf
PPTX
PDF
Magento2dbschema1 180607144053
EAV in Magento
Eav Data Model Concepts
20. Magento Austria meetup - EAV Principles
MongoDB and Ecommerce : A perfect combination
Dare to build vertical design with relational data (Entity-Attribute-Value)
Database.pdf
38. Magento Meetup Austria: Ivan Cuk - From Core to Custom. A Deep Dive into ...
Magento 2.1 ee content staging
Database design guide
Create table dimcustomer ( customerid int/tutorialoutlet
Running Head PROJECT DELIVERABLE 31PROJECT DELIVERABLE 310.docx
Inventory management system
Inventory aging report using oracle discoverer desktop
Subquery & view
Data Warehousing
Datawarehosuing
Database Management Systems Project Report
Unit 2-Data Modeling.pdf
Magento2dbschema1 180607144053
Ad

Recently uploaded (20)

PDF
Empathic Computing: Creating Shared Understanding
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Cloud computing and distributed systems.
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation theory and applications.pdf
PDF
cuic standard and advanced reporting.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Big Data Technologies - Introduction.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Empathic Computing: Creating Shared Understanding
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Dropbox Q2 2025 Financial Results & Investor Presentation
Cloud computing and distributed systems.
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Diabetes mellitus diagnosis method based random forest with bat algorithm
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation theory and applications.pdf
cuic standard and advanced reporting.pdf
Programs and apps: productivity, graphics, security and other tools
sap open course for s4hana steps from ECC to s4
Big Data Technologies - Introduction.pptx
Unlocking AI with Model Context Protocol (MCP)
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing

Entity Attribute Value (Eav)

  • 1. Entity - Attribute - Value (EAV) Data Model in Magento @Pờ Đình Tâm
  • 2. What is EAV EAV can be thought of as “vertical” modeling instead of “horizontal” modeling of columns in a database table. Instead of a table consisting of a number of columns, denoting attributes of a conceptual piece of data, the attributes are stored in one column of a separate table.
  • 3. Traditional User Table table: user_entity
  • 5. Structure of an EAV table The entity: Objects are entities (in Magento. Entities are: product, customer, order,…) The attribute: object properties are attributes The value: The value of the attribute
  • 6. Update SQL: UPDATE `eav_attribute` SET `attribute_id` = ?, `entity_type_id` = ?, `attribute_code` = ?, `attribute_model` = ?, `backend_model` = ?, `backend_type` = ?, `backend_table` = ?, `frontend_model` = ?, `frontend_input` = ?, `frontend_input_renderer` = ?, `frontend_label` = ?, `frontend_class` = ?, `source_model` = ?, `is_global` = ?, `is_visible` = ?, `is_required` = ?, `is_user_defined` = ?, `default_value` = ?, `is_searchable` = ?, `is_filterable` = ?, `is_comparable` = ?, `is_visible_on_front` = ?, `is_html_allowed_on_front` = ?, `is_unique` = ?, `is_used_for_price_rules` = ?, `is_filterable_in_search` = ?, `used_in_product_listing` = ?, `used_for_sort_by` = ?, `is_configurable` = ?, `apply_to` = ?, `position` = ?, `note` = ?, `is_visible_in_advanced_search` = ? WHERE (attribute_id='498') BIND: Array ( [0] => 498 [1] => 4 [2] => sp_test [3] => [4] => [5] => varchar [6] => [7] => [8] => text [9] => [10] => sp test [11] => [12] => [13] => 0 [14] => 1 [15] => 0 [16] => 1 [17] => [18] => 1 [19] => 0 [20] => 1 [21] => 0 [22] => 1 [23] => 0 [24] => 0 [25] => 0 [26] => 0 [27] => 0 [28] => 0 [29] => [30] => 0 [31] => [32] => 1 )
  • 7. Delete SQL: DELETE FROM `eav_attribute` WHERE (attribute_id='498')
  • 8. Read SQL: SELECT COUNT(DISTINCT e.entity_id) FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id='1' AND cat_index.visibility IN(3, 4) AND cat_index.category_id='2' WHERE ( e.entity_id in ( SELECT `t1`.`entity_id` FROM `catalog_product_entity_varchar` AS `t1` LEFT JOIN `catalog_product_entity_varchar` AS `t2` ON t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id='1' WHERE (t1.store_id = 0) AND (t1.attribute_id = 498) AND (IFNULL(t2.value, t1.value) LIKE :attribute_498) AND ( t1.entity_id IN ( SELECT `t1`.`entity_id` FROM `catalog_product_entity_int` AS `t1` LEFT JOIN `catalog_product_entity_int` AS `t2` ON t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id='1' WHERE (t1.store_id = 0) AND (t1.attribute_id = 497) AND (IFNULL(t2.value, t1.value) IN ('0', '1')) AND ( t1.entity_id IN ( SELECT `t1`.`entity_id` FROM `catalog_product_entity_int` AS `t1` LEFT JOIN `catalog_product_entity_int` AS `t2` ON t1.entity_id = t2.entity_id AND t1.attribute_id = t2.attribute_id AND t2.store_id='1' WHERE (t1.store_id = 0) AND (t1.attribute_id = 496) AND (IFNULL(t2.value, t1.value) IN ('0', '1')) ) ) ) ) ) ) BIND: Array ( [attribute_498] => %ten% )
  • 10. Read(3) Relation database: SELECT * FROM Employee WHERE Name = ‘John’ AND Nationality = ‘English
  • 11. Read(4) Self Join: SELECT t1.ID as 'ID' t1.Value AS ‘Name’, t2.Value AS ‘Nationality’ t3.Value AS Birthday FROM EAV_Data t1 LEFT JOIN EAV_Data t2 ON t1.ID = t2.ID LEFT JOIN EAV_Data t3 ON t1.ID = t3.ID WHERE t1.Attribute = ‘Name’ AND t1.Value = ‘John’ AND t2.Attribute = ‘Nationality’ AND t2.Value = ‘English’ AND t3.Attribute = ‘Birthday
  • 12. Good Provides a flexible mechanism to record the attributes associated with any entity. This EAV design requires almost no consideration of the nature of the applicable hierarchical data and requires very little time to implement The database schema does not change when the model changes
  • 13. Bad The EAV table doesn't provide a mechanism to create relationships between entities of different sub-types. The EAV table does nothing to provide a grouping of related entity types. The EAV table uses a VARCHAR column for all attribute values regardless if Dates, timestamps, integers, numerics or booleans would be more appropriate Inefficient queries. Where you would execute a simple query returning 20 columns from a single table, you end up with 20 self-joins, one for each column
  • 14. Solution Take a look at Magento Database Diagram
  • 15. EAV table with Pivot (3) Pivot SELECT * FROM ( SELECT ID , [100] AS Name , [101] AS Birthday , [102] AS Nationality FROM ( SELECT ID, EntityID, AttributeID, Value FROM EAV_Table ) p PIVOT ( MAX (Value) FOR AttributeID IN ([100], [101], [102]) ) AS pvt ) WHERE Name = 'John' AND Nationality = 'English'
  • 16. When Recommend from Amazon SimpleDB: Principally utilize index and query functions rather than more complex relational database functions Don’t want any administrative burden at all in managing their structured data Want a service that scales automatically up or down in response to demand, without user intervention Require the highest availability and can’t tolerate downtime for data backup or software maintenance
  • 17. Thanks for your attention