Repository navigation
fix: find DELETE target tables, UPSERT SET sources and CLONE sources - #2977
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
TablesNamesFinder.visit(Delete) never visited Delete.getTables(), the table list in front of FROM in T-SQL and MySQL, so DELETE secrets FROM t reported only t. visit(Upsert) skipped Upsert.getUpdateSets(), and TableDefinitionTraversal.visit(CreateTable) did not accept getCloneTable(), so UPSERT INTO t SET a = (SELECT ... FROM secrets) and CREATE TABLE copy CLONE secrets hid secrets from the finder, the adapter and the validators. UpsertValidator now validates the SET assignments too.
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 slots in which a statement names a table, so a table allowlist built on findTables lets such statements through.
DELETE secrets FROM t WHERE t.id = 1findTables returns onlyt, although rows ofsecretsare deleted. StatementVisitorAdapter.visit(Delete) and DeleteValidator already walk that list. The new visitDeleteTargets visits each entry as a DML target unless it names the alias of the FROM table, a join or a USING item, becauseDELETE s FROM secrets s JOIN t ...refers to an item that is already visited (like Update.isTargetTableAlias).UPSERT INTO t SET a = (SELECT max(pw) FROM secrets)reports onlyt, while the ON DUPLICATE KEY UPDATE sets were walked through the duplicate action. UpsertValidator had the same asymmetry and now validates both update-set lists.CREATE [SNAPSHOT] TABLE copy CLONE secretsreports onlycopyin the finder, StatementVisitorAdapter and CreateTableValidator.Tests cover the T-SQL and MySQL delete shapes, alias entries that must not become tables, both UPSERT SET forms, CLONE with and without FOR SYSTEM_TIME, and a function in an UPSERT SET assignment that the validator must reject. ./gradlew check (16850 tests) and mvn verify pass.