diff --git a/dbcon/mysql/ha_mcs_impl.cpp b/dbcon/mysql/ha_mcs_impl.cpp index 7cd602f9d..282bf8e0e 100644 --- a/dbcon/mysql/ha_mcs_impl.cpp +++ b/dbcon/mysql/ha_mcs_impl.cpp @@ -2348,8 +2348,19 @@ int ha_mcs_impl_rnd_init(TABLE* table, const std::vector& condStack) return 0; } - //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)) + /* + Update and delete code. + Note, we may be updating/deleting a different table, + and the current one is only needed for reading, + e.g. cstab1 is needed for reading in this example: + + UPDATE innotab1 SET a=100 WHERE a NOT IN (SELECT a FROM cstab1 WHERE a=1); + */ + if (!ci->isReadOnly() && // make sure the current table is being modified + (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, condStack); uint32_t sessionID = tid2sid(thd->thread_id); @@ -4079,6 +4090,7 @@ int ha_mcs_impl_external_lock(THD* thd, TABLE* table, int lock_type) return 0; } + ci->lock_type= lock_type; CalTableMap::iterator mapiter = ci->tableMap.find(table); // make sure this is a release lock (2nd) call called in diff --git a/dbcon/mysql/ha_mcs_impl_if.h b/dbcon/mysql/ha_mcs_impl_if.h index e9a433710..1719c8337 100644 --- a/dbcon/mysql/ha_mcs_impl_if.h +++ b/dbcon/mysql/ha_mcs_impl_if.h @@ -262,7 +262,8 @@ struct cal_connection_info utf8(false), useCpimport(1), delimiter('\7'), - affectedRows(0) + affectedRows(0), + lock_type(F_UNLCK) { // check if this is a slave mysql daemon isSlaveNode = checkSlave(); @@ -285,6 +286,11 @@ struct cal_connection_info return true; } + bool isReadOnly() const + { + return lock_type == F_RDLCK; + } + sm::cpsm_conhdl_t* cal_conn_hndl; std::stack cal_conn_hndl_st; int queryState; @@ -335,6 +341,7 @@ struct cal_connection_info // MCOL-1101 remove compilation unit variable rmParms std::vector rmParms; long long affectedRows; + int lock_type; }; 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).";