1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-12-24 14:20:59 +03:00

MCOL-3769 This commit divides create_SH in two parts: before rewrites and

after rewrites. We can safely fallback from SH to DH and table mode from
'before rewrites' part.
This commit is contained in:
Roman Nozdrin
2020-02-17 12:27:23 +00:00
parent f9fbb86ced
commit 3345f7a437
4 changed files with 98 additions and 87 deletions

View File

@@ -27,7 +27,7 @@ void disable_indices_for_CEJ(THD *thd_)
TABLE_LIST* global_list;
for (global_list = thd_->lex->query_tables; global_list; global_list = global_list->next_global)
{
// MCOL-652 - doing this with derived tables can cause bad things to happen
// MCOL-652 - doing this with derived tables can cause bad things to happen
if (!global_list->derived)
{
global_list->index_hints= new (thd_->mem_root) List<Index_hint>();
@@ -42,7 +42,7 @@ void disable_indices_for_CEJ(THD *thd_)
}
}
bool optimize_unflattened_subqueries_(SELECT_LEX *select_lex)
bool optimize_unflattened_subqueries_mcs(SELECT_LEX *select_lex)
{
bool result = false;
TABLE_LIST *tbl;
@@ -52,7 +52,7 @@ bool optimize_unflattened_subqueries_(SELECT_LEX *select_lex)
if (tbl->is_view_or_derived())
{
SELECT_LEX *dsl = tbl->derived->first_select();
result = optimize_unflattened_subqueries_(dsl);
result = optimize_unflattened_subqueries_mcs(dsl);
}
}
@@ -516,7 +516,7 @@ create_columnstore_derived_handler(THD* thd, TABLE_LIST *derived)
//To search for CROSS JOIN-s we use tree invariant
//G(V,E) where [V] = [E]+1
List<Item> join_preds_list;
TABLE_LIST *tl;
TABLE_LIST *tl;
for (tl = sl->get_table_list(); !unsupported_feature && tl; tl = tl->next_local)
{
Item_cond* where_icp= 0;
@@ -756,68 +756,38 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex)
{
ha_columnstore_select_handler* handler = NULL;
// MCOL-2178 Disable SP support in the select_handler for now.
// Check the session variable value to enable/disable use of
// select_handler
// Disable processing of select_result_interceptor classes
// which intercept and transform result set rows. E.g.:
// select a,b into @a1, @a2 from t1;
if (!get_select_handler(thd) || (thd->lex)->sphead ||
((thd->lex)->result &&
!((select_dumpvar *)(thd->lex)->result)->var_list.is_empty()))
if (!get_select_handler(thd))
{
return handler;
}
bool unsupported_feature = false;
// Disable SP support in the select_handler for now.
if ((thd->lex)->sphead)
{
return handler;
}
// Disable processing of select_result_interceptor classes
// which intercept and transform result set rows. E.g.:
// select a,b into @a1, @a2 from t1;
if (((thd->lex)->result &&
!((select_dumpvar *)(thd->lex)->result)->var_list.is_empty()))
{
return handler;
}
// Select_handler use the short-cut that effectively disables
// INSERT..SELECT, LDI, SELECT..INTO OUTFILE
if ((thd->lex)->sql_command == SQLCOM_INSERT_SELECT
|| (thd->lex)->sql_command == SQLCOM_CREATE_TABLE
|| (thd->lex)->exchange)
{
unsupported_feature = true;
}
JOIN *join= select_lex->join;
// Next block tries to execute the query using SH very early to fallback
// if execution fails.
if (!unsupported_feature)
{
disable_indices_for_CEJ(thd);
if (select_lex->handle_derived(thd->lex, DT_MERGE))
{
// early quit b/c of the error in handle_derived
return handler;
}
COND *conds = simplify_joins_(join, select_lex->join_list, join->conds, TRUE, FALSE);
// MCOL-3747 IN-TO-EXISTS rewrite inside MDB didn't add
// an equi-JOIN condition.
optimize_unflattened_subqueries_(select_lex);
if (conds)
{
#ifdef DEBUG_WALK_COND
conds->traverse_cond(cal_impl_if::debug_walk, NULL, Item::POSTFIX);
#endif
join->conds = conds;
}
// Impossible HAVING or WHERE
// TODO replace with function call
if (unsupported_feature
|| select_lex->having_value == Item::COND_FALSE
|| select_lex->cond_value == Item::COND_FALSE )
{
unsupported_feature = true;
restore_optimizer_flags(thd);
}
return handler;
}
bool unsupported_feature = false;
// Iterate and traverse through the item list and do not create SH
// if the unsupported (set/get_user_var) functions are present.
TABLE_LIST* table_ptr = select_lex->get_table_list();
@@ -830,31 +800,57 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex)
item_check(item, &unsupported_feature);
if (unsupported_feature)
{
break;
return handler;
}
}
}
if (!unsupported_feature)
// We apply dedicated rewrites from MDB here so MDB's data structures
// becomes dirty and CS has to raise an error in case of any problem
// or unsupported feature.
handler= new ha_columnstore_select_handler(thd, select_lex);
JOIN *join= select_lex->join;
{
handler= new ha_columnstore_select_handler(thd, select_lex);
mcs_handler_info mhi= mcs_handler_info(reinterpret_cast<void*>(handler), SELECT);
// handler::table is the place for the result set
int rc= 0;
// Skip execution for EXPLAIN queries
if (!thd->lex->describe)
disable_indices_for_CEJ(thd);
if (select_lex->handle_derived(thd->lex, DT_MERGE))
{
rc= ha_cs_impl_pushdown_init(&mhi, handler->table);
unsupported_feature = true;
handler->err_msg.assign("create_columnstore_select_handler(): \
Internal error occured in SL::handle_derived()");
}
// Return SH even if init fails b/c CS changed SELECT_LEX structures
// with simplify_joins_()
if (rc)
COND *conds = nullptr;
if (!unsupported_feature)
{
conds = simplify_joins_mcs(join, select_lex->join_list,
join->conds, TRUE, FALSE);
}
// MCOL-3747 IN-TO-EXISTS rewrite inside MDB didn't add
// an equi-JOIN condition.
if (!unsupported_feature
&& optimize_unflattened_subqueries_mcs(select_lex))
{
unsupported_feature = true;
return handler;
handler->err_msg.assign("create_columnstore_select_handler(): \
Internal error occured in optimize_unflattened_subqueries_mcs()");
}
if (!unsupported_feature && conds)
{
#ifdef DEBUG_WALK_COND
conds->traverse_cond(cal_impl_if::debug_walk, NULL, Item::POSTFIX);
#endif
join->conds = conds;
}
}
return NULL;
// We can't raise error now so set an error to raise it later in init_SH.
handler->rewrite_error= unsupported_feature;
// Return SH even if init fails b/c CS changed SELECT_LEX structures
// with simplify_joins_mcs()
return handler;
}
/***********************************************************
@@ -868,7 +864,8 @@ ha_columnstore_select_handler::ha_columnstore_select_handler(THD *thd,
SELECT_LEX* select_lex)
: select_handler(thd, mcs_hton)
{
select = select_lex;
select= select_lex;
rewrite_error= false;
}
/***********************************************************
@@ -892,10 +889,26 @@ int ha_columnstore_select_handler::init_scan()
{
DBUG_ENTER("ha_columnstore_select_handler::init_scan");
// Dummy init for SH. Actual init happens in create_SH
// to allow fallback to other handlers if SH fails.
int rc = 0;
if (!rewrite_error)
{
// handler::table is the place for the result set
// Skip execution for EXPLAIN queries
if (!thd->lex->describe)
{
mcs_handler_info mhi= mcs_handler_info(
reinterpret_cast<void*>(this), SELECT);
rc= ha_cs_impl_pushdown_init(&mhi, this->table);
}
}
else
{
my_printf_error(ER_INTERNAL_ERROR, "%s", MYF(0), err_msg.c_str());
sql_print_error("%s", err_msg.c_str());
rc= ER_INTERNAL_ERROR;
}
DBUG_RETURN(rc);
}
@@ -936,6 +949,3 @@ int ha_columnstore_select_handler::end_scan()
DBUG_RETURN(rc);
}
void ha_columnstore_select_handler::print_error(int, unsigned long)
{}