Repository navigation
fix: read KEY, INDEX, EXCLUDE and OPTIONS as names where their element does not follow - #2970
Merged
manticore-projects merged 1 commit intoDec 2, 2026
Conversation
…t does not follow Signed-off-by: minleejae <mmj9808@gmail.com>
Contributor
Author
|
@manticore-projects Thanks for the reviews! Could you share when you plan to release 5.5? |
Contributor
Thank you for your effort and contribution! |
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.
Some words start a table element or an
ALTER TABLEaction in one dialect but are plain names in another, and the parser took them as the start of that element even where it does not follow:Dialect.POSTGRESQL,KEY,INDEX,FULLTEXTandSPATIALstarted MySQL's inline index definition, although PostgreSQL has none and does not reserve these words.CREATE TABLE kv (id INT, key VARCHAR(10)),ALTER TABLE t ADD key INT,ALTER TABLE kv ALTER key TYPE BIGINTandALTER TABLE t ALTER index TYPE BIGINTwere parse errors.CONSTRAINT, a word that could start a constraint was never taken as its name, soCONSTRAINT key UNIQUE (a)(PostgreSQL) andCONSTRAINT exclude UNIQUE (a)(MySQL and PostgreSQL) failed.Dialect.MYSQLorDialect.POSTGRESQL,ALTER TABLE t ADD exclude INTstarted an exclusion constraint.OPTIONSstarted PostgreSQL's foreign-data options without their parenthesized list, so MySQL'sALTER TABLE t ALTER INDEX options INVISIBLE,ALTER CHECK options NOT ENFORCEDandALTER CONSTRAINT options ENFORCEDfailed.This change reads these words as names where their element does not follow:
isTableIndexAhead(): withDialect.POSTGRESQL,KEY,INDEX,FULLTEXTandSPATIALno longer start an index definition, and MySQL'sALTER INDEX name {VISIBLE | INVISIBLE}is not read there.isConstraintNameBeforeKindAhead(): afterCONSTRAINT, a word followed byPRIMARY KEY,UNIQUE,FOREIGN,CHECK,EXCLUDEorNOT NULLis the constraint's name.PRIMARYnever is, as MySQL and PostgreSQL reserve it, andKEY,INDEX,FULLTEXTandSPATIALare not with MySQL, which reserves them.ADDwith the two dialects usesisExcludeConstraintAhead(), asCREATE TABLEalready does:EXCLUDEstarts a constraint only beforeUSING, its elements orWHERE.isForeignDataOptionsAt():OPTIONSstarts foreign-data options only before(.Compatibility: MySQL's index definitions and unnamed constraints (
KEY k (a),CONSTRAINT UNIQUE KEY u (a),CONSTRAINT PRIMARY KEY (a)), PostgreSQL's exclusion constraints and foreign-data options parse as before. Parser result classes and public methods are unchanged. Without a dialect,KEY,INDEX,FULLTEXTandSPATIALstill start an index definition, soCREATE TABLE kv (id INT, key VARCHAR(10))still needsDialect.POSTGRESQL.Not changed: reserved words that the parser accepts as names only in some positions (
OFFSET,ONLY,RETURNINGwith MySQL;SET,BETWEENwith PostgreSQL) still fail afterDROP,TO,INDEXorADD.Reference: MySQL 8.4 CREATE TABLE (
[CONSTRAINT [symbol]] UNIQUE ...), ALTER TABLE (ALTER INDEX index_name {VISIBLE | INVISIBLE},ALTER {CHECK | CONSTRAINT} symbol [NOT] ENFORCED), Keywords and Reserved Words; PostgreSQL 18 CREATE TABLE, ALTER TABLE, SQL Key Words.Validation
ContextualKeywordNamesTest: with PostgreSQL,key,index,fulltextandspatialas columns inCREATE TABLE,ADDandALTER ... TYPE; those words andexcludeas constraint names inCREATE TABLEandADD CONSTRAINT, with and without a dialect;ADD exclude INTwith and without the dialects;optionsas index and constraint name with MySQL; and MySQL's index definitions,ADD key INTrejected with MySQL, PostgreSQL's exclusion constraint and foreign-data options as before. 15 of the 18 cases fail on the base (08e222fd6).PREPAREonly) and PostgreSQL 18.6 agreed with the branch on all 21 statements I checked, including the rejectedADD key INTandCONSTRAINT key UNIQUE (a)(MySQL) andCONSTRAINT primary UNIQUE (a)(PostgreSQL).gradle check(Spotless, Checkstyle, PMD, JaCoCo verification) andcheckGrammarAmbiguity: 16,879 tests, 0 failures, 25 skipped; no choice conflicts.AI assistance: prepared with Claude Code.