diff --git a/dbcon/mysql/ha_calpont_impl.cpp b/dbcon/mysql/ha_calpont_impl.cpp index ed824da4e..6ac717deb 100644 --- a/dbcon/mysql/ha_calpont_impl.cpp +++ b/dbcon/mysql/ha_calpont_impl.cpp @@ -4065,7 +4065,9 @@ int ha_calpont_impl_external_lock(THD* thd, TABLE* table, int lock_type) // MCOL-2178 Check for tableMap size to set this only once. ci->queryState = 0; + // Clean up the tableMap and physTablesList ci->tableMap.erase(table); + ci->physTablesList.erase(table); } else { @@ -4078,12 +4080,12 @@ int ha_calpont_impl_external_lock(THD* thd, TABLE* table, int lock_type) else if (lock_type == 2) { std::set::iterator iter = ci->physTablesList.find(table); - if ( iter != ci->physTablesList.end() ) + if (iter != ci->physTablesList.end()) { ci->physTablesList.erase(table); } - if ( iter != ci->physTablesList.end() && ci->physTablesList.empty() ) + if (iter != ci->physTablesList.end() && ci->physTablesList.empty()) { if (!ci->cal_conn_hndl) return 0; @@ -5132,12 +5134,14 @@ int ha_cs_impl_pushdown_init(mcs_handler_info* handler_info, TABLE* table) { // CS resets error in create_SH() if fallback is enabled setError(thd, ER_INTERNAL_ERROR, emsgStr); - return ER_INTERNAL_ERROR; + goto internal_error; } ci->rmParms.clear(); - ci->queryState = 1; + // SH will initiate SM in select_next() only + if (!sh) + ci->queryState= sm::QUERY_IN_PROCESS; break; } @@ -5315,8 +5319,6 @@ int ha_cs_impl_select_next(uchar* buf, TABLE* table) sm::tableid_t tableid= execplan::IDB_VTABLE_ID; sm::cpsm_conhdl_t* hndl= ci->cal_conn_hndl; - if (!ti.tpl_ctx || !ti.tpl_scan_ctx || (hndl && hndl->queryState == sm::NO_QUERY)) - { if (ti.tpl_ctx == 0) { ti.tpl_ctx = new sm::cpsm_tplh_t(); @@ -5362,6 +5364,7 @@ int ha_cs_impl_select_next(uchar* buf, TABLE* table) } } ci->tableMap[table] = ti; + hndl->queryState= sm::QUERY_IN_PROCESS; } if (!ti.tpl_ctx || !ti.tpl_scan_ctx) diff --git a/dbcon/mysql/ha_mcs_pushdown.cpp b/dbcon/mysql/ha_mcs_pushdown.cpp index bc9f26d00..48fae7624 100644 --- a/dbcon/mysql/ha_mcs_pushdown.cpp +++ b/dbcon/mysql/ha_mcs_pushdown.cpp @@ -394,7 +394,7 @@ create_columnstore_derived_handler(THD* thd, TABLE_LIST *derived) // 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 ) + || (thd->lex)->sql_command == SQLCOM_CREATE_TABLE) { unsupported_feature = true; } @@ -642,29 +642,40 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex) 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 ) + // 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; } - // 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; - } - + JOIN *join= select_lex->join; // Next block tries to execute the query using SH very early to fallback // if execution fails. if (!unsupported_feature) { - handler= new ha_columnstore_select_handler(thd, select_lex); + // TODO This part must explicitly call a list of needed optimizations mutate_optimizer_flags(thd); + join->optimization_state= JOIN::OPTIMIZATION_IN_PROGRESS; + join->optimize_inner(); + + // 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); + } + } + + if (!unsupported_feature) + { + handler= new ha_columnstore_select_handler(thd, select_lex); + // This is an ugly hack to call simplify_joins() mcs_handler_info mhi= mcs_handler_info(reinterpret_cast(handler), SELECT); // this::table is the place for the result set int rc= ha_cs_impl_pushdown_init(&mhi, handler->table); @@ -679,6 +690,23 @@ create_columnstore_select_handler(THD* thd, SELECT_LEX* select_lex) { thd->get_stmt_da()->reset_diagnostics_area(); restore_optimizer_flags(thd); + unsupported_feature = true; + } + } + + if (join->optimization_state != JOIN::NOT_OPTIMIZED) + { + if (!join->with_two_phase_optimization) + { + if (unsupported_feature && join->have_query_plan != JOIN::QEP_DELETED) + { + join->build_explain(); + } + join->optimization_state= JOIN::OPTIMIZATION_DONE; + } + else + { + join->optimization_state= JOIN::OPTIMIZATION_PHASE_1_DONE; } } diff --git a/dbcon/mysql/my.cnf b/dbcon/mysql/my.cnf index 12392a664..046476547 100644 --- a/dbcon/mysql/my.cnf +++ b/dbcon/mysql/my.cnf @@ -45,6 +45,7 @@ thread_stack = 512K lower_case_table_names=1 group_concat_max_len=512 sql_mode="ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" +#columnstore_processing_handlers_fallback = OFF; # Enable compression by default on create, set to 0 to turn off #columnstore_compression_type=2