1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

feat(plugin): All InnoDB queries are pushed down to Columnstore if columnstore_innodb_queries_uses_mcs = ON in the configuration before server start

This commit is contained in:
drrtuy
2025-05-19 18:42:23 +00:00
parent 11e5e481ab
commit 9038f0df09
4 changed files with 61 additions and 36 deletions

View File

@ -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,6 +1860,7 @@ static int columnstore_init_func(void* p)
mcs_hton->create_unit = create_columnstore_unit_handler;
mcs_hton->db_type = DB_TYPE_AUTOASSIGN;
if (get_innodb_queries_uses_mcs(current_thd))
{
auto* innodb_hton = plugin_hton(plugin_innodb);
int error = innodb_hton == nullptr; // Engine must exists!

View File

@ -4079,7 +4079,7 @@ int ha_mcs_impl_pushdown_init(mcs_handler_info* handler_info, TABLE* table, bool
if (!get_fe_conn_info_ptr())
{
set_fe_conn_info_ptr(reinterpret_cast<void*>(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)

View File

@ -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},
@ -655,3 +659,13 @@ void set_max_allowed_in_values(THD* thd, ulong value)
{
THDVAR(thd, max_allowed_in_values) = value;
}
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;
}

View File

@ -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;
}