diff --git a/dbcon/mysql/ha_calpont_execplan.cpp b/dbcon/mysql/ha_calpont_execplan.cpp index a74b2abdf..88abfb9e1 100644 --- a/dbcon/mysql/ha_calpont_execplan.cpp +++ b/dbcon/mysql/ha_calpont_execplan.cpp @@ -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. We therefore do not allow limit set to 1 here for such queries. */ - if (gwi.subSelectType != CalpontSelectExecutionPlan::IN_SUBS && - select_lex.master_unit()->global_parameters()->explicit_limit) + if (gwi.subSelectType != CalpontSelectExecutionPlan::IN_SUBS + && gwi.subSelectType != CalpontSelectExecutionPlan::EXISTS_SUBS + && select_lex.master_unit()->global_parameters()->explicit_limit) { if (select_lex.master_unit()->global_parameters()->offset_limit) { diff --git a/dbcon/mysql/ha_calpont_impl.cpp b/dbcon/mysql/ha_calpont_impl.cpp index c39cef8a0..67a524eef 100644 --- a/dbcon/mysql/ha_calpont_impl.cpp +++ b/dbcon/mysql/ha_calpont_impl.cpp @@ -2747,12 +2747,6 @@ int ha_calpont_impl_rnd_end(TABLE* table, bool is_pushdown_hand) ((thd->lex)->sql_command == SQLCOM_UPDATE_MULTI)) 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) { 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); - 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 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 ci->tableMap.erase(table); ci->physTablesList.erase(table); + thd->variables.in_subquery_conversion_threshold = IN_SUBQUERY_CONVERSION_THRESHOLD; + restore_optimizer_flags(thd); } else { - if (lock_type == 0) + if (lock_type == 0) { ci->physTablesList.insert(table); // 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) { @@ -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 // storage for cal_conn_hndl to use it later in close_connection 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(); // MCOL-2178 Enable Conversion of Big IN Predicates Into Subqueries thd->variables.in_subquery_conversion_threshold = IN_SUBQUERY_CONVERSION_THRESHOLD; diff --git a/dbcon/mysql/ha_exists_sub.cpp b/dbcon/mysql/ha_exists_sub.cpp index ee3326803..9db9294c9 100644 --- a/dbcon/mysql/ha_exists_sub.cpp +++ b/dbcon/mysql/ha_exists_sub.cpp @@ -112,7 +112,7 @@ execplan::ParseTree* ExistsSub::transform() 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; diff --git a/dbcon/mysql/ha_in_sub.cpp b/dbcon/mysql/ha_in_sub.cpp index a582ea5bf..4d1e828ce 100644 --- a/dbcon/mysql/ha_in_sub.cpp +++ b/dbcon/mysql/ha_in_sub.cpp @@ -148,7 +148,7 @@ execplan::ParseTree* InSub::transform() gwi.tbList.insert(gwi.tbList.begin(), fGwip.tbList.begin(), fGwip.tbList.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; diff --git a/dbcon/mysql/ha_mcs_pushdown.cpp b/dbcon/mysql/ha_mcs_pushdown.cpp index 3caca6189..3f034d412 100644 --- a/dbcon/mysql/ha_mcs_pushdown.cpp +++ b/dbcon/mysql/ha_mcs_pushdown.cpp @@ -286,8 +286,8 @@ void check_user_var_func(const Item* item, void* arg) if (item->type() == Item::FUNC_ITEM) { const Item_func* ifp = reinterpret_cast(item); - std::string funcName = ifp->func_name(); - if (funcName == "set_user_var" || funcName == "get_user_var") + std::string funcname = ifp->func_name(); + if (funcname == "set_user_var" || funcname == "get_user_var") { *unsupported_feature = true; } @@ -455,16 +455,8 @@ create_columnstore_derived_handler(THD* thd, TABLE_LIST *derived) SELECT_LEX *sl= unit->first_select(); 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 - // TODO replace with function call if ( unsupported_feature || sl->having_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(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 // is ready. if (!unsupported_feature && join @@ -718,15 +718,17 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex) return handler; } + // This block gives false positive in + // partitionOptimization/vTpch11. // Disable SH processing for UNION in a subquery. // This way, the server falls back to using the DH for executing // 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 && (tbl_ptr->derived->is_unit_op() || tbl_ptr->derived->fake_select_lex)) { return handler; - } + }*/ bool unsupported_feature = false; // 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 (!unsupported_feature) { - // TODO This part must explicitly call a list of needed optimizations - mutate_optimizer_flags(thd); + // Most of optimizer_switch flags disabled in external_lock join->optimization_state= JOIN::OPTIMIZATION_IN_PROGRESS; join->optimize_inner(); diff --git a/dbcon/mysql/ha_scalar_sub.cpp b/dbcon/mysql/ha_scalar_sub.cpp index debd777f0..f41482ba2 100644 --- a/dbcon/mysql/ha_scalar_sub.cpp +++ b/dbcon/mysql/ha_scalar_sub.cpp @@ -253,7 +253,7 @@ execplan::ParseTree* ScalarSub::buildParseTree(PredicateOperator* op) gwi.tbList.insert(gwi.tbList.begin(), fGwip.tbList.begin(), fGwip.tbList.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 if (!gwi.fatalParseError) diff --git a/dbcon/mysql/ha_select_sub.cpp b/dbcon/mysql/ha_select_sub.cpp index 0b003b664..708d2cca8 100644 --- a/dbcon/mysql/ha_select_sub.cpp +++ b/dbcon/mysql/ha_select_sub.cpp @@ -77,7 +77,7 @@ SCSEP SelectSubQuery::transform() gwi.tbList.insert(gwi.tbList.begin(), fGwip.tbList.begin(), fGwip.tbList.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) {