SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
Использование специальных
 типов данных PostgreSQL в
    Александр Коротков, Интаро
        Doctrine 2 ORM
            Alexander Korotkov
          aekorotkov@gmail.com




                                 Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




    Произвольный набор свойств

   • Товар (e-commerce)

   • Документ (документооборот,
     каталоги и т.д.)



                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




                         Подходы

   • Entity-Attribute-Value
   • Каждое свойство – отдельная
     колонка
   • СУБД-специфичные методы


                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




     Entity-Attribute-Value (EAV)


                   1     *             *    1
       Entity                Value              Attribute




                                                      Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




     Entity-Attribute-Value (EAV)
   • Не нужно изменять модель

   • Сложные запросы
   • Медленно


                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




                               EAV




                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




              Добавление каждого
               свойства в модель
   • Запросы работают быстро

   • Необходимо динамически
     менять модель
   • Много столбцов

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




              Добавление каждого
               свойства в модель




                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




                      PostgreSQL




                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




                             hstore


                               SQL
                           NoSQL
                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




            hstore в PostgreSQL
   • Не нужно изменять модель
   • Прозрачная работа со стороны
     PHP
   • Запросы работают быстро

   • СУБД-зависимое решение

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




          Объявление в модели
   /**
    * @var array $properties
    *
    * @ORMColumn(name="properties",
     type="hstore", nullable=true)
    */
   private $properties;

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




            Сохранение данных
   $product = new Product();
   $product->setName(‘box’);
   $product->setProperties(array(
     'w' => 80,
     'h' => 60
   ));
   $em->persist($product);
   $em->flush();

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




             Прозрачная работа




                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




         Что происходит в базе
   crm=# select id, name, properties from
   product;

    id | name | properties
   ----+------+----------------------
     1 | box | "h"=>"60", "w"=>"80"
   (1 row)

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM



            Извлечение из базы
   $product = $this->getDoctrine()
     ->getRepository(‘Product')
     ->find(1);
   print_r($product->getProperties());
   Array (
       [h] => 60
       [w] => 80
   )
                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




    Функция fetchval: фильтрация

   $query = $em->createQuery(“
     SELECT p
     FROM Product p
     WHERE
       fetchval(p.properties, 'w') =
     :value
   “)->setParameter('value', '80');

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




                               SQL
   SELECT
     ...
   FROM
     product i0_
   WHERE
     fetchval(i0_.properties, 'w') = ?

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




     Функция fetchval: сортировка

   $query = $em->createQuery(“
     SELECT
       p,
       fetchval(p.properties, 'w') AS w
     FROM Product p
     ORDER BY w
   “);

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




                               SQL
   SELECT
     ...,
     fetchval(i0_.properties, 'w') AS sclr13,
     ...
   FROM
     product i0_
   ORDER BY
     sclr13 ASC

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




              Операторы >= и <=
   $query = $em->createQuery(‘
     SELECT p
     FROM Product p
     WHERE p.properties >= :property
   ’)->setParameter('property',
     array('w' => 80), 'hstore');

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




                           Удобно




                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




                             Хак (((
   CREATE OPERATOR <=
   (
     PROCEDURE = hs_contained,
     LEFTARG = hstore,
     RIGHTARG = hstore,
     COMMUTATOR = >=,
     RESTRICT = contsel,
     JOIN = contjoinsel);

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




               Скорости нннада?
                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




                              Index
   CREATE INDEX
      i_crm_product_properties_w
   ON
      i_crm_product
      (
         fetchval(properties, 'w')
      );

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




                              Index
   CREATE INDEX
      i_crm_product_properties
   ON
      i_crm_product
   USING
      gin
   (properties);

                                                    Alexadner Korotkov
Специальные типы данных PostgreSQL в Doctrine ORM




          Спасибо за внимание!




                                                    Alexadner Korotkov

Más contenido relacionado

Destacado

Tugas 3 Rangkuman Protocol DNS, FTP, HTTP, dan SMTP
Tugas 3 Rangkuman Protocol DNS, FTP, HTTP, dan SMTPTugas 3 Rangkuman Protocol DNS, FTP, HTTP, dan SMTP
Tugas 3 Rangkuman Protocol DNS, FTP, HTTP, dan SMTPRobby Firmansyah
 
Researchers - recommendations from AIGLIA2014
Researchers - recommendations from AIGLIA2014Researchers - recommendations from AIGLIA2014
Researchers - recommendations from AIGLIA2014futureagricultures
 
Donor Relationship Management
Donor Relationship Management Donor Relationship Management
Donor Relationship Management Yellow Umbrella
 
File management 101
File management 101File management 101
File management 101Niamh Foley
 
Goose chasegroup
Goose chasegroupGoose chasegroup
Goose chasegroupLes Davy
 
Steve Wiggins: Agricultural_policy - issues of consensus and debate
Steve Wiggins: Agricultural_policy - issues of consensus and debateSteve Wiggins: Agricultural_policy - issues of consensus and debate
Steve Wiggins: Agricultural_policy - issues of consensus and debatefutureagricultures
 
Business Innovation, CSR and Competitive Advantage: Strategic pathways to value
Business Innovation, CSR and Competitive Advantage: Strategic pathways to valueBusiness Innovation, CSR and Competitive Advantage: Strategic pathways to value
Business Innovation, CSR and Competitive Advantage: Strategic pathways to valueWayne Dunn
 
Learn OpenStack from trystack.cn ——Folsom in practice
Learn OpenStack from trystack.cn  ——Folsom in practiceLearn OpenStack from trystack.cn  ——Folsom in practice
Learn OpenStack from trystack.cn ——Folsom in practiceOpenCity Community
 
How are drugs developed? - Lesson plans
How are drugs developed? - Lesson plansHow are drugs developed? - Lesson plans
How are drugs developed? - Lesson plansXplore Health
 
ร้านกาแฟวาวี
ร้านกาแฟวาวีร้านกาแฟวาวี
ร้านกาแฟวาวี0873562346
 
Powerfull point ala Wenni
Powerfull point ala WenniPowerfull point ala Wenni
Powerfull point ala WenniWenni Meliana
 
Business Presentation[1]
Business Presentation[1]Business Presentation[1]
Business Presentation[1]wellaloe
 
Our Services increase your business as a Brand name.
Our Services increase your business as a Brand name.Our Services increase your business as a Brand name.
Our Services increase your business as a Brand name.Aurelius Corporate Solutions
 
Scalable javascript application - طراحی نرم افزارهای مقیاس پذیر با جاوا اسکریپت
Scalable javascript application -  طراحی نرم افزارهای مقیاس پذیر با جاوا اسکریپتScalable javascript application -  طراحی نرم افزارهای مقیاس پذیر با جاوا اسکریپت
Scalable javascript application - طراحی نرم افزارهای مقیاس پذیر با جاوا اسکریپتefazati
 
Assessing enablers and constrainers of graduation
Assessing enablers and constrainers of graduationAssessing enablers and constrainers of graduation
Assessing enablers and constrainers of graduationfutureagricultures
 

Destacado (20)

Seven things to make your pup ONE in a million
Seven things to make your pup ONE in a millionSeven things to make your pup ONE in a million
Seven things to make your pup ONE in a million
 
Tugas 3 Rangkuman Protocol DNS, FTP, HTTP, dan SMTP
Tugas 3 Rangkuman Protocol DNS, FTP, HTTP, dan SMTPTugas 3 Rangkuman Protocol DNS, FTP, HTTP, dan SMTP
Tugas 3 Rangkuman Protocol DNS, FTP, HTTP, dan SMTP
 
Researchers - recommendations from AIGLIA2014
Researchers - recommendations from AIGLIA2014Researchers - recommendations from AIGLIA2014
Researchers - recommendations from AIGLIA2014
 
Donor Relationship Management
Donor Relationship Management Donor Relationship Management
Donor Relationship Management
 
File management 101
File management 101File management 101
File management 101
 
Proses Start-Up Komputer
Proses Start-Up KomputerProses Start-Up Komputer
Proses Start-Up Komputer
 
Goose chasegroup
Goose chasegroupGoose chasegroup
Goose chasegroup
 
Steve Wiggins: Agricultural_policy - issues of consensus and debate
Steve Wiggins: Agricultural_policy - issues of consensus and debateSteve Wiggins: Agricultural_policy - issues of consensus and debate
Steve Wiggins: Agricultural_policy - issues of consensus and debate
 
Business Innovation, CSR and Competitive Advantage: Strategic pathways to value
Business Innovation, CSR and Competitive Advantage: Strategic pathways to valueBusiness Innovation, CSR and Competitive Advantage: Strategic pathways to value
Business Innovation, CSR and Competitive Advantage: Strategic pathways to value
 
Learn OpenStack from trystack.cn ——Folsom in practice
Learn OpenStack from trystack.cn  ——Folsom in practiceLearn OpenStack from trystack.cn  ——Folsom in practice
Learn OpenStack from trystack.cn ——Folsom in practice
 
How are drugs developed? - Lesson plans
How are drugs developed? - Lesson plansHow are drugs developed? - Lesson plans
How are drugs developed? - Lesson plans
 
長野市地域きらめき隊 2016.02.02
長野市地域きらめき隊 2016.02.02長野市地域きらめき隊 2016.02.02
長野市地域きらめき隊 2016.02.02
 
Notam 24-04-2015
Notam 24-04-2015Notam 24-04-2015
Notam 24-04-2015
 
01 05-14
01 05-1401 05-14
01 05-14
 
ร้านกาแฟวาวี
ร้านกาแฟวาวีร้านกาแฟวาวี
ร้านกาแฟวาวี
 
Powerfull point ala Wenni
Powerfull point ala WenniPowerfull point ala Wenni
Powerfull point ala Wenni
 
Business Presentation[1]
Business Presentation[1]Business Presentation[1]
Business Presentation[1]
 
Our Services increase your business as a Brand name.
Our Services increase your business as a Brand name.Our Services increase your business as a Brand name.
Our Services increase your business as a Brand name.
 
Scalable javascript application - طراحی نرم افزارهای مقیاس پذیر با جاوا اسکریپت
Scalable javascript application -  طراحی نرم افزارهای مقیاس پذیر با جاوا اسکریپتScalable javascript application -  طراحی نرم افزارهای مقیاس پذیر با جاوا اسکریپت
Scalable javascript application - طراحی نرم افزارهای مقیاس پذیر با جاوا اسکریپت
 
Assessing enablers and constrainers of graduation
Assessing enablers and constrainers of graduationAssessing enablers and constrainers of graduation
Assessing enablers and constrainers of graduation
 

Más de Alexander Korotkov

Solving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsSolving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsAlexander Korotkov
 
In-memory OLTP storage with persistence and transaction support
In-memory OLTP storage with persistence and transaction supportIn-memory OLTP storage with persistence and transaction support
In-memory OLTP storage with persistence and transaction supportAlexander Korotkov
 
Jsquery - the jsonb query language with GIN indexing support
Jsquery - the jsonb query language with GIN indexing supportJsquery - the jsonb query language with GIN indexing support
Jsquery - the jsonb query language with GIN indexing supportAlexander Korotkov
 
Open Source SQL databases enter millions queries per second era
Open Source SQL databases enter millions queries per second eraOpen Source SQL databases enter millions queries per second era
Open Source SQL databases enter millions queries per second eraAlexander Korotkov
 

Más de Alexander Korotkov (7)

Solving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsSolving PostgreSQL wicked problems
Solving PostgreSQL wicked problems
 
In-memory OLTP storage with persistence and transaction support
In-memory OLTP storage with persistence and transaction supportIn-memory OLTP storage with persistence and transaction support
In-memory OLTP storage with persistence and transaction support
 
Oh, that ubiquitous JSON !
Oh, that ubiquitous JSON !Oh, that ubiquitous JSON !
Oh, that ubiquitous JSON !
 
Jsquery - the jsonb query language with GIN indexing support
Jsquery - the jsonb query language with GIN indexing supportJsquery - the jsonb query language with GIN indexing support
Jsquery - the jsonb query language with GIN indexing support
 
Our answer to Uber
Our answer to UberOur answer to Uber
Our answer to Uber
 
The future is CSN
The future is CSNThe future is CSN
The future is CSN
 
Open Source SQL databases enter millions queries per second era
Open Source SQL databases enter millions queries per second eraOpen Source SQL databases enter millions queries per second era
Open Source SQL databases enter millions queries per second era
 

Использование специальных типов данных PostgreSQL в ORM Doctrine