New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DDC-2310] [DDC-2675] Fix SQL generation on table lock hint capable platforms #910
Conversation
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DDC-2914 We use Jira to track the state of pull requests and the versions they got |
Thank you, from the bottom of my heart. I was just checking back on this today because it came up again in development. I had just forked DBAL and commented out the line that appends the lock hint. |
Just for reference: This issue was partly introduced in doctrine/dbal#257 but that PR was not the root cause of the problem because the proper SQL generation was broken ever since for this. |
@deeky666 no worries, it was easy enough to work around in the interim :) |
@deeky666 seems perfect to me! Once travis says yay, I'll merge it. =) |
@guilhermeblanco IMO this should be backported to the 2.3 and 2.4 branches also because it breaks nearly all queries ;) |
@deeky666 That's a good point -- SQL server default is transaction level READ COMMITTED, but using WITH (NOLOCK) is the equivalent of using SET TRANSACTION LEVEL READ UNCOMMITTED. This should really not append a lock hint unless explicitly requested. |
@zeroedin-bill This is a good argument. Okay then I will change that in DBAL, too. |
@zeroedin-bill @guilhermeblanco DBAL patch supplied in doctrine/dbal#508. |
@@ -269,7 +269,7 @@ public function loadOneToManyCollection(array $assoc, $sourceEntity, PersistentC | |||
* Locks all rows of this entity matching the given criteria with the specified pessimistic lock mode. | |||
* | |||
* @param array $criteria | |||
* @param int $lockMode | |||
* @param int $lockMode One of the Doctrine\DBAL\LockMode::* constants. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int|null
I suppose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet ;) This will be changed in the PR for DDC-2919.
@Ocramius It's ready now from my perspective. Your remaining remarks will be implemented in the follow-up PR :) |
👍 |
@beberlei @guilhermeblanco Is this patch okay for you? As soon as you are ok and merge I can continue on the followup DDC-2919 for further SQL Server and SQL Anywhere fixes :) |
[DDC-2310] [DDC-2675] Fix SQL generation on table lock hint capable platforms
@zeroedin-bill good advice about TRANSACTION LEVEL 👍 |
Very glad to see this getting merged! |
SQL Server and SQL Anywhere use table lock hints for locking. ORM generates wrong SQL when used in conjunction with joins, in a table inheritance scenario or in a subquery. It places the table lock hints after the
JOIN
clauses, which is wrong. The table lock hints have to be placed after each table alias in theFROM
clause.Example (current)
Example (expected)
The testsuites fail big time at the moment because of that and I suppose ORM is more or less unusable at the moment for those platforms without this patch.
I needed to adjust a lot of tests which compared compiled DQL, to make use of the platforms specific lock hint clauses.
Also I did not add new tests because there are already so many tests, where this fails without this patch that this is not necessary IMO.