-
Notifications
You must be signed in to change notification settings - Fork 16
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
Add snapshot methods to query builder/model #231
Comments
A normal SELECT statement outside of a transaction is already a snapshot read only transaction. |
So running a SELECT sets I remember there was some confusion between snapshots and timestamp bounds/single use transactions. Timestamp bounds and single use transactions are not the same as snapshots, as discussed here: |
Also if it is the case that normal SELECT statements do somehow set Eg this line here
Is the only way to create a snapshot and pass the timestamp bound to it, and that doesnt appear to be called when running a normal SELECT? |
I just tested this, if I run something like DB::connection()->table('totals')->get(); At no point does |
Finally, it should actually not be the case that regular SELECT statements use snapshots. Snapshot use should require explicit specification. This code should not run in a snapshot: DB::connection()->table('totals')->get(); However something like this should be possible DB::connection()->table('totals')->snapshot(new ExactStaleness(20))->get(); |
From what I can read from here, all non read write transactions or DMLs are snapshot read-only transactions. So running this is automatically running the statement as singleUse snapshot read-only transaction. The only reason I added |
I am confused by this. It appears perhaps the documentation is contradicting itself when it says this
So its saying you can have a timestamp bound read that is not part of a read-write transaction (which according to the documentation you linked saying theres only 3 transaction modes, read-write, snapshot, partitioned, must mean that its in a snapshot right, since it cant be partitioned), and yet this read that is in a snapshot can still lock? When the other documentation says snapshot never lock, as stated here
From my understanding, unless you explicitly call Perhaps this is a case of the documentation being unclear |
The doc really should go more into detail about how it can still block. From what I have tested in production, switching from strong reads to stale reads resulted in better performance and less blocking overall. |
Agreed, it seems confusing and like a direct contradiction currently, but it really does seem to me that the best practice if you want snapshot reads with a complete guarantee of no locking, that you should call
I am sure it does, but since the docs do seem to indicate that stale reads alone is not enough to guarantee no locks, it would make sense to add explicit snapshot usage options Your closure |
Would be great if the snapshot method could be chained directly on query builder or model method calls. I tried to suss it myself to make a PR but I am not sure the best approach.
Ideally it would be great if you could do something like
Ideally you should be able to insert the
snapshot()
method anywhere in the chain, but since snapshots use a closure to execute under the hood Im not sure how it could be made chainableThe text was updated successfully, but these errors were encountered: