我有一个查询,必须获取超过2M的结果。它失败了,我认为是因为缺乏记忆。
这是我的疑问:
$reponses = $qb ->select('r.id')
->from('PACESColleBundle:Reponse', 'r')
->join('r.user', 'u')
->andWhere($qb->expr()->in('u.id', ':tutoreSalle'))
->andWhere($qb->expr()->eq('r.banque', ':banque'))
->setParameters(['banque' => 0, 'tutoreSalle' => $tutoreSalle])
->getQuery()->getArrayResult();
$qb = $this->em->createQueryBuilder();
$qb->update('PACESColleBundle:Reponse', 'r')
->set('r.banque', 1)
->set('r.archive', 1)
->where($qb->expr()->in('r.id', ':reponses'))
->setParameters(['reponses' => $reponses]);
$qb->getQuery()->execute();
错误代表第一个查询。如何使查询构建器获取此数据量?
编辑:
将此代码更改为:
$db = $this->em->getConnection();
$query = "UPDATE reponse AS rp
SET rp.banque = 1, rp.archive = 1
WHERE EXISTS (SELECT r.id
FROM (SELECT * FROM reponse) AS r
JOIN user u ON r.user = u.id
JOIN tutore t ON u.id = t.id
JOIN tutore_groupe tg ON tg.tutore_id = t.id
WHERE tg.groupe_id = 1
AND r.id = rp.id)";
$stmt = $db->prepare($query);
$stmt->execute();
触发此错误:
General error: 1205 Lock wait timeout exceeded; try restarting transaction"
Select语句运行良好。我尝试更新时失败了。