SlideShare uma empresa Scribd logo
1 de 29
WAS IST EIGENTLICH EAV?
        Eine Einführung in das Entity-Attribute-Value Model



                                  PHP User Group Rheinhessen
                                       12.01.2010 Mainz




Daniel Nitz — www.danielnitz.de               1                12.01.2010 — PHPUG-RHH
AGENDA

          1. Definition                  4. Nachteile

          2. Anwendungsbeispiel         5. In der Praxis

          3. Vorteile                   6. Fazit



Daniel Nitz — www.danielnitz.de     2              12.01.2010 — PHPUG-RHH
DEFINITION




Daniel Nitz — www.danielnitz.de       3        12.01.2010 — PHPUG-RHH
DEFINITION


  Entity-Attribute-Value Model, auch bekannt als Object-
  Attribute-Value Model und Open Schema ist ein Datenmodell,
  welches dann zum Einsatz kommt, wenn die Anzahl der
  Attribute (Eigenschaften, Parameter) zur Beschreibung einer
  Sache (Entität oder Objekt) im Vorfeld nicht vorhersehbar sind.



Daniel Nitz — www.danielnitz.de       4           12.01.2010 — PHPUG-RHH
DEFINITION



  EAV ist ein Datenmodell für den Fall, dass die Anzahl der
  Attribute eines Objektes nicht vorhersehbar sind.




Daniel Nitz — www.danielnitz.de       5           12.01.2010 — PHPUG-RHH
DEFINITION


  Entity: Repräsentiert einen Datensatz, z.B. eine Produkt.

  Attribute: Stellt eine Eigenschaft dar, z.B. Größe, Farbe etc.

  Value: Beinhaltet den Eigenschaftswert, z.B. XL, blau etc.



Daniel Nitz — www.danielnitz.de       6                12.01.2010 — PHPUG-RHH
DEFINITION

                                  1:n               1:1
                  Entity                Attribute            Value




                       3 Tabellen verknüpft mittels Foreign Keys.



Daniel Nitz — www.danielnitz.de             7                12.01.2010 — PHPUG-RHH
HÄ?



Daniel Nitz — www.danielnitz.de    8    12.01.2010 — PHPUG-RHH
ANWENDUNGSBEISPIEL
           Unterschied EAV im Vergleich zum relationalen Design




Daniel Nitz — www.danielnitz.de     9                 12.01.2010 — PHPUG-RHH
ANWENDUNGSBEISPIEL

‣   Eine Person wird anhand einer eindeutigen Nummer
    identifiziert

‣   Eine Person hat einen Vornamen

‣   Eine Person hat einen Nachnamen

‣   Ein Person hat eine beliebige Anzahl von zusätzlichen
    Informationen (Alter, Gewicht, Größe etc.)
Daniel Nitz — www.danielnitz.de   10                12.01.2010 — PHPUG-RHH
RELATIONALES DESIGN
                                   Person             Data

                                  person_id   1:1   person_id
                                  first_name         age
                                  last_name         weight
                                                    height




Daniel Nitz — www.danielnitz.de               11                12.01.2010 — PHPUG-RHH
EAV DESIGN

                  Entity                  Attribute               Value
                                                         1:1
               entity_id          1:n
                                        attribute_id           attribute_id
                                        entity_id              value
                                        attribute_name




Daniel Nitz — www.danielnitz.de               12                 12.01.2010 — PHPUG-RHH
STORY
Relationales Design:
Die Person mit der Nummer 1 hat das Alter 30, hat ein Gewicht von 80,
hat eine Größe von 180.


EAV Design:
Die Person mit der Nummer 1 hat das Attribut Alter mit dem Wert 30.

Die Person mit der Nummer 1 hat das Attribut Gewicht mit dem Wert 80.

Die Person mit der Nummer 1 hat das Attribut Größe mit dem Wert 180.

 Daniel Nitz — www.danielnitz.de     13                 12.01.2010 — PHPUG-RHH
DESIGN PROBLEME


‣   keine Datentypen

‣   keine definierten Spalten-/Attributsets

‣   Redundanz von Attributen

‣   keine Integrität


Daniel Nitz — www.danielnitz.de   14         12.01.2010 — PHPUG-RHH
EAV DESIGN

                  Entity                  Attribute                            Value
                                                               1:1
               entity_id          1:n
                                        attribute_id                        attribute_id
                                        entity_id                           value_id
                                        attribute_name

                                                         1:1                            1:1



                                                                Value Int                Value ...

                                                               value_id                value_id
                                                               value                   value


Daniel Nitz — www.danielnitz.de               15                              12.01.2010 — PHPUG-RHH
EAV DESIGN

                  Entity                    Entity_Attribute                         Value
                                                                     1:1
               entity_id          1:n
                                            ea_id                                 ea_id
                                            entity_id                             value_id
                                            attribute_id
                                            as_id
                                                               1:1                            1:1



               Attribute Set              Attribute                   Value Int                Value ...

             as_id                      attribute_id                 value_id                value_id
             as_name                    attribute_name               value                   value


Daniel Nitz — www.danielnitz.de                   16                                12.01.2010 — PHPUG-RHH
DESIGN PROBLEME


‣   verschiedene Datentypen

‣   definierte Spalten-/Attributsets

‣   keine Redundanz von Attributen

‣   Integrität gewahrt


Daniel Nitz — www.danielnitz.de   17   12.01.2010 — PHPUG-RHH
VORTEILE




Daniel Nitz — www.danielnitz.de      18      12.01.2010 — PHPUG-RHH
VORTEILE


‣   Hohe Flexibilität in der Gestaltung von Objektstrukturen

‣   Kein DBA zur Änderung der Schemata nötig

‣   Keine zusätzliche Programmierung bei Änderung der
    Schemata nötig


Daniel Nitz — www.danielnitz.de      19            12.01.2010 — PHPUG-RHH
NACHTEILE




Daniel Nitz — www.danielnitz.de       20      12.01.2010 — PHPUG-RHH
NACHTEILE


‣   Hohe Systemlast durch komplizierte SQL Queries

‣   Komplexe Programmierung von SQL Statements

‣   Verlust von DBMS-spezifischen Funktionalitäten

‣   Verlagerung von DBMS-Funktionen in die Anwendungslogik


Daniel Nitz — www.danielnitz.de       21            12.01.2010 — PHPUG-RHH
IN DER PRAXIS




Daniel Nitz — www.danielnitz.de         22        12.01.2010 — PHPUG-RHH
EAV MODEL LIBRARY

Dmg_Db_Eav:
‣   EAV Model Implementierung für das Zend Framework

‣   Auf Basis von Zend_Db und Zend_Db_Table

‣   Nutzung von Zend_Cache



Daniel Nitz — www.danielnitz.de   23          12.01.2010 — PHPUG-RHH
CODE BEISPIEL

 $options = new Dmg_Db_Eav_Config($array);

 // Person implements Dmg_Db_Eav_Abstract
 $personModel = new Person($options);

 $persons = $personModel->addAttributeFilter('age', 30)
    	 	 	 	 	           ->addAttributeFilter('name', 'daniel')
                        ->addFilter('active', 1)
                        ->addLimit(10)
                        ->load();




Daniel Nitz — www.danielnitz.de         24         12.01.2010 — PHPUG-RHH
CODE BEISPIEL
foreach ($persons as $person) {
	 $attributes = $person->getAttributes();
	 foreach ($attributes as $attribute) {
	 	 if (!$attribute->hasOptions()) {
	 	 	 echo $attribute->getName() . ': ' . $attribute->getValue();
	 	 } else {
	 	 	 foreach ($attribute->getOptions() as $option) {
	 	 	 	 echo $option->getName() . ': ' . $option->getValue();
	 	 	 }
	 	 }
	 }
}



Daniel Nitz — www.danielnitz.de         25        12.01.2010 — PHPUG-RHH
PERFORMANCE
 #            Time                                                                         Query
 1     0.223762989044    connect

                         SELECT `e`.*, `v`.*, `a`.*, `as`.*, `g`.*, `ga`.* FROM `eav_entity` AS `e` INNER JOIN `eav_value` AS `v` ON e.entity_id = v.entity_id INNER
                         JOIN `eav_attribute` AS `a` ON v.attribute_id = a.attribute_id INNER JOIN `eav_attribute_set` AS `as` ON e.attribute_set_id =
 2     0.42297410965
                         as.attribute_set_id INNER JOIN `eav_attribute_group` AS `g` ON g.attribute_set_id = as.attribute_set_id INNER JOIN
                         `eav_attribute_group_attribute` AS `ga` ON a.attribute_id = ga.attribute_id WHERE (e.entity_id = 1)

 3     0.0507569313049   DESCRIBE `eav_entity`

                         SELECT eav_value_varchar.*, CONCAT('varchar') AS type FROM eav_value_varchar WHERE value_id IN (1, 3) UNION SELECT
 4     0.757645130157    eav_value_int.*, CONCAT('int') AS type FROM eav_value_int WHERE value_id IN (2) UNION SELECT eav_value_text.*, CONCAT('text') AS
                         type FROM eav_value_text WHERE value_id IN (4)


 ...            ...                                                                           ...



Query Zeit beim Laden eines EAV Objektes ohne Cache mit 4
Attributen, eines davon hat 6 Attributoptionen: 1.949 sec
Nach dem Caching: 0.079 sec
Daniel Nitz — www.danielnitz.de                                             26                                                  12.01.2010 — PHPUG-RHH
FAZIT




Daniel Nitz — www.danielnitz.de     27    12.01.2010 — PHPUG-RHH
FAZIT

‣   EAV bietet gute Möglichkeiten eine Anwendung in der
    Datenschicht flexibel zu halten.

‣   Es gibt jedoch nur wenige Anwendungsfälle, in denen eine EAV
    Implementierung wirklich sinnvoll ist.

‣   Ein relationales Design sollte dem EAV, wenn möglich,
    vorgezogen werden.

Daniel Nitz — www.danielnitz.de     28             12.01.2010 — PHPUG-RHH
VIELEN DANK!

                                            Daniel Nitz
                                            [ zend certified engineer ]

                                            daniel@danielnitz.de
                                            twitter.com/danielnitz




Daniel Nitz — www.danielnitz.de        29                 12.01.2010 — PHPUG-RHH

Mais conteúdo relacionado

Mais procurados

MS Sql Server: Joining Databases
MS Sql Server: Joining DatabasesMS Sql Server: Joining Databases
MS Sql Server: Joining DatabasesDataminingTools Inc
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.boyney123
 
Agile Data Engineering - Intro to Data Vault Modeling (2016)
Agile Data Engineering - Intro to Data Vault Modeling (2016)Agile Data Engineering - Intro to Data Vault Modeling (2016)
Agile Data Engineering - Intro to Data Vault Modeling (2016)Kent Graziano
 
Database programming in vb net
Database programming in vb netDatabase programming in vb net
Database programming in vb netZishan yousaf
 
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMDong-Ho Lee
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQLPeter Eisentraut
 
Sql database object
Sql database objectSql database object
Sql database objectHarry Potter
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Khaled Anaqwa
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL CommandsShrija Madhu
 
Keith Schengili-Roberts - DITA Worst Practices
Keith Schengili-Roberts - DITA Worst PracticesKeith Schengili-Roberts - DITA Worst Practices
Keith Schengili-Roberts - DITA Worst PracticesJack Molisani
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship ModelNeil Neelesh
 
今から始める Lens/Prism
今から始める Lens/Prism今から始める Lens/Prism
今から始める Lens/PrismNaoki Aoyama
 

Mais procurados (20)

MS Sql Server: Joining Databases
MS Sql Server: Joining DatabasesMS Sql Server: Joining Databases
MS Sql Server: Joining Databases
 
AngularJS入門
AngularJS入門AngularJS入門
AngularJS入門
 
Javascript best practices
Javascript best practicesJavascript best practices
Javascript best practices
 
Trigger in DBMS
Trigger in DBMSTrigger in DBMS
Trigger in DBMS
 
Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.Introduction into ES6 JavaScript.
Introduction into ES6 JavaScript.
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Agile Data Engineering - Intro to Data Vault Modeling (2016)
Agile Data Engineering - Intro to Data Vault Modeling (2016)Agile Data Engineering - Intro to Data Vault Modeling (2016)
Agile Data Engineering - Intro to Data Vault Modeling (2016)
 
Database programming in vb net
Database programming in vb netDatabase programming in vb net
Database programming in vb net
 
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVM
 
MYSQL join
MYSQL joinMYSQL join
MYSQL join
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
 
Basic SQL and History
 Basic SQL and History Basic SQL and History
Basic SQL and History
 
Sql database object
Sql database objectSql database object
Sql database object
 
EER Model
EER ModelEER Model
EER Model
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
Keith Schengili-Roberts - DITA Worst Practices
Keith Schengili-Roberts - DITA Worst PracticesKeith Schengili-Roberts - DITA Worst Practices
Keith Schengili-Roberts - DITA Worst Practices
 
Entity Relationship Model
Entity Relationship ModelEntity Relationship Model
Entity Relationship Model
 
今から始める Lens/Prism
今から始める Lens/Prism今から始める Lens/Prism
今から始める Lens/Prism
 
Joins in dbms and types
Joins in dbms and typesJoins in dbms and types
Joins in dbms and types
 

Destaque

Entity Attribute Value (Eav)
Entity   Attribute   Value (Eav)Entity   Attribute   Value (Eav)
Entity Attribute Value (Eav)Tâm
 
Dare to build vertical design with relational data (Entity-Attribute-Value)
Dare to build vertical design with relational data (Entity-Attribute-Value)Dare to build vertical design with relational data (Entity-Attribute-Value)
Dare to build vertical design with relational data (Entity-Attribute-Value)Ivo Andreev
 
Best Practices: Datawarehouse Automation Conference September 20, 2012 - Amst...
Best Practices: Datawarehouse Automation Conference September 20, 2012 - Amst...Best Practices: Datawarehouse Automation Conference September 20, 2012 - Amst...
Best Practices: Datawarehouse Automation Conference September 20, 2012 - Amst...Erik Fransen
 
Implementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord modelsImplementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord modelsKostyantyn Stepanyuk
 
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...Roland Bouman
 
Data warehouse architecture
Data warehouse architectureData warehouse architecture
Data warehouse architecturepcherukumalla
 
Data Warehouse Design and Best Practices
Data Warehouse Design and Best PracticesData Warehouse Design and Best Practices
Data Warehouse Design and Best PracticesIvo Andreev
 
Building an Effective Data Warehouse Architecture
Building an Effective Data Warehouse ArchitectureBuilding an Effective Data Warehouse Architecture
Building an Effective Data Warehouse ArchitectureJames Serra
 

Destaque (13)

Eav Data Model Concepts
Eav Data Model ConceptsEav Data Model Concepts
Eav Data Model Concepts
 
Entity Attribute Value (Eav)
Entity   Attribute   Value (Eav)Entity   Attribute   Value (Eav)
Entity Attribute Value (Eav)
 
Extensible Data Modeling
Extensible Data ModelingExtensible Data Modeling
Extensible Data Modeling
 
Dare to build vertical design with relational data (Entity-Attribute-Value)
Dare to build vertical design with relational data (Entity-Attribute-Value)Dare to build vertical design with relational data (Entity-Attribute-Value)
Dare to build vertical design with relational data (Entity-Attribute-Value)
 
Best Practices: Datawarehouse Automation Conference September 20, 2012 - Amst...
Best Practices: Datawarehouse Automation Conference September 20, 2012 - Amst...Best Practices: Datawarehouse Automation Conference September 20, 2012 - Amst...
Best Practices: Datawarehouse Automation Conference September 20, 2012 - Amst...
 
Practical Object Oriented Models In Sql
Practical Object Oriented Models In SqlPractical Object Oriented Models In Sql
Practical Object Oriented Models In Sql
 
Implementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord modelsImplementation of EAV pattern for ActiveRecord models
Implementation of EAV pattern for ActiveRecord models
 
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...
Roland bouman modern_data_warehouse_architectures_data_vault_and_anchor_model...
 
SQL Outer Joins for Fun and Profit
SQL Outer Joins for Fun and ProfitSQL Outer Joins for Fun and Profit
SQL Outer Joins for Fun and Profit
 
Modern Data Architecture
Modern Data ArchitectureModern Data Architecture
Modern Data Architecture
 
Data warehouse architecture
Data warehouse architectureData warehouse architecture
Data warehouse architecture
 
Data Warehouse Design and Best Practices
Data Warehouse Design and Best PracticesData Warehouse Design and Best Practices
Data Warehouse Design and Best Practices
 
Building an Effective Data Warehouse Architecture
Building an Effective Data Warehouse ArchitectureBuilding an Effective Data Warehouse Architecture
Building an Effective Data Warehouse Architecture
 

Was ist eigentlich EAV?

  • 1. WAS IST EIGENTLICH EAV? Eine Einführung in das Entity-Attribute-Value Model PHP User Group Rheinhessen 12.01.2010 Mainz Daniel Nitz — www.danielnitz.de 1 12.01.2010 — PHPUG-RHH
  • 2. AGENDA 1. Definition 4. Nachteile 2. Anwendungsbeispiel 5. In der Praxis 3. Vorteile 6. Fazit Daniel Nitz — www.danielnitz.de 2 12.01.2010 — PHPUG-RHH
  • 3. DEFINITION Daniel Nitz — www.danielnitz.de 3 12.01.2010 — PHPUG-RHH
  • 4. DEFINITION Entity-Attribute-Value Model, auch bekannt als Object- Attribute-Value Model und Open Schema ist ein Datenmodell, welches dann zum Einsatz kommt, wenn die Anzahl der Attribute (Eigenschaften, Parameter) zur Beschreibung einer Sache (Entität oder Objekt) im Vorfeld nicht vorhersehbar sind. Daniel Nitz — www.danielnitz.de 4 12.01.2010 — PHPUG-RHH
  • 5. DEFINITION EAV ist ein Datenmodell für den Fall, dass die Anzahl der Attribute eines Objektes nicht vorhersehbar sind. Daniel Nitz — www.danielnitz.de 5 12.01.2010 — PHPUG-RHH
  • 6. DEFINITION Entity: Repräsentiert einen Datensatz, z.B. eine Produkt. Attribute: Stellt eine Eigenschaft dar, z.B. Größe, Farbe etc. Value: Beinhaltet den Eigenschaftswert, z.B. XL, blau etc. Daniel Nitz — www.danielnitz.de 6 12.01.2010 — PHPUG-RHH
  • 7. DEFINITION 1:n 1:1 Entity Attribute Value 3 Tabellen verknüpft mittels Foreign Keys. Daniel Nitz — www.danielnitz.de 7 12.01.2010 — PHPUG-RHH
  • 8. HÄ? Daniel Nitz — www.danielnitz.de 8 12.01.2010 — PHPUG-RHH
  • 9. ANWENDUNGSBEISPIEL Unterschied EAV im Vergleich zum relationalen Design Daniel Nitz — www.danielnitz.de 9 12.01.2010 — PHPUG-RHH
  • 10. ANWENDUNGSBEISPIEL ‣ Eine Person wird anhand einer eindeutigen Nummer identifiziert ‣ Eine Person hat einen Vornamen ‣ Eine Person hat einen Nachnamen ‣ Ein Person hat eine beliebige Anzahl von zusätzlichen Informationen (Alter, Gewicht, Größe etc.) Daniel Nitz — www.danielnitz.de 10 12.01.2010 — PHPUG-RHH
  • 11. RELATIONALES DESIGN Person Data person_id 1:1 person_id first_name age last_name weight height Daniel Nitz — www.danielnitz.de 11 12.01.2010 — PHPUG-RHH
  • 12. EAV DESIGN Entity Attribute Value 1:1 entity_id 1:n attribute_id attribute_id entity_id value attribute_name Daniel Nitz — www.danielnitz.de 12 12.01.2010 — PHPUG-RHH
  • 13. STORY Relationales Design: Die Person mit der Nummer 1 hat das Alter 30, hat ein Gewicht von 80, hat eine Größe von 180. EAV Design: Die Person mit der Nummer 1 hat das Attribut Alter mit dem Wert 30. Die Person mit der Nummer 1 hat das Attribut Gewicht mit dem Wert 80. Die Person mit der Nummer 1 hat das Attribut Größe mit dem Wert 180. Daniel Nitz — www.danielnitz.de 13 12.01.2010 — PHPUG-RHH
  • 14. DESIGN PROBLEME ‣ keine Datentypen ‣ keine definierten Spalten-/Attributsets ‣ Redundanz von Attributen ‣ keine Integrität Daniel Nitz — www.danielnitz.de 14 12.01.2010 — PHPUG-RHH
  • 15. EAV DESIGN Entity Attribute Value 1:1 entity_id 1:n attribute_id attribute_id entity_id value_id attribute_name 1:1 1:1 Value Int Value ... value_id value_id value value Daniel Nitz — www.danielnitz.de 15 12.01.2010 — PHPUG-RHH
  • 16. EAV DESIGN Entity Entity_Attribute Value 1:1 entity_id 1:n ea_id ea_id entity_id value_id attribute_id as_id 1:1 1:1 Attribute Set Attribute Value Int Value ... as_id attribute_id value_id value_id as_name attribute_name value value Daniel Nitz — www.danielnitz.de 16 12.01.2010 — PHPUG-RHH
  • 17. DESIGN PROBLEME ‣ verschiedene Datentypen ‣ definierte Spalten-/Attributsets ‣ keine Redundanz von Attributen ‣ Integrität gewahrt Daniel Nitz — www.danielnitz.de 17 12.01.2010 — PHPUG-RHH
  • 18. VORTEILE Daniel Nitz — www.danielnitz.de 18 12.01.2010 — PHPUG-RHH
  • 19. VORTEILE ‣ Hohe Flexibilität in der Gestaltung von Objektstrukturen ‣ Kein DBA zur Änderung der Schemata nötig ‣ Keine zusätzliche Programmierung bei Änderung der Schemata nötig Daniel Nitz — www.danielnitz.de 19 12.01.2010 — PHPUG-RHH
  • 20. NACHTEILE Daniel Nitz — www.danielnitz.de 20 12.01.2010 — PHPUG-RHH
  • 21. NACHTEILE ‣ Hohe Systemlast durch komplizierte SQL Queries ‣ Komplexe Programmierung von SQL Statements ‣ Verlust von DBMS-spezifischen Funktionalitäten ‣ Verlagerung von DBMS-Funktionen in die Anwendungslogik Daniel Nitz — www.danielnitz.de 21 12.01.2010 — PHPUG-RHH
  • 22. IN DER PRAXIS Daniel Nitz — www.danielnitz.de 22 12.01.2010 — PHPUG-RHH
  • 23. EAV MODEL LIBRARY Dmg_Db_Eav: ‣ EAV Model Implementierung für das Zend Framework ‣ Auf Basis von Zend_Db und Zend_Db_Table ‣ Nutzung von Zend_Cache Daniel Nitz — www.danielnitz.de 23 12.01.2010 — PHPUG-RHH
  • 24. CODE BEISPIEL $options = new Dmg_Db_Eav_Config($array); // Person implements Dmg_Db_Eav_Abstract $personModel = new Person($options); $persons = $personModel->addAttributeFilter('age', 30) ->addAttributeFilter('name', 'daniel') ->addFilter('active', 1) ->addLimit(10) ->load(); Daniel Nitz — www.danielnitz.de 24 12.01.2010 — PHPUG-RHH
  • 25. CODE BEISPIEL foreach ($persons as $person) { $attributes = $person->getAttributes(); foreach ($attributes as $attribute) { if (!$attribute->hasOptions()) { echo $attribute->getName() . ': ' . $attribute->getValue(); } else { foreach ($attribute->getOptions() as $option) { echo $option->getName() . ': ' . $option->getValue(); } } } } Daniel Nitz — www.danielnitz.de 25 12.01.2010 — PHPUG-RHH
  • 26. PERFORMANCE # Time Query 1 0.223762989044 connect SELECT `e`.*, `v`.*, `a`.*, `as`.*, `g`.*, `ga`.* FROM `eav_entity` AS `e` INNER JOIN `eav_value` AS `v` ON e.entity_id = v.entity_id INNER JOIN `eav_attribute` AS `a` ON v.attribute_id = a.attribute_id INNER JOIN `eav_attribute_set` AS `as` ON e.attribute_set_id = 2 0.42297410965 as.attribute_set_id INNER JOIN `eav_attribute_group` AS `g` ON g.attribute_set_id = as.attribute_set_id INNER JOIN `eav_attribute_group_attribute` AS `ga` ON a.attribute_id = ga.attribute_id WHERE (e.entity_id = 1) 3 0.0507569313049 DESCRIBE `eav_entity` SELECT eav_value_varchar.*, CONCAT('varchar') AS type FROM eav_value_varchar WHERE value_id IN (1, 3) UNION SELECT 4 0.757645130157 eav_value_int.*, CONCAT('int') AS type FROM eav_value_int WHERE value_id IN (2) UNION SELECT eav_value_text.*, CONCAT('text') AS type FROM eav_value_text WHERE value_id IN (4) ... ... ... Query Zeit beim Laden eines EAV Objektes ohne Cache mit 4 Attributen, eines davon hat 6 Attributoptionen: 1.949 sec Nach dem Caching: 0.079 sec Daniel Nitz — www.danielnitz.de 26 12.01.2010 — PHPUG-RHH
  • 27. FAZIT Daniel Nitz — www.danielnitz.de 27 12.01.2010 — PHPUG-RHH
  • 28. FAZIT ‣ EAV bietet gute Möglichkeiten eine Anwendung in der Datenschicht flexibel zu halten. ‣ Es gibt jedoch nur wenige Anwendungsfälle, in denen eine EAV Implementierung wirklich sinnvoll ist. ‣ Ein relationales Design sollte dem EAV, wenn möglich, vorgezogen werden. Daniel Nitz — www.danielnitz.de 28 12.01.2010 — PHPUG-RHH
  • 29. VIELEN DANK! Daniel Nitz [ zend certified engineer ] daniel@danielnitz.de twitter.com/danielnitz Daniel Nitz — www.danielnitz.de 29 12.01.2010 — PHPUG-RHH