@@ -730,6 +730,9 @@ func (e *ShowExec) fetchShowColumns(ctx context.Context) error {
730730 } else if fieldPatternsLike != nil && ! fieldPatternsLike .DoMatch (col .Name .L ) {
731731 continue
732732 }
733+ if skipColumnInShowCreateTable (tb .Meta (), col .ColumnInfo , false ) {
734+ continue
735+ }
733736 desc := table .NewColDesc (col )
734737 var columnDefault any
735738 if desc .DefaultValue != nil {
@@ -1080,13 +1083,7 @@ func constructResultOfShowCreateTable(ctx sessionctx.Context, dbName *pmodel.CIS
10801083 var hasAutoIncID bool
10811084 needAddComma := false
10821085 for i , col := range tableInfo .Cols () {
1083- if col == nil || col .Hidden || col .Name == model .ExtraHandleName || col .Name == model .ExtraOriginTSName {
1084- continue
1085- }
1086- if tableInfo .SoftdeleteInfo != nil && model .IsSoftDeleteColumn (col .Name ) {
1087- continue
1088- }
1089- if tableInfo .IsActiveActive && model .IsActiveActiveColumn (col .Name ) {
1086+ if skipColumnInShowCreateTable (tableInfo , col , true ) {
10901087 continue
10911088 }
10921089 if needAddComma {
@@ -1680,6 +1677,27 @@ func fetchShowCreateTable4View(ctx sessionctx.Context, tb *model.TableInfo, buf
16801677 fmt .Fprintf (buf , ") AS %s" , tb .View .SelectStmt )
16811678}
16821679
1680+ func skipColumnInShowCreateTable (tableInfo * model.TableInfo , col * model.ColumnInfo , hidden bool ) bool {
1681+ if col == nil || col .Name == model .ExtraHandleName || col .Name == model .ExtraOriginTSName {
1682+ return true
1683+ }
1684+ if hidden && col .Hidden {
1685+ return true
1686+ }
1687+ // Keep the existing show-create-table behavior for base tables.
1688+ if tableInfo .SoftdeleteInfo != nil && model .IsSoftDeleteColumn (col .Name ) {
1689+ return true
1690+ }
1691+ if tableInfo .IsActiveActive && model .IsActiveActiveColumn (col .Name ) {
1692+ return true
1693+ }
1694+ // Views do not carry softdelete/active-active flags, but should still hide these internal columns.
1695+ if tableInfo .IsView () && (model .IsSoftDeleteColumn (col .Name ) || model .IsActiveActiveColumn (col .Name )) {
1696+ return true
1697+ }
1698+ return false
1699+ }
1700+
16831701// ConstructResultOfShowCreateDatabase constructs the result for show create database.
16841702func ConstructResultOfShowCreateDatabase (ctx sessionctx.Context , dbInfo * model.DBInfo , ifNotExists bool , buf * bytes.Buffer ) (err error ) {
16851703 sqlMode := ctx .GetSessionVars ().SQLMode
0 commit comments