Skip to content
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

added dirty read(NOLOCK) in SQLServer #4133

Merged
merged 6 commits into from
May 20, 2019
Merged

Conversation

alfonsoal1983
Copy link

@alfonsoal1983 alfonsoal1983 commented May 13, 2019

Added support for NOLOCK in mssql
Linked to this issue

#4042

return " WITH (NOLOCK)";

} else if (driver instanceof MysqlDriver || driver instanceof PostgresDriver || driver instanceof OracleDriver) {
return "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why just ignore here? I doubt it's the default setting for those drivers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, it's my first climb so I apologize in advance for any possible errors. Searching the internet I found this about equivalents to this instruction in other databases:

MySQL:
When WITH (nolock) is used in SQL Server to perform operation, it does not place shared lock (S) and also does not honor exclusive locks on table. The WITH (nolock) table hint is equivalent to READ UNCOMMITTED also known as "dirty read", it is the lowest level of isolation. If you specify table hint then it will override the current isolation level.
MySQL default isolation level is REPEATABLE READ which means locks will be placed for each operation but multiple connections can read data concurrently with out making table unavailable during read. MySQL database server does not support changing the default isolation mode as a hint like SQL Server.

Oracle:
Oracle by default provides a read-consistent view of data. The upshot of this design is that readers never block writers.

PostgreSQL:
PostgreSQL uses MVCC to minimize lock contention in order to allow for reasonable performance in multiuser environments. Readers do not conflict with writers nor other readers. The closest thing would be the NOWAIT

It's what I found about it.

Copy link
Contributor

@Kononnable Kononnable May 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand why we just pass empty sting in some drivers and not throwing LockNotSupportedOnGivenDriverError.
If driver doesn't support this it's fine but I don't think we should throw an error, not just ignore this - otherwise people using it will think that everything is working as expected while underneath typeorm would just ignore some unsupported features. I think we could omit this only if it's default behavior for those drivers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to throw in error, although really this kind of cases do not think it is an error, it would be more informative that the driver does not have that functionality. What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized that this part of the code should not be set, it is enough with the change of line 1388. I delete this part of the code.

.where("post.id = :id", { id: 1 })
.getSql();

if (connection.driver instanceof SqlServerDriver) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We limit drivers on wchich we want the test to run in two separate statements. It should be done only in one place.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not know what the correction would be, any suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I had in mind is line 103 - we're limiting there some drivers, and here in if condition we choose only one driver after all. We could put this if condition in the beginning and there will be only one place which controls test execution based on driver.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File updated

Alfonso Alonso Lorenzo added 2 commits May 13, 2019 18:11
@alfonsoal1983
Copy link
Author

Is everything correct or is something missing so that the merge can be done?

@pleerock
Copy link
Member

Looks good to me.

@alfonsoal1983
Copy link
Author

When will the changes be merged with the master branch?

@Kononnable Kononnable merged commit 0d47ccd into typeorm:master May 20, 2019
@Kononnable
Copy link
Contributor

Looks fine, so let's merge it.
Thank you for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants