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

MCOL-2178 CS now sets optimizer flags like it did in the fork-era.

This happens in external_lock() whilst locking the table.

Fixes LIMIT=1 optimization for EXISTS_SUBS subqueries.

external_lock() contains if condition that gives false positive
for SH + pushed conditions.

external_lock() now resets in_subquery_conversion_threshold
variable that governs IN_INTO_SUBQUERY optimization for
queries run in table mode.

external_lock() now purges dynamicall allocated condInfo for
SH and DH execution path.

Commented out UNION check b/c if condition gives false positives
and silently enables table mode execution for queries w/o
UNION.
This commit is contained in:
Roman Nozdrin
2019-09-13 06:29:55 -05:00
committed by root
parent 0852e316f8
commit 0c58f10d12
7 changed files with 42 additions and 29 deletions

View File

@ -7779,8 +7779,9 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex,
hash join, giving less number of rows in the output result set than expected. hash join, giving less number of rows in the output result set than expected.
We therefore do not allow limit set to 1 here for such queries. We therefore do not allow limit set to 1 here for such queries.
*/ */
if (gwi.subSelectType != CalpontSelectExecutionPlan::IN_SUBS && if (gwi.subSelectType != CalpontSelectExecutionPlan::IN_SUBS
select_lex.master_unit()->global_parameters()->explicit_limit) && gwi.subSelectType != CalpontSelectExecutionPlan::EXISTS_SUBS
&& select_lex.master_unit()->global_parameters()->explicit_limit)
{ {
if (select_lex.master_unit()->global_parameters()->offset_limit) if (select_lex.master_unit()->global_parameters()->offset_limit)
{ {

View File

@ -2747,12 +2747,6 @@ int ha_calpont_impl_rnd_end(TABLE* table, bool is_pushdown_hand)
((thd->lex)->sql_command == SQLCOM_UPDATE_MULTI)) ((thd->lex)->sql_command == SQLCOM_UPDATE_MULTI))
return rc; return rc;
if (((thd->lex)->sql_command == SQLCOM_INSERT) ||
((thd->lex)->sql_command == SQLCOM_INSERT_SELECT) )
{
force_close_fep_conn(thd, ci, true); // checking prev command rc
}
if (!ci) if (!ci)
{ {
set_fe_conn_info_ptr((void*)new cal_connection_info()); set_fe_conn_info_ptr((void*)new cal_connection_info());
@ -4042,7 +4036,11 @@ int ha_calpont_impl_external_lock(THD* thd, TABLE* table, int lock_type)
CalTableMap::iterator mapiter = ci->tableMap.find(table); CalTableMap::iterator mapiter = ci->tableMap.find(table);
if (mapiter != ci->tableMap.end() && lock_type == 2) // make sure it's the release lock (2nd) call // make sure this is a release lock (2nd) call called in
// the table mode.
if (mapiter != ci->tableMap.end()
&& (mapiter->second.condInfo && mapiter->second.csep)
&& lock_type == 2)
{ {
// table mode // table mode
if (mapiter->second.conn_hndl) if (mapiter->second.conn_hndl)
@ -4068,14 +4066,18 @@ int ha_calpont_impl_external_lock(THD* thd, TABLE* table, int lock_type)
// Clean up the tableMap and physTablesList // Clean up the tableMap and physTablesList
ci->tableMap.erase(table); ci->tableMap.erase(table);
ci->physTablesList.erase(table); ci->physTablesList.erase(table);
thd->variables.in_subquery_conversion_threshold = IN_SUBQUERY_CONVERSION_THRESHOLD;
restore_optimizer_flags(thd);
} }
else else
{ {
if (lock_type == 0) if (lock_type == 0)
{ {
ci->physTablesList.insert(table); ci->physTablesList.insert(table);
// MCOL-2178 Disable Conversion of Big IN Predicates Into Subqueries // MCOL-2178 Disable Conversion of Big IN Predicates Into Subqueries
thd->variables.in_subquery_conversion_threshold=~0; thd->variables.in_subquery_conversion_threshold=~ 0;
// Early optimizer_switch changes to avoid unsupported opt-s.
mutate_optimizer_flags(thd);
} }
else if (lock_type == 2) else if (lock_type == 2)
{ {
@ -4100,6 +4102,15 @@ int ha_calpont_impl_external_lock(THD* thd, TABLE* table, int lock_type)
// MCOL-3247 Use THD::ha_data as a per-plugin per-session // MCOL-3247 Use THD::ha_data as a per-plugin per-session
// storage for cal_conn_hndl to use it later in close_connection // storage for cal_conn_hndl to use it later in close_connection
thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr()); thd_set_ha_data(thd, mcs_hton, get_fe_conn_info_ptr());
// Clean up all tableMap entries made by cond_push
for (auto &tme: ci->tableMap)
{
if (tme.second.condInfo)
{
delete tme.second.condInfo;
tme.second.condInfo= 0;
}
}
ci->tableMap.clear(); ci->tableMap.clear();
// MCOL-2178 Enable Conversion of Big IN Predicates Into Subqueries // MCOL-2178 Enable Conversion of Big IN Predicates Into Subqueries
thd->variables.in_subquery_conversion_threshold = IN_SUBQUERY_CONVERSION_THRESHOLD; thd->variables.in_subquery_conversion_threshold = IN_SUBQUERY_CONVERSION_THRESHOLD;

View File

@ -112,7 +112,7 @@ execplan::ParseTree* ExistsSub::transform()
return NULL; return NULL;
} }
if (getSelectPlan(gwi, *(fSub->get_select_lex()), csep) != 0) if (getSelectPlan(gwi, *(fSub->get_select_lex()), csep, false, true) != 0)
{ {
fGwip.fatalParseError = true; fGwip.fatalParseError = true;

View File

@ -148,7 +148,7 @@ execplan::ParseTree* InSub::transform()
gwi.tbList.insert(gwi.tbList.begin(), fGwip.tbList.begin(), fGwip.tbList.end()); gwi.tbList.insert(gwi.tbList.begin(), fGwip.tbList.begin(), fGwip.tbList.end());
gwi.derivedTbList.insert(gwi.derivedTbList.begin(), fGwip.derivedTbList.begin(), fGwip.derivedTbList.end()); gwi.derivedTbList.insert(gwi.derivedTbList.begin(), fGwip.derivedTbList.begin(), fGwip.derivedTbList.end());
if (getSelectPlan(gwi, *(fSub->get_select_lex()), csep) != 0) if (getSelectPlan(gwi, *(fSub->get_select_lex()), csep, false, true) != 0)
{ {
fGwip.fatalParseError = true; fGwip.fatalParseError = true;

View File

@ -286,8 +286,8 @@ void check_user_var_func(const Item* item, void* arg)
if (item->type() == Item::FUNC_ITEM) if (item->type() == Item::FUNC_ITEM)
{ {
const Item_func* ifp = reinterpret_cast<const Item_func*>(item); const Item_func* ifp = reinterpret_cast<const Item_func*>(item);
std::string funcName = ifp->func_name(); std::string funcname = ifp->func_name();
if (funcName == "set_user_var" || funcName == "get_user_var") if (funcname == "set_user_var" || funcname == "get_user_var")
{ {
*unsupported_feature = true; *unsupported_feature = true;
} }
@ -455,16 +455,8 @@ create_columnstore_derived_handler(THD* thd, TABLE_LIST *derived)
SELECT_LEX *sl= unit->first_select(); SELECT_LEX *sl= unit->first_select();
bool unsupported_feature = false; bool unsupported_feature = false;
// Select_handler use the short-cut that effectively disables
// INSERT..SELECT and LDI
if ( (thd->lex)->sql_command == SQLCOM_INSERT_SELECT
|| (thd->lex)->sql_command == SQLCOM_CREATE_TABLE)
{
unsupported_feature = true;
}
// Impossible HAVING or WHERE // Impossible HAVING or WHERE
// TODO replace with function call
if ( unsupported_feature if ( unsupported_feature
|| sl->having_value == Item::COND_FALSE || sl->having_value == Item::COND_FALSE
|| sl->cond_value == Item::COND_FALSE ) || sl->cond_value == Item::COND_FALSE )
@ -517,6 +509,14 @@ create_columnstore_derived_handler(THD* thd, TABLE_LIST *derived)
} }
} }
if (!unsupported_feature && !join_preds_list.elements
&& join && join->conds)
{
Item_cond* conds= reinterpret_cast<Item_cond*>(join->conds);
conds->traverse_cond(check_walk, &unsupported_feature, Item::POSTFIX);
conds->traverse_cond(save_join_predicates, &join_preds_list, Item::POSTFIX);
}
// CROSS JOIN w/o conditions isn't supported until MCOL-301 // CROSS JOIN w/o conditions isn't supported until MCOL-301
// is ready. // is ready.
if (!unsupported_feature && join if (!unsupported_feature && join
@ -718,15 +718,17 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex)
return handler; return handler;
} }
// This block gives false positive in
// partitionOptimization/vTpch11.
// Disable SH processing for UNION in a subquery. // Disable SH processing for UNION in a subquery.
// This way, the server falls back to using the DH for executing // This way, the server falls back to using the DH for executing
// the UNION, if enabled. // the UNION, if enabled.
TABLE_LIST *tbl_ptr = select_lex->get_table_list(); /*TABLE_LIST *tbl_ptr = select_lex->get_table_list();
if (tbl_ptr && tbl_ptr->derived && if (tbl_ptr && tbl_ptr->derived &&
(tbl_ptr->derived->is_unit_op() || tbl_ptr->derived->fake_select_lex)) (tbl_ptr->derived->is_unit_op() || tbl_ptr->derived->fake_select_lex))
{ {
return handler; return handler;
} }*/
bool unsupported_feature = false; bool unsupported_feature = false;
// Select_handler use the short-cut that effectively disables // Select_handler use the short-cut that effectively disables
@ -744,8 +746,7 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex)
// if execution fails. // if execution fails.
if (!unsupported_feature) if (!unsupported_feature)
{ {
// TODO This part must explicitly call a list of needed optimizations // Most of optimizer_switch flags disabled in external_lock
mutate_optimizer_flags(thd);
join->optimization_state= JOIN::OPTIMIZATION_IN_PROGRESS; join->optimization_state= JOIN::OPTIMIZATION_IN_PROGRESS;
join->optimize_inner(); join->optimize_inner();

View File

@ -253,7 +253,7 @@ execplan::ParseTree* ScalarSub::buildParseTree(PredicateOperator* op)
gwi.tbList.insert(gwi.tbList.begin(), fGwip.tbList.begin(), fGwip.tbList.end()); gwi.tbList.insert(gwi.tbList.begin(), fGwip.tbList.begin(), fGwip.tbList.end());
gwi.derivedTbList.insert(gwi.derivedTbList.begin(), fGwip.derivedTbList.begin(), fGwip.derivedTbList.end()); gwi.derivedTbList.insert(gwi.derivedTbList.begin(), fGwip.derivedTbList.begin(), fGwip.derivedTbList.end());
if (getSelectPlan(gwi, *(fSub->get_select_lex()), csep) != 0) if (getSelectPlan(gwi, *(fSub->get_select_lex()), csep, false, true) != 0)
{ {
//@todo more in error handling //@todo more in error handling
if (!gwi.fatalParseError) if (!gwi.fatalParseError)

View File

@ -77,7 +77,7 @@ SCSEP SelectSubQuery::transform()
gwi.tbList.insert(gwi.tbList.begin(), fGwip.tbList.begin(), fGwip.tbList.end()); gwi.tbList.insert(gwi.tbList.begin(), fGwip.tbList.begin(), fGwip.tbList.end());
gwi.derivedTbList.insert(gwi.derivedTbList.begin(), fGwip.derivedTbList.begin(), fGwip.derivedTbList.end()); gwi.derivedTbList.insert(gwi.derivedTbList.begin(), fGwip.derivedTbList.begin(), fGwip.derivedTbList.end());
if (getSelectPlan(gwi, *(fSelSub->get_select_lex()), csep) != 0) if (getSelectPlan(gwi, *(fSelSub->get_select_lex()), csep, false, true) != 0)
{ {
if (!gwi.fatalParseError) if (!gwi.fatalParseError)
{ {