MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Sergei Golubchik Date:August 26 2008 12:00pm
Subject:bzr push into mysql-6.0 branch (serg:2696)
View as plain text  
 2696 Sergei Golubchik	2008-08-26 [merge]
      merge 6.0->6.0-maria
added:
  mysql-test/include/mysqlbinlog_row_engine.inc
  mysql-test/r/mysqlbinlog_row.result
  mysql-test/r/mysqlbinlog_row_big.result
  mysql-test/r/mysqlbinlog_row_innodb.result
  mysql-test/r/mysqlbinlog_row_myisam.result
  mysql-test/r/mysqlbinlog_row_trans.result
  mysql-test/t/mysqlbinlog_row.test
  mysql-test/t/mysqlbinlog_row_big.test
  mysql-test/t/mysqlbinlog_row_innodb.test
  mysql-test/t/mysqlbinlog_row_myisam.test
  mysql-test/t/mysqlbinlog_row_trans.test
modified:
  .bzrignore
  client/Makefile.am
  client/mysqlbinlog.cc
  sql/log_event.cc
  sql/log_event.h
  sql/rpl_tblmap.cc
  sql/rpl_tblmap.h
  sql/rpl_utility.h
  sql/sql_base.cc

=== modified file '.bzrignore'
--- a/.bzrignore	2008-08-20 16:21:14 +0000
+++ b/.bzrignore	2008-08-26 10:20:41 +0000
@@ -1888,4 +1888,6 @@ win/vs8cache.txt
 ylwrap
 zlib/*.ds?
 zlib/*.vcproj
+extra/libevent/event-config.h
 libmysqld/ddl_blocker.cc
+libmysqld/mdl.cc

=== modified file 'include/my_global.h'
--- a/include/my_global.h	2008-07-09 07:12:43 +0000
+++ b/include/my_global.h	2008-08-13 09:18:28 +0000
@@ -1556,7 +1556,7 @@ inline void  operator delete[](void*, vo
 #endif
 
 /* Provide __func__ macro definition for platforms that miss it. */
-#if __STDC_VERSION__ < 199901L
+#if __STDC_VERSION__ < 199901L && !defined(__func__)
 #  if __GNUC__ >= 2
 #    define __func__ __FUNCTION__
 #  else

=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl	2008-08-07 14:19:54 +0000
+++ b/mysql-test/mysql-test-run.pl	2008-08-25 18:23:18 +0000
@@ -3670,15 +3670,17 @@ sub mysqld_arguments ($$$$) {
   mtr_add_arg($args, "%s--basedir=%s", $prefix, $path_my_basedir);
   mtr_add_arg($args, "%s--character-sets-dir=%s", $prefix, $path_charsetsdir);
 
-  if ( $mysql_version_id >= 50036)
+  if (!$opt_extern)
   {
-    # By default, prevent the started mysqld to access files outside of vardir
-    mtr_add_arg($args, "%s--secure-file-priv=%s", $prefix, $opt_vardir);
-  }
+    if ( $mysql_version_id >= 50036)
+    {
+      # Prevent the started mysqld to access files outside of vardir
+      mtr_add_arg($args, "%s--secure-file-priv=%s", $prefix, $opt_vardir);
+    }
 
-  if ( $mysql_version_id >= 50000 )
-  {
-    mtr_add_arg($args, "%s--log-bin-trust-function-creators", $prefix);
+    if ( $mysql_version_id >= 50000 ) {
+      mtr_add_arg($args, "%s--log-bin-trust-function-creators", $prefix);
+    }
   }
 
   mtr_add_arg($args, "%s--default-character-set=latin1", $prefix);
@@ -3730,7 +3732,7 @@ sub mysqld_arguments ($$$$) {
 
   mtr_add_arg($args, "%s--disable-sync-frm", $prefix);  # Faster test
 
-  if ( $mysql_version_id >= 50106 )
+  if (!$opt_extern and $mysql_version_id >= 50106 )
   {
     # Turn on logging to bothe tables and file
     mtr_add_arg($args, "%s--log-output=table,file", $prefix);

=== modified file 'mysql-test/r/maria.result'
--- a/mysql-test/r/maria.result	2008-07-10 15:20:07 +0000
+++ b/mysql-test/r/maria.result	2008-08-25 18:23:18 +0000
@@ -1901,3 +1901,340 @@ check table t2 extended;
 Table	Op	Msg_type	Msg_text
 test.t2	check	status	OK
 drop table t2;
+CREATE TABLE t1 (
+col0 float DEFAULT NULL,
+col1 date DEFAULT NULL,   
+col2 double DEFAULT NULL,   
+col3 decimal(10,0) DEFAULT NULL,   
+col4 char(218) DEFAULT NULL,   
+col5 year(4) DEFAULT NULL,   
+col6 datetime DEFAULT NULL,   
+col7 varchar(39) DEFAULT NULL,   
+col8 double DEFAULT NULL,   
+col9 decimal(10,0) DEFAULT NULL,   
+col10 enum('test1','test2','test3') DEFAULT NULL,   
+col11 year(4) DEFAULT NULL,
+col12 tinytext,
+col13 tinyblob,
+col14 date DEFAULT NULL,
+col15 smallint(6) DEFAULT NULL,
+col16 varchar(81) DEFAULT NULL,
+col17 tinytext,
+col18 blob,
+col19 double DEFAULT NULL,
+col20 double DEFAULT NULL,
+col21 varchar(216) DEFAULT NULL,
+col22 enum('test1','test2','test3') DEFAULT NULL,
+col23 decimal(10,0) DEFAULT NULL,
+col24 text,
+col25 varchar(118) DEFAULT NULL,
+col26 tinytext,
+col27 tinyblob,
+col28 double DEFAULT NULL,
+col29 tinyint(4) DEFAULT NULL,
+col30 longtext,
+col31 tinyint(1) DEFAULT NULL,
+col32 char(212) DEFAULT NULL,
+col33 timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+col34 year(4) DEFAULT NULL,
+col35 tinyint(1) DEFAULT NULL,
+col36 enum('test1','test2','test3') DEFAULT NULL,
+col37 decimal(10,0) DEFAULT NULL,
+col38 tinyint(4) DEFAULT NULL,
+col39 double DEFAULT NULL,
+col40 decimal(10,0) DEFAULT NULL,
+col41 enum('test1','test2','test3') DEFAULT NULL,
+col42 longblob,
+col43 text,
+col44 blob,
+col45 year(4) DEFAULT NULL,
+col46 longtext,
+col47 int(11) DEFAULT NULL,
+col48 set('test1','test2','test3') DEFAULT NULL,
+col49 bigint(20) DEFAULT NULL,
+col50 date DEFAULT NULL,
+col51 tinyblob,
+col52 float DEFAULT NULL,
+col53 year(4) DEFAULT NULL,
+col54 decimal(10,0) DEFAULT NULL,
+col55 tinyblob,
+col56 float DEFAULT NULL,
+col57 bigint(20) DEFAULT NULL,
+col58 timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+col59 enum('test1','test2','test3') DEFAULT NULL,
+col60 bigint(20) DEFAULT NULL,
+col61 year(4) DEFAULT NULL,
+col62 year(4) DEFAULT NULL,
+col63 double DEFAULT NULL,
+col64 tinytext,
+col65 tinyint(4) DEFAULT NULL,
+col66 longtext,
+col67 time DEFAULT NULL,
+col68 bigint(20) DEFAULT NULL,
+col69 char(142) DEFAULT NULL,
+col70 longtext,
+col71 time DEFAULT NULL,
+col72 year(4) DEFAULT NULL,
+col73 longblob,
+col74 enum('test1','test2','test3') DEFAULT NULL,
+col75 decimal(10,0) DEFAULT NULL,
+col76 smallint(6) DEFAULT NULL,
+col77 tinytext,
+col78 date DEFAULT NULL,
+col79 double DEFAULT NULL,
+col80 tinyint(4) DEFAULT NULL,
+col81 float DEFAULT NULL,
+col82 bigint(20) DEFAULT NULL,
+col83 double DEFAULT NULL,
+col84 varchar(124) DEFAULT NULL,
+col85 double DEFAULT NULL,
+col86 tinyblob,
+col87 tinyblob,
+col88 double DEFAULT NULL,
+col89 date DEFAULT NULL,
+col90 decimal(10,0) DEFAULT NULL,
+col91 set('test1','test2','test3') DEFAULT NULL,
+col92 blob,
+col93 char(174) DEFAULT NULL,
+col94 double DEFAULT NULL,
+col95 tinytext,
+col96 decimal(10,0) DEFAULT NULL,
+col97 year(4) DEFAULT NULL,
+col98 tinyblob,
+col99 datetime DEFAULT NULL,
+col100 longblob,
+col101 date DEFAULT NULL,
+col102 float DEFAULT NULL,
+col103 float DEFAULT NULL,
+col104 int(11) DEFAULT NULL,
+col105 longblob,
+col106 timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+col107 float DEFAULT NULL,
+col108 text,
+col109 float DEFAULT NULL,
+col110 decimal(10,0) DEFAULT NULL,
+col111 double DEFAULT NULL,
+col112 double DEFAULT NULL,
+col113 blob,
+col114 varchar(152) DEFAULT NULL,
+col115 bigint(20) DEFAULT NULL,
+col116 decimal(10,0) DEFAULT NULL,
+col117 mediumint(9) DEFAULT NULL,
+col118 tinytext,
+col119 tinyblob,
+col120 int(11) DEFAULT NULL,
+col121 bigint(20) DEFAULT NULL,
+col122 double DEFAULT NULL,
+col123 date DEFAULT NULL,
+col124 longtext,
+col125 longtext,
+col126 double DEFAULT NULL,
+col127 varchar(84) DEFAULT NULL,
+col128 text,
+col129 double DEFAULT NULL,
+col130 enum('test1','test2','test3') DEFAULT NULL,
+col131 time DEFAULT NULL,
+col132 year(4) DEFAULT NULL,
+col133 blob,
+col134 tinytext,
+col135 double DEFAULT NULL,
+col136 tinytext,
+col137 bigint(20) DEFAULT NULL,
+col138 datetime DEFAULT NULL,
+col139 double DEFAULT NULL,
+col140 decimal(10,0) DEFAULT NULL,
+col141 longtext,
+col142 tinyint(1) DEFAULT NULL,
+col143 time DEFAULT NULL,
+col144 time DEFAULT NULL,
+col145 float DEFAULT NULL,
+col146 longblob,
+col147 float DEFAULT NULL,
+col148 text,
+col149 mediumint(9) DEFAULT NULL,
+col150 tinyblob,
+col151 tinyblob,
+col152 tinytext,
+col153 tinyblob,
+col154 tinyblob,
+col155 tinytext,
+col156 tinyint(1) DEFAULT NULL,
+col157 tinytext,
+col158 time DEFAULT NULL,
+col159 date DEFAULT NULL,
+col160 longtext,
+col161 enum('test1','test2','test3') DEFAULT NULL,
+col162 text,
+col163 decimal(10,0) DEFAULT NULL,
+col164 time DEFAULT NULL,
+col165 longblob,
+col166 tinyint(4) DEFAULT NULL,
+col167 bigint(20) DEFAULT NULL,
+col168 decimal(10,0) DEFAULT NULL,
+col169 smallint(6) DEFAULT NULL,
+col170 tinytext,
+col171 tinyint(4) DEFAULT NULL,
+col172 tinyint(1) DEFAULT NULL,
+col173 tinytext,
+col174 decimal(10,0) DEFAULT NULL,
+col175 double DEFAULT NULL
+) engine=maria;
+insert ignore into t1 set 
+col10=abs(28449) % 2,
+col11='1973',
+col12=if(abs(-30039)%100<20,null,'forgery\'s'),
+col13=if(abs(24672)%100<20,null,'adductor\'s'),
+col16=if(abs(26872)%100<20,null,'0xf810e016ee0b78e1ce8b1c6cf8d2e82bf8507453768a3908dc20cecfc9a0ac0ac00079d0645a4c'),
+col18=if(abs(-15854)%100<20,null,'unattractiveness'),
+col19=if(abs(4287439673.9896235000)%100<20,null,25288),
+col20=if(abs(4290800136.7527390000)%100<20,null,8887),
+col21=if(abs(-26086)%100<20,null,'0x2334181c6068aab18b348ecc1e2600b81e1c5f821eee3e204824'),
+col22=abs(-21921) % 2,
+col23=if(abs(1503277.6900540178)%100<20,null,-23298),
+col25=if(abs(29674)%100<20,null,'0xc8d094f888ee20c83baef8d9380a168d40f4906e742a4dc0daeacb809e64095c71d510c7c0f83a6a0a04b8d6a0d9bea2dc3d4bd44d9c5002e440707c40ead8b3eb20a100a8524b1616a338a440ea02a25a08041810a08cac087cd47b4a79f08730946c5800600ae45e1c08f637'),
+col26=if(abs(28642)%100<20,null,'insubstantiality\'s'),
+col27=if(abs(-3188)%100<20,null,'exine\'s'),
+col29=if(abs(-47)%100<20,null,-24131),
+col32=if(abs(-3658)%100<20,null,'shortener\'s'),
+col34='1917',
+col36=abs(27782) % 2,
+col37=if(abs(4864972.0244758446)%100<20,null,32302),
+col38=if(abs(97)%100<20,null,-14079),
+col39=if(abs(3362872.0521256141)%100<20,null,27191),
+col40=if(abs(3348292.2110660113)%100<20,null,-1163),
+col41=abs(-18533) % 2,
+col42=if(abs(2094)%100<20,null,'Montparnasse'),
+col43=if(abs(-15983)%100<20,null,'Massasoit\'s'),
+col44=if(abs(2497)%100<20,null,'lags'),
+col45='2057',
+col46=if(abs(-31691)%100<20,null,'miscegenation\'s'),
+col47=if(abs(-1269564297)%100<20,null,1089),
+col49=if(abs(-1815717335)%100<20,null,-17504),
+col51=if(abs(-15263)%100<20,null,'virelay'),
+col52=if(abs(2227333.3279519030)%100<20,null,-5210),
+col53='2032',
+col54=if(abs(791647.5947447127)%100<20,null,32576),
+col55=if(abs(20293)%100<20,null,'tumblebug'),
+col56=if(abs(4288698564.2967925000)%100<20,null,17141),
+col57=if(abs(-2138460927)%100<20,null,14495),
+col59=abs(7624) % 2,
+col60=if(abs(-1500892492)%100<20,null,-68),
+col63=if(abs(4290890487.3789482000)%100<20,null,-32129),
+col65=if(abs(22)%100<20,null,15722),
+col79=if(abs(4292420489.2606282000)%100<20,null,-23891),
+col84=if(abs(-21248)%100<20,null,'0x4f9888d044435050eab83cb3dcad88b01886e434e216'),
+col85=if(abs(4294260188.6230965000)%100<20,null,16867),
+col86=if(abs(-11659)%100<20,null,'prewar'),
+col87=if(abs(-2253)%100<20,null,'Radnorshire'),
+col90=if(abs(4287254529.4026613000)%100<20,null,23506),
+col92=if(abs(6472)%100<20,null,'electroplated'),
+col93=if(abs(-13523)%100<20,null,'sparkiest'),
+col95=if(abs(23998)%100<20,null,'Crimea'),
+col96=if(abs(4287719060.2789087000)%100<20,null,20527),
+col98=if(abs(-14090)%100<20,null,'firebrat'),
+col99='19161023095430',
+col100=if(abs(-31178)%100<20,null,'clinical'),
+col102=if(abs(4407547.5205542166)%100<20,null,18226),
+col103=if(abs(4286834687.5994444000)%100<20,null,27520),
+col104=if(abs(-2105663477)%100<20,null,28591),
+col105=if(abs(1929)%100<20,null,'renascent'),
+col107=if(abs(5972348.8099917602)%100<20,null,-11408),
+col108=if(abs(-11262)%100<20,null,'aircraftmen'),
+col110=if(abs(6530491.4546037167)%100<20,null,-17672),
+col111=if(abs(4289897795.5000763000)%100<20,null,3742),
+col112=if(abs(1680557.8560441907)%100<20,null,13944),
+col113=if(abs(-27195)%100<20,null,'dekameter'),
+col115=if(abs(-2083419827)%100<20,null,-17272),
+col117=if(abs(1704826)%100<20,null,17880),
+col118=if(abs(-2848)%100<20,null,'judicatory'),
+col119=if(abs(-28087)%100<20,null,'mistitles'),
+col120=if(abs(-2100119097)%100<20,null,22465),
+col121=if(abs(-1868777891)%100<20,null,15172),
+col122=if(abs(7039857.3608508557)%100<20,null,-22154),
+col125=if(abs(70)%100<20,null,'Hong\'s'),
+col126=if(abs(3820673.5968199712)%100<20,null,-24185),
+col127=if(abs(12331)%100<20,null,'0x674e14584e88fca3fed0a0b1488a440008228aa01454a65cf09e3f0fa0511c3ce2f8688450'),
+col128=if(abs(20335)%100<20,null,'Zoroaster\'s'),
+col129=if(abs(3916577.6225165562)%100<20,null,-4088),
+col130=abs(-15003) % 2,
+col132='2016',
+col134=if(abs(-26555)%100<20,null,'Caesarea'),
+col135=if(abs(4288484655.2416148000)%100<20,null,-30073),
+col136=if(abs(-17577)%100<20,null,'upbraid'),
+col137=if(abs(-1742797945)%100<20,null,-21651),
+col138='20751113181230',
+col139=if(abs(4288997063.9889216000)%100<20,null,1816),
+col141=if(abs(-31448)%100<20,null,'threnodist'),
+col142=if(abs(88)%100<20,null,-19748),
+col143='6930607',
+col144='5760250',
+col145=if(abs(3591496.9625843074)%100<20,null,76),
+col146=if(abs(20875)%100<20,null,'rename'),
+col147=if(abs(4294789439.6773582000)%100<20,null,32314),
+col148=if(abs(7072)%100<20,null,'recesses'),
+col150=if(abs(-26540)%100<20,null,'cuckoo'),
+col152=if(abs(23553)%100<20,null,'shortened'),
+col153=if(abs(-30422)%100<20,null,'inhabitant'),
+col154=if(abs(30457)%100<20,null,'Orwellian'),
+col155=if(abs(-30263)%100<20,null,'Ptolemies'),
+col156=if(abs(-41)%100<20,null,6382),
+col157=if(abs(2557)%100<20,null,'horsewhips'),
+col158='2764427',
+col160=if(abs(-15872)%100<20,null,'girlhood'),
+col161=abs(15378) % 2,
+col163=if(abs(4286662730.9309368000)%100<20,null,-19516),
+col167=if(abs(-1881918655)%100<20,null,6927),
+col169=if(abs(-14442)%100<20,null,-6392),
+col170=if(abs(29965)%100<20,null,'resynthesis'),
+col173=if(abs(-451)%100<20,null,'Clute'),
+col174=if(abs(3262594.6284981840)%100<20,null,17846);
+Warnings:
+Warning	1265	Data truncated for column 'col25' at row 1
+Warning	1264	Out of range value for column 'col29' at row 1
+Warning	1265	Data truncated for column 'col36' at row 1
+Warning	1264	Out of range value for column 'col38' at row 1
+Warning	1265	Data truncated for column 'col59' at row 1
+Warning	1264	Out of range value for column 'col65' at row 1
+Warning	1264	Out of range value for column 'col142' at row 1
+Warning	1264	Out of range value for column 'col156' at row 1
+Warning	1265	Data truncated for column 'col161' at row 1
+update ignore t1 set col165=repeat('a',7000);
+check table t1;
+Table	Op	Msg_type	Msg_text
+test.t1	check	status	OK
+drop table t1;
+create table t1 (a char(200) primary key, b int default 12345) engine=maria;
+insert t1 (a) values (repeat('0', 200));
+insert t1 (a) values (repeat('1', 200)), (repeat('2', 200)), (repeat('3', 200)),
+(repeat('4', 200)), (repeat('5', 200)), (repeat('6', 200)), (repeat('7', 200)),
+(repeat('8', 200)), (repeat('9', 200)), (repeat('a', 200)), (repeat('b', 200)),
+(repeat('c', 200)), (repeat('d', 200)), (repeat('e', 200)), (repeat('f', 200)),
+(repeat('g', 200)), (repeat('h', 200)), (repeat('i', 200)), (repeat('j', 200)),
+(repeat('k', 200)), (repeat('l', 200)), (repeat('m', 200)), (repeat('n', 200)),
+(repeat('o', 200)), (repeat('p', 200)), (repeat('q', 200)), (repeat('r', 200)),
+(repeat('s', 200)), (repeat('t', 200)), (repeat('u', 200)), (repeat('v', 200)),
+(repeat('w', 200)), (repeat('x', 200)), (repeat('y', 200)), (repeat('z', 200)),
+(repeat('+', 200)), (repeat('-', 200)), (repeat('=', 200)), (repeat('*', 200));
+select b from t1 where a >= repeat('f', 200) and a < 'k';
+b
+12345
+12345
+12345
+12345
+12345
+drop table t1;
+create table t1 (a int, b int) engine=maria transactional=1;
+insert t1 values (1,2);
+insert t1 values (2,3), (sleep(10),sleep(20)), (4,5);;
+LOCK TABLES t1 write concurrent;
+insert t1 values (7,8);
+drop table t1;
+create table t1 (a int) engine=maria transactional=1;
+insert into t1 values (1);
+lock table t1 write concurrent;
+delete from t1;
+ERROR 42000: The storage engine for the table doesn't support DELETE in WRITE CONCURRENT
+drop table t1;
+ERROR HY000: Table 't1' was locked with a READ lock and can't be updated
+unlock tables;
+drop table t1;

=== modified file 'mysql-test/r/maria2.result'
--- a/mysql-test/r/maria2.result	2008-06-10 14:44:44 +0000
+++ b/mysql-test/r/maria2.result	2008-08-12 10:59:30 +0000
@@ -1,3 +1,4 @@
+drop table if exists t1,t2;
 CREATE TABLE t1 (
 line BLOB,
 kind ENUM('po', 'pp', 'rr', 'dr', 'rd', 'ts', 'cl') NOT NULL DEFAULT 'po',
@@ -16,3 +17,44 @@ check table t1 extended;
 Table	Op	Msg_type	Msg_text
 test.t1	check	status	OK
 drop table t1;
+create table t1 (i int) engine=maria;
+create table t2 (j int) engine=maria;
+lock table t1 write, t2 read;
+alter table t1 modify i int default 1;
+insert into t1 values (2);
+alter table t1 modify i bigint default 1;
+select count(*) from t1;
+count(*)
+1
+select * from t1;
+i
+2
+unlock tables;
+drop table t1,t2;
+create table t1(id int, s char(1), unique(s)) engine=maria;
+insert into t1 values(1,"a") on duplicate key update t1.id=t1.id+1;
+insert into t1 values(1,"a") on duplicate key update t1.id=t1.id+1;
+insert into t1 select 1,"a" on duplicate key update t1.id=t1.id+1;
+select * from t1;
+id	s
+3	a
+replace into t1 select 1,"a";
+select * from t1;
+id	s
+1	a
+drop table t1;
+create table t1 (pk int primary key, apk int unique, data int) engine=maria;
+insert into t1 values (1, 1, 1), (4, 4, 4), (6, 6, 6);
+load data concurrent infile '../std_data_ln/loaddata5.dat' replace into table t1 fields terminated by '' enclosed by '' ignore 1 lines (pk, apk);
+select * from t1 order by pk;
+pk	apk	data
+1	1	1
+3	4	NULL
+5	6	NULL
+load data infile '../std_data_ln/loaddata5.dat' replace into table t1 fields terminated by '' enclosed by '' ignore 1 lines (pk, apk);
+select * from t1 order by pk;
+pk	apk	data
+1	1	1
+3	4	NULL
+5	6	NULL
+drop table t1;

=== modified file 'mysql-test/t/maria.test'
--- a/mysql-test/t/maria.test	2008-07-10 15:20:07 +0000
+++ b/mysql-test/t/maria.test	2008-08-25 18:23:18 +0000
@@ -1188,6 +1188,347 @@ insert into t2 values (repeat('x',28)), 
 check table t2 extended;
 drop table t2;
 
+CREATE TABLE t1 (
+col0 float DEFAULT NULL,
+col1 date DEFAULT NULL,   
+col2 double DEFAULT NULL,   
+col3 decimal(10,0) DEFAULT NULL,   
+col4 char(218) DEFAULT NULL,   
+col5 year(4) DEFAULT NULL,   
+col6 datetime DEFAULT NULL,   
+col7 varchar(39) DEFAULT NULL,   
+col8 double DEFAULT NULL,   
+col9 decimal(10,0) DEFAULT NULL,   
+col10 enum('test1','test2','test3') DEFAULT NULL,   
+col11 year(4) DEFAULT NULL,
+col12 tinytext,
+col13 tinyblob,
+col14 date DEFAULT NULL,
+col15 smallint(6) DEFAULT NULL,
+col16 varchar(81) DEFAULT NULL,
+col17 tinytext,
+col18 blob,
+col19 double DEFAULT NULL,
+col20 double DEFAULT NULL,
+col21 varchar(216) DEFAULT NULL,
+col22 enum('test1','test2','test3') DEFAULT NULL,
+col23 decimal(10,0) DEFAULT NULL,
+col24 text,
+col25 varchar(118) DEFAULT NULL,
+col26 tinytext,
+col27 tinyblob,
+col28 double DEFAULT NULL,
+col29 tinyint(4) DEFAULT NULL,
+col30 longtext,
+col31 tinyint(1) DEFAULT NULL,
+col32 char(212) DEFAULT NULL,
+col33 timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+col34 year(4) DEFAULT NULL,
+col35 tinyint(1) DEFAULT NULL,
+col36 enum('test1','test2','test3') DEFAULT NULL,
+col37 decimal(10,0) DEFAULT NULL,
+col38 tinyint(4) DEFAULT NULL,
+col39 double DEFAULT NULL,
+col40 decimal(10,0) DEFAULT NULL,
+col41 enum('test1','test2','test3') DEFAULT NULL,
+col42 longblob,
+col43 text,
+col44 blob,
+col45 year(4) DEFAULT NULL,
+col46 longtext,
+col47 int(11) DEFAULT NULL,
+col48 set('test1','test2','test3') DEFAULT NULL,
+col49 bigint(20) DEFAULT NULL,
+col50 date DEFAULT NULL,
+col51 tinyblob,
+col52 float DEFAULT NULL,
+col53 year(4) DEFAULT NULL,
+col54 decimal(10,0) DEFAULT NULL,
+col55 tinyblob,
+col56 float DEFAULT NULL,
+col57 bigint(20) DEFAULT NULL,
+col58 timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+col59 enum('test1','test2','test3') DEFAULT NULL,
+col60 bigint(20) DEFAULT NULL,
+col61 year(4) DEFAULT NULL,
+col62 year(4) DEFAULT NULL,
+col63 double DEFAULT NULL,
+col64 tinytext,
+col65 tinyint(4) DEFAULT NULL,
+col66 longtext,
+col67 time DEFAULT NULL,
+col68 bigint(20) DEFAULT NULL,
+col69 char(142) DEFAULT NULL,
+col70 longtext,
+col71 time DEFAULT NULL,
+col72 year(4) DEFAULT NULL,
+col73 longblob,
+col74 enum('test1','test2','test3') DEFAULT NULL,
+col75 decimal(10,0) DEFAULT NULL,
+col76 smallint(6) DEFAULT NULL,
+col77 tinytext,
+col78 date DEFAULT NULL,
+col79 double DEFAULT NULL,
+col80 tinyint(4) DEFAULT NULL,
+col81 float DEFAULT NULL,
+col82 bigint(20) DEFAULT NULL,
+col83 double DEFAULT NULL,
+col84 varchar(124) DEFAULT NULL,
+col85 double DEFAULT NULL,
+col86 tinyblob,
+col87 tinyblob,
+col88 double DEFAULT NULL,
+col89 date DEFAULT NULL,
+col90 decimal(10,0) DEFAULT NULL,
+col91 set('test1','test2','test3') DEFAULT NULL,
+col92 blob,
+col93 char(174) DEFAULT NULL,
+col94 double DEFAULT NULL,
+col95 tinytext,
+col96 decimal(10,0) DEFAULT NULL,
+col97 year(4) DEFAULT NULL,
+col98 tinyblob,
+col99 datetime DEFAULT NULL,
+col100 longblob,
+col101 date DEFAULT NULL,
+col102 float DEFAULT NULL,
+col103 float DEFAULT NULL,
+col104 int(11) DEFAULT NULL,
+col105 longblob,
+col106 timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
+col107 float DEFAULT NULL,
+col108 text,
+col109 float DEFAULT NULL,
+col110 decimal(10,0) DEFAULT NULL,
+col111 double DEFAULT NULL,
+col112 double DEFAULT NULL,
+col113 blob,
+col114 varchar(152) DEFAULT NULL,
+col115 bigint(20) DEFAULT NULL,
+col116 decimal(10,0) DEFAULT NULL,
+col117 mediumint(9) DEFAULT NULL,
+col118 tinytext,
+col119 tinyblob,
+col120 int(11) DEFAULT NULL,
+col121 bigint(20) DEFAULT NULL,
+col122 double DEFAULT NULL,
+col123 date DEFAULT NULL,
+col124 longtext,
+col125 longtext,
+col126 double DEFAULT NULL,
+col127 varchar(84) DEFAULT NULL,
+col128 text,
+col129 double DEFAULT NULL,
+col130 enum('test1','test2','test3') DEFAULT NULL,
+col131 time DEFAULT NULL,
+col132 year(4) DEFAULT NULL,
+col133 blob,
+col134 tinytext,
+col135 double DEFAULT NULL,
+col136 tinytext,
+col137 bigint(20) DEFAULT NULL,
+col138 datetime DEFAULT NULL,
+col139 double DEFAULT NULL,
+col140 decimal(10,0) DEFAULT NULL,
+col141 longtext,
+col142 tinyint(1) DEFAULT NULL,
+col143 time DEFAULT NULL,
+col144 time DEFAULT NULL,
+col145 float DEFAULT NULL,
+col146 longblob,
+col147 float DEFAULT NULL,
+col148 text,
+col149 mediumint(9) DEFAULT NULL,
+col150 tinyblob,
+col151 tinyblob,
+col152 tinytext,
+col153 tinyblob,
+col154 tinyblob,
+col155 tinytext,
+col156 tinyint(1) DEFAULT NULL,
+col157 tinytext,
+col158 time DEFAULT NULL,
+col159 date DEFAULT NULL,
+col160 longtext,
+col161 enum('test1','test2','test3') DEFAULT NULL,
+col162 text,
+col163 decimal(10,0) DEFAULT NULL,
+col164 time DEFAULT NULL,
+col165 longblob,
+col166 tinyint(4) DEFAULT NULL,
+col167 bigint(20) DEFAULT NULL,
+col168 decimal(10,0) DEFAULT NULL,
+col169 smallint(6) DEFAULT NULL,
+col170 tinytext,
+col171 tinyint(4) DEFAULT NULL,
+col172 tinyint(1) DEFAULT NULL,
+col173 tinytext,
+col174 decimal(10,0) DEFAULT NULL,
+col175 double DEFAULT NULL
+) engine=maria;
+
+insert ignore into t1 set 
+col10=abs(28449) % 2,
+col11='1973',
+col12=if(abs(-30039)%100<20,null,'forgery\'s'),
+col13=if(abs(24672)%100<20,null,'adductor\'s'),
+col16=if(abs(26872)%100<20,null,'0xf810e016ee0b78e1ce8b1c6cf8d2e82bf8507453768a3908dc20cecfc9a0ac0ac00079d0645a4c'),
+col18=if(abs(-15854)%100<20,null,'unattractiveness'),
+col19=if(abs(4287439673.9896235000)%100<20,null,25288),
+col20=if(abs(4290800136.7527390000)%100<20,null,8887),
+col21=if(abs(-26086)%100<20,null,'0x2334181c6068aab18b348ecc1e2600b81e1c5f821eee3e204824'),
+col22=abs(-21921) % 2,
+col23=if(abs(1503277.6900540178)%100<20,null,-23298),
+col25=if(abs(29674)%100<20,null,'0xc8d094f888ee20c83baef8d9380a168d40f4906e742a4dc0daeacb809e64095c71d510c7c0f83a6a0a04b8d6a0d9bea2dc3d4bd44d9c5002e440707c40ead8b3eb20a100a8524b1616a338a440ea02a25a08041810a08cac087cd47b4a79f08730946c5800600ae45e1c08f637'),
+col26=if(abs(28642)%100<20,null,'insubstantiality\'s'),
+col27=if(abs(-3188)%100<20,null,'exine\'s'),
+col29=if(abs(-47)%100<20,null,-24131),
+col32=if(abs(-3658)%100<20,null,'shortener\'s'),
+col34='1917',
+col36=abs(27782) % 2,
+col37=if(abs(4864972.0244758446)%100<20,null,32302),
+col38=if(abs(97)%100<20,null,-14079),
+col39=if(abs(3362872.0521256141)%100<20,null,27191),
+col40=if(abs(3348292.2110660113)%100<20,null,-1163),
+col41=abs(-18533) % 2,
+col42=if(abs(2094)%100<20,null,'Montparnasse'),
+col43=if(abs(-15983)%100<20,null,'Massasoit\'s'),
+col44=if(abs(2497)%100<20,null,'lags'),
+col45='2057',
+col46=if(abs(-31691)%100<20,null,'miscegenation\'s'),
+col47=if(abs(-1269564297)%100<20,null,1089),
+col49=if(abs(-1815717335)%100<20,null,-17504),
+col51=if(abs(-15263)%100<20,null,'virelay'),
+col52=if(abs(2227333.3279519030)%100<20,null,-5210),
+col53='2032',
+col54=if(abs(791647.5947447127)%100<20,null,32576),
+col55=if(abs(20293)%100<20,null,'tumblebug'),
+col56=if(abs(4288698564.2967925000)%100<20,null,17141),
+col57=if(abs(-2138460927)%100<20,null,14495),
+col59=abs(7624) % 2,
+col60=if(abs(-1500892492)%100<20,null,-68),
+col63=if(abs(4290890487.3789482000)%100<20,null,-32129),
+col65=if(abs(22)%100<20,null,15722),
+col79=if(abs(4292420489.2606282000)%100<20,null,-23891),
+col84=if(abs(-21248)%100<20,null,'0x4f9888d044435050eab83cb3dcad88b01886e434e216'),
+col85=if(abs(4294260188.6230965000)%100<20,null,16867),
+col86=if(abs(-11659)%100<20,null,'prewar'),
+col87=if(abs(-2253)%100<20,null,'Radnorshire'),
+col90=if(abs(4287254529.4026613000)%100<20,null,23506),
+col92=if(abs(6472)%100<20,null,'electroplated'),
+col93=if(abs(-13523)%100<20,null,'sparkiest'),
+col95=if(abs(23998)%100<20,null,'Crimea'),
+col96=if(abs(4287719060.2789087000)%100<20,null,20527),
+col98=if(abs(-14090)%100<20,null,'firebrat'),
+col99='19161023095430',
+col100=if(abs(-31178)%100<20,null,'clinical'),
+col102=if(abs(4407547.5205542166)%100<20,null,18226),
+col103=if(abs(4286834687.5994444000)%100<20,null,27520),
+col104=if(abs(-2105663477)%100<20,null,28591),
+col105=if(abs(1929)%100<20,null,'renascent'),
+col107=if(abs(5972348.8099917602)%100<20,null,-11408),
+col108=if(abs(-11262)%100<20,null,'aircraftmen'),
+col110=if(abs(6530491.4546037167)%100<20,null,-17672),
+col111=if(abs(4289897795.5000763000)%100<20,null,3742),
+col112=if(abs(1680557.8560441907)%100<20,null,13944),
+col113=if(abs(-27195)%100<20,null,'dekameter'),
+col115=if(abs(-2083419827)%100<20,null,-17272),
+col117=if(abs(1704826)%100<20,null,17880),
+col118=if(abs(-2848)%100<20,null,'judicatory'),
+col119=if(abs(-28087)%100<20,null,'mistitles'),
+col120=if(abs(-2100119097)%100<20,null,22465),
+col121=if(abs(-1868777891)%100<20,null,15172),
+col122=if(abs(7039857.3608508557)%100<20,null,-22154),
+col125=if(abs(70)%100<20,null,'Hong\'s'),
+col126=if(abs(3820673.5968199712)%100<20,null,-24185),
+col127=if(abs(12331)%100<20,null,'0x674e14584e88fca3fed0a0b1488a440008228aa01454a65cf09e3f0fa0511c3ce2f8688450'),
+col128=if(abs(20335)%100<20,null,'Zoroaster\'s'),
+col129=if(abs(3916577.6225165562)%100<20,null,-4088),
+col130=abs(-15003) % 2,
+col132='2016',
+col134=if(abs(-26555)%100<20,null,'Caesarea'),
+col135=if(abs(4288484655.2416148000)%100<20,null,-30073),
+col136=if(abs(-17577)%100<20,null,'upbraid'),
+col137=if(abs(-1742797945)%100<20,null,-21651),
+col138='20751113181230',
+col139=if(abs(4288997063.9889216000)%100<20,null,1816),
+col141=if(abs(-31448)%100<20,null,'threnodist'),
+col142=if(abs(88)%100<20,null,-19748),
+col143='6930607',
+col144='5760250',
+col145=if(abs(3591496.9625843074)%100<20,null,76),
+col146=if(abs(20875)%100<20,null,'rename'),
+col147=if(abs(4294789439.6773582000)%100<20,null,32314),
+col148=if(abs(7072)%100<20,null,'recesses'),
+col150=if(abs(-26540)%100<20,null,'cuckoo'),
+col152=if(abs(23553)%100<20,null,'shortened'),
+col153=if(abs(-30422)%100<20,null,'inhabitant'),
+col154=if(abs(30457)%100<20,null,'Orwellian'),
+col155=if(abs(-30263)%100<20,null,'Ptolemies'),
+col156=if(abs(-41)%100<20,null,6382),
+col157=if(abs(2557)%100<20,null,'horsewhips'),
+col158='2764427',
+col160=if(abs(-15872)%100<20,null,'girlhood'),
+col161=abs(15378) % 2,
+col163=if(abs(4286662730.9309368000)%100<20,null,-19516),
+col167=if(abs(-1881918655)%100<20,null,6927),
+col169=if(abs(-14442)%100<20,null,-6392),
+col170=if(abs(29965)%100<20,null,'resynthesis'),
+col173=if(abs(-451)%100<20,null,'Clute'),
+col174=if(abs(3262594.6284981840)%100<20,null,17846);
+
+update ignore t1 set col165=repeat('a',7000);
+check table t1;
+drop table t1;
+
+#
+# Bug#38466 maria: range query returns no data
+#
+
+create table t1 (a char(200) primary key, b int default 12345) engine=maria;
+insert t1 (a) values (repeat('0', 200));
+insert t1 (a) values (repeat('1', 200)), (repeat('2', 200)), (repeat('3', 200)),
+ (repeat('4', 200)), (repeat('5', 200)), (repeat('6', 200)), (repeat('7', 200)),
+ (repeat('8', 200)), (repeat('9', 200)), (repeat('a', 200)), (repeat('b', 200)),
+ (repeat('c', 200)), (repeat('d', 200)), (repeat('e', 200)), (repeat('f', 200)),
+ (repeat('g', 200)), (repeat('h', 200)), (repeat('i', 200)), (repeat('j', 200)),
+ (repeat('k', 200)), (repeat('l', 200)), (repeat('m', 200)), (repeat('n', 200)),
+ (repeat('o', 200)), (repeat('p', 200)), (repeat('q', 200)), (repeat('r', 200)),
+ (repeat('s', 200)), (repeat('t', 200)), (repeat('u', 200)), (repeat('v', 200)),
+ (repeat('w', 200)), (repeat('x', 200)), (repeat('y', 200)), (repeat('z', 200)),
+ (repeat('+', 200)), (repeat('-', 200)), (repeat('=', 200)), (repeat('*', 200));
+select b from t1 where a >= repeat('f', 200) and a < 'k';
+drop table t1;
+
+#
+# BUG#38492 test suite
+#
+create table t1 (a int, b int) engine=maria transactional=1;
+insert t1 values (1,2);
+--send insert t1 values (2,3), (sleep(10),sleep(20)), (4,5);
+connect (root2,localhost,root,,test);
+--connection root2
+LOCK TABLES t1 write concurrent;
+insert t1 values (7,8);
+-- disconnect root2
+connection default;
+--reap
+drop table t1;
+
+#
+# BUG#38606  test suite
+#
+create table t1 (a int) engine=maria transactional=1;
+insert into t1 values (1);
+lock table t1 write concurrent;
+# should be fixed with fully implemented versioning
+--error ER_CHECK_NOT_IMPLEMENTED
+delete from t1;
+--error 1099
+drop table t1;
+unlock tables;
+drop table t1;
+
 --disable_result_log
 --disable_query_log
 eval set global storage_engine=$default_engine, maria_page_checksum=$default_checksum;

=== modified file 'mysql-test/t/maria2.test'
--- a/mysql-test/t/maria2.test	2008-06-10 14:44:44 +0000
+++ b/mysql-test/t/maria2.test	2008-08-12 10:59:30 +0000
@@ -1,5 +1,10 @@
 --source include/have_maria.inc
 
+# Initialise
+--disable_warnings
+drop table if exists t1,t2;
+--enable_warnings
+
 # Test for BUG#36319
 # "Maria: table is not empty but DELETE and SELECT find no rows"
 
@@ -64,3 +69,43 @@ select count(*) from t1;
 select name from t1;
 check table t1 extended;
 drop table t1;
+
+#
+# Testing of ALTER TABLE under lock tables
+#
+
+create table t1 (i int) engine=maria;
+create table t2 (j int) engine=maria;
+lock table t1 write, t2 read;
+alter table t1 modify i int default 1;
+insert into t1 values (2);
+# This caused a core dump
+alter table t1 modify i bigint default 1;
+select count(*) from t1;
+select * from t1;
+unlock tables;
+drop table t1,t2;
+
+#
+# test INSERT ON DUPLICATE KEY UPDATE
+#
+
+create table t1(id int, s char(1), unique(s)) engine=maria;
+insert into t1 values(1,"a") on duplicate key update t1.id=t1.id+1;
+insert into t1 values(1,"a") on duplicate key update t1.id=t1.id+1;
+insert into t1 select 1,"a" on duplicate key update t1.id=t1.id+1;
+select * from t1;
+
+# test REPLACE SELECT
+replace into t1 select 1,"a";
+select * from t1;
+drop table t1;
+
+# test LOAD DATA INFILE REPLACE
+create table t1 (pk int primary key, apk int unique, data int) engine=maria;
+insert into t1 values (1, 1, 1), (4, 4, 4), (6, 6, 6);
+load data concurrent infile '../std_data_ln/loaddata5.dat' replace into table t1 fields terminated by '' enclosed by '' ignore 1 lines (pk, apk);
+select * from t1 order by pk;
+load data infile '../std_data_ln/loaddata5.dat' replace into table t1 fields terminated by '' enclosed by '' ignore 1 lines (pk, apk);
+select * from t1 order by pk;
+drop table t1;

=== modified file 'mysql-test/valgrind.supp'
--- a/mysql-test/valgrind.supp	2008-07-09 07:12:43 +0000
+++ b/mysql-test/valgrind.supp	2008-08-13 09:00:54 +0000
@@ -27,7 +27,7 @@
    pthread allocate_tls memory loss
    Memcheck:Leak
    fun:calloc
-   obj:/lib64/ld*.so
+   obj:/lib*/ld*.so
    fun:_dl_allocate_tls
    fun:pthread_create*
 }
@@ -396,40 +396,58 @@
 }
 
 {
-   dlopen / ptread_cancel_init memory loss on Suse Linux 10.3 64 bit
+   dlopen / ptread_cancel_init memory loss on Suse Linux 10.3 32/64 bit
    Memcheck:Leak
    fun:*alloc
-   obj:/lib64/ld-*.so
-   obj:/lib64/ld-*.so
-   obj:/lib64/ld-*.so
-   obj:/lib64/ld-*.so
-   obj:/lib64/ld-*.so
-   obj:/lib64/ld-*.so
-   obj:/lib64/libc-*.so
-   obj:/lib64/ld-*.so
-   obj:/lib64/libc-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/libc-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/libc-*.so
    fun:__libc_dlopen_mode
    fun:pthread_cancel_init
    fun:_Unwind_ForcedUnwind
-
 }
 
 {
-   dlopen / ptread_cancel_init memory loss on Suse Linux 10.3 64 bit
+   dlopen / ptread_cancel_init memory loss on Suse Linux 10.3 32/64 bit
    Memcheck:Leak
    fun:*alloc
-   obj:/lib64/ld-*.so
-   obj:/lib64/ld-*.so
-   obj:/lib64/ld-*.so
-   obj:/lib64/ld-*.so
-   obj:/lib64/libc-*.so
-   obj:/lib64/ld-*.so
-   obj:/lib64/libc-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/libc-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/libc-*.so
    fun:__libc_dlopen_mode
    fun:pthread_cancel_init
    fun:_Unwind_ForcedUnwind
 }
 
+#
+# Reading wrong addresses on SuSe Linux 10.3 32 bit
+#
+
+{
+   Reading wrong data in libc_dlopen
+   Memcheck:Addr4
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/libc-*.so
+   obj:/lib*/ld-*.so
+   obj:/lib*/libc-*.so
+   fun:__libc_dlopen_mode
+   fun:pthread_cancel_init
+}
 
 #
 # These seem to be libc threading stuff, not related to MySQL code (allocations

=== modified file 'mysys/my_pread.c'
--- a/mysys/my_pread.c	2008-06-05 16:11:22 +0000
+++ b/mysys/my_pread.c	2008-08-25 18:23:18 +0000
@@ -132,7 +132,7 @@ size_t my_pread(File Filedes, uchar *Buf
 #endif
   for (;;)
   {
-    errno=0;					/* Linux, Windows don't reset this on EOF/success */
+    errno= 0;    /* Linux, Windows don't reset this on EOF/success */
 #if !defined (HAVE_PREAD) && !defined (__WIN__)
     pthread_mutex_lock(&my_file_info[Filedes].mutex);
     readbytes= (uint) -1;

=== modified file 'sql/handler.h'
--- a/sql/handler.h	2008-08-16 15:22:47 +0000
+++ b/sql/handler.h	2008-08-24 17:52:42 +0000
@@ -2097,7 +2097,7 @@ public:
     @param    thd               The thread handle
     @param    table             The altered table, re-opened
  */
- virtual int alter_table_phase3(THD *thd, TABLE *table)
+ virtual int alter_table_phase3(THD *, TABLE *)
  {
    return HA_ERR_UNSUPPORTED;
  }

=== modified file 'sql/mdl.cc'
--- a/sql/mdl.cc	2008-07-07 15:51:20 +0000
+++ b/sql/mdl.cc	2008-08-13 10:36:29 +0000
@@ -19,6 +19,7 @@
 #include <hash.h>
 #include <mysqld_error.h>
 
+static bool mdl_initialized= 0;
 
 /**
    The lock context. Created internally for an acquired lock.
@@ -115,6 +116,7 @@ extern "C" uchar *mdl_locks_key(const uc
 
 void mdl_init()
 {
+  mdl_initialized= 1;
   pthread_mutex_init(&LOCK_mdl, NULL);
   pthread_cond_init(&COND_mdl, NULL);
   hash_init(&mdl_locks, &my_charset_bin, 16 /* FIXME */, 0, 0,
@@ -133,10 +135,14 @@ void mdl_init()
 
 void mdl_destroy()
 {
-  DBUG_ASSERT(!mdl_locks.records);
-  pthread_mutex_destroy(&LOCK_mdl);
-  pthread_cond_destroy(&COND_mdl);
-  hash_free(&mdl_locks);
+  if (mdl_initialized)
+  {
+    mdl_initialized= 0;
+    DBUG_ASSERT(!mdl_locks.records);
+    pthread_mutex_destroy(&LOCK_mdl);
+    pthread_cond_destroy(&COND_mdl);
+    hash_free(&mdl_locks);
+  }
 }
 
 

=== modified file 'sql/sql_base.cc'
--- a/sql/sql_base.cc	2008-08-22 06:48:55 +0000
+++ b/sql/sql_base.cc	2008-08-26 10:20:41 +0000
@@ -1242,6 +1242,10 @@ close_all_tables_for_name(THD *thd, TABL
     if (table->s->table_cache_key.length == key_length &&
         !memcmp(table->s->table_cache_key.str, key, key_length))
     {
+      /* Inform handler that table will be dropped after close */
+      if (table->db_stat)
+        table->file->extra(HA_EXTRA_PREPARE_FOR_DROP);
+
       /*
         Does nothing if the table is not locked.
         This allows one to use this function after a table
@@ -2032,8 +2036,6 @@ bool wait_while_table_is_used(THD *thd, 
                        table->s->table_name.str, table->s,
                        table->db_stat, table->s->version));
 
-  (void) table->file->extra(function);
-
   old_lock_type= table->reginfo.lock_type;
   mysql_lock_abort(thd, table, TRUE);	/* end threads waiting on lock */
 
@@ -2048,6 +2050,8 @@ bool wait_while_table_is_used(THD *thd, 
   tdc_remove_table(thd, TDC_RT_REMOVE_NOT_OWN,
                    table->s->db.str, table->s->table_name.str);
   pthread_mutex_unlock(&LOCK_open);
+  /* extra() call must come only after all instances above are closed */
+  (void) table->file->extra(function);
   DBUG_RETURN(FALSE);
 }
 
@@ -2074,6 +2078,7 @@ bool wait_while_table_is_used(THD *thd, 
 void drop_open_table(THD *thd, TABLE *table, const char *db_name,
                      const char *table_name)
 {
+  DBUG_ENTER("drop_open_table");
   if (table->s->tmp_table)
     close_temporary_table(thd, table, 1, 1);
   else
@@ -2085,10 +2090,12 @@ void drop_open_table(THD *thd, TABLE *ta
     table->s->version= 0;
 
     pthread_mutex_lock(&LOCK_open);
+    table->file->extra(HA_EXTRA_PREPARE_FOR_DROP);
     close_thread_table(thd, &thd->open_tables);
     quick_rm_table(table_type, db_name, table_name, 0);
     pthread_mutex_unlock(&LOCK_open);
   }
+  DBUG_VOID_RETURN;
 }
 
 

=== modified file 'sql/sql_select.cc'
--- a/sql/sql_select.cc	2008-08-16 15:22:47 +0000
+++ b/sql/sql_select.cc	2008-08-24 17:52:42 +0000
@@ -12999,7 +12999,8 @@ static bool create_internal_tmp_table(TA
 bool create_internal_tmp_table_from_heap(THD *thd, TABLE *table,
                                          ENGINE_COLUMNDEF *start_recinfo,
                                          ENGINE_COLUMNDEF **recinfo, 
-                                         int error, bool ignore_last_dupp_key_error)
+                                         int error,
+                                         bool ignore_last_dupp_key_error)
 {
   return create_internal_tmp_table_from_heap2(thd, table,
                                               start_recinfo, recinfo, error,

=== modified file 'sql/sql_table.cc'
--- a/sql/sql_table.cc	2008-07-26 16:38:20 +0000
+++ b/sql/sql_table.cc	2008-08-25 18:23:18 +0000
@@ -5786,7 +5786,7 @@ mysql_fast_or_online_alter_table(THD *th
     Upgrade the shared metadata lock to exclusive and close all
     instances of the table in the TDC except those used in this thread.
   */
-  if (wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN))
+  if (wait_while_table_is_used(thd, table, HA_EXTRA_PREPARE_FOR_RENAME))
     DBUG_RETURN(1);
 
   alter_table_manage_keys(table, table->file->indexes_are_disabled(),
@@ -7010,7 +7010,6 @@ view_err:
   if (wait_while_table_is_used(thd, table, HA_EXTRA_PREPARE_FOR_RENAME))
     goto err_new_table_cleanup;
 
-
   close_all_tables_for_name(thd, table->s,
                             new_name != table_name || new_db != db);
 
@@ -7383,7 +7382,7 @@ err:
   if (errpos >= 3 && to->file->ha_end_bulk_insert(error > 1) && error <= 0)
   {
     to->file->print_error(my_errno,MYF(0));
-    error=1;
+    error= 1;
   }
   to->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
 
@@ -7406,6 +7405,8 @@ err:
   to->file->ha_release_auto_increment();
   if (errpos >= 2 && to->file->ha_external_lock(thd,F_UNLCK))
     error=1;
+  if (error < 0 && to->file->extra(HA_EXTRA_PREPARE_FOR_RENAME))
+    error= 1;
   DBUG_RETURN(error > 0 ? -1 : 0);
 }
 

=== modified file 'storage/maria/ha_maria.cc'
--- a/storage/maria/ha_maria.cc	2008-07-10 14:58:31 +0000
+++ b/storage/maria/ha_maria.cc	2008-08-25 18:34:43 +0000
@@ -44,6 +44,7 @@ C_MODE_END
 #ifdef MARIA_CANNOT_ROLLBACK
 #define trans_register_ha(A, B, C)  do { /* nothing */ } while(0)
 #endif
+#define THD_TRN (*(TRN **)thd_ha_data(thd, maria_hton))
 
 ulong pagecache_division_limit, pagecache_age_threshold;
 ulonglong pagecache_buffer_size;
@@ -1164,7 +1165,7 @@ int ha_maria::zerofill(THD * thd, HA_CHE
   param.op_name= "zerofill";
   param.testflag= check_opt->flags | T_SILENT | T_ZEROFILL;
   param.sort_buffer_length= THDVAR(thd, sort_buffer_size);
-  error=maria_zerofill(&param, file, share->open_file_name);
+  error=maria_zerofill(&param, file, share->open_file_name.str);
 
   if (!error)
   {
@@ -1241,7 +1242,7 @@ int ha_maria::repair(THD *thd, HA_CHECK 
   param->thd= thd;
   param->tmpdir= &mysql_tmpdir_list;
   param->out_flag= 0;
-  strmov(fixed_name, share->open_file_name);
+  strmov(fixed_name, share->open_file_name.str);
 
   // Don't lock tables if we have used LOCK TABLE
   if (!thd->locked_tables_mode &&
@@ -1844,9 +1845,18 @@ bool ha_maria::is_crashed() const
           (my_disable_locking && file->s->state.open_count));
 }
 
+#define CHECK_UNTIL_WE_FULLY_IMPLEMENTED_VERSIONING(msg) \
+  do { \
+    if (file->lock.type == TL_WRITE_CONCURRENT_INSERT) \
+    { \
+      my_error(ER_CHECK_NOT_IMPLEMENTED, MYF(0), msg); \
+      return 1; \
+    } \
+  } while(0)
 
 int ha_maria::update_row(const uchar * old_data, uchar * new_data)
 {
+  CHECK_UNTIL_WE_FULLY_IMPLEMENTED_VERSIONING("UPDATE in WRITE CONCURRENT");
   ha_statistic_increment(&SSV::ha_update_count);
   if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE)
     table->timestamp_field->set_time();
@@ -1856,6 +1866,7 @@ int ha_maria::update_row(const uchar * o
 
 int ha_maria::delete_row(const uchar * buf)
 {
+  CHECK_UNTIL_WE_FULLY_IMPLEMENTED_VERSIONING("DELETE in WRITE CONCURRENT");
   ha_statistic_increment(&SSV::ha_delete_count);
   return maria_delete(file, buf);
 }
@@ -2059,11 +2070,11 @@ int ha_maria::info(uint flag)
        if table is symlinked (Ie;  Real name is not same as generated name)
     */
     data_file_name= index_file_name= 0;
-    fn_format(name_buff, file->s->open_file_name, "", MARIA_NAME_DEXT,
+    fn_format(name_buff, file->s->open_file_name.str, "", MARIA_NAME_DEXT,
               MY_APPEND_EXT | MY_UNPACK_FILENAME);
     if (strcmp(name_buff, maria_info.data_file_name))
-      data_file_name=maria_info.data_file_name;
-    fn_format(name_buff, file->s->open_file_name, "", MARIA_NAME_IEXT,
+      data_file_name =maria_info.data_file_name;
+    fn_format(name_buff, file->s->open_file_name.str, "", MARIA_NAME_IEXT,
               MY_APPEND_EXT | MY_UNPACK_FILENAME);
     if (strcmp(name_buff, maria_info.index_file_name))
       index_file_name=maria_info.index_file_name;
@@ -2085,6 +2096,21 @@ int ha_maria::extra(enum ha_extra_functi
 {
   if ((specialflag & SPECIAL_SAFE_MODE) && operation == HA_EXTRA_KEYREAD)
     return 0;
+
+  /*
+    We have to set file->trn here because in some cases we call
+    extern_lock(F_UNLOCK) (which resets file->trn) followed by maria_close()
+    without calling commit/rollback in between.  If file->trn is not set
+    we can't remove file->share from the transaction list in the extra() call.
+  */
+
+  if (!file->trn &&
+      (operation == HA_EXTRA_PREPARE_FOR_DROP ||
+       operation == HA_EXTRA_PREPARE_FOR_RENAME))
+  {
+    THD *thd= table->in_use;
+    file->trn= THD_TRN;
+  }
   return maria_extra(file, operation, 0);
 }
 
@@ -2124,8 +2150,6 @@ int ha_maria::delete_table(const char *n
   return maria_delete_table(name);
 }
 
-#define THD_TRN (*(TRN **)thd_ha_data(thd, maria_hton))
-
 int ha_maria::external_lock(THD *thd, int lock_type)
 {
   TRN *trn= THD_TRN;
@@ -2229,11 +2253,13 @@ int ha_maria::external_lock(THD *thd, in
         if (!trnman_decrement_locked_tables(trn))
         {
           /*
-            OK should not have been sent to client yet (ACID).
+            OK should not have been sent to client yet (ACID),
+            exception: connection is closed by client.
             This is a bit excessive, ACID requires this only if there are some
             changes to commit (rollback shouldn't be tested).
           */
-          DBUG_ASSERT(!thd->main_da.is_sent);
+          DBUG_ASSERT(!thd->main_da.is_sent ||
+                      thd->killed == THD::KILL_CONNECTION);
           /* autocommit ? rollback a transaction */
 #ifdef MARIA_CANNOT_ROLLBACK
           if (ma_commit(trn))
@@ -2389,6 +2415,7 @@ THR_LOCK_DATA **ha_maria::store_lock(THD
               (lock_type == TL_IGNORE || file->lock.type == TL_UNLOCK));
   if (lock_type != TL_IGNORE && file->lock.type == TL_UNLOCK)
   {
+    const enum enum_sql_command sql_command= thd->lex->sql_command;
     /*
       We have to disable concurrent inserts for INSERT ... SELECT or
       INSERT/UPDATE/DELETE with sub queries if we are using statement based
@@ -2397,24 +2424,33 @@ THR_LOCK_DATA **ha_maria::store_lock(THD
     */
     if (lock_type <= TL_READ_HIGH_PRIORITY &&
         !thd->current_stmt_binlog_row_based &&
-        (thd->lex->sql_command != SQLCOM_SELECT &&
-         thd->lex->sql_command != SQLCOM_LOCK_TABLES) &&
+        (sql_command != SQLCOM_SELECT &&
+         sql_command != SQLCOM_LOCK_TABLES) &&
         (thd->options & OPTION_BIN_LOG) &&
         mysql_bin_log.is_open())
       lock_type= TL_READ_NO_INSERT;
-    else if (lock_type == TL_WRITE_CONCURRENT_INSERT &&
-             (file->state->records == 0))
+    else if (lock_type == TL_WRITE_CONCURRENT_INSERT)
     {
+      const enum enum_duplicates duplicates= thd->lex->duplicates;
       /*
-        Bulk insert may use repair, which will cause problems if other
+        Explanation for the 3 conditions below, in order:
+
+        - Bulk insert may use repair, which will cause problems if other
         threads try to read/insert to the table: disable versioning.
         Note that our read of file->state->records is incorrect, as such
         variable may have changed when we come to start_bulk_insert() (worse
         case: we see != 0 so allow versioning, start_bulk_insert() sees 0 and
         uses repair). This is prevented because start_bulk_insert() will not
         try repair if we enabled versioning.
+        - INSERT SELECT ON DUPLICATE KEY UPDATE comes here with
+        TL_WRITE_CONCURRENT_INSERT but shouldn't because it can do
+        update/delete of a row and versioning doesn't support that
+        - same for LOAD DATA CONCURRENT REPLACE.
       */
-      lock_type= TL_WRITE;
+      if ((file->state->records == 0) ||
+          (sql_command == SQLCOM_INSERT_SELECT && duplicates == DUP_UPDATE) ||
+          (sql_command == SQLCOM_LOAD && duplicates == DUP_REPLACE))
+        lock_type= TL_WRITE;
     }
     file->lock.type= lock_type;
   }

=== modified file 'storage/maria/ma_blockrec.c'
--- a/storage/maria/ma_blockrec.c	2008-07-09 13:09:30 +0000
+++ b/storage/maria/ma_blockrec.c	2008-08-11 14:40:32 +0000
@@ -3073,7 +3073,7 @@ static my_bool write_block_record(MARIA_
     }
     else
     {
-      if (my_multi_malloc(MY_WME, &log_array,
+      if (!my_multi_malloc(MY_WME, &log_array,
                           (uint) ((bitmap_blocks->count +
                                    TRANSLOG_INTERNAL_PARTS + 2) *
                                   sizeof(*log_array)),

=== modified file 'storage/maria/ma_check.c'
--- a/storage/maria/ma_check.c	2008-07-10 15:20:07 +0000
+++ b/storage/maria/ma_check.c	2008-08-25 18:23:18 +0000
@@ -2476,7 +2476,7 @@ int maria_repair(HA_CHECK *param, regist
   {
     /* Get real path for data file */
     if ((new_file= my_create(fn_format(param->temp_filename,
-                                       share->data_file_name, "",
+                                       share->data_file_name.str, "",
                                        DATA_TMP_EXT, 2+4),
                              0,param->tmpfile_createflag,
                              MYF(0))) < 0)
@@ -2680,7 +2680,7 @@ int maria_repair(HA_CHECK *param, regist
       my_close(new_file, MYF(MY_WME));
     new_file= -1;
     change_data_file_descriptor(info, -1);
-    if (maria_change_to_newfile(share->data_file_name,MARIA_NAME_DEXT,
+    if (maria_change_to_newfile(share->data_file_name.str, MARIA_NAME_DEXT,
                                 DATA_TMP_EXT,
                                 (param->testflag & T_BACKUP_DATA ?
                                  MYF(MY_REDEL_MAKE_BACKUP): MYF(0)) |
@@ -2992,8 +2992,8 @@ int maria_sort_index(HA_CHECK *param, re
   (void)(my_close(share->kfile.file, MYF(MY_WME)));
   share->kfile.file = -1;
   pthread_mutex_unlock(&share->intern_lock);
-  (void)(my_close(new_file,MYF(MY_WME)));
-  if (maria_change_to_newfile(share->index_file_name, MARIA_NAME_IEXT,
+  (void) my_close(new_file,MYF(MY_WME));
+  if (maria_change_to_newfile(share->index_file_name.str, MARIA_NAME_IEXT,
                               INDEX_TMP_EXT, sync_dir) ||
       _ma_open_keyfile(share))
     goto err2;
@@ -3524,7 +3524,7 @@ int maria_repair_by_sort(HA_CHECK *param
   {
     /* Get real path for data file */
     if ((new_file=my_create(fn_format(param->temp_filename,
-                                      share->data_file_name, "",
+                                      share->data_file_name.str, "",
                                       DATA_TMP_EXT, 2+4),
                             0,param->tmpfile_createflag,
                             MYF(0))) < 0)
@@ -3789,7 +3789,7 @@ int maria_repair_by_sort(HA_CHECK *param
         new_file= -1;
       }
       change_data_file_descriptor(info, -1);
-      if (maria_change_to_newfile(share->data_file_name,MARIA_NAME_DEXT,
+      if (maria_change_to_newfile(share->data_file_name.str, MARIA_NAME_DEXT,
                                   DATA_TMP_EXT,
                                   (param->testflag & T_BACKUP_DATA ?
                                    MYF(MY_REDEL_MAKE_BACKUP): MYF(0)) |
@@ -4070,7 +4070,7 @@ int maria_repair_parallel(HA_CHECK *para
   {
     /* Get real path for data file */
     if ((new_file= my_create(fn_format(param->temp_filename,
-                                       share->data_file_name, "",
+                                       share->data_file_name.str, "",
                                        DATA_TMP_EXT,
                                        2+4),
                              0,param->tmpfile_createflag,
@@ -4397,7 +4397,7 @@ err:
     {
       my_close(new_file,MYF(0));
       info->dfile.file= new_file= -1;
-      if (maria_change_to_newfile(share->data_file_name,MARIA_NAME_DEXT,
+      if (maria_change_to_newfile(share->data_file_name.str, MARIA_NAME_DEXT,
                                   DATA_TMP_EXT,
                                   MYF((param->testflag & T_BACKUP_DATA ?
                                        MY_REDEL_MAKE_BACKUP : 0) |
@@ -6236,7 +6236,7 @@ static my_bool create_new_data_handle(MA
   MARIA_HA *new_info;
   DBUG_ENTER("create_new_data_handle");
 
-  if (!(sort_info->new_info= maria_open(info->s->open_file_name, O_RDWR,
+  if (!(sort_info->new_info= maria_open(info->s->open_file_name.str, O_RDWR,
                                         HA_OPEN_COPY | HA_OPEN_FOR_REPAIR)))
     DBUG_RETURN(1);
 

=== modified file 'storage/maria/ma_checkpoint.c'
--- a/storage/maria/ma_checkpoint.c	2008-07-05 11:03:21 +0000
+++ b/storage/maria/ma_checkpoint.c	2008-08-25 11:49:47 +0000
@@ -820,7 +820,7 @@ static int collect_tables(LEX_STRING *st
       */
       share->in_checkpoint= MARIA_CHECKPOINT_LOOKS_AT_ME;
       /** @todo avoid strlen() */
-      total_names_length+= strlen(share->open_file_name);
+      total_names_length+= share->open_file_name.length;
     }
   }
 
@@ -894,7 +894,7 @@ static int collect_tables(LEX_STRING *st
        @todo We should not look at tables which didn't change since last
        checkpoint.
     */
-    DBUG_PRINT("info",("looking at table '%s'", share->open_file_name));
+    DBUG_PRINT("info",("looking at table '%s'", share->open_file_name.str));
     if (state_copy == state_copies_end) /* we have no more cached states */
     {
       /*
@@ -978,8 +978,7 @@ static int collect_tables(LEX_STRING *st
     DBUG_PRINT("info", ("ignore_share: %d", ignore_share));
     if (!ignore_share)
     {
-      /** @todo avoid strlen */
-      uint open_file_name_len= strlen(share->open_file_name) + 1;
+      uint open_file_name_len= share->open_file_name.length + 1;
       /* remember the descriptors for background flush */
       *(dfiles_end++)= dfile;
       *(kfiles_end++)= kfile;
@@ -1000,7 +999,7 @@ static int collect_tables(LEX_STRING *st
         If no crash, maria_close() will write the exact value.
       */
       state_copy->state.first_bitmap_with_space= ~(ulonglong)0;
-      memcpy(ptr, share->open_file_name, open_file_name_len);
+      memcpy(ptr, share->open_file_name.str, open_file_name_len);
       ptr+= open_file_name_len;
       if (cmp_translog_addr(share->state.is_of_horizon,
                             checkpoint_start_log_horizon) >= 0)

=== modified file 'storage/maria/ma_close.c'
--- a/storage/maria/ma_close.c	2008-07-09 21:25:29 +0000
+++ b/storage/maria/ma_close.c	2008-08-25 18:23:18 +0000
@@ -69,6 +69,10 @@ int maria_close(register MARIA_HA *info)
   if (flag)
   {
     /* Last close of file; Flush everything */
+
+    /* Check that we don't have any dangling pointers from the transaction */
+    DBUG_ASSERT(share->in_trans == 0);
+
     if (share->kfile.file >= 0)
     {
       if ((*share->once_end)(share))

=== modified file 'storage/maria/ma_create.c'
--- a/storage/maria/ma_create.c	2008-07-09 21:25:29 +0000
+++ b/storage/maria/ma_create.c	2008-08-25 18:23:18 +0000
@@ -1349,9 +1349,9 @@ int _ma_update_state_lsns_sub(MARIA_SHAR
     int res;
     LEX_CUSTRING log_array[TRANSLOG_INTERNAL_PARTS + 1];
     /* table name is logged only for information */
-    log_array[TRANSLOG_INTERNAL_PARTS + 0].str=    share->open_file_name;
+    log_array[TRANSLOG_INTERNAL_PARTS + 0].str=    share->open_file_name.str;
     log_array[TRANSLOG_INTERNAL_PARTS + 0].length=
-      strlen(log_array[TRANSLOG_INTERNAL_PARTS + 0].str) + 1;
+      share->open_file_name.length + 1;
     if ((res= translog_write_record(&lsn, LOGREC_IMPORTED_TABLE,
                                     &dummy_transaction_object, NULL,
                                     (translog_size_t)

=== modified file 'storage/maria/ma_dbug.c'
--- a/storage/maria/ma_dbug.c	2008-06-26 17:48:42 +0000
+++ b/storage/maria/ma_dbug.c	2008-08-25 18:23:18 +0000
@@ -184,7 +184,7 @@ my_bool _ma_check_table_is_closed(const 
   {
     MARIA_HA *info=(MARIA_HA*) pos->data;
     MARIA_SHARE *share= info->s;
-    if (!strcmp(share->unique_file_name,filename))
+    if (!strcmp(share->unique_file_name.str, filename))
     {
       if (share->last_version)
       {

=== modified file 'storage/maria/ma_delete.c'
--- a/storage/maria/ma_delete.c	2008-07-09 21:25:29 +0000
+++ b/storage/maria/ma_delete.c	2008-08-25 18:23:18 +0000
@@ -122,8 +122,9 @@ int maria_delete(MARIA_HA *info,const uc
   allow_break();			/* Allow SIGHUP & SIGINT */
   if (info->invalidator != 0)
   {
-    DBUG_PRINT("info", ("invalidator... '%s' (delete)", share->open_file_name));
-    (*info->invalidator)(share->open_file_name);
+    DBUG_PRINT("info", ("invalidator... '%s' (delete)",
+                        share->open_file_name.str));
+    (*info->invalidator)(share->open_file_name.str);
     info->invalidator=0;
   }
   DBUG_RETURN(0);
@@ -780,6 +781,7 @@ static int underflow(register MARIA_HA *
       first_key)
   {
     size_t tmp_length;
+    uint next_page_flag;
     /* Use page right of anc-page */
     DBUG_PRINT("test",("use right page"));
 
@@ -805,6 +807,7 @@ static int underflow(register MARIA_HA *
                            DFLT_INIT_HITS, buff, 0, &next_page_link))
       goto err;
     next_buff_length= _ma_get_page_used(share, buff);
+    next_page_flag=   _ma_get_keypage_flag(share,buff);
     DBUG_DUMP("next", buff, next_buff_length);
 
     /* find keys to make a big key-page */
@@ -829,7 +832,7 @@ static int underflow(register MARIA_HA *
     _ma_store_page_used(share, buff, buff_length);
 
     /* Set page flag from combination of both key pages and parting key */
-    page_flag= (_ma_get_keypage_flag(share, buff) |
+    page_flag= (next_page_flag |
                 _ma_get_keypage_flag(share, leaf_buff));
     if (anc_key.flag & (SEARCH_USER_KEY_HAS_TRANSID |
                         SEARCH_PAGE_KEY_HAS_TRANSID))

=== modified file 'storage/maria/ma_extra.c'
--- a/storage/maria/ma_extra.c	2008-06-26 05:18:28 +0000
+++ b/storage/maria/ma_extra.c	2008-08-25 18:23:18 +0000
@@ -322,6 +322,13 @@ int maria_extra(MARIA_HA *info, enum ha_
     if (share->kfile.file >= 0)
       _ma_decrement_open_count(info);
     pthread_mutex_lock(&share->intern_lock);
+    if (info->trn)
+    {
+      _ma_remove_table_from_trnman(share, info->trn);
+      /* Ensure we don't point to the deleted data in trn */
+      info->state= info->state_start= &share->state.state;
+    }
+
     type= do_flush ? FLUSH_RELEASE : FLUSH_IGNORE_CHANGED;
     if (_ma_flush_table_files(info, MARIA_FLUSH_DATA | MARIA_FLUSH_INDEX,
                               type, type))
@@ -340,7 +347,7 @@ int maria_extra(MARIA_HA *info, enum ha_
       if (do_flush)
       {
         /* Save the state so that others can find it from disk. */
-        if (_ma_state_info_write(share, 1 | 2) ||
+        if ((share->changed && _ma_state_info_write(share, 1 | 2)) ||
             my_sync(share->kfile.file, MYF(0)))
           error= my_errno;
         else

=== modified file 'storage/maria/ma_info.c'
--- a/storage/maria/ma_info.c	2008-06-05 16:11:22 +0000
+++ b/storage/maria/ma_info.c	2008-08-25 18:23:18 +0000
@@ -81,8 +81,8 @@ int maria_status(MARIA_HA *info, registe
     x->sortkey= -1;				/* No clustering */
     x->rec_per_key	= share->state.rec_per_key_part;
     x->key_map	 	= share->state.key_map;
-    x->data_file_name   = share->data_file_name;
-    x->index_file_name  = share->index_file_name;
+    x->data_file_name   = share->data_file_name.str;
+    x->index_file_name  = share->index_file_name.str;
     x->data_file_type   = share->data_file_type;
   }
   if ((flag & HA_STATUS_TIME) && !my_fstat(info->dfile.file, &state, MYF(0)))
@@ -118,13 +118,14 @@ int maria_status(MARIA_HA *info, registe
     void
 */
 
-void _ma_report_error(int errcode, const char *file_name)
+void _ma_report_error(int errcode, const LEX_STRING *name)
 {
-  size_t  length;
+  size_t length;
+  const char *file_name= name->str;
   DBUG_ENTER("_ma_report_error");
   DBUG_PRINT("enter",("errcode %d, table '%s'", errcode, file_name));
 
-  if ((length= strlen(file_name)) > 64)
+  if ((length= name->length) > 64)
   {
     /* we first remove the directory */
     size_t dir_length= dirname_length(file_name);

=== modified file 'storage/maria/ma_keycache.c'
--- a/storage/maria/ma_keycache.c	2007-10-04 17:33:42 +0000
+++ b/storage/maria/ma_keycache.c	2008-08-25 11:49:47 +0000
@@ -105,8 +105,8 @@ int maria_assign_to_pagecache(MARIA_HA *
   share->pagecache= pagecache;
 
   /* store the key cache in the global hash structure for future opens */
-  if (multi_pagecache_set((uchar*) share->unique_file_name,
-			  share->unique_name_length,
+  if (multi_pagecache_set((uchar*) share->unique_file_name.str,
+                          share->unique_file_name.length,
 			  share->pagecache))
     error= my_errno;
   pthread_mutex_unlock(&share->intern_lock);

=== modified file 'storage/maria/ma_locking.c'
--- a/storage/maria/ma_locking.c	2008-07-09 21:25:29 +0000
+++ b/storage/maria/ma_locking.c	2008-08-25 18:23:18 +0000
@@ -34,7 +34,7 @@ int maria_lock_database(MARIA_HA *info, 
                       lock_type, info->lock_type, share->r_locks,
                       share->w_locks,
                       share->global_changed, share->state.open_count,
-                      share->index_file_name));
+                      share->index_file_name.str));
   if (share->options & HA_OPTION_READ_ONLY_DATA ||
       info->lock_type == lock_type)
     DBUG_RETURN(0);

=== modified file 'storage/maria/ma_loghandler.c'
--- a/storage/maria/ma_loghandler.c	2008-07-09 21:25:29 +0000
+++ b/storage/maria/ma_loghandler.c	2008-08-25 18:23:18 +0000
@@ -7686,7 +7686,7 @@ int translog_assign_id_to_share(MARIA_HA
   DBUG_ASSERT(share->data_file_type == BLOCK_RECORD);
   /* re-check under mutex to avoid having 2 ids for the same share */
   pthread_mutex_lock(&share->intern_lock);
-  if (likely(share->id == 0))
+  if (unlikely(share->id == 0))
   {
     LSN lsn;
     LEX_CUSTRING log_array[TRANSLOG_INTERNAL_PARTS + 2];
@@ -7717,13 +7717,13 @@ int translog_assign_id_to_share(MARIA_HA
       is not realpath-ed, etc) which is good: the log can be moved to another
       directory and continue working.
     */
-    log_array[TRANSLOG_INTERNAL_PARTS + 1].str= share->open_file_name;
-    /**
-       @todo if we had the name's length in MARIA_SHARE we could avoid this
-       strlen()
-    */
+    log_array[TRANSLOG_INTERNAL_PARTS + 1].str= share->open_file_name.str;
     log_array[TRANSLOG_INTERNAL_PARTS + 1].length=
-      strlen(share->open_file_name) + 1;
+      share->open_file_name.length + 1;
+    /*
+      We can't unlock share->intern_lock before the log entry is written to
+      ensure no one uses the id before it's logged.
+    */
     if (unlikely(translog_write_record(&lsn, LOGREC_FILE_ID, trn, tbl_info,
                                        (translog_size_t)
                                        (sizeof(log_data) +

=== modified file 'storage/maria/ma_open.c'
--- a/storage/maria/ma_open.c	2008-07-09 21:25:29 +0000
+++ b/storage/maria/ma_open.c	2008-08-25 18:23:18 +0000
@@ -62,7 +62,7 @@ MARIA_HA *_ma_test_if_reopen(const char 
   {
     MARIA_HA *info=(MARIA_HA*) pos->data;
     MARIA_SHARE *share= info->s;
-    if (!strcmp(share->unique_file_name,filename) && share->last_version)
+    if (!strcmp(share->unique_file_name.str,filename) && share->last_version)
       return info;
   }
   return 0;
@@ -212,7 +212,7 @@ err:
   if ((save_errno == HA_ERR_CRASHED) ||
       (save_errno == HA_ERR_CRASHED_ON_USAGE) ||
       (save_errno == HA_ERR_CRASHED_ON_REPAIR))
-    _ma_report_error(save_errno, share->open_file_name);
+    _ma_report_error(save_errno, &share->open_file_name);
   switch (errpos) {
   case 6:
     (*share->end)(&info);
@@ -480,6 +480,10 @@ MARIA_HA *maria_open(const char *name, i
     /* Add space for node pointer */
     share->base.max_key_length+= share->base.key_reflength;
 
+    share->unique_file_name.length= strlen(name_buff);
+    share->index_file_name.length=  strlen(index_name);
+    share->data_file_name.length=   strlen(data_name);
+    share->open_file_name.length=   strlen(name);
     if (!my_multi_malloc(MY_WME,
 			 &share,sizeof(*share),
 			 &share->state.rec_per_key_part,
@@ -495,10 +499,14 @@ MARIA_HA *maria_open(const char *name, i
 			 (share->base.fields+1)*sizeof(MARIA_COLUMNDEF),
                          &share->column_nr, share->base.fields*sizeof(uint16),
 			 &share->blobs,sizeof(MARIA_BLOB)*share->base.blobs,
-			 &share->unique_file_name,strlen(name_buff)+1,
-			 &share->index_file_name,strlen(index_name)+1,
-			 &share->data_file_name,strlen(data_name)+1,
-                         &share->open_file_name,strlen(name)+1,
+			 &share->unique_file_name.str,
+			 share->unique_file_name.length+1,
+			 &share->index_file_name.str,
+                         share->index_file_name.length+1,
+			 &share->data_file_name.str,
+                         share->data_file_name.length+1,
+                         &share->open_file_name.str,
+                         share->open_file_name.length+1,
 			 &share->state.key_root,keys*sizeof(my_off_t),
 			 &share->mmap_lock,sizeof(rw_lock_t),
 			 NullS))
@@ -512,11 +520,10 @@ MARIA_HA *maria_open(const char *name, i
 	   (char*) nulls_per_key_part, sizeof(long)*key_parts);
     memcpy((char*) share->state.key_root,
 	   (char*) key_root, sizeof(my_off_t)*keys);
-    strmov(share->unique_file_name, name_buff);
-    share->unique_name_length= (uint) strlen(name_buff);
-    strmov(share->index_file_name,  index_name);
-    strmov(share->data_file_name,   data_name);
-    strmov(share->open_file_name,   name);
+    strmov(share->unique_file_name.str, name_buff);
+    strmov(share->index_file_name.str, index_name);
+    strmov(share->data_file_name.str,  data_name);
+    strmov(share->open_file_name.str,  name);
 
     share->block_size= share->base.block_size;   /* Convenience */
     {
@@ -886,7 +893,12 @@ err:
   if ((save_errno == HA_ERR_CRASHED) ||
       (save_errno == HA_ERR_CRASHED_ON_USAGE) ||
       (save_errno == HA_ERR_CRASHED_ON_REPAIR))
-    _ma_report_error(save_errno, name);
+  {
+    LEX_STRING tmp_name;
+    tmp_name.str= (char*) name;
+    tmp_name.length= strlen(name);
+    _ma_report_error(save_errno, &tmp_name);
+  }
   if (save_errno == HA_ERR_OLD_FILE) /* uuid is different ? */
     save_errno= HA_ERR_CRASHED_ON_USAGE; /* the code to trigger auto-repair */
   switch (errpos) {
@@ -1186,6 +1198,7 @@ uint _ma_state_info_write(MARIA_SHARE *s
   res= _ma_state_info_write_sub(share->kfile.file, &share->state, pWrite);
   if (pWrite & 4)
     pthread_mutex_unlock(&share->intern_lock);
+  share->changed= 0;
   return res;
 }
 
@@ -1506,10 +1519,10 @@ my_bool _ma_keyseg_write(File file, cons
   ulong pos;
 
   *ptr++= keyseg->type;
-  *ptr++= keyseg->language;
+  *ptr++= keyseg->language & 0xFF; /* Collation ID, low byte */
   *ptr++= keyseg->null_bit;
   *ptr++= keyseg->bit_start;
-  *ptr++= keyseg->bit_end;
+  *ptr++= keyseg->language >> 8; /* Collation ID, high byte */
   *ptr++= keyseg->bit_length;
   mi_int2store(ptr,keyseg->flag);	ptr+= 2;
   mi_int2store(ptr,keyseg->length);	ptr+= 2;
@@ -1528,13 +1541,14 @@ uchar *_ma_keyseg_read(uchar *ptr, HA_KE
    keyseg->language	= *ptr++;
    keyseg->null_bit	= *ptr++;
    keyseg->bit_start	= *ptr++;
-   keyseg->bit_end	= *ptr++;
+   keyseg->language	+= ((uint16) (*ptr++)) << 8;
    keyseg->bit_length   = *ptr++;
    keyseg->flag		= mi_uint2korr(ptr);  ptr+= 2;
    keyseg->length	= mi_uint2korr(ptr);  ptr+= 2;
    keyseg->start	= mi_uint4korr(ptr);  ptr+= 4;
    keyseg->null_pos	= mi_uint4korr(ptr);  ptr+= 4;
-   keyseg->charset=0;				/* Will be filled in later */
+   keyseg->bit_end	= 0;
+   keyseg->charset      = 0;                   /* Will be filled in later */
    if (keyseg->null_bit)
      keyseg->bit_pos= (uint16)(keyseg->null_pos + (keyseg->null_bit == 7));
    else
@@ -1711,7 +1725,7 @@ int _ma_open_datafile(MARIA_HA *info, MA
                       File file_to_dup __attribute__((unused)))
 {
   info->dfile.file= share->bitmap.file.file=
-    my_open(share->data_file_name, share->mode | O_SHARE,
+    my_open(share->data_file_name.str, share->mode | O_SHARE,
             MYF(MY_WME));
   return info->dfile.file >= 0 ? 0 : 1;
 }
@@ -1724,7 +1738,7 @@ int _ma_open_keyfile(MARIA_SHARE *share)
     against a concurrent checkpoint.
   */
   pthread_mutex_lock(&share->intern_lock);
-  share->kfile.file= my_open(share->unique_file_name,
+  share->kfile.file= my_open(share->unique_file_name.str,
                              share->mode | O_SHARE,
                              MYF(MY_WME));
   pthread_mutex_unlock(&share->intern_lock);

=== modified file 'storage/maria/ma_pagecache.c'
--- a/storage/maria/ma_pagecache.c	2008-05-29 15:44:11 +0000
+++ b/storage/maria/ma_pagecache.c	2008-08-25 18:29:05 +0000
@@ -305,12 +305,13 @@ struct st_pagecache_block_link
   ulonglong last_hit_time; /* timestamp of the last hit                      */
   WQUEUE
     wqueue[COND_SIZE];    /* queues on waiting requests for new/old pages    */
-  uint requests;          /* number of requests for the block                */
-  uint status;            /* state of the block                              */
-  uint pins;              /* pin counter                                     */
-  uint wlocks;            /* write locks counter                             */
-  uint rlocks;            /* read locks counter                              */
-  uint rlocks_queue;      /* rd. locks waiting wr. lock of this thread       */
+  uint32 requests;        /* number of requests for the block                */
+  uint32 pins;            /* pin counter                                     */
+  uint32 wlocks;          /* write locks counter                             */
+  uint32 rlocks;          /* read locks counter                              */
+  uint32 rlocks_queue;    /* rd. locks waiting wr. lock of this thread       */
+  uint16 status;          /* state of the block                              */
+  int16  error;           /* error code for block in case of error */
   enum PCBLOCK_TEMPERATURE temperature; /* block temperature: cold, warm, hot*/
   enum pagecache_page_type type; /* type of the block                        */
   uint hits_left;         /* number of hits left until promotion             */
@@ -592,16 +593,16 @@ extern my_bool translog_flush(TRANSLOG_A
 
   RETURN
     0   - OK
-    !=0 - Error
+    1   - Error
 */
 
-static uint pagecache_fwrite(PAGECACHE *pagecache,
-                             PAGECACHE_FILE *filedesc,
-                             uchar *buffer,
-                             pgcache_page_no_t pageno,
-                             enum pagecache_page_type type
-                             __attribute__((unused)),
-                             myf flags)
+static my_bool pagecache_fwrite(PAGECACHE *pagecache,
+                                PAGECACHE_FILE *filedesc,
+                                uchar *buffer,
+                                pgcache_page_no_t pageno,
+                                enum pagecache_page_type type
+                                __attribute__((unused)),
+                                myf flags)
 {
   DBUG_ENTER("pagecache_fwrite");
   DBUG_ASSERT(type != PAGECACHE_READ_UNKNOWN_PAGE);
@@ -2068,6 +2069,7 @@ restart:
                             (my_bool)(block->hash_link ? 1 : 0));
           PCBLOCK_INFO(block);
           block->status= error ? PCBLOCK_ERROR : 0;
+          block->error=  (int16) my_errno;
 #ifndef DBUG_OFF
           block->type= PAGECACHE_EMPTY_PAGE;
           if (error)
@@ -2606,6 +2608,7 @@ static void read_block(PAGECACHE *pageca
     if (error)
     {
       block->status|= PCBLOCK_ERROR;
+      block->error=   (int16) my_errno;
       my_debug_put_break_here();
     }
     else
@@ -2618,6 +2621,7 @@ static void read_block(PAGECACHE *pageca
       {
         DBUG_PRINT("error", ("read callback problem"));
         block->status|= PCBLOCK_ERROR;
+        block->error=  (int16) my_errno;
         my_debug_put_break_here();
       }
     }
@@ -3107,7 +3111,7 @@ uchar *pagecache_read(PAGECACHE *pagecac
                       enum pagecache_page_lock lock,
                       PAGECACHE_BLOCK_LINK **page_link)
 {
-  int error= 0;
+  my_bool error= 0;
   enum pagecache_page_pin pin= lock_to_pin[test(buff==0)][lock];
   PAGECACHE_BLOCK_LINK *fake_link;
   my_bool reg_request;
@@ -3229,6 +3233,8 @@ restart:
         pagecache_pthread_mutex_lock(&pagecache->cache_lock);
 #endif
       }
+      else
+        my_errno= block->error;
     }
 
     remove_reader(block);
@@ -3286,7 +3292,7 @@ static my_bool pagecache_delete_internal
                                          PAGECACHE_HASH_LINK *page_link,
                                          my_bool flush)
 {
-  int error= 0;
+  my_bool error= 0;
   if (block->status & PCBLOCK_CHANGED)
   {
     if (flush)
@@ -3313,6 +3319,7 @@ static my_bool pagecache_delete_internal
       if (error)
       {
         block->status|= PCBLOCK_ERROR;
+        block->error=   (int16) my_errno;
         my_debug_put_break_here();
         goto err;
       }
@@ -3361,7 +3368,7 @@ my_bool pagecache_delete_by_link(PAGECAC
                                  enum pagecache_page_lock lock,
                                  my_bool flush)
 {
-  int error= 0;
+  my_bool error= 0;
   enum pagecache_page_pin pin= PAGECACHE_PIN_LEFT_PINNED;
   DBUG_ENTER("pagecache_delete_by_link");
   DBUG_PRINT("enter", ("fd: %d block 0x%lx  %s  %s",
@@ -3460,7 +3467,7 @@ my_bool pagecache_delete(PAGECACHE *page
                          enum pagecache_page_lock lock,
                          my_bool flush)
 {
-  int error= 0;
+  my_bool error= 0;
   enum pagecache_page_pin pin= lock_to_pin[0][lock];
   DBUG_ENTER("pagecache_delete");
   DBUG_PRINT("enter", ("fd: %u  page: %lu  %s  %s",
@@ -3648,7 +3655,7 @@ my_bool pagecache_write_part(PAGECACHE *
 {
   PAGECACHE_BLOCK_LINK *block= NULL;
   PAGECACHE_BLOCK_LINK *fake_link;
-  int error= 0;
+  my_bool error= 0;
   int need_lock_change= write_lock_change_table[lock].need_lock_change;
   my_bool reg_request;
 #ifndef DBUG_OFF
@@ -3771,6 +3778,7 @@ restart:
         {
           DBUG_PRINT("error", ("read callback problem"));
           block->status|= PCBLOCK_ERROR;
+          block->error= (int16) my_errno;
           my_debug_put_break_here();
         }
         KEYCACHE_DBUG_PRINT("key_cache_insert",
@@ -3860,10 +3868,10 @@ no_key_cache:
       uchar *page_buffer= (uchar *) alloca(pagecache->block_size);
 
       pagecache->global_cache_read++;
-      if ((error= pagecache_fread(pagecache, file,
-                                  page_buffer,
-                                  pageno,
-                                  pagecache->readwrite_flags)))
+      if ((error= (pagecache_fread(pagecache, file,
+                                   page_buffer,
+                                   pageno,
+                                   pagecache->readwrite_flags) != 0)))
         goto end;
       if ((file->read_callback)(page_buffer, pageno, file->callback_data))
       {
@@ -3987,7 +3995,7 @@ static int flush_cached_blocks(PAGECACHE
                                int *first_errno)
 {
   int rc= PCFLUSH_OK;
-  int error;
+  my_bool error;
   uint count= (uint) (end-cache);
   DBUG_ENTER("flush_cached_blocks");
   *first_errno= 0;
@@ -4067,6 +4075,7 @@ static int flush_cached_blocks(PAGECACHE
     if (error)
     {
       block->status|= PCBLOCK_ERROR;
+      block->error=   (int16) my_errno;
       my_debug_put_break_here();
       if (!*first_errno)
         *first_errno= my_errno ? my_errno : -1;

=== modified file 'storage/maria/ma_recovery.c'
--- a/storage/maria/ma_recovery.c	2008-07-09 21:25:29 +0000
+++ b/storage/maria/ma_recovery.c	2008-08-25 18:23:18 +0000
@@ -866,7 +866,7 @@ prototype_redo_exec_hook(REDO_RENAME_TAB
       ALERT_USER();
       goto end;
     }
-    if (close_one_table(info->s->open_file_name, rec->lsn) ||
+    if (close_one_table(info->s->open_file_name.str, rec->lsn) ||
         maria_close(info))
       goto end;
     info= NULL;
@@ -1008,7 +1008,7 @@ prototype_redo_exec_hook(REDO_REPAIR_TAB
   tprint(tracef, "   repairing...\n");
 
   maria_chk_init(&param);
-  param.isam_file_name= name= info->s->open_file_name;
+  param.isam_file_name= name= info->s->open_file_name.str;
   param.testflag= uint8korr(rec->header + FILEID_STORE_SIZE);
   param.tmpdir= maria_tmpdir;
   DBUG_ASSERT(maria_tmpdir);
@@ -1085,7 +1085,7 @@ prototype_redo_exec_hook(REDO_DROP_TABLE
       ALERT_USER();
       goto end;
     }
-    if (close_one_table(info->s->open_file_name, rec->lsn) ||
+    if (close_one_table(info->s->open_file_name.str, rec->lsn) ||
         maria_close(info))
       goto end;
     info= NULL;
@@ -1141,7 +1141,7 @@ prototype_redo_exec_hook(FILE_ID)
   info= all_tables[sid].info;
   if (info != NULL)
   {
-    tprint(tracef, "   Closing table '%s'\n", info->s->open_file_name);
+    tprint(tracef, "   Closing table '%s'\n", info->s->open_file_name.str);
     prepare_table_for_close(info, rec->lsn);
     if (maria_close(info))
     {
@@ -1201,7 +1201,7 @@ static int new_table(uint16 sid, const c
       It could be that we have in the log
       FILE_ID(t1,10) ... (t1 was flushed) ... FILE_ID(t1,12);
     */
-    if (close_one_table(share->open_file_name, lsn_of_file_id))
+    if (close_one_table(share->open_file_name.str, lsn_of_file_id))
       goto end;
   }
   if (!share->base.born_transactional)
@@ -1230,7 +1230,7 @@ static int new_table(uint16 sid, const c
   if (maria_is_crashed(info))
   {
     eprint(tracef, "Table '%s' is crashed, skipping it. Please repair it with"
-           " maria_chk -r", share->open_file_name);
+           " maria_chk -r", share->open_file_name.str);
     error= -1; /* not fatal, try with other tables */
     goto end;
     /*
@@ -2828,7 +2828,7 @@ static MARIA_HA *get_MARIA_HA_from_REDO_
     return NULL;
   }
   share= info->s;
-  tprint(tracef, ", '%s'", share->open_file_name);
+  tprint(tracef, ", '%s'", share->open_file_name.str);
   DBUG_ASSERT(in_redo_phase);
   if (cmp_translog_addr(rec->lsn, share->lsn_of_file_id) <= 0)
   {
@@ -2899,7 +2899,7 @@ static MARIA_HA *get_MARIA_HA_from_UNDO_
     return NULL;
   }
   share= info->s;
-  tprint(tracef, ", '%s'", share->open_file_name);
+  tprint(tracef, ", '%s'", share->open_file_name.str);
   if (cmp_translog_addr(rec->lsn, share->lsn_of_file_id) <= 0)
   {
     tprint(tracef, ", table's LOGREC_FILE_ID has LSN (%lu,0x%lx) more recent"
@@ -3188,7 +3188,7 @@ static my_bool close_one_table(const cha
        internal_table++)
   {
     MARIA_HA *info= internal_table->info;
-    if ((info != NULL) && !strcmp(info->s->open_file_name, name))
+    if ((info != NULL) && !strcmp(info->s->open_file_name.str, name))
     {
       prepare_table_for_close(info, addr);
       if (maria_close(info))
@@ -3234,6 +3234,16 @@ void _ma_tmp_disable_logging_for_table(M
 
   /* if we disabled before writing the record, record wouldn't reach log */
   share->now_transactional= FALSE;
+
+  /*
+    Reset state pointers. This is needed as in ALTER table we may do
+    commit fllowed by _ma_renable_logging_for_table and then
+    info->state may point to a state that was deleted by
+    _ma_trnman_end_trans_hook()
+   */
+  share->state.common= *info->state;
+  info->state= &share->state.common;
+
   /*
     Some code in ma_blockrec.c assumes a trn even if !now_transactional but in
     this case it only reads trn->rec_lsn, which has to be LSN_IMPOSSIBLE and
@@ -3275,6 +3285,7 @@ my_bool _ma_reenable_logging_for_table(M
       in not transactional mode
     */
     _ma_copy_nontrans_state_information(info);
+    _ma_reset_history(info->s);
 
     if (flush_pages)
     {

=== modified file 'storage/maria/ma_search.c'
--- a/storage/maria/ma_search.c	2008-07-05 11:03:21 +0000
+++ b/storage/maria/ma_search.c	2008-08-24 13:29:34 +0000
@@ -116,7 +116,8 @@ int _ma_search(register MARIA_HA *info, 
 	((keyinfo->flag & (HA_NOSAME | HA_NULL_PART)) != HA_NOSAME ||
 	 (key->flag & SEARCH_PART_KEY) || info->s->base.born_transactional))
     {
-      if ((error= _ma_search(info, key, nextflag,
+      if ((error= _ma_search(info, key, (nextflag | SEARCH_FIND) &
+                             ~(SEARCH_BIGGER | SEARCH_SMALLER | SEARCH_LAST),
                              _ma_kpos(nod_flag,keypos))) >= 0 ||
           my_errno != HA_ERR_KEY_NOT_FOUND)
         DBUG_RETURN(error);
@@ -338,10 +339,8 @@ int _ma_seq_search(const MARIA_KEY *key,
                           comp_flag | tmp_key.flag,
                           not_used)) >= 0)
       break;
-#ifdef EXTRA_DEBUG
-    DBUG_PRINT("loop",("page: 0x%lx  key: '%s'  flag: %d", (long) page, t_buff,
-                       flag));
-#endif
+    DBUG_PRINT("loop_extra",("page: 0x%lx  key: '%s'  flag: %d",
+                             (long) page, t_buff, flag));
     memcpy(buff,t_buff,length);
     *ret_pos=page;
   }
@@ -2195,9 +2194,10 @@ int _ma_calc_bin_pack_key_length(const M
 
     if (next_length > ref_length)
     {
-      /* We put a key with different case between two keys with the same prefix
-         Extend next key to have same prefix as
-         this key */
+      /*
+        We put a key with different case between two keys with the same prefix
+        Extend next key to have same prefix as this key
+      */
       s_temp->n_ref_length= ref_length;
       s_temp->prev_length=  next_length-ref_length;
       s_temp->prev_key+=    ref_length;
@@ -2207,13 +2207,13 @@ int _ma_calc_bin_pack_key_length(const M
     }
     /* Check how many characters are identical to next key */
     key= s_temp->key+next_length;
+    s_temp->prev_length= 0;
     while (*key++ == *next_key++) ;
     if ((ref_length= (uint) (key - s_temp->key)-1) == next_length)
     {
       s_temp->next_key_pos=0;
       return (s_temp->move_length= length);  /* Can't pack next key */
     }
-    s_temp->prev_length=0;
     s_temp->n_ref_length=ref_length;
     return s_temp->move_length= (int) (length-(ref_length - next_length) -
                                        next_length_pack +

=== modified file 'storage/maria/ma_state.c'
--- a/storage/maria/ma_state.c	2008-07-05 11:03:21 +0000
+++ b/storage/maria/ma_state.c	2008-08-18 22:21:22 +0000
@@ -79,6 +79,9 @@ my_bool _ma_setup_live_state(MARIA_HA *i
 
   pthread_mutex_lock(&share->intern_lock);
   share->in_trans++;
+  DBUG_PRINT("info", ("share: 0x%lx  in_trans: %d",
+                      (ulong) share, share->in_trans));
+
   history= share->state_history;
 
   /*
@@ -359,19 +362,20 @@ my_bool _ma_trnman_end_trans_hook(TRN *t
 {
   my_bool error= 0;
   MARIA_USED_TABLES *tables, *next;
+  DBUG_ENTER("_ma_trnman_end_trans_hook");
   
   for (tables= (MARIA_USED_TABLES*) trn->used_tables;
        tables;
        tables= next)
   {
+    MARIA_SHARE *share= tables->share;
     next= tables->next;
     if (commit)
     {
-      MARIA_SHARE *share= tables->share;
       MARIA_STATE_HISTORY *history;
 
       pthread_mutex_lock(&share->intern_lock);
-      if (active_transactions &&
+      if (active_transactions && share->now_transactional &&
           trnman_exists_active_transactions(share->state_history->trid,
                                             trn->commit_trid, 1))
       {
@@ -405,16 +409,69 @@ my_bool _ma_trnman_end_trans_hook(TRN *t
         /* Remove not visible states */
         share->state_history= _ma_remove_not_visible_states(history, 0, 1);
       }
+      DBUG_PRINT("info", ("share: 0x%lx  in_trans: %d",
+                          (ulong) share, share->in_trans));
+      share->in_trans--;
+      pthread_mutex_unlock(&share->intern_lock);
+    }
+    else
+    {
+#ifndef DBUG_OFF
+      /*
+        We need to keep share->in_trans correct in the debug library
+        because of the assert in maria_close()
+      */
+      pthread_mutex_lock(&share->intern_lock);
       share->in_trans--;
       pthread_mutex_unlock(&share->intern_lock);
+#endif
     }
     my_free(tables, MYF(0));
   }
   trn->used_tables= 0;
-  return error;
+  DBUG_RETURN(error);
+}
+
+
+/**
+   Remove table from trnman_list
+
+   @notes
+     This is used when we unlock a table from a group of locked tables
+     just before doing a rename or drop table.
+
+     share->internal_lock must be locked when function is called
+*/
+
+void _ma_remove_table_from_trnman(MARIA_SHARE *share, TRN *trn)
+{
+  MARIA_USED_TABLES *tables, **prev;
+  DBUG_ENTER("_ma_remove_table_from_trnman");
+  DBUG_PRINT("enter", ("share: 0x%lx  in_trans: %d",
+                       (ulong) share, share->in_trans));
+
+  safe_mutex_assert_owner(&share->intern_lock);
+  
+  for (prev= (MARIA_USED_TABLES**) &trn->used_tables, tables= *prev;
+       tables;
+       tables= *prev)
+  {
+    if (tables->share == share)
+    {
+      *prev= tables->next;
+      share->in_trans--;
+      DBUG_PRINT("info", ("in_trans: %d", share->in_trans));
+      my_free(tables, MYF(0));
+      break;
+    }
+    prev= &tables->next;
+  }
+  DBUG_VOID_RETURN;
 }
 
 
+
+
 /****************************************************************************
   The following functions are called by thr_lock() in threaded applications
   for transactional tables.
@@ -509,6 +566,23 @@ void _ma_copy_nontrans_state_information
 }
 
 
+void _ma_reset_history(MARIA_SHARE *share)
+{
+  MARIA_STATE_HISTORY *history, *next;
+
+  share->state_history->trid= 0;          /* Visibly by all */
+  share->state_history->state= share->state.state;
+  history= share->state_history->next;
+  share->state_history->next= 0;
+
+  for (; history; history= next)
+  {
+    next= history->next;
+    my_free(history, MYF(0));
+  }
+}
+
+
 /****************************************************************************
   Virtual functions to check if row is visible
 ****************************************************************************/

=== modified file 'storage/maria/ma_state.h'
--- a/storage/maria/ma_state.h	2008-07-05 11:03:21 +0000
+++ b/storage/maria/ma_state.h	2008-07-12 14:14:28 +0000
@@ -77,3 +77,5 @@ my_bool _ma_row_visible_always(MARIA_HA 
 my_bool _ma_row_visible_non_transactional_table(MARIA_HA *info);
 my_bool _ma_row_visible_transactional_table(MARIA_HA *info);
 void _ma_remove_not_visible_states_with_lock(struct st_maria_share *share);
+void _ma_remove_table_from_trnman(struct st_maria_share *share, TRN *trn);
+void _ma_reset_history(struct st_maria_share *share);

=== modified file 'storage/maria/ma_update.c'
--- a/storage/maria/ma_update.c	2008-06-26 17:48:42 +0000
+++ b/storage/maria/ma_update.c	2008-08-25 18:23:18 +0000
@@ -188,8 +188,9 @@ int maria_update(register MARIA_HA *info
   allow_break();				/* Allow SIGHUP & SIGINT */
   if (info->invalidator != 0)
   {
-    DBUG_PRINT("info", ("invalidator... '%s' (update)", share->open_file_name));
-    (*info->invalidator)(share->open_file_name);
+    DBUG_PRINT("info", ("invalidator... '%s' (update)",
+                        share->open_file_name.str));
+    (*info->invalidator)(share->open_file_name.str);
     info->invalidator=0;
   }
   DBUG_RETURN(0);

=== modified file 'storage/maria/ma_write.c'
--- a/storage/maria/ma_write.c	2008-07-09 21:25:29 +0000
+++ b/storage/maria/ma_write.c	2008-08-25 18:23:18 +0000
@@ -227,8 +227,8 @@ int maria_write(MARIA_HA *info, uchar *r
   if (info->invalidator != 0)
   {
     DBUG_PRINT("info", ("invalidator... '%s' (update)",
-                        share->open_file_name));
-    (*info->invalidator)(share->open_file_name);
+                        share->open_file_name.str));
+    (*info->invalidator)(share->open_file_name.str);
     info->invalidator=0;
   }
 

=== modified file 'storage/maria/maria_def.h'
--- a/storage/maria/maria_def.h	2008-06-26 05:18:28 +0000
+++ b/storage/maria/maria_def.h	2008-08-25 11:49:47 +0000
@@ -274,10 +274,10 @@ typedef struct st_maria_share
   MARIA_PACK pack;			/* Data about packed records */
   MARIA_BLOB *blobs;			/* Pointer to blobs */
   uint16 *column_nr;			/* Original column order */
-  char *unique_file_name;		/* realpath() of index file */
-  char *data_file_name;			/* Resolved path names from symlinks */
-  char *index_file_name;
-  char *open_file_name;			/* parameter to open filename */
+  LEX_STRING unique_file_name;		/* realpath() of index file */
+  LEX_STRING data_file_name;		/* Resolved path names from symlinks */
+  LEX_STRING index_file_name;
+  LEX_STRING open_file_name;		/* parameter to open filename */
   uchar *file_map;			/* mem-map of file if possible */
   PAGECACHE *pagecache;			/* ref to the current key cache */
   MARIA_DECODE_TREE *decode_trees;
@@ -345,7 +345,6 @@ typedef struct st_maria_share
   ulong max_pack_length;
   ulong state_diff_length;
   uint rec_reflength;			/* rec_reflength in use now */
-  uint unique_name_length;
   uint keypage_header;
   uint32 ftparsers;			/* Number of distinct ftparsers
 						   + 1 */
@@ -661,7 +660,7 @@ struct st_maria_handler
 */
 #define maria_print_error(SHARE, ERRNO)                         \
   do{ if (!maria_in_ha_maria)                                   \
-      _ma_report_error((ERRNO), (SHARE)->index_file_name); }    \
+      _ma_report_error((ERRNO), &(SHARE)->index_file_name); }    \
   while(0)
 #else
 #define maria_print_error(SHARE, ERRNO) while (0)
@@ -1029,7 +1028,7 @@ extern uint _ma_pack_get_block_info(MARI
                                     size_t *rec_buff_size,
                                     File file, my_off_t filepos);
 extern void _ma_store_blob_length(uchar *pos, uint pack_length, uint length);
-extern void _ma_report_error(int errcode, const char *file_name);
+extern void _ma_report_error(int errcode, const LEX_STRING *file_name);
 extern my_bool _ma_memmap_file(MARIA_HA *info);
 extern void _ma_unmap_file(MARIA_HA *info);
 extern uint _ma_save_pack_length(uint version, uchar * block_buff,

=== modified file 'storage/maria/maria_ftdump.c'
--- a/storage/maria/maria_ftdump.c	2008-06-26 17:48:42 +0000
+++ b/storage/maria/maria_ftdump.c	2008-08-25 18:23:18 +0000
@@ -100,7 +100,8 @@ int main(int argc,char *argv[])
   if ((inx >= info->s->base.keys) ||
       !(info->s->keyinfo[inx].flag & HA_FULLTEXT))
   {
-    printf("Key %d in table %s is not a FULLTEXT key\n", inx, info->s->open_file_name);
+    printf("Key %d in table %s is not a FULLTEXT key\n", inx,
+           info->s->open_file_name.str);
     goto err;
   }
 

=== modified file 'storage/maria/maria_pack.c'
--- a/storage/maria/maria_pack.c	2008-07-09 21:25:29 +0000
+++ b/storage/maria/maria_pack.c	2008-08-25 18:23:18 +0000
@@ -510,11 +510,11 @@ static int compress(PACK_MRG_INFO *mrg,c
 
   /* Create temporary or join file */
   if (backup)
-    (void)(fn_format(org_name,isam_file->s->open_file_name,"",MARIA_NAME_DEXT,
-                   2));
+    (void) fn_format(org_name,isam_file->s->open_file_name.str,
+                     "",MARIA_NAME_DEXT, 2);
   else
-    (void)(fn_format(org_name,isam_file->s->open_file_name,"",MARIA_NAME_DEXT,
-                   2+4+16));
+    (void) fn_format(org_name,isam_file->s->open_file_name.str,
+                     "",MARIA_NAME_DEXT, 2+4+16);
 
   if (init_pagecache(maria_pagecache, MARIA_MIN_PAGE_CACHE_SIZE, 0, 0,
                      maria_block_size, MY_WME) == 0)
@@ -709,7 +709,7 @@ static int compress(PACK_MRG_INFO *mrg,c
       if (backup)
       {
 	if (my_rename(org_name,make_old_name(temp_name,
-                                             isam_file->s->open_file_name),
+                                             isam_file->s->open_file_name.str),
 		      MYF(MY_WME)))
 	  error=1;
 	else

=== modified file 'storage/myisam/mi_search.c'
--- a/storage/myisam/mi_search.c	2008-05-29 15:44:11 +0000
+++ b/storage/myisam/mi_search.c	2008-08-25 18:23:18 +0000
@@ -1802,13 +1802,13 @@ _mi_calc_bin_pack_key_length(MI_KEYDEF *
     }
     /* Check how many characters are identical to next key */
     key= s_temp->key+next_length;
+    s_temp->prev_length= 0;
     while (*key++ == *next_key++) ;
     if ((ref_length= (uint) (key - s_temp->key)-1) == next_length)
     {
       s_temp->next_key_pos=0;
       return length;                            /* can't pack next key */
     }
-    s_temp->prev_length=0;
     s_temp->n_ref_length=ref_length;
     return (int) (length-(ref_length - next_length) - next_length_pack +
                   get_pack_length(ref_length));

Thread
bzr push into mysql-6.0 branch (serg:2696) Sergei Golubchik26 Aug