ddl: throw warning when ALTER TABLE ORDER BY on table with primary key (#14324)
This commit is contained in:
committed by
pingcap-github-bot
parent
d07728468f
commit
2b7b657f42
@ -4295,6 +4295,24 @@ func (s *testDBSuite2) TestDDLWithInvalidTableInfo(c *C) {
|
||||
c.Assert(err.Error(), Equals, "[parser:1064]You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 94 near \"then (b / a) end));\" ")
|
||||
}
|
||||
|
||||
func (s *testDBSuite1) TestAlterOrderBy(c *C) {
|
||||
s.tk = testkit.NewTestKit(c, s.store)
|
||||
s.tk.MustExec("use " + s.schemaName)
|
||||
s.tk.MustExec("create table ob (pk int primary key, c int default 1, c1 int default 1, KEY cl(c1))")
|
||||
|
||||
// Test order by with primary key
|
||||
s.tk.MustExec("alter table ob order by c")
|
||||
c.Assert(s.tk.Se.GetSessionVars().StmtCtx.WarningCount(), Equals, uint16(1))
|
||||
s.tk.MustQuery("show warnings").Check(testutil.RowsWithSep("|", "Warning|1105|ORDER BY ignored as there is a user-defined clustered index in the table 'ob'"))
|
||||
|
||||
// Test order by with no primary key
|
||||
s.tk.MustExec("drop table if exists ob")
|
||||
s.tk.MustExec("create table ob (c int default 1, c1 int default 1, KEY cl(c1))")
|
||||
s.tk.MustExec("alter table ob order by c")
|
||||
c.Assert(s.tk.Se.GetSessionVars().StmtCtx.WarningCount(), Equals, uint16(0))
|
||||
s.tk.MustExec("drop table if exists ob")
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Make sure it will only be executed once.
|
||||
domain.SchemaOutOfDateRetryInterval = int64(50 * time.Millisecond)
|
||||
|
||||
@ -2068,6 +2068,8 @@ func (d *ddl) AlterTable(ctx sessionctx.Context, ident ast.Ident, specs []*ast.A
|
||||
}
|
||||
case ast.AlterTableSetTiFlashReplica:
|
||||
err = d.AlterTableSetTiFlashReplica(ctx, ident, spec.TiFlashReplica)
|
||||
case ast.AlterTableOrderByColumns:
|
||||
err = d.OrderByColumns(ctx, ident)
|
||||
default:
|
||||
// Nothing to do now.
|
||||
}
|
||||
@ -4201,3 +4203,14 @@ func (d *ddl) RepairTable(ctx sessionctx.Context, table *ast.TableName, createSt
|
||||
err = d.callHookOnChanged(err)
|
||||
return errors.Trace(err)
|
||||
}
|
||||
|
||||
func (d *ddl) OrderByColumns(ctx sessionctx.Context, ident ast.Ident) error {
|
||||
_, tb, err := d.getSchemaAndTableByIdent(ctx, ident)
|
||||
if err != nil {
|
||||
return errors.Trace(err)
|
||||
}
|
||||
if tb.Meta().GetPkColInfo() != nil {
|
||||
ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Errorf("ORDER BY ignored as there is a user-defined clustered index in the table '%s'", ident.Name))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user