spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

Better performance from mapper custom without relations #270

Open dertin opened 5 years ago

dertin commented 5 years ago

I have found a way to make the answer quicker when I need to make a query without having to care about the relations of the entities.

faster

$this->connection()->fetchAll( 'SELECT test.*, foo.text FROM test INNER JOIN foo ON foo.id = test.idFoo' );
$this->connection()->executeUpdate('DELETE FROM test');

slower $this->query('SELECT test.*, foo.text FROM test INNER JOIN foo ON foo.id = test.idFoo' );

The query() method applies actions in all relationships and this slows down the result, sometimes it is not necessary, when you can perform join in the sql statement.

Tested in blackfire.io