-
Notifications
You must be signed in to change notification settings - Fork 3.9k
sql: avoid splitting the planner when expanding sub-queries #11730
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
Conversation
@vivekmenezes could you guide me about how to best test this. You explain in the linked issue we can check that all leases are released. How do you propose to do this? My proposal would be to add a new directive in our |
Look at the code in lease.go that references removeOnceDereferenced . From the logic tests we should always set this to true, that way the leases are released as soon as they are dereferenced. And then at the end of each test file query the lease table and ensure there are no records. |
thanks for fixing it! |
Should there be a Reviewed 1 of 1 files at r1. Comments from Reviewable |
@tamird yes, that's a good idea too! |
is what tamir is referring to |
I've used that before, thanks |
0939d00
to
5bec628
Compare
Ok I have added the NoCopy members and a specific test. PTAL. |
5bec628
to
5156138
Compare
Reviewed 4 of 4 files at r2. pkg/sql/lease_test.go, line 646 at r2 (raw file):
s/err/_/ pkg/sql/lease_test.go, line 677 at r2 (raw file):
remove Comments from Reviewable |
RemoveOnceDereferenced: true, | ||
LeaseReleasedEvent: func(lease *csql.LeaseState, err error) { | ||
if lease.Name == "foo" { | ||
fooRelease <- struct{}{} |
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.
close fooRelease
// The above SELECT has acquired a lease on the table. Now close the | ||
// session, which should release the new lease and delete it because | ||
// of the testing knob set above. | ||
sqlDB.Close() |
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.
is this really needed?
TFYRs! Review status: all files reviewed at latest revision, 4 unresolved discussions, all commit checks successful. pkg/sql/lease_test.go, line 646 at r2 (raw file): Previously, tamird (Tamir Duberstein) wrote…
Done. pkg/sql/lease_test.go, line 648 at r2 (raw file): Previously, vivekmenezes wrote…
Done. pkg/sql/lease_test.go, line 668 at r2 (raw file): Previously, vivekmenezes wrote…
the leases are not released until the session is closed. Closing the connection releases the session. pkg/sql/lease_test.go, line 677 at r2 (raw file): Previously, tamird (Tamir Duberstein) wrote…
Done. Comments from Reviewable |
cb0eda1
to
f5a9477
Compare
Reviewed 1 of 1 files at r3. Comments from Reviewable |
f5a9477
to
200f9eb
Compare
Review status: 4 of 5 files reviewed at latest revision, 2 unresolved discussions, some commit checks failed. pkg/sql/lease_test.go, line 668 at r2 (raw file): Previously, knz (kena) wrote…
https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/executor.go#L673 is where it gets released at the end of a transaction. Are you sure this is needed? Comments from Reviewable |
LGTM |
200f9eb
to
9802f30
Compare
TFYRs Review status: 2 of 5 files reviewed at latest revision, 2 unresolved discussions. pkg/sql/lease_test.go, line 668 at r2 (raw file): Previously, vivekmenezes wrote…
No you are right the close was unnecessary! Thanks for hinting. Comments from Reviewable |
a6e35bd
to
173ea52
Compare
Prior to this patch, the code that expands sub-queries would duplicate the `planner` object to create the sub-query planNode's recursively. This was perceived to be needed, as indicated by a previous comment that had been erased in 4acdc8a, because there may be nested sub-queries that would cause the `subqueryVisitor` embedded in planner to be reset during the recursion. The problem with this approach is that whichever leases were acquired by the sub-queries, and embedded in the planner copy, are then lost after the sub-query is replaced and cannot be released at the end of the session. This patch fixes this problem by ensuring the same planner object is reused throughout the recursion, and preserves only the state of the embedded `subqueryVisitor` across the recursive call. A proper long-term protection against this type of issue would be to avoid embedding visitors in the planner object, and instead managing a cache of visitor objects if profiling shows that visitor allocation is hurting performance.
173ea52
to
db58a73
Compare
Prior to this patch, the code that expands sub-queries would duplicate
the
planner
object to create the sub-query planNode'srecursively. This was perceived to be needed, as indicated by a
previous comment that had been erased in
4acdc8a, because there may be nested
sub-queries that would cause the
subqueryVisitor
embedded in plannerto be reset during the recursion.
The problem with this approach is that whichever leases were acquired
by the sub-queries, and embedded in the planner copy, are then lost
after the sub-query is replaced and cannot be released at the end of
the session.
This patch fixes this problem by ensuring the same planner object is
reused throughout the recursion, and preserves only the state of the
embedded
subqueryVisitor
across the recursive call.A proper long-term protection against this type of issue would be to
avoid embedding visitors in the planner object, and instead managing a
cache of visitor objects if profiling shows that visitor allocation is
hurting performance.
Fixes #11701.
This change is