1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-08 14:22:09 +03:00

Merge pull request #1095 from mariadb-corporation/MCOL-3769_3

MCOL-3769 This commit divides create_SH() in two parts.
Conflicts:
	dbcon/mysql/ha_mcs_pushdown.cpp
This commit is contained in:
Gagan Goel
2020-03-18 14:37:02 -04:00
committed by Patrick LeBlanc
parent eb26fa6539
commit 1e9946e23a
4 changed files with 68 additions and 86 deletions

View File

@@ -18,7 +18,7 @@
// Search simplify_joins() function in the server's code for detail // Search simplify_joins() function in the server's code for detail
COND * COND *
simplify_joins_(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top, simplify_joins_mcs(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top,
bool in_sj) bool in_sj)
{ {
TABLE_LIST *table; TABLE_LIST *table;
@@ -26,7 +26,7 @@ simplify_joins_(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top,
TABLE_LIST *prev_table= 0; TABLE_LIST *prev_table= 0;
List_iterator<TABLE_LIST> li(*join_list); List_iterator<TABLE_LIST> li(*join_list);
bool straight_join= MY_TEST(join->select_options & SELECT_STRAIGHT_JOIN); bool straight_join= MY_TEST(join->select_options & SELECT_STRAIGHT_JOIN);
DBUG_ENTER("simplify_joins"); DBUG_ENTER("simplify_joins_mcs");
/* /*
Try to simplify join operations from join_list. Try to simplify join operations from join_list.
@@ -54,7 +54,7 @@ simplify_joins_(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top,
the outer join is converted to an inner join and the outer join is converted to an inner join and
the corresponding on expression is added to E. the corresponding on expression is added to E.
*/ */
expr= simplify_joins_(join, &nested_join->join_list, expr= simplify_joins_mcs(join, &nested_join->join_list,
expr, FALSE, in_sj || table->sj_on_expr); expr, FALSE, in_sj || table->sj_on_expr);
if (!table->prep_on_expr || expr != table->on_expr) if (!table->prep_on_expr || expr != table->on_expr)
@@ -67,7 +67,7 @@ simplify_joins_(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top,
} }
nested_join->used_tables= (table_map) 0; nested_join->used_tables= (table_map) 0;
nested_join->not_null_tables=(table_map) 0; nested_join->not_null_tables=(table_map) 0;
conds= simplify_joins_(join, &nested_join->join_list, conds, top, conds= simplify_joins_mcs(join, &nested_join->join_list, conds, top,
in_sj || table->sj_on_expr); in_sj || table->sj_on_expr);
used_tables= nested_join->used_tables; used_tables= nested_join->used_tables;
not_null_tables= nested_join->not_null_tables; not_null_tables= nested_join->not_null_tables;

View File

@@ -20,7 +20,7 @@
#include "idb_mysql.h" #include "idb_mysql.h"
COND *simplify_joins_(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top, bool in_sj); COND *simplify_joins_mcs(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top, bool in_sj);
#endif #endif

View File

@@ -27,7 +27,7 @@ void disable_indices_for_CEJ(THD *thd_)
TABLE_LIST* global_list; TABLE_LIST* global_list;
for (global_list = thd_->lex->query_tables; global_list; global_list = global_list->next_global) 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) if (!global_list->derived)
{ {
global_list->index_hints= new (thd_->mem_root) List<Index_hint>(); 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; bool result = false;
TABLE_LIST *tbl; TABLE_LIST *tbl;
@@ -52,7 +52,7 @@ bool optimize_unflattened_subqueries_(SELECT_LEX *select_lex)
if (tbl->is_view_or_derived()) if (tbl->is_view_or_derived())
{ {
SELECT_LEX *dsl = tbl->derived->first_select(); SELECT_LEX *dsl = tbl->derived->first_select();
result = optimize_unflattened_subqueries_(dsl); result = optimize_unflattened_subqueries_mcs(dsl);
} }
} }
@@ -796,9 +796,6 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex)
// Disable SP support in the select_handler for now. // Disable SP support in the select_handler for now.
if ((thd->lex)->sphead) if ((thd->lex)->sphead)
{ {
//std::string warnMsg("Select Handler doesn't support SP.");
//push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
// CS_WARNING_ID, warnMsg.c_str());
return handler; return handler;
} }
@@ -808,9 +805,6 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex)
if (((thd->lex)->result && if (((thd->lex)->result &&
!((select_dumpvar *)(thd->lex)->result)->var_list.is_empty())) !((select_dumpvar *)(thd->lex)->result)->var_list.is_empty()))
{ {
//std::string warnMsg("Select Handler doesn't assign variables values.");
//push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
// CS_WARNING_ID, warnMsg.c_str());
return handler; return handler;
} }
@@ -830,14 +824,10 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex)
|| (thd->lex)->exchange) || (thd->lex)->exchange)
{ {
//std::string warnMsg("Query inserts its result. Select Handler doesn't work.");
//push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
// CS_WARNING_ID, warnMsg.c_str());
return handler; return handler;
} }
bool unsupported_feature = false; bool unsupported_feature = false;
logging::Message::Args args;
// Iterate and traverse through the item list and do not create SH // Iterate and traverse through the item list and do not create SH
// if the unsupported (set/get_user_var) functions are present. // if the unsupported (set/get_user_var) functions are present.
TABLE_LIST* table_ptr = select_lex->get_table_list(); TABLE_LIST* table_ptr = select_lex->get_table_list();
@@ -850,80 +840,57 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex)
item_check(item, &unsupported_feature); item_check(item, &unsupported_feature);
if (unsupported_feature) if (unsupported_feature)
{ {
//std::string warnMsg("Select Handler doesn't work b/c of the unsupported item found in item_check()");
//push_warning(thd, Sql_condition::WARN_LEVEL_WARN,
// CS_WARNING_ID, warnMsg.c_str());
return handler; return handler;
} }
} }
} }
// We apply dedicated rewrites from MDB here so the data structures // 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. // 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; 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); disable_indices_for_CEJ(thd);
if (select_lex->handle_derived(thd->lex, DT_MERGE)) if (select_lex->handle_derived(thd->lex, DT_MERGE))
{ {
// early quit b/c of the error in handle_derived unsupported_feature = true;
return handler; handler->err_msg.assign("create_columnstore_select_handler(): \
Internal error occured in SL::handle_derived()");
} }
COND *conds = NULL; COND *conds = nullptr;
conds = simplify_joins_(join, select_lex->join_list, join->conds, TRUE, FALSE); 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 // MCOL-3747 IN-TO-EXISTS rewrite inside MDB didn't add
// an equi-JOIN condition. // an equi-JOIN condition.
optimize_unflattened_subqueries_(select_lex); if (!unsupported_feature
&& optimize_unflattened_subqueries_mcs(select_lex))
{
unsupported_feature = true;
handler->err_msg.assign("create_columnstore_select_handler(): \
Internal error occured in optimize_unflattened_subqueries_mcs()");
}
if (conds) if (!unsupported_feature && conds)
{ {
#ifdef DEBUG_WALK_COND #ifdef DEBUG_WALK_COND
conds->traverse_cond(cal_impl_if::debug_walk, NULL, Item::POSTFIX); conds->traverse_cond(cal_impl_if::debug_walk, NULL, Item::POSTFIX);
#endif #endif
join->conds = conds; 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);
}
} }
// Restore back the saved group_list // We can't raise error now so set an error to raise it later in init_SH.
if (group_list_ptrs) handler->rewrite_error= unsupported_feature;
{
restore_group_list(select_lex, group_list_ptrs);
}
if (!unsupported_feature) // Return SH even if init fails b/c CS changed SELECT_LEX structures
{ // with simplify_joins_mcs()
handler= new ha_columnstore_select_handler(thd, select_lex); return handler;
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)
{
rc= ha_cs_impl_pushdown_init(&mhi, handler->table);
}
// Return SH even if init fails b/c CS changed SELECT_LEX structures
// with simplify_joins_()
if (rc)
unsupported_feature = true;
return handler;
}
return NULL;
} }
/*********************************************************** /***********************************************************
@@ -937,7 +904,8 @@ ha_columnstore_select_handler::ha_columnstore_select_handler(THD *thd,
SELECT_LEX* select_lex) SELECT_LEX* select_lex)
: select_handler(thd, mcs_hton) : select_handler(thd, mcs_hton)
{ {
select = select_lex; select= select_lex;
rewrite_error= false;
} }
/*********************************************************** /***********************************************************
@@ -961,10 +929,26 @@ int ha_columnstore_select_handler::init_scan()
{ {
DBUG_ENTER("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; 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); DBUG_RETURN(rc);
} }
@@ -1005,6 +989,3 @@ int ha_columnstore_select_handler::end_scan()
DBUG_RETURN(rc); DBUG_RETURN(rc);
} }
void ha_columnstore_select_handler::print_error(int, unsigned long)
{}

View File

@@ -80,9 +80,9 @@ class ha_mcs_group_by_handler: public group_by_handler
public: public:
ha_mcs_group_by_handler(THD* thd_arg, Query* query); ha_mcs_group_by_handler(THD* thd_arg, Query* query);
~ha_mcs_group_by_handler(); ~ha_mcs_group_by_handler();
int init_scan(); int init_scan() override;
int next_row(); int next_row() override;
int end_scan(); int end_scan() override;
List<Item>* select; List<Item>* select;
TABLE_LIST* table_list; TABLE_LIST* table_list;
@@ -114,9 +114,9 @@ private:
public: public:
ha_columnstore_derived_handler(THD* thd_arg, TABLE_LIST *tbl); ha_columnstore_derived_handler(THD* thd_arg, TABLE_LIST *tbl);
~ha_columnstore_derived_handler(); ~ha_columnstore_derived_handler();
int init_scan(); int init_scan() override;
int next_row(); int next_row() override;
int end_scan(); int end_scan() override;
void print_error(int, unsigned long); void print_error(int, unsigned long);
}; };
@@ -139,12 +139,13 @@ private:
COLUMNSTORE_SHARE *share; COLUMNSTORE_SHARE *share;
public: public:
bool rewrite_error;
std::string err_msg;
ha_columnstore_select_handler(THD* thd_arg, SELECT_LEX* sel); ha_columnstore_select_handler(THD* thd_arg, SELECT_LEX* sel);
~ha_columnstore_select_handler(); ~ha_columnstore_select_handler();
int init_scan(); int init_scan() override;
int next_row(); int next_row() override;
int end_scan(); int end_scan() override;
void print_error(int, unsigned long);
}; };
#endif #endif