Commit 329076db authored by unknown's avatar unknown
Browse files

BUG#8547: Wrong errormessage when dropping table that does not exist in NDB

 - Added tescases
 - Added handling of HA_ERR_NO_SUCH_TABLE in mysql_rm_table_part2 so that 
   error messages now are consistent


mysql-test/r/ndb_autodiscover.result:
  Added tess for dropping tables that does not exists in engine
mysql-test/t/ndb_autodiscover.test:
  Added tess for dropping tables that does not exists in engine
sql/ha_ndbcluster.cc:
  Updated delete_table and drop_table to retrn HA_ERR_NO_SUCH_TABLE if table was not found in engine.
  Clear error after calling mysql_rm_table_part2 from mysql_find_files
sql/sql_table.cc:
  Added handling of the case when table does not exist in storage engine but on disk as .frm file.
parent 841a9c38
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -167,6 +167,25 @@ show status like 'handler_discover%';
Variable_name	Value
Handler_discover	0
drop table t4;
ERROR 42S02: Unknown table 't4'
create table t4(
id int not null primary key,
name char(27)
) engine=ndb;
insert into t4 values (1, "Automatic");
select * from t4;
id	name
1	Automatic
select * from t4;
ERROR 42S02: Table 'test.t4' doesn't exist
drop table if exists t4;
Warnings:
Note	1051	Unknown table 't4'
drop table t5;
ERROR 42S02: Unknown table 't5'
drop table if exists t5;
Warnings:
Note	1051	Unknown table 't5'
flush status;
create table t4(
id int not null primary key,
+22 −0
Original line number Diff line number Diff line
@@ -209,8 +209,30 @@ select * from t4;
select * from t4;

show status like 'handler_discover%';
--error 1051
drop table t4;

create table t4(
  id int not null primary key,
  name char(27)
) engine=ndb;
insert into t4 values (1, "Automatic");
select * from t4;

# Remove the table from NDB
system exec $NDB_TOOLS_DIR/ndb_drop_table --no-defaults -d test t4 >> $NDB_TOOLS_OUTPUT ; 

--error 1146
select * from t4;

drop table if exists t4;

# Test that dropping a table that does not exists
# on  disk or in NDB gives same result as above
--error 1051
drop table t5;
drop table if exists t5;


#######################################################
# Test that a table that has been dropped from NDB
+23 −25
Original line number Diff line number Diff line
@@ -157,7 +157,7 @@ static const err_code_mapping err_map[]=
  { 721, HA_ERR_TABLE_EXIST, 1 },
  { 4244, HA_ERR_TABLE_EXIST, 1 },

  { 709, HA_ERR_NO_SUCH_TABLE, 1 },
  { 709, HA_ERR_NO_SUCH_TABLE, 0 },
  { 284, HA_ERR_NO_SUCH_TABLE, 1 },

  { 266, HA_ERR_LOCK_WAIT_TIMEOUT, 1 },
@@ -2368,7 +2368,6 @@ void ha_ndbcluster::print_results()
    Field *field;
    void* ptr;
    NdbValue value;
    NdbBlob *ndb_blob;

    buf[0]= 0;
    field= table->field[f];
@@ -2382,7 +2381,6 @@ void ha_ndbcluster::print_results()

    if (! (field->flags & BLOB_FLAG))
    {
      ndb_blob= NULL;
      if (value.rec->isNULL())
      {
        my_snprintf(buf, sizeof(buf), "NULL");
@@ -2396,7 +2394,7 @@ void ha_ndbcluster::print_results()
    }
    else
    {
      ndb_blob= value.blob;
      NdbBlob *ndb_blob= value.blob;
      bool isNull= TRUE;
      ndb_blob->getNull(isNull);
      if (isNull) {
@@ -3959,26 +3957,30 @@ int ha_ndbcluster::alter_table_name(const char *to)


/*
  Delete a table from NDB Cluster
  Delete table from NDB Cluster

 */

int ha_ndbcluster::delete_table(const char *name)
{
  DBUG_ENTER("delete_table");
  DBUG_ENTER("ha_ndbcluster::delete_table");
  DBUG_PRINT("enter", ("name: %s", name));
  set_dbname(name);
  set_tabname(name);

  if (check_ndb_connection())
    DBUG_RETURN(HA_ERR_NO_CONNECTION);
  // Remove .ndb file

  /* Call ancestor function to delete .ndb file */
  handler::delete_table(name);
  
  /* Drop the table from NDB */
  DBUG_RETURN(drop_table());
}


/*
  Drop a table in NDB Cluster
  Drop table in NDB Cluster
 */

int ha_ndbcluster::drop_table()
@@ -3989,15 +3991,9 @@ int ha_ndbcluster::drop_table()
  DBUG_ENTER("drop_table");
  DBUG_PRINT("enter", ("Deleting %s", m_tabname));

  release_metadata();
  if (dict->dropTable(m_tabname))
  {
    const NdbError err= dict->getNdbError();
    if (err.code == 709)
      ; // 709: No such table existed
    else 
    ERR_RETURN(dict->getNdbError());
  }  
  release_metadata();
  DBUG_RETURN(0);
}

@@ -4482,10 +4478,12 @@ int ndbcluster_find_files(THD *thd,const char *db,const char *path,
      table_list.db= (char*) db;
      table_list.alias= table_list.table_name= (char*)file_name;
      (void)mysql_rm_table_part2(thd, &table_list,
				 /* if_exists */ TRUE, 
				 /* if_exists */ FALSE,
				 /* drop_temporary */ FALSE,
				 /* drop_view */ FALSE,
				 /* dont_log_query*/ TRUE);
      /* Clear error message that is returned when table is deleted */
      thd->clear_error();
    }
  }

+15 −0
Original line number Diff line number Diff line
@@ -249,6 +249,21 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
	if (!(error=my_delete(path,MYF(MY_WME))))
	  some_tables_deleted=1;
      }
      if (error == HA_ERR_NO_SUCH_TABLE)
      {
        /* The table did not exist in engine */
        if (if_exists)
        {
          push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
                              ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
                              table->table_name);
          error= 0;
        }
        /* Delete the table definition file */
        strmov(end,reg_ext);
        if (!(my_delete(path,MYF(MY_WME))))
          some_tables_deleted=1;
      }
    }
    if (error)
    {