Repository navigation
fix: read MySQL and PostgreSQL unreserved keywords as DDL names, and running/final/approximate before IN (...) - #2972
Open
minleejae wants to merge 3 commits into
Conversation
Signed-off-by: minleejae <mmj9808@gmail.com>
… after DDL keywords Signed-off-by: minleejae <mmj9808@gmail.com>
…a function name Signed-off-by: minleejae <mmj9808@gmail.com>
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.
Two kinds of names that MySQL 8.4 or PostgreSQL 18 accepts were still parse errors.
Keywords the dialect does not reserve, in DDL name positions.
isReservedKeywordAsIdentifier()accepts a guarded reserved keyword as a name only after a few words such asTABLE,COLUMN,(or,, or when its follower rules it safe. After the other words that DDL always follows with a name, these keywords failed withDialect.MYSQLandDialect.POSTGRESQL, although the servers do not reserve them:OFFSET,ONLY,RETURNING,ANY,SOMEandVALUE, as inALTER TABLE t ADD COLUMN c INT AFTER offset,ALTER TABLE t DROP only,ALTER TABLE t RENAME COLUMN c TO returning,ALTER TABLE t ADD INDEX offset (a),CREATE TABLE t (a INT, KEY any (a))andALTER TABLE t ADD FOREIGN KEY (a) REFERENCES value (b).SETandBETWEEN, as inALTER TABLE t ADD set INT,ALTER TABLE t ALTER set TYPE BIGINT,ALTER INDEX set RENAME TO ix,ALTER TABLE t SET SCHEMA betweenandCREATE SEQUENCE set, andIF,GROUPINGandVALUESas referenced tables, as inREFERENCES if (b).DialectKeywordNames.isNameAfter()now reads these keywords as names right after such a word:ADD,ALTER,DROP,MODIFY,TO,INDEX,KEY,REFERENCES,DATABASE,SCHEMA,VIEW,TRIGGER,PARTITIONandAFTER.ADD,ALTER,DROP,TO,INDEX,PARTITION,SCHEMA,SEQUENCE,VIEW,TRIGGER,REFERENCES,AUTHORIZATION,INHERITandATTRIBUTEforSETandBETWEEN;REFERENCESforIF,GROUPINGandVALUES.isReservedKeywordAsIdentifier()consults it after the check for PostgreSQL'sONLYrelation prefix.QUALIFYis left out:INFORMATION_SCHEMA.KEYWORDSlists it as non-reserved, but MySQL 8.4 rejected it as a column, table and index name in every form I tried.A column named
running,finalorapproximatebefore a keyword and a parenthesis. The checks for MATCH_RECOGNIZE'sRUNNING | FINAL function(...)and for theAPPROXIMATEprefix of a function call looked only at the third token, soWHERE running IN (1, 2),WHERE final LIKE ('a%'),CHECK (approximate IN (1, 2))andPARTITION BY RANGE (running) (PARTITION ...)failed,runningandapproximatein every dialect.SELECT approximate(x) FROM t, a call of a function namedapproximate, failed as well. These prefixes are now read only before a function name (isFunctionNameToken()): an identifier or a non-reserved keyword.APPROXIMATE COUNT(DISTINCT a)andFINAL COUNT(*)/RUNNING LAST(a)inMEASURESparse as before.The pull request has three commits: a refactoring that moves the keyword lists of #2969 into the nested class
DialectKeywordNames, without changing behaviour, asAlterConstraintLookaheaddoes to keep code out ofCCJSqlParser.class; the DDL names; and the function prefixes.Compatibility: parser result classes and public methods are unchanged. Without a dialect and with other dialects, the DDL names are unchanged. Statements that parsed before give the same model and
toString(); among themLIMIT 10 OFFSET 5,OFFSET 1 ROWS FETCH NEXT 2 ROWS ONLY,START TRANSACTION READ ONLY,JSON_VALUE(... RETURNING ...),INSERT INTO t VALUE (1),a = ANY (SELECT ...),UPDATE t SET,a BETWEEN 1 AND 2,CREATE INDEX ON t (a),DROP INDEX IF EXISTS i,ALTER TYPE ty ADD VALUE 'x',ALTER TABLE ONLY tandTRUNCATE ONLY t.Not changed: with MySQL,
OFFSET,ONLYandRETURNINGstill fail as aliases (SELECT a offset FROM t offset), as the new name ofCHANGE(CHANGE c offset INT), andonlyinINSERT INTO only (a),ALTER TABLE only.tandTRUNCATE TABLE only. There the MySQL dialect keeps the readings thatPostgreSqlCursorTest,MySqlLockTablesTestandPostgreSQLModifyFormsTestpin: the standardOFFSET ... ROWSand PostgreSQL'sONLYprefix.Reference: MySQL 8.4 Keywords and Reserved Words, ALTER TABLE; PostgreSQL 18 SQL Key Words, ALTER TABLE; MATCH_RECOGNIZE (
RUNNING/FINAL).Validation
KeywordsTest: the keywords in the listed positions with their dialects;running,finalandapproximatebeforeIN (...),LIKE (...),= (...)and inCHECK (... IN ...), with and without a dialect; and the clauses, operators and function calls above, which keep their readings. 83 of the 84 new cases fail on the base (1038c30f8).PREPAREonly) for 216, MySQL 8.0.46 for the 6 thatPREPAREdoes not take (ALTER DATABASE,CREATE TRIGGER), and PostgreSQL 18.6 for 114. The only errors were semantic, such as a missing table or role.gradle check(Spotless, Checkstyle, PMD, JaCoCo verification) andcheckGrammarAmbiguity: 18,788 tests, 0 failures, 25 skipped; no choice conflicts. The first two commits pass the same check on their own (18,704 and 18,779 tests).AI assistance: prepared with Claude Code.