0

内部結合を使用した簡単なクエリがあります

$qb = $this->createQueryBuilder('r')
    ->innerJoin('UserBundle:User', 'u')
    ->where('r.nick = u.id')
    ->andWhere('r.odobera=:id')
    ->setParameter('id', $id)
    ->orderBy('r.time', 'DESC')
    ->setMaxResults(50);

return $qb->getQuery()->getResult();

それは1つのクエリですよね?しかし、プロファイラーには

SELECT t0.username AS [...] FROM users t0 WHERE t0.id = ? LIMIT 1
Parameters: [1465] 
[Display runnable query]
Time: 1.79 ms [   Explain query ]
 SELECT r0_.id AS id0, [...] FROM requests r0_ INNER [...] ORDER BY r0_.time DESC LIMIT 50
Parameters: [1465] 
[Display runnable query]
Time: 0.67 ms [   Explain query ]
 SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['2072'] 
[Display runnable query]
Time: 0.64 ms [   Explain query ]
 SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['2386'] 
[Display runnable query]
Time: 0.50 ms [   Explain query ]
 SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['79'] 
[Display runnable query]
Time: 0.50 ms [   Explain query ]
 SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['2432'] 
[Display runnable query]
Time: 0.50 ms [   Explain query ]
 SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['40'] 
[Display runnable query]
Time: 0.52 ms [   Explain query ]
 SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['2090'] 
[Display runnable query]
Time: 0.46 ms [   Explain query ]
 SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['1044'] 
[Display runnable query]
Time: 0.51 ms [   Explain query ]
 SELECT t0.username AS username1, [...] FROM users t0 WHERE t0.id = ?
Parameters: ['27'] 
[Display runnable query]
Time: 0.54 ms [   Explain query ]

各レコードの「結合」ごとに 1 つのクエリ...なぜですか?

PS: このテキストは、「ただ」非常に多くの詳細で質問を送信できないため、この投稿を長くするためのものです..しかし、私の問題は非常によく説明されていると思います. ところで:私は友人に尋ねました、そして彼は同様の問題を抱えています)

4

1 に答える 1

0

何を選択するかを指定しなかったのでrequests、水和した場所だけです。

select()クエリビルダーのメソッドで何をハイドレートするかを指定できます:

$qb = $this->createQueryBuilder('r')
     ->select(array('r', 'u'))
     ->innerJoin('UserBundle:User', 'u')
     ->where('r.nick = u.id')
     ->andWhere('r.odobera=:id')
     ->setParameter('id', $id)
     ->orderBy('r.time', 'DESC')
     ->setMaxResults(50);

return $qb->getQuery()->getResult();
于 2013-03-03T19:42:50.780 に答える