From 5a4cdba54415faf7dd0b5afdb8ed683dea1c126b Mon Sep 17 00:00:00 2001
From: Sergei Golubchik <serg@mysql.com>
Date: Wed, 6 Aug 2008 23:52:55 +0200
Subject: [PATCH] fixes for failing test suite

storage/maria/ma_write.c:
  select ... group by ... - take temporary tables into account, they have TRN->pins == 0
storage/maria/trnman.c:
  one cannot modify TRN->trid, it's a key in the trid_to_trn
  hash, if trid is modified, TRN won't be found (and deleted in
  trnman_free_trn) from the hash.
---
 storage/maria/ma_write.c | 15 ++++++++++++++-
 storage/maria/trnman.c   |  2 +-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/storage/maria/ma_write.c b/storage/maria/ma_write.c
index 87a49d61285..53a0e08a793 100644
--- a/storage/maria/ma_write.c
+++ b/storage/maria/ma_write.c
@@ -185,8 +185,21 @@ int maria_write(MARIA_HA *info, uchar *record)
                                                         buff, record, filepos,
                                                         info->trn->trid)))
         {
-          TRN *blocker=trnman_trid_to_trn(info->trn, info->dup_key_trid);
+          TRN *blocker;
           DBUG_PRINT("error",("Got error: %d on write",my_errno));
+          /*
+            explicit check for our own trid, because temp tables
+            aren't transactional and don't have a proper TRN so the code
+            below doesn't work for them
+            XXX a better test perhaps ?
+          */
+          if (info->dup_key_trid == info->trn->trid)
+          {
+            if (local_lock_tree)
+              rw_unlock(&keyinfo->root_lock);
+            goto err;
+          }
+          blocker= trnman_trid_to_trn(info->trn, info->dup_key_trid);
           /*
             if blocker TRN was not found, it means that the conflicting
             transaction was committed long time ago. It could not be
diff --git a/storage/maria/trnman.c b/storage/maria/trnman.c
index d2077f8f4c6..c232442b904 100644
--- a/storage/maria/trnman.c
+++ b/storage/maria/trnman.c
@@ -758,6 +758,7 @@ TRN *trnman_recreate_trn_from_recovery(uint16 shortid, TrID longid)
   TrID old_trid_generator= global_trid_generator;
   TRN *trn;
   DBUG_ASSERT(maria_in_recovery && !maria_multi_threaded);
+  global_trid_generator= longid-1; /* force a correct trid in the new trn */
   if (unlikely((trn= trnman_new_trn(NULL, NULL)) == NULL))
     return NULL;
   /* deallocate excessive allocations of trnman_new_trn() */
@@ -766,7 +767,6 @@ TRN *trnman_recreate_trn_from_recovery(uint16 shortid, TrID longid)
   short_trid_to_active_trn[trn->short_id]= 0;
   DBUG_ASSERT(short_trid_to_active_trn[shortid] == NULL);
   short_trid_to_active_trn[shortid]= trn;
-  trn->trid= longid;
   trn->short_id= shortid;
   return trn;
 }
-- 
2.30.9