-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
sql: remove round-trips from common DISCARD ALL #95876
sql: remove round-trips from common DISCARD ALL #95876
Conversation
It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR? 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
Epic: none Release note: None
In cockroachdb#86246 we introduced logic to discard schemas when running DISCARD ALL and DISCARD TEMP. This logic did expensive kv operations unconditionally; if the session knew it had never created a temporary schema, we'd still fetch all databases and proceed to search all databases for a temp schema. This is very expensive. Fixes: cockroachdb#95864 Release note (performance improvement): In 22.2, we introduced support for `DISCARD TEMP` and made `DISCARD ALL` actually discard temp tables. This implementation ran expensive logic to discover temp schemas rather than consulting in-memory data structures. As a result, `DISCARD ALL`, which is issued regularly by connection pools, became an expensive operation when it should be cheap. This problem is now resolved.
This is an uncached round-trip. It makes `DISCARD` expensive. In cockroachdb#86485 we implemented `SET SESSION AUTHORIZATION DEFAULT`, this added an extra sql query to `DISCARD ALL` to check if the role we'd become exists. This is almost certainly unintentional in the case where the role we'd become is the current session role. I think this just happened because of code consolidation. We now no longer check if the current session role exists. This removes the last round-trip from DISCARD ALL. Release note (performance improvement): In 22.2, logic was added to make `SET SESSION AUTHORIZATION DEFAULT` not a no-op. This implementation used more general code for setting the role for a session which made sure that the role exists. The check for whether a role exists is currently uncached. We don't need to check if the role we already are exists. This improves the performance of `DISCARD ALL` in addition to `SET SESSION AUTHORIZATION DEFAULT`.
fcd41dd
to
74487fc
Compare
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.
Thanks for the fix!
TFTR! bors r+ |
Build failed (retrying...): |
Build succeeded: |
Encountered an error creating backports. Some common things that can go wrong:
You might need to create your backport manually using the backport tool. error creating merge commit from 66e265e to blathers/backport-release-22.2-95876: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict [] you may need to manually resolve merge conflicts with the backport tool. Backport to branch 22.2.x failed. See errors above. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
sql: avoid checking if a role exists when setting to the current role
This is an uncached round-trip. It makes
DISCARD
expensive.In #86485 we implemented
SET SESSION AUTHORIZATION DEFAULT
, this added an extra sql query toDISCARD ALL
to check if the role we'd become exists. This is almostcertainly unintentional in the case where the role we'd become is the
current session role. I think this just happened because of code
consolidation.
We now no longer check if the current session role exists. This removes
the last round-trip from DISCARD ALL.
sql: use in-memory session data to decide what to do in DISCARD
In #86246 we introduced logic to discard schemas when running DISCARD ALL and DISCARD TEMP. This logic did expensive kv operations unconditionally; if the session knew it had never created a temporary schema, we'd still fetch all databases and proceed to search all databases for a temp schema. This is very expensive.
Fixes: #95864
Release note (performance improvement): In 22.2, logic was added to make
SET SESSION AUTHORIZATION DEFAULT
not a no-op. This implementation usedmore general code for setting the role for a session which made sure that
the role exists. The check for whether a role exists is currently uncached.
We don't need to check if the role we already are exists. This improves the
performance of
DISCARD ALL
in addition toSET SESSION AUTHORIZATION DEFAULT
.Release note (performance improvement): In 22.2, we introduced support for
DISCARD TEMP
and madeDISCARD ALL
actually discard temp tables. This implementation ran expensive logic to discover temp schemas rather than consulting in-memory data structures. As a result,DISCARD ALL
, which is issued regularly by connection pools, became an expensive operation when it should be cheap. This problem is now resolved.