fix: collect tables from all SELECT and DML trailing clauses in TablesNamesFinder - #2517
Merged
manticore-projects merged 1 commit intoAug 31, 2026
Conversation
Contributor
|
Awesome job! |
fudianchn
marked this pull request as draft
August 31, 2026 12:42
fudianchn
force-pushed
the
fix/tables-names-finder-select-clauses
branch
from
August 31, 2026 12:44
71d254b to
afbc87c
Compare
fudianchn
marked this pull request as ready for review
August 31, 2026 12:45
…sNamesFinder TablesNamesFinder visited only a subset of the Expression/Table-bearing children of PlainSelect, ParenthesedSelect, SetOperationList, Values, Delete, Update and FromItem-attached pivots, silently dropping tables located in INTO and INTO TEMP targets, DISTINCT ON, LATERAL VIEW generator functions, PREFERRING, GROUP BY (incl. GROUPING SETS), QUALIFY, WINDOW definitions, SETTINGS, PIVOT/UNPIVOT/PIVOT XML and the ORDER BY / LIMIT / LIMIT BY / OFFSET / FETCH clauses shared by every Select subclass (and by the MySQL single-table DELETE / UPDATE). Complete the traversal reusing the same ExpressionVisitor and FromItemVisitor default helpers used by SelectVisitorAdapter and StatementVisitorAdapter, and implement PivotVisitor so pivot contents (incl. the PivotXml IN subquery) are reached through dispatch. Signed-off-by: fudianchn <fudianchn@gmail.com>
fudianchn
force-pushed
the
fix/tables-names-finder-select-clauses
branch
from
August 31, 2026 12:48
afbc87c to
002ebc6
Compare
Contributor
Author
|
After your comment I pushed two more updates to the branch:
Full suite: 4971 tests, 0 failures. |
Contributor
|
Thank you for fixing this! |
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.
AI disclosure: this change was prepared with AI coding agents, reviewed and revised line by line by me.
What
TablesNamesFindernow traverses all Expression- and Table-bearing clauses of the SELECT family and the DML trailing clauses it previously skipped, so tables located in those clauses are collected instead of silently dropped.Why
TablesNamesFinderis the public helper for table extraction (SQL analysis, auditing, firewalls); a silently incomplete result is the worst failure mode for those consumers. All shapes in #2516 parse fine today and return incomplete table sets. This continues the family fixed by #2478 / #2479 (piped queries, DML side clauses, analytic clauses).How
PlainSelect: DISTINCT ON items, INTO tables, LATERAL VIEW generator functions, PREFERRING, GROUP BY (incl. GROUPING SETS), QUALIFY, WINDOW definitions, PIVOT / UNPIVOT, ORDER BY, LIMIT / LIMIT BY, OFFSET, FETCH, SETTINGS, INTO TEMP target.ParenthesedSelect,SetOperationList,Values: the ORDER BY / LIMIT / OFFSET / FETCH clauses they carry themselves.Delete,Update: their ORDER BY and LIMIT clauses (MySQL single-table DML).PIVOT XML ... IN (SELECT ...)subquery) is reached via the newly implementedPivotVisitor, the same mechanism asMergeOperationVisitor/PipeOperationVisitorin fix: complete TablesNamesFinder traversal for piped queries, DML side clauses and analytic functions (#2478) #2479.All traversals reuse the
ExpressionVisitor/FromItemVisitordefault helpers (visitOrderBy,visitLimit,visit(GroupByElement),visitUpdateSets,visitPreferringClause,visitTables,visitFromItem) already used bySelectVisitorAdapterandStatementVisitorAdapter. TwoSelectVisitorAdapter@todos (windowDefinitions,lateralViews) are covered too, because both can carry subqueries.Root cause
The finder's visit methods traversed only a subset of the Expression- and Table-bearing children; the adapters already covered most of these clauses, the finder did not.
Testing
TablesNamesFinderTest, one per shape from [BUG] JSQLParser 5.4-SNAPSHOT : all RDBMS : TablesNamesFinder silently misses tables in many SELECT and DML clauses (INTO, GROUP BY, QUALIFY, WINDOW, ORDER BY, LIMIT, DISTINCT ON, LATERAL VIEW, PIVOT XML, SETTINGS) #2516: each failed on master before the change and passes with it. Two mutants verified (removing the INTO traversal and the Table pivot traversal makes their tests fail).gradlew test --tests TablesNamesFinderTest-> 106 passed.INTO OUTFILE/DUMPFILEfields,TOP, Oracle hint, procedure analyse, KSQL window, OPTION clause).Verification of the original issue
With this change every shape in the #2516 matrix returns the complete table set.
Fixes #2516