diff --git a/stmt/stmts/drop.go b/stmt/stmts/drop.go index 8f7b685e25..dbbe15980d 100644 --- a/stmt/stmts/drop.go +++ b/stmt/stmts/drop.go @@ -111,6 +111,8 @@ func (s *DropTableStmt) Exec(ctx context.Context) (rset.Recordset, error) { var notExistTables []string for _, ti := range s.TableIdents { err := sessionctx.GetDomain(ctx).DDL().DropTable(ctx, ti.Full(ctx)) + // TODO: we should return special error for table not exist, checking "not exist" is not enough, + // because some other errors may contain this error string too. if err != nil && strings.HasSuffix(err.Error(), "not exist") { notExistTables = append(notExistTables, ti.String()) } else if err != nil { diff --git a/stmt/stmts/drop_test.go b/stmt/stmts/drop_test.go index 9c5af84d58..46c6ea47e7 100644 --- a/stmt/stmts/drop_test.go +++ b/stmt/stmts/drop_test.go @@ -57,6 +57,8 @@ func (s *testStmtSuite) TestDropTable(c *C) { c.Assert(mf.Len(), Greater, 0) mustExec(c, s.testDB, testSQL) + mustExec(c, s.testDB, "create table if not exists t (c int)") + mustExec(c, s.testDB, "drop table t") } func (s *testStmtSuite) TestDropIndex(c *C) { diff --git a/structure/hash.go b/structure/hash.go index 7e8ab37fa0..2dd24c77d0 100644 --- a/structure/hash.go +++ b/structure/hash.go @@ -140,7 +140,7 @@ func (t *TxStructure) HLen(key []byte) (int64, error) { func (t *TxStructure) HDel(key []byte, fields ...[]byte) error { metaKey := t.encodeHashMetaKey(key) meta, err := t.loadHashMeta(metaKey) - if err != nil { + if err != nil || meta.IsEmpty() { return errors.Trace(err) } diff --git a/structure/structure_test.go b/structure/structure_test.go index 11f7cb6073..9a769c259a 100644 --- a/structure/structure_test.go +++ b/structure/structure_test.go @@ -239,6 +239,9 @@ func (s *tesTxStructureSuite) TestHash(c *C) { c.Assert(err, IsNil) c.Assert(l, Equals, int64(0)) + err = tx.HDel(key, []byte("fake_key")) + c.Assert(err, IsNil) + err = tx.Commit() c.Assert(err, IsNil)