[DDC-1602] Executors for Class Table Inheritance (JOINED) are extremely slow on MySQL Created: 15/Jan/12 Updated: 27/Jun/12 |
|
| Status: | Open |
| Project: | Doctrine 2 - ORM |
| Component/s: | DQL |
| Affects Version/s: | 2.2-BETA2 |
| Fix Version/s: | None |
| Security Level: | All |
| Type: | Improvement | Priority: | Major |
| Reporter: | Michael Moravec | Assignee: | Benjamin Eberlei |
| Resolution: | Unresolved | Votes: | 3 |
| Labels: | None | ||
| Environment: |
Debian, MySQL 5.5.17 |
||
| Description |
|
Update and delete executors for Class Table Inheritance (JOINED) are extremely slow on MySQL platform. It is most probably due to use of subselect on the temporary table. /** * @Entity * @InheritanceType("JOINED") * @DiscriminatorColumn(name="discr", type="string") * @DiscriminatorMap({"root" = "Root", "a" = "SubA"}) */ class Root { /** * @Column(type="integer") * @Id * @GeneratedValue */ private $id; /** * @Column(type="integer") */ private $xyz; } /** * @Entity */ class SubA extends Root { /** * @Column(type="integer") */ private $foo; } Now lets perform a simple DQL UPDATE: UPDATE Entities\Root r SET r.xyz = 123 WHERE r.id > ? (note: always the upper half of entries) CREATE TEMPORARY TABLE Root_id_tmp (id INT NOT NULL) INSERT INTO Root_id_tmp (id) SELECT t0.id FROM Root t0 LEFT JOIN SubA s0_ ON t0.id = s0_.id WHERE t0.id > 25000 UPDATE Root SET xyz = 123 WHERE (id) IN (SELECT id FROM Root_id_tmp) DROP TEMPORARY TABLE Root_id_tmp The time spent on this on MySQL 5.5.17 and PostgreSQL 9.1 is:
As you can see, MySQL is drastically slower on even relatively small tables. This currently makes Doctrine unusable for this type of inheritance on MySQL. The solution probably would be to avoid subselect in WHERE clause in Doctrine\ORM\Query\Exec\MultiTableUpdateExecutor and Doctrine\ORM\Query\Exec\MultiTableDeleteExecutor. Feel free to try/modify the test script yourself, it's here. |
| Comments |
| Comment by Benjamin Eberlei [ 15/Jan/12 ] | ||||||||||||||||
|
Its not a bug as it works. The performance drawback of JTI is discussed in the manual http://www.doctrine-project.org/docs/orm/2.1/en/reference/inheritance-mapping.html. Changing this would be an improvement where we would hint if databases prefer subselects or joins for different operations. This would increase complexity of the SQL generation since now we are getting along with just one SQL generation strategy. | ||||||||||||||||
| Comment by Michael Moravec [ 11/May/12 ] | ||||||||||||||||
|
Any chance to get this implemented before 2.3? | ||||||||||||||||
| Comment by Michael Moravec [ 11/May/12 ] | ||||||||||||||||
|
I've made a change in DBAL and ORM code to implement a solution issue. It's currently more likely a proof of concept. With the change, my results are (approximately):
Currently only update executor was changed. Looking forward for your opinions. | ||||||||||||||||
| Comment by Michael Moravec [ 27/Jun/12 ] | ||||||||||||||||
|
bump |