From 2f2c5642f60492b142f33373039b1faabe92a6ca Mon Sep 17 00:00:00 2001 From: heikki Date: Tue, 21 Mar 2006 15:57:55 +0000 Subject: [PATCH] Fix MySQL-5.1 bug http://bugs.mysql.com/bug.php?id=17992 and its duplicate http://bugs.mysql.com/bug.php?id=17134 : MySQL's partitioned table code does not set prebuilt->sql_stat_start right if it does an insert in the same statement after doing a search first in the same partition table. We now write trx id always to the buffer, not just when flag sql_stat_start is on. This will waste CPU time very slightly. --- row/row0ins.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/row/row0ins.c b/row/row0ins.c index caf5d835c57..4ecf4020e01 100644 --- a/row/row0ins.c +++ b/row/row0ins.c @@ -2451,7 +2451,15 @@ row_ins_step( /* If this is the first time this node is executed (or when execution resumes after wait for the table IX lock), set an - IX lock on the table and reset the possible select node. */ + IX lock on the table and reset the possible select node. MySQL's + partitioned table code may also call an insert within the same + SQL statement AFTER it has used this tbale handle to do a search. + This happens, for example, when a row update moves it to another + partition. In that case, we have already set the IX lock on the + table during the search operation, and there is no need to set + it again here. But we must write thx->id to to node->trx_id_buf. */ + + trx_write_trx_id(node->trx_id_buf, trx->id); if (node->state == INS_NODE_SET_IX_LOCK) { @@ -2459,13 +2467,11 @@ row_ins_step( its transaction, or it has been committed: */ if (UT_DULINT_EQ(trx->id, node->trx_id)) { - /* No need to do IX-locking or write trx id to buf */ + /* No need to do IX-locking */ goto same_trx; } - trx_write_trx_id(node->trx_id_buf, trx->id); - err = lock_table(0, node->table, LOCK_IX, thr); if (err != DB_SUCCESS) {