Doctrine2 を使用してクエリに With(nolock) ヒントを追加しようとしています。FROM 句の (最初の->setLockMode(LockMode::NONE)->getSQL();
) テーブルにWITH(NOLOCK) を追加しました。説明します:
$dql='SELECT e, o FROM Porject:Example e JOIN e.owner o';
$query = $this->getEntityManager()->createQuery($dql);
try{
$this->getEntityManager()->getConnection()->beginTransaction();
$result = $query ->setLockMode(LockMode::NONE)->getSQL();
$this->getEntityManager()->getConnection()->commit();
} catch (\Exception $e) {
$this->getEntityManager()->getConnection()->rollback();
throw $e;
}
期待される:
SELECT c0_.prop1, c0_.prop2, c1_.prop1, c1_.prop2
FROM examples c0_ WITH(NOLOCK)
INNER JOIN owners c1_ WITH(NOLOCK) ON c1_.id= c0_ownerId`
私が本当に得たもの:
SELECT c0_.prop1, c0_.prop2, c1_.prop1, c1_.prop2
FROM examples c0_ WITH(NOLOCK)
INNER JOIN owners c1_ ON c1_.id= c0_ownerId`
考えられる解決策:
try {
$this->getEntityManager()->getConnection()->beginTransaction();
$this->getEntityManager()->getConnection()->setTransactionIsolation(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED);
$result = $query->getArrayResult();
$this->getEntityManager()->getConnection()->commit();
} catch (\Exception $e) {
$this->getEntityManager()->getConnection()->rollback();
throw $e;
}
しかし、分離レベルwith(nolock)
を使用するよりも行うのが同じかどうかはわかりません。READ_UNCOMMITTED
編集:で投稿されたトランザクションを開始することは、クエリのすべてのテーブルでwith(nolock)をTRANSACTION_READ_UNCOMMITTED
実行することと同じです。