Skip to content

Accept named FOREIGN KEY and CHECK drops without a dialect - #2789

Open
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:fix/named-constraint-drop-default-mode-20261013
Open

minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:fix/named-constraint-drop-default-mode-20261013

Conversation

@minleejae

@minleejae minleejae commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Parse ALTER TABLE t DROP FOREIGN KEY fk and ALTER TABLE t DROP CHECK ck without selecting a dialect. These common MySQL actions fail in the default configuration, as reported in #990 and #1129. Dialect.MYSQL has accepted them since #2675.

Current design (As-is)

The named form is selected only when the dialect is MYSQL:

  • Without a dialect, only the legacy parenthesized DROP FOREIGN KEY (cols) form is accepted.
  • Dialect.MARIADB also rejects DROP FOREIGN KEY fk, although MariaDB supports it.

Target design (To-be)

  • Without a dialect, accept the named FOREIGN KEY and CHECK drops, exactly as with Dialect.MYSQL.
  • With Dialect.MARIADB, accept the named FOREIGN KEY drop. MariaDB has no DROP CHECK, so that form stays rejected.
  • Keep rejecting both in other dialects, which drop constraints with DROP CONSTRAINT.
  • A parenthesized FOREIGN KEY column list keeps the legacy form.
  • The AST is unchanged: DROP_FOREIGN_KEY/DROP_CHECK with getConstraintName().
  • Update the usage guide.

Validation

  • 8 new tests cover:
    • default-mode round trips with plain and quoted names, including the combined DROP FOREIGN KEY fk1, DROP CHECK c1;
    • MariaDB acceptance and rejection;
    • rejection in the PostgreSQL, Oracle and SQL Server dialects;
    • the legacy parenthesized form.
  • Java 17 offline Gradle spotlessApply check: 10,102 tests, 10,077 passed, 25 skipped, zero failures/errors. The grammar choice conflict check passes.
  • Database runs, with SQL rendered both without a dialect and with the server's dialect:
    • MySQL 8.4 and 8.0: 4 statements each succeed in original and rendered form.
    • MariaDB 11.4: DROP FOREIGN KEY fk1 succeeds; DROP CHECK c1 is rejected by both the server and the parser in MariaDB mode.
    • PostgreSQL 18.3: the named FOREIGN KEY drop is rejected by both.

Integration validation

Applied #2788, #2789, #2790, #2791 and #2792 together on master (166f0a27):

ALTER TABLE ... DROP FOREIGN KEY fk and DROP CHECK ck were only accepted
with Dialect.MYSQL, so the default parser configuration rejected these
common MySQL actions (JSQLParser#990, JSQLParser#1129). Accept them without a dialect as in
MySQL, accept the named FOREIGN KEY form for MariaDB, which has no DROP
CHECK, and keep rejecting them in other dialects. A parenthesized
FOREIGN KEY column list keeps the legacy form.

Signed-off-by: minleejae <mmj9808@gmail.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant