SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances

SSIS Tutorial For Beginners | SQL Server Integration Services (SSIS) | MSBI T...
SSIS Tutorial For Beginners | SQL Server Integration Services (SSIS) | MSBI T...SSIS Tutorial For Beginners | SQL Server Integration Services (SSIS) | MSBI T...
SSIS Tutorial For Beginners | SQL Server Integration Services (SSIS) | MSBI T...Edureka!
 
Sql server-integration-services-ssis-step-by-step-sample-chapters
Sql server-integration-services-ssis-step-by-step-sample-chaptersSql server-integration-services-ssis-step-by-step-sample-chapters
Sql server-integration-services-ssis-step-by-step-sample-chaptersNadinKa Karimou
 
Introduction of ssis
Introduction of ssisIntroduction of ssis
Introduction of ssisdeepakk073
 
SQL Server Integration Services
SQL Server Integration ServicesSQL Server Integration Services
SQL Server Integration ServicesRobert MacLean
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity FrameworkDoncho Minkov
 
1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - IntroductionVarun A M
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScriptShahDhruv21
 
Martesclass: Google Data Studio
Martesclass: Google Data StudioMartesclass: Google Data Studio
Martesclass: Google Data StudioAukera
 
Spring cheat sheet
Spring cheat sheetSpring cheat sheet
Spring cheat sheetMark Papis
 
Databases in Android Application
Databases in Android ApplicationDatabases in Android Application
Databases in Android ApplicationMark Lester Navarro
 
Binary Search Tree and AVL
Binary Search Tree and AVLBinary Search Tree and AVL
Binary Search Tree and AVLKatang Isip
 
Hosting a website on IIS Server
Hosting a website on IIS ServerHosting a website on IIS Server
Hosting a website on IIS ServerDinesh Vasamshetty
 

Tendances (20)

SSIS Tutorial For Beginners | SQL Server Integration Services (SSIS) | MSBI T...
SSIS Tutorial For Beginners | SQL Server Integration Services (SSIS) | MSBI T...SSIS Tutorial For Beginners | SQL Server Integration Services (SSIS) | MSBI T...
SSIS Tutorial For Beginners | SQL Server Integration Services (SSIS) | MSBI T...
 
Triggers and Stored Procedures
Triggers and Stored ProceduresTriggers and Stored Procedures
Triggers and Stored Procedures
 
Sql server-integration-services-ssis-step-by-step-sample-chapters
Sql server-integration-services-ssis-step-by-step-sample-chaptersSql server-integration-services-ssis-step-by-step-sample-chapters
Sql server-integration-services-ssis-step-by-step-sample-chapters
 
PowerBI Training
PowerBI Training PowerBI Training
PowerBI Training
 
Introduction of ssis
Introduction of ssisIntroduction of ssis
Introduction of ssis
 
SQL Server Integration Services
SQL Server Integration ServicesSQL Server Integration Services
SQL Server Integration Services
 
4.C#
4.C#4.C#
4.C#
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
 
1. SQL Basics - Introduction
1. SQL Basics - Introduction1. SQL Basics - Introduction
1. SQL Basics - Introduction
 
BI para todos
BI para todosBI para todos
BI para todos
 
Cognos demo.
Cognos demo.Cognos demo.
Cognos demo.
 
BINARY SEARCH TREE
BINARY SEARCH TREEBINARY SEARCH TREE
BINARY SEARCH TREE
 
Event In JavaScript
Event In JavaScriptEvent In JavaScript
Event In JavaScript
 
Martesclass: Google Data Studio
Martesclass: Google Data StudioMartesclass: Google Data Studio
Martesclass: Google Data Studio
 
Power bi
Power biPower bi
Power bi
 
Spring cheat sheet
Spring cheat sheetSpring cheat sheet
Spring cheat sheet
 
Databases in Android Application
Databases in Android ApplicationDatabases in Android Application
Databases in Android Application
 
Binary Search Tree and AVL
Binary Search Tree and AVLBinary Search Tree and AVL
Binary Search Tree and AVL
 
Power bi
Power biPower bi
Power bi
 
Hosting a website on IIS Server
Hosting a website on IIS ServerHosting a website on IIS Server
Hosting a website on IIS Server
 

En vedette

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
 

En vedette (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