Repository navigation
fix: find tables in TOP, star REPLACE and DECLARE initializers - #2902
Open
tanjiroK-coder wants to merge 1 commit into
Open
tanjiroK-coder wants to merge 1 commit into
tanjiroK-coder wants to merge 1 commit into
Conversation
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.
TablesNamesFinder skips three expression slots that the parser models: the TOP expression of a PlainSelect, the REPLACE and APPLY items of a
*ort.*column transformer, and the initializers of DECLARE. The AllColumns, AllTableColumns and DeclareStatement visits were empty, and visitPlainSelectBody never looked at getTop(). A subquery in any of those positions is dropped from the result, soSELECT TOP ((SELECT count(*) FROM secrets)) a FROM tandSELECT * REPLACE ((SELECT max(pw) FROM secrets) AS a) FROM treturn onlyt, andDECLARE @x INT = (SELECT max(pw) FROM secrets)returns no table at all, although each statement readssecrets. A table allowlist built on findTables lets those reads through. I found them by placing one subquery in about 270 expression positions and checking which ones the finder missed. The visitor now walks the TOP expression, the transformer apply and replace items and each DECLARE default expression, the same way the COLUMNS(...) visit already walks its transformers. The time-travel clauses (FOR SYSTEM_TIME AS OF ...) and DECLARE TABLE column specs are kept as raw strings by the parser, so they stay out of scope here. Seven parameterized TablesNamesFinderTest cases fail before and pass after, and./gradlew checkpasses.