From 9734a25a3511f11a67c0d54c077161b072c8bd67 Mon Sep 17 00:00:00 2001 From: Andrew Hutchings Date: Thu, 12 Dec 2019 22:58:20 +0000 Subject: [PATCH] MCOL-3672 Fix double-DML execution Direct update/delete executed doUpdateDelete as well as the regular execution route for doUpdateDelete. This patch only executes doUpdateDelete the first time and direct update/delete collects the counts. --- dbcon/mysql/ha_mcs_impl.cpp | 21 ++++++++++++--------- dbcon/mysql/ha_mcs_impl_if.h | 4 +++- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/dbcon/mysql/ha_mcs_impl.cpp b/dbcon/mysql/ha_mcs_impl.cpp index aad6a5546..b1130f273 100644 --- a/dbcon/mysql/ha_mcs_impl.cpp +++ b/dbcon/mysql/ha_mcs_impl.cpp @@ -1194,7 +1194,7 @@ vector getOnUpdateTimestampColumns(string& schema, string& tableName, in return returnVal; } -uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi, ha_rows *affected_rows) +uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi) { if (get_fe_conn_info_ptr() == NULL) set_fe_conn_info_ptr((void*)new cal_connection_info()); @@ -2218,8 +2218,7 @@ uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi, ha_rows *affected_rows) } else { - if (affected_rows) - *affected_rows = dmlRowCount; + ci->affectedRows = dmlRowCount; } push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_WARN_DATA_OUT_OF_RANGE, errorMsg.c_str()); @@ -2227,8 +2226,7 @@ uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi, ha_rows *affected_rows) else { // if (dmlRowCount != 0) //Bug 5117. Handling self join. - if (affected_rows) - *affected_rows = dmlRowCount; + ci->affectedRows = dmlRowCount; //cout << " error status " << ci->rc << " and rowcount = " << dmlRowCount << endl; } @@ -2289,8 +2287,13 @@ int ha_mcs_impl_direct_update_delete_rows(ha_rows *affected_rows) cal_impl_if::gp_walk_info gwi; gwi.thd = thd; - int rc = doUpdateDelete(thd, gwi, affected_rows); - return rc; + cal_connection_info* ci = reinterpret_cast(get_fe_conn_info_ptr()); + if (ci) + { + *affected_rows = ci->affectedRows; + } + + return 0; } int ha_mcs_impl_rnd_init(TABLE* table) @@ -2352,7 +2355,7 @@ int ha_mcs_impl_rnd_init(TABLE* table) //Update and delete code if ( ((thd->lex)->sql_command == SQLCOM_UPDATE) || ((thd->lex)->sql_command == SQLCOM_DELETE) || ((thd->lex)->sql_command == SQLCOM_DELETE_MULTI) || ((thd->lex)->sql_command == SQLCOM_UPDATE_MULTI)) - return doUpdateDelete(thd, gwi, NULL); + return doUpdateDelete(thd, gwi); uint32_t sessionID = tid2sid(thd->thread_id); boost::shared_ptr csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID); @@ -4899,7 +4902,7 @@ int ha_cs_impl_pushdown_init(mcs_handler_info* handler_info, TABLE* table) //Update and delete code if ( ((thd->lex)->sql_command == SQLCOM_UPDATE) || ((thd->lex)->sql_command == SQLCOM_DELETE) || ((thd->lex)->sql_command == SQLCOM_DELETE_MULTI) || ((thd->lex)->sql_command == SQLCOM_UPDATE_MULTI)) - return doUpdateDelete(thd, gwi, NULL); + return doUpdateDelete(thd, gwi); uint32_t sessionID = tid2sid(thd->thread_id); boost::shared_ptr csc = CalpontSystemCatalog::makeCalpontSystemCatalog(sessionID); diff --git a/dbcon/mysql/ha_mcs_impl_if.h b/dbcon/mysql/ha_mcs_impl_if.h index ded01c9f1..3c1d2ada6 100644 --- a/dbcon/mysql/ha_mcs_impl_if.h +++ b/dbcon/mysql/ha_mcs_impl_if.h @@ -260,7 +260,8 @@ struct cal_connection_info useXbit(false), utf8(false), useCpimport(1), - delimiter('\7') + delimiter('\7'), + affectedRows(0) { // check if this is a slave mysql daemon isSlaveNode = checkSlave(); @@ -331,6 +332,7 @@ struct cal_connection_info std::vector columnTypes; // MCOL-1101 remove compilation unit variable rmParms std::vector rmParms; + long long affectedRows; }; const std::string infinidb_err_msg = "\nThe query includes syntax that is not supported by MariaDB Columnstore. Use 'show warnings;' to get more information. Review the MariaDB Columnstore Syntax guide for additional information on supported distributed syntax or consider changing the MariaDB Columnstore Operating Mode (infinidb_vtable_mode).";