DDC-1706: aggregate all writes does not work #2148

Closed
opened 2026-01-22 13:42:41 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 15, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user jforet:

I have 1 entity :

namespace Test\DoctrineBundle\Entity;
use Doctrine\ORM\Mapping as ORM;

/****
 * Test\DoctrineBundle\Entity\User
 *
 * @ORM\Table(name="user")
 * @ORM\Entity
 */
class User
{
    /****
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /****
     * @ORM\Column(name="name", type="string", length=255)
     */
    private $name;

...

In controller, i create 2 users, i persist and i flush

    public function indexAction()
    {
        $em = $this->getDoctrine()->getEntityManager();
        $repository = $em->getRepository('TestDoctrineBundle:User');

        $user = new User();
        $user->setName('name-'.rand(1, 1000));
        $em->persist($user);

        $user = new User();
        $user->setName('name-'.rand(1, 1000));
        $em->persist($user);

        $em->flush();
        return array();
    }

Results, i have 3 requests
[2012-03-15 08:23:53] doctrine.DEBUG: SET NAMES UTF8
[2012-03-15 08:23:53] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-683"})
[2012-03-15 08:23:53] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-638"})

I expect to have only 2 requests because i think "INSERT" lines have to be into one single transaction.

I am on dev environment, because in production, i can not know how many request i have.

Originally created by @doctrinebot on GitHub (Mar 15, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user jforet: I have 1 entity : ``` namespace Test\DoctrineBundle\Entity; use Doctrine\ORM\Mapping as ORM; /**** * Test\DoctrineBundle\Entity\User * * @ORM\Table(name="user") * @ORM\Entity */ class User { /**** * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /**** * @ORM\Column(name="name", type="string", length=255) */ private $name; ... ``` In controller, i create 2 users, i persist and i flush ``` public function indexAction() { $em = $this->getDoctrine()->getEntityManager(); $repository = $em->getRepository('TestDoctrineBundle:User'); $user = new User(); $user->setName('name-'.rand(1, 1000)); $em->persist($user); $user = new User(); $user->setName('name-'.rand(1, 1000)); $em->persist($user); $em->flush(); return array(); } ``` Results, i have 3 requests [2012-03-15 08:23:53] doctrine.DEBUG: SET NAMES UTF8 [2012-03-15 08:23:53] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-683"}) [2012-03-15 08:23:53] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-638"}) I expect to have only 2 requests because i think "INSERT" lines have to be into one single transaction. I am on dev environment, because in production, i can not know how many request i have.
admin added the Bug label 2026-01-22 13:42:41 +01:00
admin closed this issue 2026-01-22 13:42:41 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 15, 2012):

Comment created by @beberlei:

This has nothing to do with each other. You are just showing the log output. The Begin and Commit Statements are not listed in the log, the queries are still executed consequitevly, but they are aggregated in the transaction.

@doctrinebot commented on GitHub (Mar 15, 2012): Comment created by @beberlei: This has nothing to do with each other. You are just showing the log output. The Begin and Commit Statements are not listed in the log, the queries are still executed consequitevly, but they are aggregated in the transaction.
Author
Owner

@doctrinebot commented on GitHub (Mar 15, 2012):

Comment created by jforet:

Thank you, Benjamin. Ok I understand what you say.
But I think it's too simple, or the tools provide incomplete information.

1st sample :

$user = new User();
$user->setName('name-1');
$em->persist($user);

$user = new User();
$user->setName('name-2');
$em->persist($user);

$em->flush();

$user = new User();
$user->setName('name-3');
$em->persist($user);

$em->flush();

$user = new User();
$user->setName('name-4');
$em->persist($user);

$em->flush();

The dev.log gives 4 queries ; the webprofiler bar in sf shows 4 queries.
[2012-03-15 11:50:01] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-1"})
[2012-03-15 11:50:01] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-2"})
[2012-03-15 11:50:01] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-3"})
[2012-03-15 11:50:01] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-4"})

2nd sample :

$user = new User();
$user->setName('name-1');
$em->persist($user);

$user = new User();
$user->setName('name-2');
$em->persist($user);

$user = new User();
$user->setName('name-3');
$em->persist($user);

$user = new User();
$user->setName('name-4');
$em->persist($user);

$em->flush();

The dev.log gives 4 queries ; the webprofiler bar in sf shows 4 queries.
[2012-03-15 11:51:31] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-1"})
[2012-03-15 11:51:31] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-2"})
[2012-03-15 11:51:31] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-3"})
[2012-03-15 11:51:31] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-4"})

In 1st sample, there is 3 transactions.
In 2nd sample, there is 1 transaction.

Is there a possibility to know number of transactions because i think it can help developpers in order to have better performances.

Maybe it is not in doctrine, it is in Symfony webprofiler; what do you think ?

@doctrinebot commented on GitHub (Mar 15, 2012): Comment created by jforet: Thank you, Benjamin. Ok I understand what you say. But I think it's too simple, or the tools provide incomplete information. **1st sample :** ``` $user = new User(); $user->setName('name-1'); $em->persist($user); $user = new User(); $user->setName('name-2'); $em->persist($user); $em->flush(); $user = new User(); $user->setName('name-3'); $em->persist($user); $em->flush(); $user = new User(); $user->setName('name-4'); $em->persist($user); $em->flush(); ``` The dev.log gives 4 queries ; the webprofiler bar in sf shows 4 queries. [2012-03-15 11:50:01] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-1"}) [2012-03-15 11:50:01] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-2"}) [2012-03-15 11:50:01] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-3"}) [2012-03-15 11:50:01] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-4"}) **2nd sample :** ``` $user = new User(); $user->setName('name-1'); $em->persist($user); $user = new User(); $user->setName('name-2'); $em->persist($user); $user = new User(); $user->setName('name-3'); $em->persist($user); $user = new User(); $user->setName('name-4'); $em->persist($user); $em->flush(); ``` The dev.log gives 4 queries ; the webprofiler bar in sf shows 4 queries. [2012-03-15 11:51:31] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-1"}) [2012-03-15 11:51:31] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-2"}) [2012-03-15 11:51:31] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-3"}) [2012-03-15 11:51:31] doctrine.DEBUG: INSERT INTO user (name) VALUES (?) ({"1":"name-4"}) In 1st sample, there is 3 transactions. In 2nd sample, there is 1 transaction. Is there a possibility to know number of transactions because i think it can help developpers in order to have better performances. Maybe it is not in doctrine, it is in Symfony webprofiler; what do you think ?
Author
Owner

@doctrinebot commented on GitHub (Mar 15, 2012):

Comment created by @beberlei:

Well the Symfony debug profiler only shows the queries, not the transactions. If you need the transactions you can extend it of course, for example listening to the "onFlush" event that marks the start of a UnitOfwork transaction. Its still not a bug and we won't add it to the core Doctrine bundle.

EntityManager#flush wrapping the transaction is discussed at length in the documentation.

@doctrinebot commented on GitHub (Mar 15, 2012): Comment created by @beberlei: Well the Symfony debug profiler only shows the queries, not the transactions. If you need the transactions you can extend it of course, for example listening to the "onFlush" event that marks the start of a UnitOfwork transaction. Its still not a bug and we won't add it to the core Doctrine bundle. EntityManager#flush wrapping the transaction is discussed at length in the documentation.
Author
Owner

@doctrinebot commented on GitHub (Mar 15, 2012):

Issue was closed with resolution "Won't Fix"

@doctrinebot commented on GitHub (Mar 15, 2012): Issue was closed with resolution "Won't Fix"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2148