Doctrineã®ãã«ã¯ã¤ã³ãµã¼ãã¯ãã«ãã¤ã³ãµã¼ãã§ã¯ãªã[Doctrine][Symfony2][ORM]
ä»åã¯Doctrineã®æ³¨æç¹çãªæã®åå¿é²ã¨ãã¦ã
Doctrine 2 Batch Processing — Doctrine Project
doctrineã®ãã«ã¯ã¤ã³ãµã¼ãã¯insertæã1ã¤ã«ã¾ã¨ããããããã§ã¯ãªã
åã¯ãã«ã¯ã¤ã³ãµã¼ãã¨ããã°æ¬¡ã®ãããªSQLãæ³åãã¦ãã¾ããã
insert into (...) values (...), (...), (...), ...
ãããã¼ãã«ã«å¯¾ãã¦è¤æ°è¡ã¤ã³ãµã¼ãããããã¨ãã«ãinsertæã並ã¹ãªãã¦ãã¤ã³ãµã¼ãããå¤ã並ã¹ã¦ããã°ãã®åæ°åã¤ã³ãµã¼ãããã¨ãããã¤ã§ãã
æ®éã®ã¤ã³ãµã¼ãã並ã¹ããããé常ã«é«éãã¤åãåãããã®ãï¼åã§æ¸ãã®ã§ã¹ãã¼ãã§ãã
ã£ã¦ããDoctrineã§ããã®åããã§ãããã ã¼ã¨ç°¡åã«æã£ã¦ãã¾ã£ãã®ã§ãããããèªãã¨Doctrineã®æä¾ããbulk insertã¯ãã®ãããªæåã§ã¯ãªããããªã®ã§ãã
Doctrineæ°ã
Some people seem to be wondering why Doctrine does not use multi-inserts (insert into (...) values (...), (...), (...), ... First of all, this syntax is only supported on mysql and newer postgresql versions. Secondly, there is no easy way to get hold of all the generated identifiers in such a multi-insert when using AUTO_INCREMENT or SERIAL and an ORM needs the identifiers for identity management of the objects. Lastly, insert performance is rarely the bottleneck of an ORM. Normal inserts are more than fast enough for most situations and if you really want to do fast bulk inserts, then a multi-insert is not the best way anyway, i.e. Postgres COPY or Mysql LOAD DATA INFILE are several orders of magnitude faster. These are the reasons why it is not worth the effort to implement an abstraction that performs multi-inserts on mysql and postgresql in an ORM. I hope that clears up some questionmarks.
åãæ³åãã¦ãããã«ã¯ã¤ã³ãµã¼ãã¯ãã«ãã¤ã³ãµã¼ã
ã¨ããè¨èã§è¡¨ç¾ããã¦ãã¦ãDoctrineã¯ããã§ã¯ãªããã¨æ¸ããã¦ãã¾ãã
ãã®ãã«ãã¤ã³ãµã¼ãè¨æ³ã¯mysqlã¨æ°ããpostgresqlã§ãããµãã¼ãããã¦ããªãããããã®ä¸æ©æ½è±¡åã¬ã¤ã¤ã¼ã§ããDoctrine ORMã¨ãã¦ã¯ãã®å½¢ããµãã¼ãã¯ããªãã¨ã
ORMã¨ãã¦ã¯æ®éã®insertãããã«ããã¯ã«ãªããã¨ã¯ã¾ãç¨(使ãæ¹ãéã)ã§ãã©ããã¦ãæ©ããæ±ããinsertãããããªããã«ãã¤ã³ãµã¼ããããããé«éãªãã¡ã¤ã«ãã¼ãã«ããã¤ã³ãµã¼ãLOAD DATA INFILE
ããã¾ããããã¨ã
ãããªãããªæ¨ã®è¨è¿°ãããã¦ãã¾ãã
ææ³
確ãã«ORMã ããã£ã¦ããçå°ã«ãªãã®ã§ããããã¾ããã£ããèªãã§ãªãã£ãåã¯ãããããã使ãããã ããORMã«ãã®ãã«ã¯ã¤ã³ãµã¼ãæ©è½ã¤ãã¦ã«ã¸ã¥ã¢ã«ã«ã§ããããã«ãªã£ãã®ãã¼ï¼è²¬åã¯ã¡ãã£ã¨è¶ ãã¦ãæãããã©ä¾¿å©ãã¨ãã¬ã¼ããªãããããããã :)ãã¨æã£ã¦ãã¾ãã¾ããw
ã ããä¸ã§è²¼ã£ãããã¥ã¡ã³ãã®ä¾ã§ãbulk sizeã20ãªãã¦ããå°ãããµã¤ãºã®ã¤ã³ãµã¼ããµã¤ã¯ã«ã ã£ãã®ã§ãããbulk sizeãæ®éã®ãã«ãã¤ã³ãµã¼ãã£ã½ã大ããããã¨ãã®åã®insertãèµ°ã£ã¦DBã¸ã®insertæ»æã¿ããã«ãªã£ã¦ãã¾ãã®ã§ï½
ãããã§å³å¹æ§ãæ±ãããããã¨ããªãã¨æã(ãªãããã«ããããåãã¹ã)ã®ã§ãã¡ã¢ãªå¹çã¨éãã®ãã©ã³ã¹ãèããæã«ã¬ãã¬ãã¨æéã¯ã¾ãæ°ã«ããéè¡é転ãããã¿ãããªã®ããã®Doctrineã®æä¾ããbulk insertæ©è½ã§å®è£ ãããè¯ãã®ã§ã¯ãªãããªã¼ã¨æãã¾ããã
ã©ããã¦ããã«ãã¤ã³ãµã¼ããããããã°DBALã¬ã¤ã¤ã¼ã使ã£ã¦ç´ã«æ¸ãã¦ãã¾ãã°OKã¨æãã¾ã:)
ã¨ããèªåçã«ã¯è ¹è½ã¡ããã¨ããã§ãã¡ã¤ããã®ã§è¯ãã£ãã§ãã
ã¾ã¨ã
- Doctrineã®bulk insertã¯ããè¦ããã«ãã¤ã³ãµã¼ãã§ã¯ãªã
- ãã«ãã¤ã³ãµã¼ããããããã°DBALãç¨ãã¦SQLãæ¸ã
- 大è¦æ¨¡ãã¼ã¿ãé«éã«å¦çããããã°ãã«ãã¤ã³ãµã¼ãã§ã¯ãªããã¡ã¤ã«ã§ã®ã¤ã³ãµã¼ããè¡ã
ãããã«
ããåã®ããã«ä¿ã«è¨ããã«ãã¤ã³ãµã¼ãã®æè¦ã§ä½¿ã£ã¦ããæ¹ã¯ãçæãï¼ å¤§è¦æ¨¡ãã¼ã¿ã®æã«æ³å以ä¸ã«æéãããã£ããæ³å以ä¸ã«è² è·ãããã£ãããã¦ãã¾ãããããã¾ããã
解éã®ééã£ã¦ãæã¨ããã£ããæãã¦ãã ããã¨ã¨ã¦ãå¬ããã§ãmm