From 4b86890cf701c9f79918321f12c1d4e1bfe4bbae Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Mon, 20 Jan 2020 14:26:39 -0800 Subject: [PATCH] MCOL-128 Support ALTER TABLE...ENGINE=Columnstore Also implements: * ALTER TABLE from Columnstore to another engine * MCOL-3349 CREATE TABLE ... AS SELECT. --- dbcon/mysql/ha_mcs_ddl.cpp | 36 +++++++++++++++++++++++------------- dbcon/mysql/ha_mcs_impl.cpp | 5 ++++- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/dbcon/mysql/ha_mcs_ddl.cpp b/dbcon/mysql/ha_mcs_ddl.cpp index 43671055e..8454b8cce 100644 --- a/dbcon/mysql/ha_mcs_ddl.cpp +++ b/dbcon/mysql/ha_mcs_ddl.cpp @@ -2400,14 +2400,10 @@ int ha_mcs_impl_create_(const char* name, TABLE* table_arg, HA_CREATE_INFO* crea return 1; } - // @bug 3908. error out primary key for now. + // Send notice if primary key specified that it is not supported if (table_arg->key_info && table_arg->key_info->name.length && string(table_arg->key_info->name.str) == "PRIMARY") { - string emsg = logging::IDBErrorInfo::instance()->errorMsg(ERR_CONSTRAINTS); - setError(thd, ER_CHECK_NOT_IMPLEMENTED, emsg); - ci.alterTableState = cal_connection_info::NOT_ALTER; - ci.isAlter = false; - return 1; + push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, WARN_OPTION_IGNORED, "INDEXES"); } int compressiontype = get_compression_type(thd); @@ -2452,22 +2448,25 @@ int ha_mcs_impl_create_(const char* name, TABLE* table_arg, HA_CREATE_INFO* crea return 1; } - // - // Check if this is a "CREATE TABLE ... LIKE " statement. + // Check if this is one of + // * "CREATE TABLE ... LIKE " + // * "ALTER TABLE ... ENGINE=Columnstore" + // * "CREATE TABLE ... AS ..." // If so generate a full create table statement using the properties of // the source table. Note that source table has to be a columnstore table and // we only check for currently supported options. // - if (thd->lex->create_info.like()) + if ((thd->lex->sql_command == SQLCOM_CREATE_TABLE && thd->lex->used_tables) || + (thd->lex->sql_command == SQLCOM_ALTER_TABLE && create_info->used_fields & HA_CREATE_USED_ENGINE) || + (thd->lex->create_info.like())) { TABLE_SHARE *share = table_arg->s; my_bitmap_map *old_map; // To save the read_set char datatype_buf[MAX_FIELD_WIDTH], def_value_buf[MAX_FIELD_WIDTH]; String datatype, def_value; ostringstream oss; - string tbl_name (name+2); - std::replace(tbl_name.begin(), tbl_name.end(), '/', '.'); + string tbl_name = string(share->db.str) + "." + string(share->table_name.str); // Save the current read_set map and mark it for read old_map= tmp_use_all_columns(table_arg, table_arg->read_set); @@ -2505,10 +2504,18 @@ int ha_mcs_impl_create_(const char* name, TABLE* table_arg, HA_CREATE_INFO* crea // Process table level options + /* TODO: uncomment when we support AUTO_INCREMENT if (create_info->auto_increment_value > 1) { oss << " AUTO_INCREMENT=" << create_info->auto_increment_value; } + */ + + if (create_info->auto_increment_value > 1) + { + push_warning(thd, Sql_condition::WARN_LEVEL_NOTE, WARN_OPTION_IGNORED, "AUTO INCREMENT"); + } + if (share->table_charset) { @@ -2539,7 +2546,7 @@ int ha_mcs_impl_create_(const char* name, TABLE* table_arg, HA_CREATE_INFO* crea oss << ";"; stmt = oss.str(); - + tmp_restore_column_map(table_arg->read_set, old_map); } @@ -2600,7 +2607,7 @@ int ha_mcs_impl_delete_table_(const char* db, const char* name, cal_connection_i string emsg; - if (thd->lex->sql_command == SQLCOM_DROP_DB) + if ((thd->lex->sql_command == SQLCOM_DROP_DB) || (thd->lex->sql_command == SQLCOM_ALTER_TABLE)) { std::string tableName(name); tableName.erase(0, tableName.rfind("/") + 1); @@ -2636,6 +2643,9 @@ int ha_mcs_impl_rename_table_(const char* from, const char* to, cal_connection_i decode_file_path(to, decodedDbTo, decodedTblTo); string stmt; + // This case is already handled + if (thd->lex->create_info.used_fields & HA_CREATE_USED_ENGINE) + return 0; if (thd->slave_thread && !get_replication_slave(thd)) return 0; diff --git a/dbcon/mysql/ha_mcs_impl.cpp b/dbcon/mysql/ha_mcs_impl.cpp index 766cfbea7..532e67843 100644 --- a/dbcon/mysql/ha_mcs_impl.cpp +++ b/dbcon/mysql/ha_mcs_impl.cpp @@ -2362,8 +2362,11 @@ int ha_mcs_impl_rnd_init(TABLE* table) } #endif - if ( (thd->lex)->sql_command == SQLCOM_ALTER_TABLE ) + // If ALTER TABLE and not ENGINE= we don't need rnd_init (gets us in a bad state) + if ((thd->lex->sql_command == SQLCOM_ALTER_TABLE) && !(thd->lex->create_info.used_fields & HA_CREATE_USED_ENGINE)) + { return 0; + } //Update and delete code if ( ((thd->lex)->sql_command == SQLCOM_UPDATE) || ((thd->lex)->sql_command == SQLCOM_DELETE) || ((thd->lex)->sql_command == SQLCOM_DELETE_MULTI) || ((thd->lex)->sql_command == SQLCOM_UPDATE_MULTI))