You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
MCOL-5890: DROP TABLE IF EXISTS should not generate errors for non existing tables
This commit is contained in:
committed by
Leonid Fedorov
parent
a6ab9bd615
commit
3e20a3d566
@ -244,7 +244,7 @@ ZEROFILL
|
|||||||
%type <columnType> approximate_numeric_type
|
%type <columnType> approximate_numeric_type
|
||||||
%type <str> opt_display_width
|
%type <str> opt_display_width
|
||||||
%type <str> opt_display_precision_scale_null
|
%type <str> opt_display_precision_scale_null
|
||||||
%type <str> opt_if_exists
|
%type <flag> opt_if_exists
|
||||||
%type <str> opt_if_not_exists
|
%type <str> opt_if_not_exists
|
||||||
%type <str> opt_signed
|
%type <str> opt_signed
|
||||||
%type <str> opt_zerofill
|
%type <str> opt_zerofill
|
||||||
@ -314,10 +314,10 @@ stmt:
|
|||||||
;
|
;
|
||||||
|
|
||||||
drop_table_statement:
|
drop_table_statement:
|
||||||
DROP TABLE opt_if_exists qualified_name {$$ = new DropTableStatement($4, false);}
|
DROP TABLE opt_if_exists qualified_name {$$ = new DropTableStatement($4, false, $3);}
|
||||||
| DROP TABLE opt_if_exists qualified_name CASCADE CONSTRAINTS
|
| DROP TABLE opt_if_exists qualified_name CASCADE CONSTRAINTS
|
||||||
{
|
{
|
||||||
{$$ = new DropTableStatement($4, true);}
|
{$$ = new DropTableStatement($4, true, $3);}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -1371,7 +1371,7 @@ struct DropTableStatement : public SqlStatement
|
|||||||
DropTableStatement() : fTableName(nullptr)
|
DropTableStatement() : fTableName(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
EXPORT DropTableStatement(QualifiedName* qualifiedName, bool cascade);
|
EXPORT DropTableStatement(QualifiedName* qualifiedName, bool cascade, bool ifExists = false);
|
||||||
|
|
||||||
/** @brief Dump to stdout. */
|
/** @brief Dump to stdout. */
|
||||||
EXPORT std::ostream& put(std::ostream& os) const override;
|
EXPORT std::ostream& put(std::ostream& os) const override;
|
||||||
@ -1390,7 +1390,8 @@ struct DropTableStatement : public SqlStatement
|
|||||||
}
|
}
|
||||||
|
|
||||||
QualifiedName* fTableName;
|
QualifiedName* fTableName;
|
||||||
bool fCascade;
|
bool fCascade = false;
|
||||||
|
bool fIfExists = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief DebugStatement
|
/** @brief DebugStatement
|
||||||
|
@ -29,15 +29,14 @@ using namespace std;
|
|||||||
|
|
||||||
namespace ddlpackage
|
namespace ddlpackage
|
||||||
{
|
{
|
||||||
DropTableStatement::DropTableStatement(QualifiedName* qualifiedName, bool cascade)
|
DropTableStatement::DropTableStatement(QualifiedName* qualifiedName, bool cascade, bool ifExists)
|
||||||
: fTableName(qualifiedName), fCascade(cascade)
|
: fTableName(qualifiedName), fCascade(cascade), fIfExists(ifExists)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ostream& DropTableStatement::put(ostream& os) const
|
ostream& DropTableStatement::put(ostream& os) const
|
||||||
{
|
{
|
||||||
os << "Drop Table: " << *fTableName << " "
|
os << "Drop Table: " << *fTableName << " " << "C=" << fCascade << endl;
|
||||||
<< "C=" << fCascade << endl;
|
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,20 +178,37 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackageInternal(ddlpack
|
|||||||
if (ie.errorCode() == ERR_TABLE_NOT_IN_CATALOG)
|
if (ie.errorCode() == ERR_TABLE_NOT_IN_CATALOG)
|
||||||
{
|
{
|
||||||
Message::Args args;
|
Message::Args args;
|
||||||
Message message(1);
|
args.add("Table ");
|
||||||
args.add("Table does not exist in ColumnStore.");
|
args.add(tableName.schema + "." + tableName.table);
|
||||||
|
args.add(" does not exist in ColumnStore.");
|
||||||
|
|
||||||
|
if (dropTableStmt->fIfExists) // Check if "IF EXISTS" is specified
|
||||||
|
{
|
||||||
|
Message message(1); // Informational log level
|
||||||
|
message.format(args);
|
||||||
|
result.result = NO_ERROR; // Success, no error
|
||||||
|
result.message = message;
|
||||||
|
fSessionManager.committed(txnID); // No action needed, commit
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Message message(9); // Error log level
|
||||||
message.format(args);
|
message.format(args);
|
||||||
result.result = DROP_TABLE_NOT_IN_CATALOG_ERROR;
|
result.result = DROP_TABLE_NOT_IN_CATALOG_ERROR;
|
||||||
result.message = message;
|
result.message = message;
|
||||||
fSessionManager.rolledback(txnID);
|
fSessionManager.rolledback(txnID);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.result = DROP_ERROR;
|
result.result = DROP_ERROR;
|
||||||
Message::Args args;
|
Message::Args args;
|
||||||
Message message(9);
|
Message message(9);
|
||||||
args.add("Drop table failed due to ");
|
args.add("Drop table ");
|
||||||
|
args.add(tableName.schema + "." + tableName.table);
|
||||||
|
args.add(" failed due to ");
|
||||||
args.add(ie.what());
|
args.add(ie.what());
|
||||||
message.format(args);
|
message.format(args);
|
||||||
result.message = message;
|
result.message = message;
|
||||||
@ -517,8 +534,7 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackageInternal(ddlpack
|
|||||||
|
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
{
|
{
|
||||||
cout << txnID.id << " rolledback transaction "
|
cout << txnID.id << " rolledback transaction " << " and valid is " << txnID.valid << endl;
|
||||||
<< " and valid is " << txnID.valid << endl;
|
|
||||||
fSessionManager.rolledback(txnID);
|
fSessionManager.rolledback(txnID);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
16
mysql-test/columnstore/bugfixes/mcol-5890.result
Normal file
16
mysql-test/columnstore/bugfixes/mcol-5890.result
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
DROP DATABASE IF EXISTS MCOL5890;
|
||||||
|
CREATE DATABASE MCOL5890;
|
||||||
|
USE MCOL5890;
|
||||||
|
# Test 1: DROP TABLE IF EXISTS on non-existent table
|
||||||
|
DROP TABLE IF EXISTS test.does_not_exist;
|
||||||
|
Warnings:
|
||||||
|
Note 1051 Unknown table 'test.does_not_exist'
|
||||||
|
# Test 2: DROP TABLE on non-existent table
|
||||||
|
DROP TABLE test.does_not_exist;
|
||||||
|
ERROR 42S02: Unknown table 'test.does_not_exist'
|
||||||
|
# Test 3: DROP TABLE IF EXISTS on existing table
|
||||||
|
CREATE TABLE t1 (id INT) ENGINE=ColumnStore;
|
||||||
|
DROP TABLE IF EXISTS t1;
|
||||||
|
SELECT * FROM t1;
|
||||||
|
ERROR 42S02: Table 'MCOL5890.t1' doesn't exist
|
||||||
|
DROP DATABASE MCOL5890;
|
29
mysql-test/columnstore/bugfixes/mcol-5890.test
Normal file
29
mysql-test/columnstore/bugfixes/mcol-5890.test
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
-- source ../include/have_columnstore.inc
|
||||||
|
|
||||||
|
# Setup: Create a test database
|
||||||
|
--disable_warnings
|
||||||
|
DROP DATABASE IF EXISTS MCOL5890;
|
||||||
|
CREATE DATABASE MCOL5890;
|
||||||
|
USE MCOL5890;
|
||||||
|
--enable_warnings
|
||||||
|
|
||||||
|
# Test 1: DROP TABLE IF EXISTS on a non-existent table should succeed silently
|
||||||
|
--echo # Test 1: DROP TABLE IF EXISTS on non-existent table
|
||||||
|
DROP TABLE IF EXISTS test.does_not_exist;
|
||||||
|
|
||||||
|
# Test 2: DROP TABLE on a non-existent table should fail with ER_BAD_TABLE_ERROR
|
||||||
|
--echo # Test 2: DROP TABLE on non-existent table
|
||||||
|
--error ER_BAD_TABLE_ERROR
|
||||||
|
DROP TABLE test.does_not_exist;
|
||||||
|
|
||||||
|
# Test 3: DROP TABLE IF EXISTS on an existing table should succeed
|
||||||
|
--echo # Test 3: DROP TABLE IF EXISTS on existing table
|
||||||
|
CREATE TABLE t1 (id INT) ENGINE=ColumnStore;
|
||||||
|
DROP TABLE IF EXISTS t1;
|
||||||
|
|
||||||
|
# Verify table is dropped
|
||||||
|
--error ER_NO_SUCH_TABLE
|
||||||
|
SELECT * FROM t1;
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
DROP DATABASE MCOL5890;
|
Reference in New Issue
Block a user