From e34df639d9601ca5fef5441ba23bb46fe7e33fab Mon Sep 17 00:00:00 2001 From: Zach Musgrave Date: Mon, 31 Aug 2026 19:25:02 +0000 Subject: [PATCH] Add Cascade field to DDL for DROP statements MySQL parses but ignores CASCADE on DROP TABLE, so the grammar never sets this field; integrators with CASCADE semantics (e.g. Postgres dialects) set it when constructing the statement. --- go/vt/sqlparser/ast.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/go/vt/sqlparser/ast.go b/go/vt/sqlparser/ast.go index 74d94947dc7..34d3392af95 100644 --- a/go/vt/sqlparser/ast.go +++ b/go/vt/sqlparser/ast.go @@ -2332,6 +2332,11 @@ type DDL struct { Temporary bool ConstraintIfExists bool + // Cascade is set for DROP statements with CASCADE behavior: dependent objects should be dropped along with the + // named objects. MySQL parses but ignores CASCADE, so the MySQL grammar never sets this field; integrators with + // CASCADE semantics (e.g. Postgres dialects) set it when constructing the statement. + Cascade bool + // This exposes the start and end index of the string that makes up the sub statement of the query given. // Meaning is specific to the different kinds of statements with sub statements, e.g. views, trigger definitions. // For statements defined within a MySQL special comment (/*! */), we have to fudge the offset a bit because we won't @@ -2529,7 +2534,11 @@ func (node *DDL) Format(buf *TrackedBuffer) { if node.Temporary { temporary = " " + TemporaryStr } - buf.Myprintf("%s%s table%s %v", node.Action, temporary, exists, node.FromTables) + cascade := "" + if node.Cascade { + cascade = " cascade" + } + buf.Myprintf("%s%s table%s %v%s", node.Action, temporary, exists, node.FromTables, cascade) } case RenameStr: buf.Myprintf("%s table %v to %v", node.Action, node.FromTables[0], node.ToTables[0])