Repository navigation
Conversation
…utation classifier Extend the SQL statement mutation classifier so it recognizes additional PostgreSQL functions that change shared server-side state even though they are called from inside a plain SELECT wrapper: - pg_terminate_backend, which ends another session (the classifier already recognized the sibling pg_cancel_backend). - the advisory-lock family (pg_advisory_lock / _shared / _unlock / _unlock_shared / _unlock_all / _xact_lock / _xact_lock_shared and their pg_try_* counterparts). Each acquires or releases a server-side lock that outlives the statement and is observable by every other session, so the call changes shared state despite reading like a boolean probe. These are added to the existing PostgreSQL-scoped function name set, so the change is additive and does not affect other dialects. Parametrized unit tests cover each new form and confirm a plain SELECT stays non-mutating. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Comment on lines
+1366
to
+1376
| "PG_ADVISORY_LOCK", | ||
| "PG_ADVISORY_LOCK_SHARED", | ||
| "PG_ADVISORY_UNLOCK", | ||
| "PG_ADVISORY_UNLOCK_SHARED", | ||
| "PG_ADVISORY_UNLOCK_ALL", | ||
| "PG_ADVISORY_XACT_LOCK", | ||
| "PG_ADVISORY_XACT_LOCK_SHARED", | ||
| "PG_TRY_ADVISORY_LOCK", | ||
| "PG_TRY_ADVISORY_LOCK_SHARED", | ||
| "PG_TRY_ADVISORY_XACT_LOCK", | ||
| "PG_TRY_ADVISORY_XACT_LOCK_SHARED", |
Contributor
There was a problem hiding this comment.
Suggestion: These names make SELECTs skip automatic row limits; selecting over a large table can acquire locks for many rows, leaving session locks held and exhausting server resources.
Assessment: 🟠 Major · 🔁 Occurrence: Rarely · 🏷️ Performance
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/sql/parse.py
**Line:** 1366:1376
**Comment:**
*Performance: These names make SELECTs skip automatic row limits; selecting over a large table can acquire locks for many rows, leaving session locks held and exhausting server resources.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #46687 +/- ##
=======================================
Coverage 86.42% 86.42%
=======================================
Files 3183 3183
Lines 222605 222605
Branches 52996 52996
=======================================
Hits 192377 192377
Misses 26758 26758
Partials 3470 3470
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
The SQL statement mutation classifier (
SQLStatement.is_mutating()insuperset/sql/parse.py) flags statements that change state so callers can tell them apart from plain reads. It already recognizes a set of PostgreSQL functions that mutate shared server-side state even when invoked from inside aSELECT. This adds a few more that were not yet in that set, for completeness and consistency with the ones already handled:pg_terminate_backend, which ends another session (the siblingpg_cancel_backendwas already recognized).pg_advisory_lock/_shared/_unlock/_unlock_shared/_unlock_all/_xact_lock/_xact_lock_sharedand theirpg_try_*forms). Each acquires or releases a server-side lock that outlives the statement and is observable by every other session, so the call changes shared state despite reading like a boolean probe.The new names are added to the existing PostgreSQL-scoped function set, so the change is additive and does not affect other dialects.
TESTING INSTRUCTIONS
Extends the parametrized unit tests in
tests/unit_tests/sql/parse_tests.py. Run:pytest tests/unit_tests/sql/parse_tests.pyADDITIONAL INFORMATION