From 7d5275e1bd70fd278d8b44553bd4a42259906c01 Mon Sep 17 00:00:00 2001 From: Roman Nozdrin Date: Mon, 15 Jul 2019 21:58:45 +0300 Subject: [PATCH] MCOL-2178 CS now doesn't initiate a scan when MDB explicitly set scan to false in rnd_init(). sortItemIsInGroupRec() now has a base case for Item_Field and this prevents unbound recursion. Fixes fromSub() call with incorrect number of arguments. CS now doesn't ask for statistics unless a user explicitly asks for it using calsettrace(). --- dbcon/mysql/ha_calpont.cpp | 6 ++- dbcon/mysql/ha_calpont_execplan.cpp | 6 ++- dbcon/mysql/ha_calpont_impl.cpp | 10 +++- dbcon/mysql/sm.cpp | 84 +++++++++++++++-------------- dbcon/mysql/sm.h | 2 +- 5 files changed, 62 insertions(+), 46 deletions(-) diff --git a/dbcon/mysql/ha_calpont.cpp b/dbcon/mysql/ha_calpont.cpp index 19c37fd73..50b69c297 100644 --- a/dbcon/mysql/ha_calpont.cpp +++ b/dbcon/mysql/ha_calpont.cpp @@ -527,7 +527,11 @@ int ha_calpont::rnd_init(bool scan) { DBUG_ENTER("ha_calpont::rnd_init"); - int rc = ha_calpont_impl_rnd_init(table); + int rc = 0; + if(scan) + { + rc = ha_calpont_impl_rnd_init(table); + } DBUG_RETURN(rc); } diff --git a/dbcon/mysql/ha_calpont_execplan.cpp b/dbcon/mysql/ha_calpont_execplan.cpp index 3526a2175..e5c58cdcb 100644 --- a/dbcon/mysql/ha_calpont_execplan.cpp +++ b/dbcon/mysql/ha_calpont_execplan.cpp @@ -273,6 +273,10 @@ bool sortItemIsInGroupRec(Item* sort_item, Item* group_item) Item_ref* ifp_sort_ref = reinterpret_cast(sort_item); found = sortItemIsInGroupRec(*ifp_sort_ref->ref, group_item); } + else if (!found && sort_item->type() == Item::FIELD_ITEM) + { + return found; + } // seeking for a group_item match for (uint32_t i = 0; !found && i < ifp_sort->argument_count(); i++) @@ -6085,7 +6089,7 @@ int getSelectPlan(gp_walk_info& gwi, SELECT_LEX& select_lex, (table_ptr->derived->first_select())->print(gwi.thd, &str, QT_ORDINARY); SELECT_LEX* select_cursor = table_ptr->derived->first_select(); - FromSubQuery fromSub(gwi, select_cursor, false, isPushdownHand); + FromSubQuery fromSub(gwi, select_cursor, isPushdownHand); string alias(table_ptr->alias.str); fromSub.alias(lower(alias)); diff --git a/dbcon/mysql/ha_calpont_impl.cpp b/dbcon/mysql/ha_calpont_impl.cpp index c7c15ec8e..83cddcb4c 100644 --- a/dbcon/mysql/ha_calpont_impl.cpp +++ b/dbcon/mysql/ha_calpont_impl.cpp @@ -3062,7 +3062,10 @@ int ha_calpont_impl_rnd_end(TABLE* table, bool is_pushdown_hand) try { - sm::tpl_close(ti.tpl_ctx, &hndl, ci->stats); + { + bool ask_4_stats = (ci->traceFlags) ? true : false; + sm::tpl_close(ti.tpl_ctx, &hndl, ci->stats, ask_4_stats); + } // set conn hndl back. could be changed in tpl_close if (MIGR::infinidb_vtable.vtable_state == MIGR::INFINIDB_DISABLE_VTABLE) @@ -5124,7 +5127,10 @@ int ha_calpont_impl_group_by_end(ha_calpont_group_by_handler* group_hand, TABLE* { if(hndl) { - sm::tpl_close(ti.tpl_ctx, &hndl, ci->stats, clearScanCtx); + { + bool ask_4_stats = (ci->traceFlags) ? true : false; + sm::tpl_close(ti.tpl_ctx, &hndl, ci->stats, ask_4_stats, clearScanCtx); + } // Normaly stats variables are set in external_lock method but we set it here // since they we pretend we are in vtable_disabled mode and the stats vars won't be set. // We sum the stats up here since server could run a number of diff --git a/dbcon/mysql/sm.cpp b/dbcon/mysql/sm.cpp index 5df01dda6..8dc5c0414 100644 --- a/dbcon/mysql/sm.cpp +++ b/dbcon/mysql/sm.cpp @@ -373,17 +373,16 @@ status_t tpl_close ( cpsm_tplh_t* ntplh, cpsm_conhdl_t** conn_hdl, QueryStats& stats, + bool ask_4_stats, bool clear_scan_ctx) { cpsm_conhdl_t* hndl = *conn_hdl; -#if IDB_SM_DEBUG SMDEBUGLOG << "tpl_close: hndl" << hndl << " ntplh " << ntplh; if (ntplh) SMDEBUGLOG << " tableid: " << ntplh->tableid; SMDEBUGLOG << endl; -#endif delete ntplh; // determine end of result set and end of statement execution @@ -391,57 +390,60 @@ tpl_close ( cpsm_tplh_t* ntplh, { // Get the query stats ByteStream bs; - ByteStream::quadbyte qb = 3; - bs << qb; - hndl->write(bs); - + // Ask for a stats only if a user explicitly asks + if(ask_4_stats) + { + ByteStream::quadbyte qb = 3; + bs << qb; + hndl->write(bs); + } // MCOL-1601 Dispose of unused empty RowGroup if (clear_scan_ctx) { + std::cout << "tpl_close() clear_scan_ctx read" << std::endl; bs = hndl->exeMgr->read(); } -#if IDB_SM_DEBUG SMDEBUGLOG << "tpl_close hndl->exeMgr: " << hndl->exeMgr << endl; -#endif //keep reading until we get a string - //TODO: really need to fix this! Why is ExeMgr sending other stuff? - for (int tries = 0; tries < 10; tries++) + // Ask for a stats only if a user explicitly asks + if(ask_4_stats) { - bs = hndl->exeMgr->read(); + for (int tries = 0; tries < 10; tries++) + { + bs = hndl->exeMgr->read(); - if (bs.length() == 0) break; + if (bs.length() == 0) break; - try - { - bs >> hndl->queryStats; - bs >> hndl->extendedStats; - bs >> hndl->miniStats; - stats.unserialize(bs); - stats.setEndTime(); - stats.insert(); - break; + try + { + bs >> hndl->queryStats; + bs >> hndl->extendedStats; + bs >> hndl->miniStats; + stats.unserialize(bs); + stats.setEndTime(); + stats.insert(); + break; + } + catch (IDBExcept&) + { + // @bug4732 + end_query(hndl); + throw; + } + catch (...) + { + // querystats messed up. close connection. + // no need to throw for querystats protocol error, like for tablemode. + SMDEBUGLOG << "tpl_close() exception whilst getting stats" << endl; + end_query(hndl); + sm_cleanup(hndl); + *conn_hdl = 0; + return STATUS_OK; + //throw runtime_error(string("tbl_close catch exception: ") + e.what()); + } } - catch (IDBExcept&) - { - // @bug4732 - end_query(hndl); - throw; - } - catch (...) - { - // querystats messed up. close connection. - // no need to throw for querystats protocol error, like for tablemode. -#if IDB_SM_DEBUG - SMDEBUGLOG << "tpl_close() exception whilst getting stats" << endl; -#endif - end_query(hndl); - sm_cleanup(hndl); - *conn_hdl = 0; - return STATUS_OK; - //throw runtime_error(string("tbl_close catch exception: ") + e.what()); - } - } + } //stats end_query(hndl); } diff --git a/dbcon/mysql/sm.h b/dbcon/mysql/sm.h index dafa64419..32cb1aa18 100644 --- a/dbcon/mysql/sm.h +++ b/dbcon/mysql/sm.h @@ -282,7 +282,7 @@ extern status_t tpl_open(tableid_t, cpsm_tplh_t*, cpsm_conhdl_t*); extern status_t tpl_scan_open(tableid_t, sp_cpsm_tplsch_t&, cpsm_conhdl_t*); extern status_t tpl_scan_fetch(sp_cpsm_tplsch_t&, cpsm_conhdl_t*, int* k = 0); extern status_t tpl_scan_close(sp_cpsm_tplsch_t&); -extern status_t tpl_close(cpsm_tplh_t*, cpsm_conhdl_t**, querystats::QueryStats& stats, bool clear_scan_ctx = false); +extern status_t tpl_close(cpsm_tplh_t*, cpsm_conhdl_t**, querystats::QueryStats& stats, bool ask_4_stats, bool clear_scan_ctx = false); }