diff --git a/dbcon/mysql/is_columnstore.h b/dbcon/mysql/is_columnstore.h index 27f899007..487f98d1a 100644 --- a/dbcon/mysql/is_columnstore.h +++ b/dbcon/mysql/is_columnstore.h @@ -21,3 +21,66 @@ int is_columnstore_extents_plugin_init(void* p); int is_columnstore_files_plugin_init(void* p); int is_columnstore_tables_plugin_init(void* p); int is_columnstore_columns_plugin_init(void* p); + + +class InformationSchemaCond +{ + StringBuffer mBufferTableName; + StringBuffer mBufferTableSchema; + String *mTableName; + String *mTableSchema; +public: + InformationSchemaCond() + :mBufferTableName(system_charset_info), + mBufferTableSchema(system_charset_info), + mTableName(nullptr), + mTableSchema(nullptr) + { } + const String *tableName() const { return mTableName; } + const String *tableSchema() const { return mTableSchema; } + static bool eqName(const String &a, const std::string &b) + { + return a.length() == b.length() && !memcmp(a.ptr(), b.data(), a.length()); + } + static bool eqName(const String *a, const std::string &b) + { + return !a || eqName(*a, b); + } + bool match(const std::string &schema, const std::string &table) const + { + return eqName(mTableName, table) && eqName(mTableSchema, schema); + } + + void getCondItem(Item_field *item_field, Item *item_const) + { + if (strcasecmp(item_field->field_name.str, "table_name") == 0) + { + mTableName = item_const->val_str(&mBufferTableName); + } + else if (strcasecmp(item_field->field_name.str, "table_schema") == 0) + { + mTableSchema = item_const->val_str(&mBufferTableSchema); + } + } + + void getCondItemBoolFunc2(Item_bool_func2 *func) + { + Item_field *field = dynamic_cast(func->arguments()[0]->real_item()); + if (field && func->arguments()[1]->const_item()) + getCondItem(field, func->arguments()[1]); + } + + void getCondItems(COND* cond) + { + if (Item_bool_func2 *func = dynamic_cast(cond)) + { + getCondItemBoolFunc2(func); + } + else if (Item_cond_and *subcond = dynamic_cast(cond)) + { + List_iterator li(*(subcond)->argument_list()); + for (Item *item = li++; item ; item = li++ ) + getCondItems(item); + } + } +}; diff --git a/dbcon/mysql/is_columnstore_columns.cpp b/dbcon/mysql/is_columnstore_columns.cpp index 1166b13d0..437360489 100644 --- a/dbcon/mysql/is_columnstore_columns.cpp +++ b/dbcon/mysql/is_columnstore_columns.cpp @@ -57,62 +57,12 @@ ST_FIELD_INFO is_columnstore_columns_fields[] = Show::CEnd() }; -static void get_cond_item(Item_func* item, String** table, String** db) -{ - char tmp_char[MAX_FIELD_WIDTH]; - Item_field* item_field = (Item_field*) item->arguments()[0]->real_item(); - - if (strcasecmp(item_field->field_name.str, "table_name") == 0) - { - String str_buf(tmp_char, sizeof(tmp_char), system_charset_info); - *table = item->arguments()[1]->val_str(&str_buf); - return; - } - else if (strcasecmp(item_field->field_name.str, "table_schema") == 0) - { - String str_buf(tmp_char, sizeof(tmp_char), system_charset_info); - *db = item->arguments()[1]->val_str(&str_buf); - return; - } -} - -static void get_cond_items(COND* cond, String** table, String** db) -{ - if (cond->type() == Item::FUNC_ITEM) - { - Item_func* fitem = (Item_func*) cond; - - if (fitem->arguments()[0]->real_item()->type() == Item::FIELD_ITEM && - fitem->arguments()[1]->const_item()) - { - get_cond_item(fitem, table, db); - } - } - else if ((cond->type() == Item::COND_ITEM) && (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)) - { - List_iterator li(*((Item_cond*) cond)->argument_list()); - Item* item; - - while ((item = li++)) - { - if (item->type() == Item::FUNC_ITEM) - { - get_cond_item((Item_func*)item, table, db); - } - else - { - get_cond_items(item, table, db); - } - } - } -} static int is_columnstore_columns_fill(THD* thd, TABLE_LIST* tables, COND* cond) { CHARSET_INFO* cs = system_charset_info; TABLE* table = tables->table; - String* table_name = NULL; - String* db_name = NULL; + InformationSchemaCond isCond; boost::shared_ptr systemCatalogPtr = execplan::CalpontSystemCatalog::makeCalpontSystemCatalog(execplan::CalpontSystemCatalog::idb_tid2sid(thd->thread_id)); @@ -124,27 +74,14 @@ static int is_columnstore_columns_fill(THD* thd, TABLE_LIST* tables, COND* cond) if (cond) { - get_cond_items(cond, &table_name, &db_name); + isCond.getCondItems(cond); } for (std::vector >::const_iterator it = catalog_tables.begin(); it != catalog_tables.end(); ++it) { - if (db_name) - { - if ((*it).second.schema.compare(db_name->ptr()) != 0) - { - continue; - } - } - - if (table_name) - { - if ((*it).second.table.compare(table_name->ptr()) != 0) - { - continue; - } - } + if (!isCond.match((*it).second.schema, (*it).second.table)) + continue; execplan::CalpontSystemCatalog::RIDList column_rid_list; diff --git a/dbcon/mysql/is_columnstore_tables.cpp b/dbcon/mysql/is_columnstore_tables.cpp index 178d14f71..5ba5e95a3 100644 --- a/dbcon/mysql/is_columnstore_tables.cpp +++ b/dbcon/mysql/is_columnstore_tables.cpp @@ -43,62 +43,12 @@ ST_FIELD_INFO is_columnstore_tables_fields[] = Show::CEnd() }; -static void get_cond_item(Item_func* item, String** table, String** db) -{ - char tmp_char[MAX_FIELD_WIDTH]; - Item_field* item_field = (Item_field*) item->arguments()[0]->real_item(); - - if (strcasecmp(item_field->field_name.str, "table_name") == 0) - { - String str_buf(tmp_char, sizeof(tmp_char), system_charset_info); - *table = item->arguments()[1]->val_str(&str_buf); - return; - } - else if (strcasecmp(item_field->field_name.str, "table_schema") == 0) - { - String str_buf(tmp_char, sizeof(tmp_char), system_charset_info); - *db = item->arguments()[1]->val_str(&str_buf); - return; - } -} - -static void get_cond_items(COND* cond, String** table, String** db) -{ - if (cond->type() == Item::FUNC_ITEM) - { - Item_func* fitem = (Item_func*) cond; - - if (fitem->arguments()[0]->real_item()->type() == Item::FIELD_ITEM && - fitem->arguments()[1]->const_item()) - { - get_cond_item(fitem, table, db); - } - } - else if ((cond->type() == Item::COND_ITEM) && (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)) - { - List_iterator li(*((Item_cond*) cond)->argument_list()); - Item* item; - - while ((item = li++)) - { - if (item->type() == Item::FUNC_ITEM) - { - get_cond_item((Item_func*)item, table, db); - } - else - { - get_cond_items(item, table, db); - } - } - } -} static int is_columnstore_tables_fill(THD* thd, TABLE_LIST* tables, COND* cond) { CHARSET_INFO* cs = system_charset_info; TABLE* table = tables->table; - String* table_name = NULL; - String* db_name = NULL; + InformationSchemaCond isCond; boost::shared_ptr systemCatalogPtr = execplan::CalpontSystemCatalog::makeCalpontSystemCatalog(execplan::CalpontSystemCatalog::idb_tid2sid(thd->thread_id)); @@ -107,7 +57,7 @@ static int is_columnstore_tables_fill(THD* thd, TABLE_LIST* tables, COND* cond) if (cond) { - get_cond_items(cond, &table_name, &db_name); + isCond.getCondItems(cond); } const std::vector< std::pair > catalog_tables @@ -116,21 +66,8 @@ static int is_columnstore_tables_fill(THD* thd, TABLE_LIST* tables, COND* cond) for (std::vector >::const_iterator it = catalog_tables.begin(); it != catalog_tables.end(); ++it) { - if (db_name) - { - if ((*it).second.schema.compare(db_name->ptr()) != 0) - { - continue; - } - } - - if (table_name) - { - if ((*it).second.table.compare(table_name->ptr()) != 0) - { - continue; - } - } + if (!isCond.match((*it).second.schema, (*it).second.table)) + continue; try { diff --git a/mysql-test/columnstore/basic/r/i_s.result b/mysql-test/columnstore/basic/r/i_s.result new file mode 100644 index 000000000..e15913003 --- /dev/null +++ b/mysql-test/columnstore/basic/r/i_s.result @@ -0,0 +1,50 @@ +# +# MCOL-4757 Empty set in SELECT * INFORMATION_SCHEMA.COLUMNSTORE_TABLES WHERE TABLE_NAME='t1' +# +DROP DATABASE IF EXISTS mcs_mcol4757; +CREATE DATABASE mcs_db_mcol4757; +USE mcs_db_mcol4757; +CREATE TABLE mcs_tbl_mcol4757 (x DECIMAL(38)) ENGINE=ColumnStore; +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_TABLES +WHERE TABLE_SCHEMA='mcs_db_mcol4757'; +TABLE_SCHEMA TABLE_NAME +mcs_db_mcol4757 mcs_tbl_mcol4757 +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_TABLES +WHERE TABLE_NAME='mcs_tbl_mcol4757'; +TABLE_SCHEMA TABLE_NAME +mcs_db_mcol4757 mcs_tbl_mcol4757 +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_TABLES +WHERE TABLE_SCHEMA='mcs_db_mcol4757' AND TABLE_NAME='mcs_tbl_mcol4757'; +TABLE_SCHEMA TABLE_NAME +mcs_db_mcol4757 mcs_tbl_mcol4757 +SET @s='mcs_db_mcol4757'; +SET @t='mcs_tbl_mcol4757'; +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_TABLES WHERE TABLE_SCHEMA=@s; +TABLE_SCHEMA TABLE_NAME +mcs_db_mcol4757 mcs_tbl_mcol4757 +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_TABLES WHERE TABLE_NAME=@t; +TABLE_SCHEMA TABLE_NAME +mcs_db_mcol4757 mcs_tbl_mcol4757 +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_TABLES WHERE LENGTH(TABLE_SCHEMA); +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS +WHERE TABLE_SCHEMA='mcs_db_mcol4757'; +TABLE_SCHEMA TABLE_NAME +mcs_db_mcol4757 mcs_tbl_mcol4757 +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS +WHERE TABLE_NAME='mcs_tbl_mcol4757'; +TABLE_SCHEMA TABLE_NAME +mcs_db_mcol4757 mcs_tbl_mcol4757 +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS +WHERE TABLE_SCHEMA='mcs_db_mcol4757' AND TABLE_NAME='mcs_tbl_mcol4757'; +TABLE_SCHEMA TABLE_NAME +mcs_db_mcol4757 mcs_tbl_mcol4757 +SET @s='mcs_db_mcol4757'; +SET @t='mcs_tbl_mcol4757'; +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS WHERE TABLE_SCHEMA=@s; +TABLE_SCHEMA TABLE_NAME +mcs_db_mcol4757 mcs_tbl_mcol4757 +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS WHERE TABLE_NAME=@t; +TABLE_SCHEMA TABLE_NAME +mcs_db_mcol4757 mcs_tbl_mcol4757 +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS WHERE LENGTH(TABLE_SCHEMA); +DROP DATABASE mcs_db_mcol4757; diff --git a/mysql-test/columnstore/basic/t/i_s.test b/mysql-test/columnstore/basic/t/i_s.test new file mode 100644 index 000000000..34d7f4dd6 --- /dev/null +++ b/mysql-test/columnstore/basic/t/i_s.test @@ -0,0 +1,56 @@ +--source ../include/have_columnstore.inc + +--echo # +--echo # MCOL-4757 Empty set in SELECT * INFORMATION_SCHEMA.COLUMNSTORE_TABLES WHERE TABLE_NAME='t1' +--echo # + +--disable_warnings +DROP DATABASE IF EXISTS mcs_mcol4757; +--enable_warnings +CREATE DATABASE mcs_db_mcol4757; +USE mcs_db_mcol4757; + +CREATE TABLE mcs_tbl_mcol4757 (x DECIMAL(38)) ENGINE=ColumnStore; + +# +# Testing COLUMNSTORE_TABLES +# + +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_TABLES + WHERE TABLE_SCHEMA='mcs_db_mcol4757'; +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_TABLES + WHERE TABLE_NAME='mcs_tbl_mcol4757'; +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_TABLES + WHERE TABLE_SCHEMA='mcs_db_mcol4757' AND TABLE_NAME='mcs_tbl_mcol4757'; + +SET @s='mcs_db_mcol4757'; +SET @t='mcs_tbl_mcol4757'; +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_TABLES WHERE TABLE_SCHEMA=@s; +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_TABLES WHERE TABLE_NAME=@t; + +--disable_result_log +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_TABLES WHERE LENGTH(TABLE_SCHEMA); +--enable_result_log + +# +# Testing COLUMNSTORE_COLUMNS +# + +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS + WHERE TABLE_SCHEMA='mcs_db_mcol4757'; +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS + WHERE TABLE_NAME='mcs_tbl_mcol4757'; +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS + WHERE TABLE_SCHEMA='mcs_db_mcol4757' AND TABLE_NAME='mcs_tbl_mcol4757'; + +SET @s='mcs_db_mcol4757'; +SET @t='mcs_tbl_mcol4757'; +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS WHERE TABLE_SCHEMA=@s; +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS WHERE TABLE_NAME=@t; + +--disable_result_log +SELECT TABLE_SCHEMA, TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNSTORE_COLUMNS WHERE LENGTH(TABLE_SCHEMA); +--enable_result_log + + +DROP DATABASE mcs_db_mcol4757;