diff --git a/dbcon/mysql/ha_mcs.cpp b/dbcon/mysql/ha_mcs.cpp index 3a6af6f1e..9e7edbd88 100644 --- a/dbcon/mysql/ha_mcs.cpp +++ b/dbcon/mysql/ha_mcs.cpp @@ -1808,6 +1808,8 @@ static handler* ha_mcs_cache_create_handler(handlerton* hton, TABLE_SHARE* table return new (mem_root) ha_mcs_cache(hton, table, mem_root); } +bool get_innodb_queries_uses_mcs(THD* thd); + /****************************************************************************** ha_mcs Plugin code ******************************************************************************/ @@ -1858,16 +1860,17 @@ static int columnstore_init_func(void* p) mcs_hton->create_unit = create_columnstore_unit_handler; mcs_hton->db_type = DB_TYPE_AUTOASSIGN; -{ - auto* innodb_hton = plugin_hton(plugin_innodb); - int error = innodb_hton == nullptr; // Engine must exists! - if (error) + if (get_innodb_queries_uses_mcs(current_thd)) { - my_error(HA_ERR_INITIALIZATION, MYF(0), "Could not find storage engine %s", name.str); + auto* innodb_hton = plugin_hton(plugin_innodb); + int error = innodb_hton == nullptr; // Engine must exists! + if (error) + { + my_error(HA_ERR_INITIALIZATION, MYF(0), "Could not find storage engine %s", name.str); + } + innodb_hton->create_select = create_columnstore_select_handler; + innodb_hton->create_unit = create_columnstore_unit_handler; } - innodb_hton->create_select = create_columnstore_select_handler; - innodb_hton->create_unit = create_columnstore_unit_handler; -} #ifdef HAVE_PSI_INTERFACE uint count = sizeof(all_mutexes) / sizeof(all_mutexes[0]); diff --git a/dbcon/mysql/ha_mcs_impl.cpp b/dbcon/mysql/ha_mcs_impl.cpp index 0d44660f5..4c2552634 100644 --- a/dbcon/mysql/ha_mcs_impl.cpp +++ b/dbcon/mysql/ha_mcs_impl.cpp @@ -4077,9 +4077,9 @@ int ha_mcs_impl_pushdown_init(mcs_handler_info* handler_info, TABLE* table, bool boost::shared_ptr csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID); csc->identity(CalpontSystemCatalog::FE); - if (!get_fe_conn_info_ptr()) + if (!get_fe_conn_info_ptr()) { - set_fe_conn_info_ptr(reinterpret_cast(new cal_connection_info(), thd)); + set_fe_conn_info_ptr((void*)new cal_connection_info()); thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr()); } @@ -4127,33 +4127,33 @@ int ha_mcs_impl_pushdown_init(mcs_handler_info* handler_info, TABLE* table, bool bool localQuery = (get_local_query(thd) > 0 ? true : false); { - // ci->stats.reset(); // reset query stats - // ci->stats.setStartTime(); - // if (thd->main_security_ctx.user) - // { - // ci->stats.fUser = thd->main_security_ctx.user; - // } - // else - // { - // ci->stats.fUser = ""; - // } + ci->stats.reset(); // reset query stats + ci->stats.setStartTime(); + if (thd->main_security_ctx.user) + { + ci->stats.fUser = thd->main_security_ctx.user; + } + else + { + ci->stats.fUser = ""; + } - // if (thd->main_security_ctx.host) - // ci->stats.fHost = thd->main_security_ctx.host; - // else if (thd->main_security_ctx.host_or_ip) - // ci->stats.fHost = thd->main_security_ctx.host_or_ip; - // else - // ci->stats.fHost = "unknown"; + if (thd->main_security_ctx.host) + ci->stats.fHost = thd->main_security_ctx.host; + else if (thd->main_security_ctx.host_or_ip) + ci->stats.fHost = thd->main_security_ctx.host_or_ip; + else + ci->stats.fHost = "unknown"; - // try - // { - // ci->stats.userPriority(ci->stats.fHost, ci->stats.fUser); - // } - // catch (std::exception& e) - // { - // string msg = string("Columnstore User Priority - ") + e.what(); - // ci->warningMsg = msg; - // } + try + { + ci->stats.userPriority(ci->stats.fHost, ci->stats.fUser); + } + catch (std::exception& e) + { + string msg = string("Columnstore User Priority - ") + e.what(); + ci->warningMsg = msg; + } // if the previous query has error, re-establish the connection if (ci->queryState != 0) diff --git a/dbcon/mysql/ha_mcs_sysvars.cpp b/dbcon/mysql/ha_mcs_sysvars.cpp index aaeecbc04..029dae8a0 100644 --- a/dbcon/mysql/ha_mcs_sysvars.cpp +++ b/dbcon/mysql/ha_mcs_sysvars.cpp @@ -220,6 +220,9 @@ static MYSQL_THDVAR_ULONG(max_allowed_in_values, PLUGIN_VAR_RQCMDARG, "The maximum length of the entries in the IN query clause.", NULL, NULL, 6000, 1, ~0U, 1); +static MYSQL_THDVAR_BOOL(innodb_queries_uses_mcs, PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY, + "Direct all InnoDB-only queries into MCS via Select Handler.", NULL, NULL, 0); + st_mysql_sys_var* mcs_system_variables[] = {MYSQL_SYSVAR(compression_type), MYSQL_SYSVAR(fe_conn_info_ptr), MYSQL_SYSVAR(original_optimizer_flags), @@ -260,6 +263,7 @@ st_mysql_sys_var* mcs_system_variables[] = {MYSQL_SYSVAR(compression_type), MYSQL_SYSVAR(s3_region), MYSQL_SYSVAR(pron), MYSQL_SYSVAR(max_allowed_in_values), + MYSQL_SYSVAR(innodb_queries_uses_mcs), NULL}; st_mysql_show_var mcs_status_variables[] = {{"columnstore_version", (char*)&cs_version, SHOW_CHAR}, @@ -654,4 +658,14 @@ ulong get_max_allowed_in_values(THD* thd) void set_max_allowed_in_values(THD* thd, ulong value) { THDVAR(thd, max_allowed_in_values) = value; -} \ No newline at end of file +} + +bool get_innodb_queries_uses_mcs(THD* thd) +{ + return THDVAR(thd, innodb_queries_uses_mcs); +} + +void set_innodb_queries_uses_mcs(THD* thd, bool value) +{ + THDVAR(thd, innodb_queries_uses_mcs) = value; +} diff --git a/utils/libmysql_client/libmysql_client.cpp b/utils/libmysql_client/libmysql_client.cpp index 074ab16f8..540718183 100644 --- a/utils/libmysql_client/libmysql_client.cpp +++ b/utils/libmysql_client/libmysql_client.cpp @@ -96,6 +96,14 @@ int LibMySQL::init(const char* h, unsigned int p, const char* u, const char* w, return ret; } + // Disable Select Handler to avoid recursive SH execution path for CES. + static const std::string disableSelectHandler = "SET SESSION columnstore_select_handler = OFF"; + if (mysql_real_query(fCon, disableSelectHandler.c_str(), disableSelectHandler.length()) != 0) + { + fErrStr = "fatal error setting columnstore_select_handler=OFF in libmysql_client lib"; + ret = -1; + return ret; + } return ret; }