List:Commits« Previous MessageNext Message »
From:marc.alff Date:February 5 2008 11:44pm
Subject:bk commit into 5.1 tree (malff:1.2661) BUG#12093
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of malff.  When malff does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2008-02-05 16:44:14-07:00, malff@stripped. +30 -0
  WL#4166 (Prepared statements: automatic re-prepare)
  Bug#12093 (SP not found on second PS execution if another thread drops other
  SP in between)
  
  Temporary patch, aggregating WL#4165 and WL#4166.
  NOT READY FOR REVIEW, NOT READY FOR PRODUCTION
  
  Misc cleanup

  mysql-test/r/ps_1general.result@stripped, 2008-02-05 16:44:08-07:00, malff@stripped. +5 -9
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  mysql-test/r/ps_ddl.result@stripped, 2008-02-05 16:44:08-07:00, malff@stripped. +2338 -1060
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  mysql-test/r/query_cache_ps_no_prot.result@stripped, 2008-02-05 16:44:08-07:00, malff@stripped. +10 -10
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  mysql-test/r/query_cache_ps_ps_prot.result@stripped, 2008-02-05 16:44:08-07:00, malff@stripped. +10 -10
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  mysql-test/r/sp-error.result@stripped, 2008-02-05 16:44:08-07:00, malff@stripped. +3 -2
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  mysql-test/r/trigger.result@stripped, 2008-02-05 16:44:08-07:00, malff@stripped. +0 -1
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  mysql-test/t/disabled.def@stripped, 2008-02-05 16:44:09-07:00, malff@stripped. +1 -1
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  mysql-test/t/ps_1general.test@stripped, 2008-02-05 16:44:09-07:00, malff@stripped. +5 -1
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  mysql-test/t/ps_ddl.test@stripped, 2008-02-05 16:44:09-07:00, malff@stripped. +303 -315
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  mysql-test/t/sp-error.test@stripped, 2008-02-05 16:44:09-07:00, malff@stripped. +0 -8
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  mysql-test/t/trigger.test@stripped, 2008-02-05 16:44:09-07:00, malff@stripped. +3 -4
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/mysql_priv.h@stripped, 2008-02-05 16:44:09-07:00, malff@stripped. +1 -1
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/mysqld.cc@stripped, 2008-02-05 16:44:09-07:00, malff@stripped. +4 -2
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/parse_file.cc@stripped, 2008-02-05 16:44:09-07:00, malff@stripped. +1 -1
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/share/errmsg.txt@stripped, 2008-02-05 16:44:11-07:00, malff@stripped. +7 -0
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/sp.cc@stripped, 2008-02-05 16:44:09-07:00, malff@stripped. +155 -52
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/sp.h@stripped, 2008-02-05 16:44:09-07:00, malff@stripped. +1 -0
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/sp_head.cc@stripped, 2008-02-05 16:44:09-07:00, malff@stripped. +64 -0
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/sp_head.h@stripped, 2008-02-05 16:44:09-07:00, malff@stripped. +8 -0
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/sql_base.cc@stripped, 2008-02-05 16:44:10-07:00, malff@stripped. +154 -36
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/sql_class.cc@stripped, 2008-02-05 16:44:10-07:00, malff@stripped. +257 -10
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/sql_class.h@stripped, 2008-02-05 16:44:10-07:00, malff@stripped. +230 -2
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/sql_insert.cc@stripped, 2008-02-05 16:44:10-07:00, malff@stripped. +4 -1
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/sql_prepare.cc@stripped, 2008-02-05 16:44:10-07:00, malff@stripped. +1044 -98
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/sql_table.cc@stripped, 2008-02-05 16:44:10-07:00, malff@stripped. +4 -1
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/sql_view.cc@stripped, 2008-02-05 16:44:10-07:00, malff@stripped. +77 -2
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/sql_view.h@stripped, 2008-02-05 16:44:11-07:00, malff@stripped. +2 -0
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/table.cc@stripped, 2008-02-05 16:44:11-07:00, malff@stripped. +57 -0
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  sql/table.h@stripped, 2008-02-05 16:44:11-07:00, malff@stripped. +8 -0
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

  tests/mysql_client_test.c@stripped, 2008-02-05 16:44:11-07:00, malff@stripped. +4 -5
    NOT READY FOR REVIEW, NOT READY FOR PRODUCTION

diff -Nrup a/mysql-test/r/ps_1general.result b/mysql-test/r/ps_1general.result
--- a/mysql-test/r/ps_1general.result	2007-09-20 02:56:25 -06:00
+++ b/mysql-test/r/ps_1general.result	2008-02-05 16:44:08 -07:00
@@ -143,8 +143,7 @@ b char(30)
 );
 insert into t5( a, b, c) values( 9, 'recreated table', 9);
 execute stmt2 ;
-a	b	c
-9	recreated table	9
+ERROR HY000: Prepared statement result set has changed, rebind needed
 drop table t5 ;
 create table t5
 (
@@ -155,8 +154,7 @@ d timestamp default current_timestamp
 );
 insert into t5( a, b, c) values( 9, 'recreated table', 9);
 execute stmt2 ;
-a	b	c
-9	recreated table	9
+ERROR HY000: Prepared statement result set has changed, rebind needed
 drop table t5 ;
 create table t5
 (
@@ -167,8 +165,7 @@ c int
 );
 insert into t5( a, b, c) values( 9, 'recreated table', 9);
 execute stmt2 ;
-a	b	c
-9	recreated table	9
+ERROR HY000: Prepared statement result set has changed, rebind needed
 drop table t5 ;
 create table t5
 (
@@ -178,8 +175,7 @@ c int
 );
 insert into t5( b, c) values( 'recreated table', 9);
 execute stmt2 ;
-a	b	c
-2004-02-29 18:01:59	recreated table	9
+ERROR HY000: Prepared statement result set has changed, rebind needed
 drop table t5 ;
 create table t5
 (
@@ -189,7 +185,7 @@ f3 int
 );
 insert into t5( f1, f2, f3) values( 9, 'recreated table', 9);
 execute stmt2 ;
-ERROR 42S22: Unknown column 'test.t5.a' in 'field list'
+ERROR HY000: Prepared statement result set has changed, rebind needed
 drop table t5 ;
 prepare stmt1 from ' select * from t1 where a <= 2 ' ;
 execute stmt1 ;
diff -Nrup a/mysql-test/r/ps_ddl.result b/mysql-test/r/ps_ddl.result
--- a/mysql-test/r/ps_ddl.result	2007-12-14 17:46:22 -07:00
+++ b/mysql-test/r/ps_ddl.result	2008-02-05 16:44:08 -07:00
@@ -1,10 +1,11 @@
+SELECT VARIABLE_VALUE from
+INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
+into @base_count ;
+set @expected = 0;
 =====================================================================
 Testing 1: NOTHING -> TABLE transitions
 =====================================================================
 drop table if exists t1;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 prepare stmt from 'select * from t1';
 ERROR 42S02: Table 'test.t1' doesn't exist
 =====================================================================
@@ -17,92 +18,144 @@ Testing 3: NOTHING -> VIEW transitions
 Testing 4: TABLE -> NOTHING transitions
 =====================================================================
 drop table if exists t4;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t4(a int);
 prepare stmt from 'select * from t4';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t4;
 execute stmt;
 ERROR 42S02: Table 'test.t4' doesn't exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 ERROR 42S02: Table 'test.t4' doesn't exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 =====================================================================
 Testing 5: TABLE -> TABLE (DDL) transitions
 =====================================================================
 drop table if exists t5;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t5(a int);
-prepare stmt from 'select * from t5';
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+prepare stmt from 'select a from t5';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t5 add column (b int);
+set @expected = @expected + 1;
 execute stmt;
-a	b
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
-execute stmt;
-a	b
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t5;
 =====================================================================
 Testing 6: TABLE -> TABLE (TRIGGER) transitions
 =====================================================================
 drop table if exists t6;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t6(a int);
 prepare stmt from 'insert into t6(a) value (?)';
 set @val=1;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=2;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 create trigger t6_bi before insert on t6 for each row
 begin
 set @message= "t6_bi";
@@ -110,20 +163,33 @@ end
 $$
 set @message="none";
 set @val=3;
+set @expected = @expected + 1;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi
 set @val=4;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi
@@ -131,20 +197,32 @@ prepare stmt from 'insert into t6(a) val
 set @message="none";
 set @val=5;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi
 set @message="none";
 set @val=6;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi
@@ -155,21 +233,34 @@ end
 $$
 set @message="none";
 set @val=7;
+set @expected = @expected + 1;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi
 set @message="none";
 set @val=8;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi
@@ -177,20 +268,32 @@ prepare stmt from 'insert into t6(a) val
 set @message="none";
 set @val=9;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi
 set @message="none";
 set @val=10;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi
@@ -202,20 +305,33 @@ end
 $$
 set @message="none";
 set @val=11;
+set @expected = @expected + 1;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi (2)
 set @val=12;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi (2)
@@ -223,20 +339,32 @@ prepare stmt from 'insert into t6(a) val
 set @message="none";
 set @val=13;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi (2)
 set @message="none";
 set @val=14;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi (2)
@@ -248,21 +376,34 @@ end
 $$
 set @message="none";
 set @val=15;
+set @expected = @expected + 1;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi (2)
 set @message="none";
 set @val=16;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi (2)
@@ -270,40 +411,65 @@ prepare stmt from 'insert into t6(a) val
 set @message="none";
 set @val=17;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi (2)
 set @message="none";
 set @val=18;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 t6_bi (2)
 drop trigger t6_bi;
 set @message="none";
 set @val=19;
+set @expected = @expected + 1;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 none
 set @val=20;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 none
@@ -311,38 +477,63 @@ prepare stmt from 'insert into t6(a) val
 set @message="none";
 set @val=21;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 none
 set @val=22;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 none
 drop trigger t6_bd;
 set @val=23;
+set @expected = @expected + 1;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 none
 set @val=24;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select @message;
 @message
 none
@@ -386,9 +577,6 @@ drop table if exists t7_audit;
 drop procedure if exists audit_proc;
 drop function if exists audit_func;
 drop view if exists audit_view;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t7_proc(a int);
 create table t7_func(a int);
 create table t7_view(a int);
@@ -414,155 +602,294 @@ for each row set NEW.reason="trigger v1"
 prepare stmt_proc from 'insert into t7_proc(a) value (?)';
 set @val=101;
 execute stmt_proc using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=102;
 execute stmt_proc using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop procedure audit_proc;
 create procedure audit_proc(a int)
 insert into t7_audit values (NULL, a, "proc v2");
 set @val=103;
+set @expected = @expected + 1;
 execute stmt_proc using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=104;
 execute stmt_proc using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 prepare stmt_func from 'insert into t7_func(a) value (?)';
 set @val=201;
 execute stmt_func using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=202;
 execute stmt_func using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop function audit_func;
 create function audit_func() returns varchar(50)
 return "func v2";
 set @val=203;
+set @expected = @expected + 1;
 execute stmt_func using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=204;
 execute stmt_func using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 prepare stmt_view from 'insert into t7_view(a) value (?)';
 set @val=301;
 execute stmt_view using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=302;
 execute stmt_view using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop view audit_view;
 create view audit_view as select "view v2" as reason from dual;
 set @val=303;
+set @expected = @expected + 1;
 execute stmt_view using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=304;
 execute stmt_view using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 prepare stmt_table from 'insert into t7_table(a) value (?)';
 set @val=401;
 execute stmt_table using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=402;
 execute stmt_table using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t7_dependent_table add column comments varchar(100) default NULL;
 set @val=403;
+set @expected = @expected + 1;
 execute stmt_table using @val;
 ERROR 21S01: Column count doesn't match value count at row 1
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=404;
+set @expected = @expected + 1;
 execute stmt_table using @val;
 ERROR 21S01: Column count doesn't match value count at row 1
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t7_dependent_table drop column comments;
 set @val=405;
+set @expected = @expected + 1;
 execute stmt_table using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-3
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=406;
 execute stmt_table using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-3
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 prepare stmt_table_trigger from 'insert into t7_table(a) value (?)';
 set @val=501;
 execute stmt_table_trigger using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-3
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=502;
 execute stmt_table_trigger using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-3
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop trigger t7_table_trigger_bi;
 create trigger t7_table_trigger_bi before insert on t7_dependent_table
 for each row set NEW.reason="trigger v2";
 set @val=503;
+set @expected = @expected + 1;
 execute stmt_table_trigger using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-4
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=504;
 execute stmt_table_trigger using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-4
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select * from t7_audit order by new_a;
 old_a	new_a	reason
 NULL	101	proc v1
@@ -601,150 +928,237 @@ drop view audit_view;
 Testing 8: TABLE -> TEMPORARY TABLE transitions
 =====================================================================
 drop table if exists t8;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t8(a int);
 prepare stmt from 'select * from t8';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t8;
 create temporary table t8(a int);
+set @expected = @expected + 1;
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t8;
 =====================================================================
 Testing 9: TABLE -> VIEW transitions
 =====================================================================
 drop table if exists t9;
 drop table if exists t9_b;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t9(a int);
 create table t9_b(a int);
 prepare stmt from 'select * from t9';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t9;
 create view t9 as select * from t9_b;
+set @expected = @expected + 1;
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop view t9;
 drop table t9_b;
 =====================================================================
 Testing 10: TEMPORARY TABLE -> NOTHING transitions
 =====================================================================
 drop temporary table if exists t10;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create temporary table t10(a int);
 prepare stmt from 'select * from t10';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop temporary table t10;
 execute stmt;
 ERROR 42S02: Table 'test.t10' doesn't exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 ERROR 42S02: Table 'test.t10' doesn't exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 =====================================================================
 Testing 11: TEMPORARY TABLE -> TABLE transitions
 =====================================================================
 drop table if exists t11;
 drop temporary table if exists t11;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t11(a int);
 insert into t11(a) value (1);
 create temporary table t11(a int);
 prepare stmt from 'select * from t11';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop temporary table t11;
+set @expected = @expected + 1;
 execute stmt;
 a
 1
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 a
 1
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select * from t11;
 a
 1
@@ -753,37 +1167,59 @@ drop table t11;
 Testing 12: TEMPORARY TABLE -> TEMPORARY TABLE (DDL) transitions
 =====================================================================
 drop temporary table if exists t12;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create temporary table t12(a int);
-prepare stmt from 'select * from t12';
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+prepare stmt from 'select a from t12';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop temporary table t12;
 create temporary table t12(a int, b int);
+set @expected = @expected + 1;
 execute stmt;
-a	b
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
-execute stmt;
-a	b
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select * from t12;
 a	b
 drop table t12;
@@ -792,38 +1228,60 @@ Testing 13: TEMPORARY TABLE -> VIEW tran
 =====================================================================
 drop temporary table if exists t13;
 drop table if exists t13_b;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create temporary table t13(a int);
 create table t13_b(a int);
 prepare stmt from 'select * from t13';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop temporary table t13;
 create view t13 as select * from t13_b;
+set @expected = @expected + 1;
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop view t13;
 drop table t13_b;
 =====================================================================
@@ -831,75 +1289,120 @@ Testing 14: VIEW -> NOTHING transitions
 =====================================================================
 drop view if exists t14;
 drop table if exists t14_b;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t14_b(a int);
 create view t14 as select * from t14_b;
 prepare stmt from 'select * from t14';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop view t14;
+set @expected = @expected + 1;
 execute stmt;
 ERROR 42S02: Table 'test.t14' doesn't exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+set @expected = @expected + 1;
 execute stmt;
 ERROR 42S02: Table 'test.t14' doesn't exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t14_b;
 =====================================================================
 Testing 15: VIEW -> TABLE transitions
 =====================================================================
 drop view if exists t15;
 drop table if exists t15_b;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t15_b(a int);
 create view t15 as select * from t15_b;
 prepare stmt from 'select * from t15';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop view t15;
 create table t15(a int);
+set @expected = @expected + 1;
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t15_b;
 drop table t15;
 =====================================================================
@@ -907,38 +1410,60 @@ Testing 16: VIEW -> TEMPORARY TABLE tran
 =====================================================================
 drop view if exists t16;
 drop table if exists t16_b;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t16_b(a int);
 create view t16 as select * from t16_b;
 prepare stmt from 'select * from t16';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop view t16;
 create temporary table t16(a int);
+set @expected = @expected + 1;
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t16_b;
 drop temporary table t16;
 =====================================================================
@@ -946,9 +1471,6 @@ Testing 17: VIEW -> VIEW (DDL) transitio
 =====================================================================
 drop view if exists t17;
 drop table if exists t17_b;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t17_b(a int);
 insert into t17_b values (10), (20), (30);
 create view t17 as select a, 2*a as b, 3*a as c from t17_b;
@@ -963,44 +1485,69 @@ a	b	c
 10	20	30
 20	40	60
 30	60	90
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 a	b	c
 10	20	30
 20	40	60
 30	60	90
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop view t17;
-create view t17 as select a, 2*a as b, 10*a as c from t17_b;
+create view t17 as select a, 2*a as b, 5*a as c from t17_b;
 select * from t17;
 a	b	c
-10	20	100
-20	40	200
-30	60	300
+10	20	50
+20	40	100
+30	60	150
+set @expected = @expected + 1;
 execute stmt;
 a	b	c
-10	20	100
-20	40	200
-30	60	300
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+10	20	50
+20	40	100
+30	60	150
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 a	b	c
-10	20	100
-20	40	200
-30	60	300
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+10	20	50
+20	40	100
+30	60	150
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t17_b;
 drop view t17;
 =====================================================================
@@ -1013,9 +1560,6 @@ drop view if exists t18_view;
 drop view if exists t18_table;
 drop function if exists view_func;
 drop view if exists view_view;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t18(a int);
 insert into t18 values (1), (2), (3);
 create function view_func(x int) returns int
@@ -1031,117 +1575,192 @@ a	b
 1	2
 2	3
 3	4
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt_func;
 a	b
 1	2
 2	3
 3	4
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop function view_func;
 create function view_func(x int) returns int
 return x*x;
+set @expected = @expected + 1;
 execute stmt_func;
 a	b
 1	1
 2	4
 3	9
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt_func;
 a	b
 1	1
 2	4
 3	9
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 prepare stmt_view from 'select * from t18_view';
 execute stmt_view;
 a	b
 1	view v1
 2	view v1
 3	view v1
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt_view;
 a	b
 1	view v1
 2	view v1
 3	view v1
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop view view_view;
 create view view_view as select "view v2" as reason from dual;
+set @expected = @expected + 1;
 execute stmt_view;
 a	b
 1	view v2
 2	view v2
 3	view v2
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt_view;
 a	b
 1	view v2
 2	view v2
 3	view v2
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 prepare stmt_table from 'select * from t18_table';
 execute stmt_table;
 a
 1
 2
 3
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt_table;
 a
 1
 2
 3
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t18 add column comments varchar(50) default NULL;
+set @expected = @expected + 1;
 execute stmt_table;
 a
 1
 2
 3
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt_table;
 a
 1
 2
 3
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t18;
 drop table t18_dependent_table;
 drop view t18_func;
@@ -1153,9 +1772,6 @@ drop view view_view;
 Testing 19: Special tables (INFORMATION_SCHEMA)
 =====================================================================
 drop procedure if exists proc_19;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 prepare stmt from
 'select ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE
  from INFORMATION_SCHEMA.ROUTINES where
@@ -1164,115 +1780,178 @@ create procedure proc_19() select "hi th
 execute stmt;
 ROUTINE_SCHEMA	ROUTINE_NAME	ROUTINE_TYPE
 test	proc_19	PROCEDURE
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 ROUTINE_SCHEMA	ROUTINE_NAME	ROUTINE_TYPE
 test	proc_19	PROCEDURE
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop procedure proc_19;
 create procedure proc_19() select "hi there, again";
 execute stmt;
 ROUTINE_SCHEMA	ROUTINE_NAME	ROUTINE_TYPE
 test	proc_19	PROCEDURE
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 ROUTINE_SCHEMA	ROUTINE_NAME	ROUTINE_TYPE
 test	proc_19	PROCEDURE
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop procedure proc_19;
 =====================================================================
 Testing 20: Special tables (log tables)
 =====================================================================
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 prepare stmt from
 'select * from mysql.general_log where argument=\'IMPOSSIBLE QUERY STRING\'';
 execute stmt;
 event_time	user_host	thread_id	server_id	command_type	argument
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 event_time	user_host	thread_id	server_id	command_type	argument
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 event_time	user_host	thread_id	server_id	command_type	argument
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 event_time	user_host	thread_id	server_id	command_type	argument
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 =====================================================================
 Testing 21: Special tables (system tables)
 =====================================================================
 drop procedure if exists proc_21;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 prepare stmt from
 'select type, db, name from mysql.proc where name=\'proc_21\'';
 create procedure proc_21() select "hi there";
 execute stmt;
 type	db	name
 PROCEDURE	test	proc_21
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 type	db	name
 PROCEDURE	test	proc_21
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop procedure proc_21;
 create procedure proc_21() select "hi there, again";
 execute stmt;
 type	db	name
 PROCEDURE	test	proc_21
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 type	db	name
 PROCEDURE	test	proc_21
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop procedure proc_21;
 =====================================================================
 Testing 22: Special tables (views temp tables)
 =====================================================================
 drop table if exists t22_b;
 drop view if exists t22;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t22_b(a int);
 create algorithm=temptable view t22 as select a*a as a2 from t22_b;
 show create view t22;
@@ -1285,19 +1964,31 @@ a2
 1
 4
 9
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 a2
 1
 4
 9
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 insert into t22_b values (4), (5), (6);
 execute stmt;
 a2
@@ -1307,10 +1998,16 @@ a2
 16
 25
 36
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 a2
 1
@@ -1319,10 +2016,16 @@ a2
 16
 25
 36
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t22_b;
 drop view t22;
 =====================================================================
@@ -1330,9 +2033,6 @@ Testing 23: Special tables (internal joi
 =====================================================================
 drop table if exists t23_a;
 drop table if exists t23_b;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t23_a(a int);
 create table t23_b(b int);
 prepare stmt from 'select * from t23_a join t23_b';
@@ -1349,10 +2049,16 @@ a	b
 1	30
 2	30
 3	30
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 a	b
 1	10
@@ -1364,10 +2070,16 @@ a	b
 1	30
 2	30
 3	30
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 insert into t23_a values (4);
 insert into t23_b values (40);
 execute stmt;
@@ -1388,10 +2100,16 @@ a	b
 2	40
 3	40
 4	40
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 a	b
 1	10
@@ -1410,45 +2128,72 @@ a	b
 2	40
 3	40
 4	40
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t23_a;
 drop table t23_b;
 =====================================================================
 Testing 24: Special statements
 =====================================================================
 drop table if exists t24_alter;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t24_alter(a int);
 prepare stmt from 'alter table t24_alter add column b int';
 execute stmt;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t24_alter;
 create table t24_alter(a1 int, a2 int);
 execute stmt;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t24_alter drop column b;
 execute stmt;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t24_alter drop column b;
 execute stmt;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t24_alter;
 drop table if exists t24_repair;
 create table t24_repair(a int);
@@ -1457,36 +2202,60 @@ prepare stmt from 'repair table t24_repa
 execute stmt;
 Table	Op	Msg_type	Msg_text
 test.t24_repair	repair	status	OK
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t24_repair;
 create table t24_repair(a1 int, a2 int);
 insert into t24_repair values (1, 10), (2, 20), (3, 30);
 execute stmt;
 Table	Op	Msg_type	Msg_text
 test.t24_repair	repair	status	OK
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t24_repair add column b varchar(50) default NULL;
 execute stmt;
 Table	Op	Msg_type	Msg_text
 test.t24_repair	repair	status	OK
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t24_repair drop column b;
 execute stmt;
 Table	Op	Msg_type	Msg_text
 test.t24_repair	repair	status	OK
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t24_repair;
 drop table if exists t24_analyze;
 create table t24_analyze(a int);
@@ -1495,36 +2264,60 @@ prepare stmt from 'analyze table t24_ana
 execute stmt;
 Table	Op	Msg_type	Msg_text
 test.t24_analyze	analyze	status	OK
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t24_analyze;
 create table t24_analyze(a1 int, a2 int);
 insert into t24_analyze values (1, 10), (2, 20), (3, 30);
 execute stmt;
 Table	Op	Msg_type	Msg_text
 test.t24_analyze	analyze	status	OK
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t24_analyze add column b varchar(50) default NULL;
 execute stmt;
 Table	Op	Msg_type	Msg_text
 test.t24_analyze	analyze	status	OK
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t24_analyze drop column b;
 execute stmt;
 Table	Op	Msg_type	Msg_text
 test.t24_analyze	analyze	status	OK
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t24_analyze;
 drop table if exists t24_optimize;
 create table t24_optimize(a int);
@@ -1533,176 +2326,308 @@ prepare stmt from 'optimize table t24_op
 execute stmt;
 Table	Op	Msg_type	Msg_text
 test.t24_optimize	optimize	status	OK
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t24_optimize;
 create table t24_optimize(a1 int, a2 int);
 insert into t24_optimize values (1, 10), (2, 20), (3, 30);
 execute stmt;
 Table	Op	Msg_type	Msg_text
 test.t24_optimize	optimize	status	OK
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t24_optimize add column b varchar(50) default NULL;
 execute stmt;
 Table	Op	Msg_type	Msg_text
 test.t24_optimize	optimize	status	OK
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t24_optimize drop column b;
 execute stmt;
 Table	Op	Msg_type	Msg_text
 test.t24_optimize	optimize	status	OK
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t24_optimize;
 drop procedure if exists changing_proc;
 prepare stmt from 'show create procedure changing_proc';
 execute stmt;
 ERROR 42000: PROCEDURE changing_proc does not exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 ERROR 42000: PROCEDURE changing_proc does not exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 create procedure changing_proc() begin end;
 execute stmt;
 Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
 changing_proc		CREATE DEFINER=`root`@`localhost` PROCEDURE `changing_proc`()
 begin end	latin1	latin1_swedish_ci	latin1_swedish_ci
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
 changing_proc		CREATE DEFINER=`root`@`localhost` PROCEDURE `changing_proc`()
 begin end	latin1	latin1_swedish_ci	latin1_swedish_ci
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop procedure changing_proc;
 create procedure changing_proc(x int, y int) begin end;
 execute stmt;
 Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
 changing_proc		CREATE DEFINER=`root`@`localhost` PROCEDURE `changing_proc`(x int, y int)
 begin end	latin1	latin1_swedish_ci	latin1_swedish_ci
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 Procedure	sql_mode	Create Procedure	character_set_client	collation_connection	Database Collation
 changing_proc		CREATE DEFINER=`root`@`localhost` PROCEDURE `changing_proc`(x int, y int)
 begin end	latin1	latin1_swedish_ci	latin1_swedish_ci
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop procedure changing_proc;
 execute stmt;
 ERROR 42000: PROCEDURE changing_proc does not exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 ERROR 42000: PROCEDURE changing_proc does not exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop function if exists changing_func;
 prepare stmt from 'show create function changing_func';
 execute stmt;
 ERROR 42000: FUNCTION changing_func does not exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 ERROR 42000: FUNCTION changing_func does not exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 create function changing_func() returns int return 0;
 execute stmt;
 Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
 changing_func		CREATE DEFINER=`root`@`localhost` FUNCTION `changing_func`() RETURNS int(11)
 return 0	latin1	latin1_swedish_ci	latin1_swedish_ci
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
 changing_func		CREATE DEFINER=`root`@`localhost` FUNCTION `changing_func`() RETURNS int(11)
 return 0	latin1	latin1_swedish_ci	latin1_swedish_ci
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop function changing_func;
 create function changing_func(x int, y int) returns int return x+y;
 execute stmt;
 Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
 changing_func		CREATE DEFINER=`root`@`localhost` FUNCTION `changing_func`(x int, y int) RETURNS int(11)
 return x+y	latin1	latin1_swedish_ci	latin1_swedish_ci
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 Function	sql_mode	Create Function	character_set_client	collation_connection	Database Collation
 changing_func		CREATE DEFINER=`root`@`localhost` FUNCTION `changing_func`(x int, y int) RETURNS int(11)
 return x+y	latin1	latin1_swedish_ci	latin1_swedish_ci
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop function changing_func;
 execute stmt;
 ERROR 42000: FUNCTION changing_func does not exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 ERROR 42000: FUNCTION changing_func does not exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table if exists t24_trigger;
 create table t24_trigger(a int);
 prepare stmt from 'show create trigger t24_bi;';
 execute stmt;
 ERROR HY000: Trigger does not exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 ERROR HY000: Trigger does not exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 create trigger t24_bi before insert on t24_trigger for each row
 begin
 set @message= "t24_bi";
@@ -1714,239 +2639,427 @@ t24_bi		CREATE DEFINER=`root`@`localhost
 begin
 set @message= "t24_bi";
 end	latin1	latin1_swedish_ci	latin1_swedish_ci
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 Trigger	sql_mode	SQL Original Statement	character_set_client	collation_connection	Database Collation
 t24_bi		CREATE DEFINER=`root`@`localhost` trigger t24_bi before insert on t24_trigger for each row
 begin
 set @message= "t24_bi";
 end	latin1	latin1_swedish_ci	latin1_swedish_ci
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop trigger t24_bi;
 create trigger t24_bi before insert on t24_trigger for each row
 begin
 set @message= "t24_bi (2)";
 end
 $$
+set @expected = @expected + 1;
 execute stmt;
 Trigger	sql_mode	SQL Original Statement	character_set_client	collation_connection	Database Collation
 t24_bi		CREATE DEFINER=`root`@`localhost` trigger t24_bi before insert on t24_trigger for each row
 begin
 set @message= "t24_bi (2)";
 end	latin1	latin1_swedish_ci	latin1_swedish_ci
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 Trigger	sql_mode	SQL Original Statement	character_set_client	collation_connection	Database Collation
 t24_bi		CREATE DEFINER=`root`@`localhost` trigger t24_bi before insert on t24_trigger for each row
 begin
 set @message= "t24_bi (2)";
 end	latin1	latin1_swedish_ci	latin1_swedish_ci
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop trigger t24_bi;
 execute stmt;
 ERROR HY000: Trigger does not exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 ERROR HY000: Trigger does not exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t24_trigger;
 =====================================================================
 Testing 25: Testing the strength of TABLE_SHARE version
 =====================================================================
 drop table if exists t25_num_col;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t25_num_col(a int);
-prepare stmt from 'select * from t25_num_col';
+prepare stmt from 'select a from t25_num_col';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t25_num_col add column b varchar(50) default NULL;
+set @expected = @expected + 1;
 execute stmt;
-a	b
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
-execute stmt;
-a	b
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t25_num_col;
 drop table if exists t25_col_name;
 create table t25_col_name(a int);
 prepare stmt from 'select * from t25_col_name';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t25_col_name change a b int;
+set @expected = @expected + 1;
 execute stmt;
-b
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
-execute stmt;
-b
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+ERROR HY000: Prepared statement result set has changed, rebind needed
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+set @expected = @expected + 1;
+execute stmt;
+ERROR HY000: Prepared statement result set has changed, rebind needed
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t25_col_name;
 drop table if exists t25_col_type;
 create table t25_col_type(a int);
 prepare stmt from 'select * from t25_col_type';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t25_col_type change a a varchar(10);
+set @expected = @expected + 1;
 execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-3
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-3
+ERROR HY000: Prepared statement result set has changed, rebind needed
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+set @expected = @expected + 1;
+execute stmt;
+ERROR HY000: Prepared statement result set has changed, rebind needed
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t25_col_type;
 drop table if exists t25_col_type_length;
 create table t25_col_type_length(a varchar(10));
 prepare stmt from 'select * from t25_col_type_length';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-3
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-3
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t25_col_type_length change a a varchar(20);
+set @expected = @expected + 1;
 execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-4
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-4
+ERROR HY000: Prepared statement result set has changed, rebind needed
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+set @expected = @expected + 1;
+execute stmt;
+ERROR HY000: Prepared statement result set has changed, rebind needed
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t25_col_type_length;
 drop table if exists t25_col_null;
 create table t25_col_null(a varchar(10));
 prepare stmt from 'select * from t25_col_null';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-4
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-4
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t25_col_null change a a varchar(10) NOT NULL;
+set @expected = @expected + 1;
 execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-5
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-5
+ERROR HY000: Prepared statement result set has changed, rebind needed
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+set @expected = @expected + 1;
+execute stmt;
+ERROR HY000: Prepared statement result set has changed, rebind needed
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t25_col_null;
 drop table if exists t25_col_default;
 create table t25_col_default(a int, b int DEFAULT 10);
 prepare stmt from 'insert into t25_col_default(a) values (?)';
 set @val=1;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-5
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=2;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-5
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t25_col_default change b b int DEFAULT 20;
 set @val=3;
+set @expected = @expected + 1;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-5
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 set @val=4;
 execute stmt using @val;
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-5
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 select * from t25_col_default;
 a	b
 1	10
@@ -1959,29 +3072,54 @@ create table t25_index(a varchar(10));
 prepare stmt from 'select * from t25_index';
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-5
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-5
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 create index i1 on t25_index(a);
+set @expected = @expected + 1;
 execute stmt;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-6
-execute stmt;
-a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-6
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t25_index;
 drop table if exists t25_index_unique;
 create table t25_index_unique(a varchar(10), b varchar(10));
@@ -1996,16 +3134,28 @@ t25_index_unique	CREATE TABLE `t25_index
 prepare stmt from 'select * from t25_index_unique';
 execute stmt;
 a	b
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-6
-execute stmt;
-a	b
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-6
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a	b
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 alter table t25_index_unique drop index i1;
 create unique index i1 on t25_index_unique(a, b);
 show create table t25_index_unique;
@@ -2015,18 +3165,31 @@ t25_index_unique	CREATE TABLE `t25_index
   `b` varchar(10) DEFAULT NULL,
   UNIQUE KEY `i1` (`a`,`b`)
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
+set @expected = @expected + 1;
 execute stmt;
 a	b
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-7
-execute stmt;
-a	b
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-7
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+execute stmt;
+a	b
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t25_index_unique;
 =====================================================================
 Testing reported bugs
@@ -2035,9 +3198,6 @@ drop table if exists table_12093;
 drop function if exists func_12093;
 drop function if exists func_12093_unrelated;
 drop procedure if exists proc_12093;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table table_12093(a int);
 create function func_12093()
 returns int
@@ -2055,88 +3215,137 @@ prepare stmt_sp from 'call proc_12093(fu
 execute stmt_sf;
 func_12093()
 0
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt_sp;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop function func_12093_unrelated;
 drop procedure proc_12093_unrelated;
 execute stmt_sf;
 func_12093()
 0
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt_sp;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt_sf;
 func_12093()
 0
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt_sp;
 a
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 deallocate prepare stmt_sf;
 deallocate prepare stmt_sp;
 drop table table_12093;
 drop function func_12093;
 drop procedure proc_12093;
 drop function if exists func_21294;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create function func_21294() returns int return 10;
 prepare stmt from "select func_21294()";
 execute stmt;
 func_21294()
 10
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop function func_21294;
 create function func_21294() returns int return 10;
 execute stmt;
 func_21294()
 10
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop function func_21294;
 create function func_21294() returns int return 20;
+set @expected = @expected + 1;
 execute stmt;
 func_21294()
 20
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 deallocate prepare stmt;
 drop function func_21294;
 drop table if exists t_27420_100;
 drop table if exists t_27420_101;
 drop view if exists v_27420;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t_27420_100(a int);
 insert into t_27420_100 values (1), (2);
 create table t_27420_101(a int);
@@ -2149,35 +3358,52 @@ execute stmt;
 X	Y
 1	1
 2	2
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop view v_27420;
 create table v_27420(X int, Y int);
+set @expected = @expected + 1;
 execute stmt;
 X	Y
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table v_27420;
 create table v_27420 (a int, b int, filler char(200));
+set @expected = @expected + 1;
 execute stmt;
-a	b	filler
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-2
+ERROR HY000: Prepared statement result set has changed, rebind needed
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 deallocate prepare stmt;
 drop table t_27420_100;
 drop table t_27420_101;
 drop table v_27420;
 drop table if exists t_27430_1;
 drop table if exists t_27430_2;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t_27430_1 (a int not null, oref int not null, key(a));
 insert into t_27430_1 values
 (1, 1),
@@ -2199,20 +3425,32 @@ oref	a	Z
 2	2	0
 3	1234	0
 4	1234	0
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 oref	a	Z
 1	1	1
 2	2	0
 3	1234	0
 4	1234	0
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table t_27430_1, t_27430_2;
 create table t_27430_1 (a int, oref int, key(a));
 insert into t_27430_1 values 
@@ -2227,35 +3465,38 @@ insert into t_27430_2 values
 (2,2),
 (NULL, 3),
 (NULL, 4);
+set @expected = @expected + 1;
 execute stmt;
-oref	a	Z
-1	1	1
-2	2	0
-3	NULL	NULL
-4	NULL	0
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
-execute stmt;
-oref	a	Z
-1	1	1
-2	2	0
-3	NULL	NULL
-4	NULL	0
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+ERROR HY000: Prepared statement result set has changed, rebind needed
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
+set @expected = @expected + 1;
+execute stmt;
+ERROR HY000: Prepared statement result set has changed, rebind needed
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 deallocate prepare stmt;
 drop table t_27430_1;
 drop table t_27430_2;
 drop table if exists t_27690_1;
 drop view if exists v_27690_1;
 drop table if exists v_27690_2;
-SELECT VARIABLE_VALUE from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
-into @base_count ;
 create table t_27690_1 (a int, b int);
 insert into t_27690_1 values (1,1),(2,2);
 create table v_27690_1 as select * from t_27690_1;
@@ -2267,34 +3508,59 @@ a	b	a	b
 2	2	1	1
 1	1	2	2
 2	2	2	2
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 a	b	a	b
 1	1	1	1
 2	2	1	1
 1	1	2	2
 2	2	2	2
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 drop table v_27690_1;
 execute stmt;
 ERROR 42S02: Table 'test.v_27690_1' doesn't exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 ERROR 42S02: Table 'test.v_27690_1' doesn't exist
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-0
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 create view v_27690_1 as select A.a, A.b from t_27690_1 A, t_27690_1 B;
+set @expected = @expected + 1;
 execute stmt;
 a	b	a	b
 1	1	1	1
@@ -2305,10 +3571,16 @@ a	b	a	b
 2	2	2	2
 1	1	2	2
 2	2	2	2
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 execute stmt;
 a	b	a	b
 1	1	1	1
@@ -2319,10 +3591,16 @@ a	b	a	b
 2	2	2	2
 1	1	2	2
 2	2	2	2
-SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
-REPREPARED
-1
+SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+AS `CHECK`, 
+(VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+where variable_name='COM_STMT_REPREPARE' ;
+CHECK	OFFSET
+PASSED	0
 deallocate prepare stmt;
 drop table t_27690_1;
 drop view v_27690_1;
diff -Nrup a/mysql-test/r/query_cache_ps_no_prot.result b/mysql-test/r/query_cache_ps_no_prot.result
--- a/mysql-test/r/query_cache_ps_no_prot.result	2007-08-31 10:42:12 -06:00
+++ b/mysql-test/r/query_cache_ps_no_prot.result	2008-02-05 16:44:08 -07:00
@@ -312,63 +312,63 @@ c1
 10
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	21
+Qcache_hits	22
 execute stmt1;
 c1
 10
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	21
+Qcache_hits	23
 ---- switch to connection con1 ----
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	21
+Qcache_hits	23
 execute stmt3;
 c1
 10
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	21
+Qcache_hits	24
 execute stmt3;
 c1
 10
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	21
+Qcache_hits	25
 execute stmt3;
 c1
 10
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	21
+Qcache_hits	26
 ---- switch to connection default ----
 set global query_cache_size=0;
 prepare stmt1 from "select * from t1 where c1=?";
 set global query_cache_size=100000;
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	21
+Qcache_hits	26
 set @a=1;
 execute stmt1 using @a;
 c1
 1
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	21
+Qcache_hits	26
 set @a=100;
 execute stmt1 using @a;
 c1
 100
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	21
+Qcache_hits	26
 set @a=10;
 execute stmt1 using @a;
 c1
 10
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	21
+Qcache_hits	26
 drop table t1;
 ---- disconnect connection con1 ----
 ########################################################################
diff -Nrup a/mysql-test/r/query_cache_ps_ps_prot.result b/mysql-test/r/query_cache_ps_ps_prot.result
--- a/mysql-test/r/query_cache_ps_ps_prot.result	2007-08-31 10:42:12 -06:00
+++ b/mysql-test/r/query_cache_ps_ps_prot.result	2008-02-05 16:44:08 -07:00
@@ -312,63 +312,63 @@ c1
 10
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	19
+Qcache_hits	20
 execute stmt1;
 c1
 10
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	19
+Qcache_hits	21
 ---- switch to connection con1 ----
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	19
+Qcache_hits	21
 execute stmt3;
 c1
 10
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	19
+Qcache_hits	22
 execute stmt3;
 c1
 10
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	19
+Qcache_hits	23
 execute stmt3;
 c1
 10
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	19
+Qcache_hits	24
 ---- switch to connection default ----
 set global query_cache_size=0;
 prepare stmt1 from "select * from t1 where c1=?";
 set global query_cache_size=100000;
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	19
+Qcache_hits	24
 set @a=1;
 execute stmt1 using @a;
 c1
 1
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	19
+Qcache_hits	24
 set @a=100;
 execute stmt1 using @a;
 c1
 100
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	19
+Qcache_hits	24
 set @a=10;
 execute stmt1 using @a;
 c1
 10
 show status like 'Qcache_hits';
 Variable_name	Value
-Qcache_hits	19
+Qcache_hits	24
 drop table t1;
 ---- disconnect connection con1 ----
 ########################################################################
diff -Nrup a/mysql-test/r/sp-error.result b/mysql-test/r/sp-error.result
--- a/mysql-test/r/sp-error.result	2008-01-23 16:21:04 -07:00
+++ b/mysql-test/r/sp-error.result	2008-02-05 16:44:08 -07:00
@@ -796,7 +796,7 @@ bug11834_2()
 10
 drop function bug11834_1;
 execute stmt;
-ERROR 42000: FUNCTION test.bug11834_2 does not exist
+ERROR 42000: FUNCTION test.bug11834_1 does not exist
 deallocate prepare stmt;
 drop function bug11834_2;
 DROP FUNCTION IF EXISTS bug12953|
@@ -1045,7 +1045,8 @@ select bug12329();
 bug12329()
 101
 execute stmt1;
-ERROR 42S02: Table 'test.t2' doesn't exist
+bug12329()
+101
 deallocate prepare stmt1;
 drop function bug12329;
 drop table t1, t2;
diff -Nrup a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result
--- a/mysql-test/r/trigger.result	2007-11-29 04:42:23 -07:00
+++ b/mysql-test/r/trigger.result	2008-02-05 16:44:08 -07:00
@@ -820,7 +820,6 @@ call p1();
 drop trigger t1_bi;
 create trigger t1_bi after insert on t1 for each row insert into t3 values (new.id);
 execute stmt1;
-ERROR 42S02: Table 'test.t3' doesn't exist
 call p1();
 ERROR 42S02: Table 'test.t3' doesn't exist
 deallocate prepare stmt1;
diff -Nrup a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def
--- a/mysql-test/t/disabled.def	2008-01-24 07:40:13 -07:00
+++ b/mysql-test/t/disabled.def	2008-02-05 16:44:09 -07:00
@@ -22,4 +22,4 @@ innodb_mysql         : Bug#32724: innodb
 wait_timeout         : Bug#32801 wait_timeout.test fails randomly
 ctype_create         : Bug#32965 main.ctype_create fails
 status               : Bug#32966 main.status fails
-ps_ddl               : Bug#12093 2007-12-14 pending WL#4165 / WL#4166
+## ps_ddl               : Bug#12093 2007-12-14 pending WL#4165 / WL#4166
diff -Nrup a/mysql-test/t/ps_1general.test b/mysql-test/t/ps_1general.test
--- a/mysql-test/t/ps_1general.test	2007-08-15 02:18:40 -06:00
+++ b/mysql-test/t/ps_1general.test	2008-02-05 16:44:09 -07:00
@@ -172,6 +172,7 @@ create table t5
   b char(30)
 );
 insert into t5( a, b, c) values( 9, 'recreated table', 9);
+--error ER_PS_REBIND
 execute stmt2 ;
 drop table t5 ;
 # 3. drop + create table (same column names/types/order+extra column) 
@@ -184,6 +185,7 @@ create table t5
   d timestamp default current_timestamp
 );
 insert into t5( a, b, c) values( 9, 'recreated table', 9);
+--error ER_PS_REBIND
 execute stmt2 ;
 drop table t5 ;
 # 4. drop + create table (same column names/types, different order +
@@ -196,6 +198,7 @@ create table t5
   c int
 );
 insert into t5( a, b, c) values( 9, 'recreated table', 9);
+--error ER_PS_REBIND
 execute stmt2 ;
 drop table t5 ;
 # 5. drop + create table (same column names/order, different types)
@@ -207,6 +210,7 @@ create table t5
   c int
 );
 insert into t5( b, c) values( 'recreated table', 9);
+--error ER_PS_REBIND
 execute stmt2 ;
 drop table t5 ;
 # 6. drop + create table (same column types/order, different names) 
@@ -218,7 +222,7 @@ create table t5
   f3 int
 );
 insert into t5( f1, f2, f3) values( 9, 'recreated table', 9);
---error 1054
+--error ER_PS_REBIND
 execute stmt2 ;
 drop table t5 ;
 
diff -Nrup a/mysql-test/t/ps_ddl.test b/mysql-test/t/ps_ddl.test
--- a/mysql-test/t/ps_ddl.test	2007-12-14 17:46:22 -07:00
+++ b/mysql-test/t/ps_ddl.test	2008-02-05 16:44:09 -07:00
@@ -55,8 +55,28 @@ let $base_count = SELECT VARIABLE_VALUE 
 INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
 into @base_count ;
 
-let $reprepared = SELECT VARIABLE_VALUE - @base_count AS REPREPARED from
-INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE' ;
+let $check = SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
+  WHEN 0 THEN "PASSED"
+  ELSE "FAILED"
+  END
+ AS `CHECK`, 
+ (VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
+ from INFORMATION_SCHEMA.SESSION_STATUS
+ where variable_name='COM_STMT_REPREPARE' ;
+
+eval $base_count;
+set @expected = 0;
+
+# Maintainer:
+# When not expecting a re-prepare, write the test like this:
+#   execute stmt;
+#   eval $check;
+#
+# When expecting a re-prepare, write the test like this:
+#   set @expected = @expected + 1;
+#   execute stmt;
+#   eval $check;
+#
 
 --echo =====================================================================
 --echo Testing 1: NOTHING -> TABLE transitions
@@ -66,8 +86,6 @@ INFORMATION_SCHEMA.SESSION_STATUS where 
 drop table if exists t1;
 --enable_warnings
 
-eval $base_count;
-
 # can not be tested since prepare failed
 --error ER_NO_SUCH_TABLE
 prepare stmt from 'select * from t1';
@@ -92,23 +110,21 @@ prepare stmt from 'select * from t1';
 drop table if exists t4;
 --enable_warnings
 
-eval $base_count;
-
 create table t4(a int);
 
 prepare stmt from 'select * from t4';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t4;
 --error ER_NO_SUCH_TABLE
 execute stmt;
-eval $reprepared;
+eval $check;
 --error ER_NO_SUCH_TABLE
 execute stmt;
-eval $reprepared;
+eval $check;
 
 --echo =====================================================================
 --echo Testing 5: TABLE -> TABLE (DDL) transitions
@@ -118,23 +134,21 @@ eval $reprepared;
 drop table if exists t5;
 --enable_warnings
 
-eval $base_count;
-
 create table t5(a int);
 
-prepare stmt from 'select * from t5';
+prepare stmt from 'select a from t5';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t5 add column (b int);
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t5;
 
@@ -155,17 +169,15 @@ drop table t5;
 drop table if exists t6;
 --enable_warnings
 
-eval $base_count;
-
 create table t6(a int);
 
 prepare stmt from 'insert into t6(a) value (?)';
 set @val=1;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 set @val=2;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 
 # Relevant trigger: execute should reprepare
 delimiter $$;
@@ -178,25 +190,25 @@ delimiter ;$$
 
 set @message="none";
 set @val=3;
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 set @val=4;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 
 prepare stmt from 'insert into t6(a) value (?)';
 set @message="none";
 set @val=5;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 set @message="none";
 set @val=6;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 
 # Unrelated trigger: execute can pass of fail, implementation dependent
@@ -210,25 +222,26 @@ delimiter ;$$
 
 set @message="none";
 set @val=7;
+set @expected = @expected + 1;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 set @message="none";
 set @val=8;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 
 prepare stmt from 'insert into t6(a) value (?)';
 set @message="none";
 set @val=9;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 set @message="none";
 set @val=10;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 
 # Relevant trigger: execute should reprepare
@@ -243,25 +256,25 @@ delimiter ;$$
 
 set @message="none";
 set @val=11;
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 set @val=12;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 
 prepare stmt from 'insert into t6(a) value (?)';
 set @message="none";
 set @val=13;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 set @message="none";
 set @val=14;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 
 # Unrelated trigger: execute can pass of fail, implementation dependent
@@ -276,63 +289,62 @@ delimiter ;$$
 
 set @message="none";
 set @val=15;
+set @expected = @expected + 1;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 set @message="none";
 set @val=16;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 
 prepare stmt from 'insert into t6(a) value (?)';
 set @message="none";
 set @val=17;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 set @message="none";
 set @val=18;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 
 drop trigger t6_bi;
 
 set @message="none";
 set @val=19;
-# safe to re-execute
+set @expected = @expected + 1;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 set @val=20;
-# safe to re-execute
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 
 prepare stmt from 'insert into t6(a) value (?)';
 set @message="none";
 set @val=21;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 set @val=22;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 
 drop trigger t6_bd;
 
 set @val=23;
-# safe to re-execute
+set @expected = @expected + 1;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 set @val=24;
-# safe to re-execute
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 select @message;
 
 select * from t6 order by a;
@@ -363,8 +375,6 @@ drop function if exists audit_func;
 drop view if exists audit_view;
 --enable_warnings
 
-eval $base_count;
-
 create table t7_proc(a int);
 create table t7_func(a int);
 create table t7_view(a int);
@@ -400,10 +410,10 @@ create trigger t7_table_trigger_bi befor
 prepare stmt_proc from 'insert into t7_proc(a) value (?)';
 set @val=101;
 execute stmt_proc using @val;
-eval $reprepared;
+eval $check;
 set @val=102;
 execute stmt_proc using @val;
-eval $reprepared;
+eval $check;
 
 drop procedure audit_proc;
 
@@ -411,20 +421,21 @@ create procedure audit_proc(a int)
   insert into t7_audit values (NULL, a, "proc v2");
 
 set @val=103;
+set @expected = @expected + 1;
 execute stmt_proc using @val;
-eval $reprepared;
+eval $check;
 set @val=104;
 execute stmt_proc using @val;
-eval $reprepared;
+eval $check;
 
 
 prepare stmt_func from 'insert into t7_func(a) value (?)';
 set @val=201;
 execute stmt_func using @val;
-eval $reprepared;
+eval $check;
 set @val=202;
 execute stmt_func using @val;
-eval $reprepared;
+eval $check;
 
 drop function audit_func;
 
@@ -432,19 +443,20 @@ create function audit_func() returns var
   return "func v2";
 
 set @val=203;
+set @expected = @expected + 1;
 execute stmt_func using @val;
-eval $reprepared;
+eval $check;
 set @val=204;
 execute stmt_func using @val;
-eval $reprepared;
+eval $check;
 
 prepare stmt_view from 'insert into t7_view(a) value (?)';
 set @val=301;
 execute stmt_view using @val;
-eval $reprepared;
+eval $check;
 set @val=302;
 execute stmt_view using @val;
-eval $reprepared;
+eval $check;
 
 drop view audit_view;
 
@@ -455,52 +467,53 @@ create view audit_view as select "view v
 # This is because the table trigger is cached and is not invalidated.
 
 set @val=303;
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt_view using @val;
-eval $reprepared;
+eval $check;
 set @val=304;
 execute stmt_view using @val;
-eval $reprepared;
+eval $check;
 
 
 prepare stmt_table from 'insert into t7_table(a) value (?)';
 set @val=401;
 execute stmt_table using @val;
-eval $reprepared;
+eval $check;
 set @val=402;
 execute stmt_table using @val;
-eval $reprepared;
+eval $check;
 
 alter table t7_dependent_table add column comments varchar(100) default NULL;
 
 set @val=403;
-# REPREPARED +1
+set @expected = @expected + 1;
 --error ER_WRONG_VALUE_COUNT_ON_ROW
 execute stmt_table using @val;
-eval $reprepared;
+eval $check;
 set @val=404;
+set @expected = @expected + 1;
 --error ER_WRONG_VALUE_COUNT_ON_ROW
 execute stmt_table using @val;
-eval $reprepared;
+eval $check;
 
 alter table t7_dependent_table drop column comments;
 
 set @val=405;
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt_table using @val;
-eval $reprepared;
+eval $check;
 set @val=406;
 execute stmt_table using @val;
-eval $reprepared;
+eval $check;
 
 
 prepare stmt_table_trigger from 'insert into t7_table(a) value (?)';
 set @val=501;
 execute stmt_table_trigger using @val;
-eval $reprepared;
+eval $check;
 set @val=502;
 execute stmt_table_trigger using @val;
-eval $reprepared;
+eval $check;
 
 drop trigger t7_table_trigger_bi;
 
@@ -508,12 +521,12 @@ create trigger t7_table_trigger_bi befor
   for each row set NEW.reason="trigger v2";
 
 set @val=503;
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt_table_trigger using @val;
-eval $reprepared;
+eval $check;
 set @val=504;
 execute stmt_table_trigger using @val;
-eval $reprepared;
+eval $check;
 
 select * from t7_audit order by new_a;
 
@@ -538,24 +551,22 @@ drop view audit_view;
 drop table if exists t8;
 --enable_warnings
 
-eval $base_count;
-
 create table t8(a int);
 
 prepare stmt from 'select * from t8';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t8;
 create temporary table t8(a int);
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t8;
 
@@ -568,25 +579,23 @@ drop table if exists t9;
 drop table if exists t9_b;
 --enable_warnings
 
-eval $base_count;
-
 create table t9(a int);
 create table t9_b(a int);
 
 prepare stmt from 'select * from t9';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t9;
 create view t9 as select * from t9_b;
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop view t9;
 drop table t9_b;
@@ -599,23 +608,21 @@ drop table t9_b;
 drop temporary table if exists t10;
 --enable_warnings
 
-eval $base_count;
-
 create temporary table t10(a int);
 
 prepare stmt from 'select * from t10';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop temporary table t10;
 --error ER_NO_SUCH_TABLE
 execute stmt;
-eval $reprepared;
+eval $check;
 --error ER_NO_SUCH_TABLE
 execute stmt;
-eval $reprepared;
+eval $check;
 
 --echo =====================================================================
 --echo Testing 11: TEMPORARY TABLE -> TABLE transitions
@@ -626,25 +633,23 @@ drop table if exists t11;
 drop temporary table if exists t11;
 --enable_warnings
 
-eval $base_count;
-
 create table t11(a int);
 insert into t11(a) value (1);
 create temporary table t11(a int);
 
 prepare stmt from 'select * from t11';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop temporary table t11;
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 select * from t11;
 drop table t11;
@@ -657,24 +662,22 @@ drop table t11;
 drop temporary table if exists t12;
 --enable_warnings
 
-eval $base_count;
-
 create temporary table t12(a int);
 
-prepare stmt from 'select * from t12';
+prepare stmt from 'select a from t12';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop temporary table t12;
 create temporary table t12(a int, b int);
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 select * from t12;
 drop table t12;
@@ -688,25 +691,23 @@ drop temporary table if exists t13;
 drop table if exists t13_b;
 --enable_warnings
 
-eval $base_count;
-
 create temporary table t13(a int);
 create table t13_b(a int);
 
 prepare stmt from 'select * from t13';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop temporary table t13;
 create view t13 as select * from t13_b;
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop view t13;
 drop table t13_b;
@@ -720,26 +721,25 @@ drop view if exists t14;
 drop table if exists t14_b;
 --enable_warnings
 
-eval $base_count;
-
 create table t14_b(a int);
 create view t14 as select * from t14_b;
 
 prepare stmt from 'select * from t14';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop view t14;
 
-# REPREPARED +1
+set @expected = @expected + 1;
 --error ER_NO_SUCH_TABLE
 execute stmt;
-eval $reprepared;
+eval $check;
+set @expected = @expected + 1;
 --error ER_NO_SUCH_TABLE
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t14_b;
 
@@ -752,25 +752,23 @@ drop view if exists t15;
 drop table if exists t15_b;
 --enable_warnings
 
-eval $base_count;
-
 create table t15_b(a int);
 create view t15 as select * from t15_b;
 
 prepare stmt from 'select * from t15';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop view t15;
 create table t15(a int);
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t15_b;
 drop table t15;
@@ -784,25 +782,23 @@ drop view if exists t16;
 drop table if exists t16_b;
 --enable_warnings
 
-eval $base_count;
-
 create table t16_b(a int);
 create view t16 as select * from t16_b;
 
 prepare stmt from 'select * from t16';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop view t16;
 create temporary table t16(a int);
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t16_b;
 drop temporary table t16;
@@ -816,8 +812,6 @@ drop view if exists t17;
 drop table if exists t17_b;
 --enable_warnings
 
-eval $base_count;
-
 create table t17_b(a int);
 insert into t17_b values (10), (20), (30);
 
@@ -826,19 +820,19 @@ select * from t17;
 
 prepare stmt from 'select * from t17';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop view t17;
-create view t17 as select a, 2*a as b, 10*a as c from t17_b;
+create view t17 as select a, 2*a as b, 5*a as c from t17_b;
 select * from t17;
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t17_b;
 drop view t17;
@@ -865,8 +859,6 @@ drop function if exists view_func;
 drop view if exists view_view;
 --enable_warnings
 
-eval $base_count;
-
 # TODO: insertable view -> trigger
 # TODO: insertable view -> trigger -> proc ?
 
@@ -886,47 +878,48 @@ create view t18_table as select * from t
 
 prepare stmt_func from 'select * from t18_func';
 execute stmt_func;
-eval $reprepared;
+eval $check;
 execute stmt_func;
-eval $reprepared;
+eval $check;
 
 drop function view_func;
 create function view_func(x int) returns int
   return x*x;
 
+set @expected = @expected + 1;
 execute stmt_func;
-eval $reprepared;
+eval $check;
 execute stmt_func;
-eval $reprepared;
+eval $check;
 
 prepare stmt_view from 'select * from t18_view';
 execute stmt_view;
-eval $reprepared;
+eval $check;
 execute stmt_view;
-eval $reprepared;
+eval $check;
 
 drop view view_view;
 create view view_view as select "view v2" as reason from dual;
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt_view;
-eval $reprepared;
+eval $check;
 execute stmt_view;
-eval $reprepared;
+eval $check;
 
 prepare stmt_table from 'select * from t18_table';
 execute stmt_table;
-eval $reprepared;
+eval $check;
 execute stmt_table;
-eval $reprepared;
+eval $check;
 
 alter table t18 add column comments varchar(50) default NULL;
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt_table;
-eval $reprepared;
+eval $check;
 execute stmt_table;
-eval $reprepared;
+eval $check;
 
 drop table t18;
 drop table t18_dependent_table;
@@ -944,8 +937,6 @@ drop view view_view;
 drop procedure if exists proc_19;
 --enable_warnings
 
-eval $base_count;
-
 # Using a temporary table internally should not confuse the prepared
 # statement code, and should not raise ER_PS_INVALIDATED errors
 prepare stmt from
@@ -956,17 +947,17 @@ prepare stmt from
 create procedure proc_19() select "hi there";
 
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop procedure proc_19;
 create procedure proc_19() select "hi there, again";
 
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop procedure proc_19;
 
@@ -974,19 +965,17 @@ drop procedure proc_19;
 --echo Testing 20: Special tables (log tables)
 --echo =====================================================================
 
-eval $base_count;
-
 prepare stmt from
  'select * from mysql.general_log where argument=\'IMPOSSIBLE QUERY STRING\'';
 
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 --echo =====================================================================
 --echo Testing 21: Special tables (system tables)
@@ -996,25 +985,23 @@ eval $reprepared;
 drop procedure if exists proc_21;
 --enable_warnings
 
-eval $base_count;
-
 prepare stmt from
  'select type, db, name from mysql.proc where name=\'proc_21\'';
 
 create procedure proc_21() select "hi there";
 
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop procedure proc_21;
 create procedure proc_21() select "hi there, again";
 
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop procedure proc_21;
 
@@ -1027,8 +1014,6 @@ drop table if exists t22_b;
 drop view if exists t22;
 --enable_warnings
 
-eval $base_count;
-
 create table t22_b(a int);
 
 create algorithm=temptable view t22 as select a*a as a2 from t22_b;
@@ -1041,15 +1026,15 @@ prepare stmt from 'select * from t22';
 
 insert into t22_b values (1), (2), (3);
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 insert into t22_b values (4), (5), (6);
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t22_b;
 drop view t22;
@@ -1063,8 +1048,6 @@ drop table if exists t23_a;
 drop table if exists t23_b;
 --enable_warnings
 
-eval $base_count;
-
 create table t23_a(a int);
 create table t23_b(b int);
 
@@ -1075,16 +1058,16 @@ prepare stmt from 'select * from t23_a j
 insert into t23_a values (1), (2), (3);
 insert into t23_b values (10), (20), (30);
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 insert into t23_a values (4);
 insert into t23_b values (40);
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t23_a;
 drop table t23_b;
@@ -1099,28 +1082,26 @@ drop table t23_b;
 drop table if exists t24_alter;
 --enable_warnings
 
-eval $base_count;
-
 create table t24_alter(a int);
 
 prepare stmt from 'alter table t24_alter add column b int';
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t24_alter;
 create table t24_alter(a1 int, a2 int);
 
 # t24_alter has changed, and it's not a problem
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t24_alter drop column b;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t24_alter drop column b;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t24_alter;
 
@@ -1135,7 +1116,7 @@ insert into t24_repair values (1), (2), 
 
 prepare stmt from 'repair table t24_repair';
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t24_repair;
 create table t24_repair(a1 int, a2 int);
@@ -1143,15 +1124,15 @@ insert into t24_repair values (1, 10), (
 
 # t24_repair has changed, and it's not a problem
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t24_repair add column b varchar(50) default NULL;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t24_repair drop column b;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t24_repair;
 
@@ -1166,7 +1147,7 @@ insert into t24_analyze values (1), (2),
 
 prepare stmt from 'analyze table t24_analyze';
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t24_analyze;
 create table t24_analyze(a1 int, a2 int);
@@ -1174,15 +1155,15 @@ insert into t24_analyze values (1, 10), 
 
 # t24_analyze has changed, and it's not a problem
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t24_analyze add column b varchar(50) default NULL;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t24_analyze drop column b;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t24_analyze;
 
@@ -1197,7 +1178,7 @@ insert into t24_optimize values (1), (2)
 
 prepare stmt from 'optimize table t24_optimize';
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t24_optimize;
 create table t24_optimize(a1 int, a2 int);
@@ -1205,15 +1186,15 @@ insert into t24_optimize values (1, 10),
 
 # t24_optimize has changed, and it's not a problem
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t24_optimize add column b varchar(50) default NULL;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t24_optimize drop column b;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t24_optimize;
 
@@ -1226,35 +1207,35 @@ drop procedure if exists changing_proc;
 prepare stmt from 'show create procedure changing_proc';
 --error ER_SP_DOES_NOT_EXIST
 execute stmt;
-eval $reprepared;
+eval $check;
 --error ER_SP_DOES_NOT_EXIST
 execute stmt;
-eval $reprepared;
+eval $check;
 
 create procedure changing_proc() begin end;
 
 # changing_proc has changed, and it's not a problem
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop procedure changing_proc;
 create procedure changing_proc(x int, y int) begin end;
 
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop procedure changing_proc;
 
 --error ER_SP_DOES_NOT_EXIST
 execute stmt;
-eval $reprepared;
+eval $check;
 --error ER_SP_DOES_NOT_EXIST
 execute stmt;
-eval $reprepared;
+eval $check;
 
 # SQLCOM_SHOW_CREATE_FUNC:
 
@@ -1265,35 +1246,35 @@ drop function if exists changing_func;
 prepare stmt from 'show create function changing_func';
 --error ER_SP_DOES_NOT_EXIST
 execute stmt;
-eval $reprepared;
+eval $check;
 --error ER_SP_DOES_NOT_EXIST
 execute stmt;
-eval $reprepared;
+eval $check;
 
 create function changing_func() returns int return 0;
 
 # changing_proc has changed, and it's not a problem
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop function changing_func;
 create function changing_func(x int, y int) returns int return x+y;
 
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop function changing_func;
 
 --error ER_SP_DOES_NOT_EXIST
 execute stmt;
-eval $reprepared;
+eval $check;
 --error ER_SP_DOES_NOT_EXIST
 execute stmt;
-eval $reprepared;
+eval $check;
 
 # SQLCOM_SHOW_CREATE_TRIGGER:
 
@@ -1306,10 +1287,10 @@ create table t24_trigger(a int);
 prepare stmt from 'show create trigger t24_bi;';
 --error ER_TRG_DOES_NOT_EXIST
 execute stmt;
-eval $reprepared;
+eval $check;
 --error ER_TRG_DOES_NOT_EXIST
 execute stmt;
-eval $reprepared;
+eval $check;
 
 delimiter $$;
 create trigger t24_bi before insert on t24_trigger for each row
@@ -1321,9 +1302,9 @@ delimiter ;$$
 
 # t24_bi has changed, and it's not a problem
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop trigger t24_bi;
 delimiter $$;
@@ -1335,19 +1316,20 @@ $$
 delimiter ;$$
 
 # t24_bi has changed, and it's not a problem
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop trigger t24_bi;
 
 --error ER_TRG_DOES_NOT_EXIST
 execute stmt;
-eval $reprepared;
+eval $check;
 --error ER_TRG_DOES_NOT_EXIST
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t24_trigger;
 
@@ -1361,23 +1343,21 @@ drop table t24_trigger;
 drop table if exists t25_num_col;
 --enable_warnings
 
-eval $base_count;
-
 create table t25_num_col(a int);
 
-prepare stmt from 'select * from t25_num_col';
+prepare stmt from 'select a from t25_num_col';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t25_num_col add column b varchar(50) default NULL;
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t25_num_col;
 
@@ -1391,17 +1371,20 @@ create table t25_col_name(a int);
 
 prepare stmt from 'select * from t25_col_name';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t25_col_name change a b int;
 
-# REPREPARED +1
+set @expected = @expected + 1;
+--error ER_PS_REBIND
 execute stmt;
-eval $reprepared;
+eval $check;
+set @expected = @expected + 1;
+--error ER_PS_REBIND
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t25_col_name;
 
@@ -1415,17 +1398,20 @@ create table t25_col_type(a int);
 
 prepare stmt from 'select * from t25_col_type';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t25_col_type change a a varchar(10);
 
-# REPREPARED +1
+set @expected = @expected + 1;
+--error ER_PS_REBIND
 execute stmt;
-eval $reprepared;
+eval $check;
+set @expected = @expected + 1;
+--error ER_PS_REBIND
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t25_col_type;
 
@@ -1439,17 +1425,20 @@ create table t25_col_type_length(a varch
 
 prepare stmt from 'select * from t25_col_type_length';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t25_col_type_length change a a varchar(20);
 
-# REPREPARED +1
+set @expected = @expected + 1;
+--error ER_PS_REBIND
 execute stmt;
-eval $reprepared;
+eval $check;
+set @expected = @expected + 1;
+--error ER_PS_REBIND
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t25_col_type_length;
 
@@ -1463,17 +1452,20 @@ create table t25_col_null(a varchar(10))
 
 prepare stmt from 'select * from t25_col_null';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t25_col_null change a a varchar(10) NOT NULL;
 
-# REPREPARED +1
+set @expected = @expected + 1;
+--error ER_PS_REBIND
 execute stmt;
-eval $reprepared;
+eval $check;
+set @expected = @expected + 1;
+--error ER_PS_REBIND
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t25_col_null;
 
@@ -1488,22 +1480,23 @@ create table t25_col_default(a int, b in
 prepare stmt from 'insert into t25_col_default(a) values (?)';
 set @val=1;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 set @val=2;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 
 alter table t25_col_default change b b int DEFAULT 20;
 
 set @val=3;
 # Must insert the correct default value for b
+set @expected = @expected + 1;
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 
 set @val=4;
 # Must insert the correct default value for b
 execute stmt using @val;
-eval $reprepared;
+eval $check;
 
 select * from t25_col_default;
 
@@ -1519,17 +1512,17 @@ create table t25_index(a varchar(10));
 
 prepare stmt from 'select * from t25_index';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 create index i1 on t25_index(a);
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t25_index;
 
@@ -1546,20 +1539,20 @@ show create table t25_index_unique;
 
 prepare stmt from 'select * from t25_index_unique';
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 alter table t25_index_unique drop index i1;
 create unique index i1 on t25_index_unique(a, b);
 
 show create table t25_index_unique;
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table t25_index_unique;
 
@@ -1579,8 +1572,6 @@ drop function if exists func_12093_unrel
 drop procedure if exists proc_12093;
 --enable_warnings
 
-eval $base_count;
-
 connect (con1,localhost,root,,);
 
 connection default;
@@ -1609,9 +1600,9 @@ prepare stmt_sf from 'select func_12093(
 prepare stmt_sp from 'call proc_12093(func_12093())';
 
 execute stmt_sf;
-eval $reprepared;
+eval $check;
 execute stmt_sp;
-eval $reprepared;
+eval $check;
 
 connection con1;
 
@@ -1622,17 +1613,17 @@ connection default;
 
 # previously, failed with --error 1305
 execute stmt_sf;
-eval $reprepared;
+eval $check;
 # previously, failed with --error 1305
 execute stmt_sp;
-eval $reprepared;
+eval $check;
 
 # previously, failed with --error 1305
 execute stmt_sf;
-eval $reprepared;
+eval $check;
 # previously, failed with --error 1305
 execute stmt_sp;
-eval $reprepared;
+eval $check;
 
 deallocate prepare stmt_sf;
 deallocate prepare stmt_sp;
@@ -1652,26 +1643,25 @@ drop procedure proc_12093;
 drop function if exists func_21294;
 --enable_warnings
 
-eval $base_count;
-
 create function func_21294() returns int return 10;
 
 prepare stmt from "select func_21294()";
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop function func_21294;
 create function func_21294() returns int return 10;
 
 # might pass or fail, implementation dependent
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop function func_21294;
 create function func_21294() returns int return 20;
 
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 deallocate prepare stmt;
 drop function func_21294;
@@ -1687,8 +1677,6 @@ drop table if exists t_27420_101;
 drop view if exists v_27420;
 --enable_warnings
 
-eval $base_count;
-
 connect (con1,localhost,root,,);
 
 connection default;
@@ -1706,7 +1694,7 @@ create view v_27420 as select t_27420_10
 prepare stmt from 'select * from v_27420';
 
 execute stmt;
-eval $reprepared;
+eval $check;
 
 connection con1;
 
@@ -1715,9 +1703,9 @@ create table v_27420(X int, Y int);
 
 connection default;
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 connection con1;
 
@@ -1727,9 +1715,10 @@ create table v_27420 (a int, b int, fill
 
 connection default;
 
-# REPREPARED +1
+set @expected = @expected + 1;
+--error ER_PS_REBIND
 execute stmt;
-eval $reprepared;
+eval $check;
 
 disconnect con1;
 
@@ -1748,8 +1737,6 @@ drop table if exists t_27430_1;
 drop table if exists t_27430_2;
 --enable_warnings
 
-eval $base_count;
-
 create table t_27430_1 (a int not null, oref int not null, key(a));
 insert into t_27430_1 values
   (1, 1),
@@ -1769,9 +1756,9 @@ prepare stmt from 
  'select oref, a, a in (select a from t_27430_1 where oref=t_27430_2.oref) Z from t_27430_2';
 
 execute stmt; 
-eval $reprepared;
+eval $check;
 execute stmt; 
-eval $reprepared;
+eval $check;
 
 drop table t_27430_1, t_27430_2;
 
@@ -1790,11 +1777,14 @@ insert into t_27430_2 values
   (NULL, 3),
   (NULL, 4);
 
-# REPREPARED +1
+set @expected = @expected + 1;
+--error ER_PS_REBIND
 execute stmt;
-eval $reprepared;
+eval $check;
+set @expected = @expected + 1;
+--error ER_PS_REBIND
 execute stmt;
-eval $reprepared;
+eval $check;
 
 deallocate prepare stmt;
 drop table t_27430_1;
@@ -1811,8 +1801,6 @@ drop view if exists v_27690_1;
 drop table if exists v_27690_2;
 --enable_warnings
 
-eval $base_count;
-
 create table t_27690_1 (a int, b int);
 insert into t_27690_1 values (1,1),(2,2);
 
@@ -1822,27 +1810,27 @@ create table v_27690_2 as select * from 
 prepare stmt from 'select * from v_27690_1, v_27690_2'; 
 
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 drop table v_27690_1;
 
 --error ER_NO_SUCH_TABLE
 execute stmt;
-eval $reprepared;
+eval $check;
 
 --error ER_NO_SUCH_TABLE
 execute stmt;
-eval $reprepared;
+eval $check;
 
 create view v_27690_1 as select A.a, A.b from t_27690_1 A, t_27690_1 B;
 
-# REPREPARED +1
+set @expected = @expected + 1;
 execute stmt;
-eval $reprepared;
+eval $check;
 execute stmt;
-eval $reprepared;
+eval $check;
 
 deallocate prepare stmt;
 drop table t_27690_1;
diff -Nrup a/mysql-test/t/sp-error.test b/mysql-test/t/sp-error.test
--- a/mysql-test/t/sp-error.test	2008-01-23 16:21:04 -07:00
+++ b/mysql-test/t/sp-error.test	2008-02-05 16:44:09 -07:00
@@ -1114,10 +1114,6 @@ execute stmt;
 drop function bug11834_1;
 # Attempt to execute statement should return proper error and 
 # should not crash server.
-
-# NOTE! The error we get from the below query indicates that the sp bug11834_2
-# does not exist(this is wrong but can be accepted)
-# This behaviour has been reported as bug#21294
 --error ER_SP_DOES_NOT_EXIST
 execute stmt;
 deallocate prepare stmt;
@@ -1470,10 +1466,6 @@ execute stmt1;
 drop function bug12329;
 create function bug12329() returns int return (select a+100 from t2);
 select bug12329();
-# Until we implement proper mechanism for invalidation of PS/SP when table
-# or SP's are changed the following statement will fail with 'Table ... was
-# not locked' error (this mechanism should be based on the new TDC).
---error ER_NO_SUCH_TABLE 
 execute stmt1;
 deallocate prepare stmt1;
 drop function bug12329; 
diff -Nrup a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test
--- a/mysql-test/t/trigger.test	2007-11-29 04:42:23 -07:00
+++ b/mysql-test/t/trigger.test	2008-02-05 16:44:09 -07:00
@@ -997,11 +997,10 @@ call p1();
 # Altering trigger forcing it use different set of tables
 drop trigger t1_bi;
 create trigger t1_bi after insert on t1 for each row insert into t3 values (new.id);
-# Until we implement proper mechanism for invalidation of PS/SP when table
-# or SP's are changed these two statements will fail with 'Table ... was
-# not locked' error (this mechanism should be based on the new TDC).
---error ER_NO_SUCH_TABLE 
 execute stmt1;
+# Until we implement proper mechanism for invalidation of SP when table
+# or SP's are changed this statements will fail with 'Table ... was
+# not locked' error (this mechanism should be based on the new TDC).
 --error ER_NO_SUCH_TABLE 
 call p1();
 deallocate prepare stmt1;
diff -Nrup a/sql/mysql_priv.h b/sql/mysql_priv.h
--- a/sql/mysql_priv.h	2007-12-14 06:01:09 -07:00
+++ b/sql/mysql_priv.h	2008-02-05 16:44:09 -07:00
@@ -1177,7 +1177,7 @@ TABLE_SHARE *get_cached_table_share(cons
 TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type update,
                    uint lock_flags);
 TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT* mem,
-		  bool *refresh, uint flags);
+		  bool *refresh, bool *invalidated, uint flags);
 bool name_lock_locked_table(THD *thd, TABLE_LIST *tables);
 bool reopen_name_locked_table(THD* thd, TABLE_LIST* table_list, bool link_in);
 TABLE *table_cache_insert_placeholder(THD *thd, const char *key,
diff -Nrup a/sql/mysqld.cc b/sql/mysqld.cc
--- a/sql/mysqld.cc	2007-12-20 13:32:51 -07:00
+++ b/sql/mysqld.cc	2008-02-05 16:44:09 -07:00
@@ -2899,6 +2899,7 @@ SHOW_VAR com_status_vars[]= {
   {"stmt_execute",         (char*) offsetof(STATUS_VAR, com_stmt_execute), SHOW_LONG_STATUS},
   {"stmt_fetch",           (char*) offsetof(STATUS_VAR, com_stmt_fetch), SHOW_LONG_STATUS},
   {"stmt_prepare",         (char*) offsetof(STATUS_VAR, com_stmt_prepare), SHOW_LONG_STATUS},
+  {"stmt_reprepare",       (char*) offsetof(STATUS_VAR, com_stmt_reprepare), SHOW_LONG_STATUS},
   {"stmt_reset",           (char*) offsetof(STATUS_VAR, com_stmt_reset), SHOW_LONG_STATUS},
   {"stmt_send_long_data",  (char*) offsetof(STATUS_VAR, com_stmt_send_long_data), SHOW_LONG_STATUS},
   {"truncate",             (char*) offsetof(STATUS_VAR, com_stat[(uint) SQLCOM_TRUNCATE]), SHOW_LONG_STATUS},
@@ -2987,7 +2988,7 @@ static int init_common_variables(const c
     We have few debug-only commands in com_status_vars, only visible in debug
     builds. for simplicity we enable the assert only in debug builds
 
-    There are 7 Com_ variables which don't have corresponding SQLCOM_ values:
+    There are 8 Com_ variables which don't have corresponding SQLCOM_ values:
     (TODO strictly speaking they shouldn't be here, should not have Com_ prefix
     that is. Perhaps Stmt_ ? Comstmt_ ? Prepstmt_ ?)
 
@@ -2996,6 +2997,7 @@ static int init_common_variables(const c
       Com_stmt_execute         => com_stmt_execute
       Com_stmt_fetch           => com_stmt_fetch
       Com_stmt_prepare         => com_stmt_prepare
+      Com_stmt_reprepare       => com_stmt_reprepare
       Com_stmt_reset           => com_stmt_reset
       Com_stmt_send_long_data  => com_stmt_send_long_data
 
@@ -3004,7 +3006,7 @@ static int init_common_variables(const c
     of SQLCOM_ constants.
   */
   compile_time_assert(sizeof(com_status_vars)/sizeof(com_status_vars[0]) - 1 ==
-                     SQLCOM_END + 7);
+                     SQLCOM_END + 8);
 #endif
 
   load_defaults(conf_file_name, groups, &argc, &argv);
diff -Nrup a/sql/parse_file.cc b/sql/parse_file.cc
--- a/sql/parse_file.cc	2007-07-30 02:33:44 -06:00
+++ b/sql/parse_file.cc	2008-02-05 16:44:09 -07:00
@@ -429,7 +429,7 @@ sql_parse_prepare(const LEX_STRING *file
   File file;
   DBUG_ENTER("sql_parse_prepare");
 
-  if (!my_stat(file_name->str, &stat_info, MYF(MY_WME)))
+  if (!my_stat(file_name->str, &stat_info, MYF(0)))
   {
     DBUG_RETURN(0);
   }
diff -Nrup a/sql/share/errmsg.txt b/sql/share/errmsg.txt
--- a/sql/share/errmsg.txt	2007-11-14 06:28:21 -07:00
+++ b/sql/share/errmsg.txt	2008-02-05 16:44:11 -07:00
@@ -6114,3 +6114,10 @@ ER_TRG_CANT_OPEN_TABLE
 
 ER_CANT_CREATE_SROUTINE
   eng "Cannot create stored routine `%-.64s`. Check warnings"
+
+ER_NEED_REPREPARE
+  eng "(Internal) Prepared statement needs to be re-prepared"
+
+ER_PS_REBIND
+  eng "Prepared statement result set has changed, rebind needed"
+
diff -Nrup a/sql/sp.cc b/sql/sp.cc
--- a/sql/sp.cc	2007-12-18 01:58:22 -07:00
+++ b/sql/sp.cc	2008-02-05 16:44:09 -07:00
@@ -1798,6 +1798,156 @@ static void sp_update_stmt_used_routines
 }
 
 
+/**
+  This helper ensures that a given Stored Function or Stored Procedure
+  is present in the corresponding per session cache,
+  and loads the Stored Function/Procedure from storage into the cache,
+  if necessary.
+  @param [in] thd Current thread
+  @param [in] type Type of stored object to lookup/load
+  @param [in] name Name of the stored object
+  @param [out] sphp Stored object refreshed in the cache, if found
+  @return An error status
+    @retval 0 Success, sphp will contain the stored object fetched, if any
+*/
+
+static int
+sp_cache_load(THD *thd, Sroutine_hash_entry *entry, sp_head **sphp)
+{
+  sp_cache **cp;
+  sp_head *sp;
+  int ret;
+  Object_version sp_version;
+  sp_name name(thd, entry->key.str, entry->key.length);
+  int type= entry->key.str[0];
+
+  DBUG_ENTER("sp_cache_load");
+
+  DBUG_ASSERT(sphp);
+  DBUG_ASSERT(type == TYPE_ENUM_PROCEDURE ||
+              type == TYPE_ENUM_TRIGGER ||
+              type == TYPE_ENUM_FUNCTION);
+
+  /* Triggers are cached in the stored procedure cache. */
+  cp= (type == TYPE_ENUM_FUNCTION ? &thd->sp_func_cache : &thd->sp_proc_cache);
+
+  sp= sp_cache_lookup(cp, &name);
+
+  if (! sp)
+  {
+    switch ((ret= db_find_routine(thd, type, &name, &sp)))
+    {
+    case SP_OK:
+      sp_cache_insert(cp, sp);
+
+      if (thd->m_object_observer && type != TYPE_ENUM_TRIGGER)
+      {
+        sp->make_object_version(& sp_version);
+
+        if (thd->m_object_observer->notify(thd, & sp_version))
+          DBUG_RETURN(1);
+      }
+
+      *sphp= sp;
+      ret= 0;
+      break;
+    case SP_KEY_NOT_FOUND:
+      if (thd->m_object_observer && type != TYPE_ENUM_TRIGGER)
+      {
+        sp_head::make_object_null_version(& sp_version,
+                                          type,
+                                          name.m_db,
+                                          name.m_name);
+
+        if (thd->m_object_observer->notify(thd, & sp_version))
+          DBUG_RETURN(1);
+      }
+
+      *sphp= NULL;
+      ret= 0;
+      break;
+    default:
+      /*
+        Any error when loading an existing routine is either some problem
+        with the mysql.proc table, or a parse error because the contents
+        has been tampered with (in which case we clear that error).
+      */
+      if (ret == SP_PARSE_ERROR)
+        thd->clear_error();
+      /*
+        If we cleared the parse error, or when db_find_routine() flagged
+        an error with it's return value without calling my_error(), we
+        set the generic "mysql.proc table corrupt" error here.
+       */
+      if (! thd->is_error())
+      {
+        /*
+          SP allows full NAME_LEN chars thus he have to allocate enough
+          size in bytes. Otherwise there is stack overrun could happen
+          if multibyte sequence is `name`. `db` is still safe because the
+          rest of the server checks against NAME_LEN bytes and not chars.
+          Hence, the overrun happens only if the name is in length > 32 and
+          uses multibyte (cyrillic, greek, etc.)
+        */
+        char n[NAME_LEN*2+2];
+
+        /* m_qname.str is not always \0 terminated */
+        memcpy(n, name.m_qname.str, name.m_qname.length);
+        n[name.m_qname.length]= '\0';
+        my_error(ER_SP_PROC_TABLE_CORRUPT, MYF(0), n, ret);
+        ret= 1;
+      }
+      break;
+    }
+  }
+  else
+  {
+    if (thd->m_object_observer && type != TYPE_ENUM_TRIGGER)
+    {
+      sp->make_object_version(& sp_version);
+
+      if (thd->m_object_observer->notify(thd, & sp_version))
+        DBUG_RETURN(1);
+    }
+
+    ret= 0;
+    *sphp= sp;
+  }
+
+  DBUG_RETURN(ret);
+}
+
+
+/**
+  Refresh all the routines used by a statement in the session cache.
+  Note that routines that can be found are reloaded,
+  while routines that can not be found are ignored.
+  @param [in] thd Current thread
+  @param [in] lex Statement semantic tree
+  @return An error status
+    @retval 0 Success
+*/
+int
+sp_refresh_routines(THD *thd, LEX *lex)
+{
+  Sroutine_hash_entry *start;
+  int ret= 0;
+
+  DBUG_ENTER("sp_recache_routines");
+  start= (Sroutine_hash_entry *)lex->sroutines_list.first;
+
+  for (Sroutine_hash_entry *rt= start; rt; rt= rt->next)
+  {
+    sp_head *sp;
+
+    ret= sp_cache_load(thd, rt, &sp);
+
+    if (ret)
+      break;
+  }
+  DBUG_RETURN(ret);
+}
+
 /*
   Cache sub-set of routines used by statement, add tables used by these
   routines to statement table list. Do the same for all routines used
@@ -1832,60 +1982,13 @@ sp_cache_routines_and_add_tables_aux(THD
 
   for (Sroutine_hash_entry *rt= start; rt; rt= rt->next)
   {
-    sp_name name(thd, rt->key.str, rt->key.length);
-    int type= rt->key.str[0];
     sp_head *sp;
 
-    if (!(sp= sp_cache_lookup((type == TYPE_ENUM_FUNCTION ?
-                              &thd->sp_func_cache : &thd->sp_proc_cache),
-                              &name)))
-    {
-      switch ((ret= db_find_routine(thd, type, &name, &sp)))
-      {
-      case SP_OK:
-        {
-          if (type == TYPE_ENUM_FUNCTION)
-            sp_cache_insert(&thd->sp_func_cache, sp);
-          else
-            sp_cache_insert(&thd->sp_proc_cache, sp);
-        }
-        break;
-      case SP_KEY_NOT_FOUND:
-        ret= SP_OK;
-        break;
-      default:
-        /*
-          Any error when loading an existing routine is either some problem
-          with the mysql.proc table, or a parse error because the contents
-          has been tampered with (in which case we clear that error).
-        */
-        if (ret == SP_PARSE_ERROR)
-          thd->clear_error();
-        /*
-          If we cleared the parse error, or when db_find_routine() flagged
-          an error with it's return value without calling my_error(), we
-          set the generic "mysql.proc table corrupt" error here.
-         */
-        if (! thd->is_error())
-        {
-          /*
-            SP allows full NAME_LEN chars thus he have to allocate enough
-            size in bytes. Otherwise there is stack overrun could happen
-            if multibyte sequence is `name`. `db` is still safe because the
-            rest of the server checks agains NAME_LEN bytes and not chars.
-            Hence, the overrun happens only if the name is in length > 32 and
-            uses multibyte (cyrillic, greek, etc.)
-          */
-          char n[NAME_LEN*2+2];
-
-          /* m_qname.str is not always \0 terminated */
-          memcpy(n, name.m_qname.str, name.m_qname.length);
-          n[name.m_qname.length]= '\0';
-          my_error(ER_SP_PROC_TABLE_CORRUPT, MYF(0), n, ret);
-        }
-        break;
-      }
-    }
+    ret= sp_cache_load(thd, rt, &sp);
+
+    if (ret)
+      break;
+
     if (sp)
     {
       if (!(first && first_no_prelock))
diff -Nrup a/sql/sp.h b/sql/sp.h
--- a/sql/sp.h	2007-10-17 02:13:53 -06:00
+++ b/sql/sp.h	2008-02-05 16:44:09 -07:00
@@ -70,6 +70,7 @@ void sp_add_used_routine(LEX *lex, Query
                          sp_name *rt, char rt_type);
 void sp_remove_not_own_routines(LEX *lex);
 void sp_update_sp_used_routines(HASH *dst, HASH *src);
+int sp_refresh_routines(THD *thd, LEX *lex);
 int sp_cache_routines_and_add_tables(THD *thd, LEX *lex,
                                      bool first_no_prelock);
 int sp_cache_routines_and_add_tables_for_view(THD *thd, LEX *lex,
diff -Nrup a/sql/sp_head.cc b/sql/sp_head.cc
--- a/sql/sp_head.cc	2008-01-23 15:36:39 -07:00
+++ b/sql/sp_head.cc	2008-02-05 16:44:09 -07:00
@@ -22,6 +22,7 @@
 #include "sp_pcontext.h"
 #include "sp_rcontext.h"
 #include "sp_cache.h"
+#include "my_md5.h"
 
 /*
   Sufficient max length of printed destinations and frame offsets (all uints).
@@ -535,6 +536,56 @@ sp_head::sp_head()
   DBUG_VOID_RETURN;
 }
 
+int sp_head::make_object_version(Object_version * version)
+{
+  int rc;
+
+  switch(m_type)
+  {
+  case TYPE_ENUM_FUNCTION:
+    rc= version->m_oid.set_function(m_db, m_name);
+    break;
+  case TYPE_ENUM_PROCEDURE:
+    rc= version->m_oid.set_procedure(m_db, m_name);
+    break;
+  case TYPE_ENUM_TRIGGER:
+  default:
+    DBUG_ASSERT(false);
+    rc= 1;
+  }
+
+  version->m_vid.set_md5(m_md5_value);
+
+  return rc;
+}
+
+int sp_head::make_object_null_version(
+  Object_version * version,
+  int type,
+  const LEX_STRING& db,
+  const LEX_STRING& name)
+{
+  int rc;
+
+  switch(type)
+  {
+  case TYPE_ENUM_FUNCTION:
+    rc= version->m_oid.set_function(db, name);
+    break;
+  case TYPE_ENUM_PROCEDURE:
+    rc= version->m_oid.set_procedure(db, name);
+    break;
+  case TYPE_ENUM_TRIGGER:
+  default:
+    DBUG_ASSERT(false);
+    rc= 1;
+  }
+
+  version->m_vid.set_null();
+
+  return rc;
+}
+
 
 void
 sp_head::init(LEX *lex)
@@ -632,6 +683,8 @@ sp_head::set_stmt_end(THD *thd)
 {
   Lex_input_stream *lip= thd->m_lip; /* shortcut */
   const char *end_ptr= lip->get_cpp_ptr(); /* shortcut */
+  my_MD5_CTX context;
+  uchar digest[16];
 
   /* Make the string of parameters. */
 
@@ -667,6 +720,17 @@ sp_head::set_stmt_end(THD *thd)
   m_defstr.length= end_ptr - lip->get_cpp_buf();
   m_defstr.str= thd->strmake(lip->get_cpp_buf(), m_defstr.length);
   trim_whitespace(thd->charset(), & m_defstr);
+
+  my_MD5Init(&context);
+  my_MD5Update(&context,(uchar *) m_defstr.str, m_defstr.length);
+  my_MD5Final(digest, &context);
+
+  sprintf(m_md5_value,
+          "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+          digest[0], digest[1], digest[2], digest[3],
+          digest[4], digest[5], digest[6], digest[7],
+          digest[8], digest[9], digest[10], digest[11],
+          digest[12], digest[13], digest[14], digest[15]);
 }
 
 
diff -Nrup a/sql/sp_head.h b/sql/sp_head.h
--- a/sql/sp_head.h	2008-01-23 15:36:39 -07:00
+++ b/sql/sp_head.h	2008-02-05 16:44:09 -07:00
@@ -194,6 +194,14 @@ public:
   LEX_STRING m_defstr;
   LEX_STRING m_definer_user;
   LEX_STRING m_definer_host;
+  char m_md5_value[33];
+
+  int make_object_version(Object_version * version);
+  static int make_object_null_version(
+    Object_version * version,
+    int type,
+    const LEX_STRING& db,
+    const LEX_STRING& name);
 
 private:
   Stored_program_creation_ctx *m_creation_ctx;
diff -Nrup a/sql/sql_base.cc b/sql/sql_base.cc
--- a/sql/sql_base.cc	2008-01-19 12:32:43 -07:00
+++ b/sql/sql_base.cc	2008-02-05 16:44:10 -07:00
@@ -2566,7 +2566,7 @@ bool check_if_table_exists(THD *thd, TAB
 
 
 TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
-		  bool *refresh, uint flags)
+                  bool *refresh, bool *invalidated, uint flags)
 {
   reg1	TABLE *table;
   char	key[MAX_DBKEY_LENGTH];
@@ -2578,9 +2578,12 @@ TABLE *open_table(THD *thd, TABLE_LIST *
   /* Parsing of partitioning information from .frm needs thd->lex set up. */
   DBUG_ASSERT(thd->lex->is_lex_started);
 
+  DBUG_ASSERT(refresh);
+  DBUG_ASSERT(invalidated);
+  *invalidated= FALSE;
+
   /* find a unused table in the open table cache */
-  if (refresh)
-    *refresh=0;
+  *refresh=0;
 
   /* an open table operation needs a lot of the stack space */
   if (check_stack_overrun(thd, STACK_MIN_SIZE_FOR_OPEN, (uchar *)&alias))
@@ -2621,7 +2624,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
                       (ulong) table->query_id, (uint) thd->server_id,
                       (ulong) thd->variables.pseudo_thread_id));
 	  my_error(ER_CANT_REOPEN_TABLE, MYF(0), table->alias);
-	  DBUG_RETURN(0);
+          goto end_null;
 	}
 	table->query_id= thd->query_id;
 	thd->thread_specific_used= TRUE;
@@ -2634,7 +2637,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
   if (flags & MYSQL_OPEN_TEMPORARY_ONLY)
   {
     my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->table_name);
-    DBUG_RETURN(0);
+    goto end_null;
   }
 
   /*
@@ -2667,7 +2670,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
           */
           my_error(ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG, MYF(0),
                    table->s->table_name.str);
-          DBUG_RETURN(0);
+          goto end_null;
         }
         /*
           When looking for a usable TABLE, ignore MERGE children, as they
@@ -2742,7 +2745,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
         {
           DBUG_ASSERT(table_list->view != 0);
           VOID(pthread_mutex_unlock(&LOCK_open));
-          DBUG_RETURN(0); // VIEW
+          goto end_null; // VIEW
         }
         VOID(pthread_mutex_unlock(&LOCK_open));
       }
@@ -2758,7 +2761,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
       my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db, table_list->alias);
     else
       my_error(ER_TABLE_NOT_LOCKED, MYF(0), alias);
-    DBUG_RETURN(0);
+    goto end_null;
   }
 
   /*
@@ -2793,10 +2796,9 @@ TABLE *open_table(THD *thd, TABLE_LIST *
            ! (flags & MYSQL_LOCK_IGNORE_FLUSH))
   {
     /* Someone did a refresh while thread was opening tables */
-    if (refresh)
-      *refresh=1;
+    *refresh=1;
     VOID(pthread_mutex_unlock(&LOCK_open));
-    DBUG_RETURN(0);
+    goto end_null;
   }
 
   /*
@@ -2863,7 +2865,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
       {
 	VOID(pthread_mutex_unlock(&LOCK_open));
         my_error(ER_UPDATE_TABLE_USED, MYF(0), table->s->table_name.str);
-        DBUG_RETURN(0);
+        goto end_null;
       }
 
       /*
@@ -2908,9 +2910,8 @@ TABLE *open_table(THD *thd, TABLE_LIST *
         There is a refresh in progress for this table.
         Signal the caller that it has to try again.
       */
-      if (refresh)
-	*refresh=1;
-      DBUG_RETURN(0);
+      *refresh=1;
+      goto end_null;
     }
   }
   if (table)
@@ -2944,7 +2945,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
       if (check_if_table_exists(thd, table_list, &exists))
       {
         VOID(pthread_mutex_unlock(&LOCK_open));
-        DBUG_RETURN(NULL);
+        goto end_null;
       }
 
       if (!exists)
@@ -2955,7 +2956,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
         if (!(table= table_cache_insert_placeholder(thd, key, key_length)))
         {
           VOID(pthread_mutex_unlock(&LOCK_open));
-          DBUG_RETURN(NULL);
+          goto end_null;
         }
         /*
           Link placeholder to the open tables list so it will be automatically
@@ -2966,7 +2967,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
         table->next= thd->open_tables;
         thd->open_tables= table;
         VOID(pthread_mutex_unlock(&LOCK_open));
-        DBUG_RETURN(table);
+        goto end_table;
       }
       /* Table exists. Let us try to open it. */
     }
@@ -2975,7 +2976,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
     if (!(table=(TABLE*) my_malloc(sizeof(*table),MYF(MY_WME))))
     {
       VOID(pthread_mutex_unlock(&LOCK_open));
-      DBUG_RETURN(NULL);
+      goto end_null;
     }
 
     error= open_unireg_entry(thd, table, table_list, alias, key, key_length,
@@ -2984,7 +2985,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
     {
       my_free((uchar*)table, MYF(0));
       VOID(pthread_mutex_unlock(&LOCK_open));
-      DBUG_RETURN(NULL);
+      goto end_null;
     }
     if (table_list->view || error < 0)
     {
@@ -2997,7 +2998,7 @@ TABLE *open_table(THD *thd, TABLE_LIST *
 
       my_free((uchar*)table, MYF(0));
       VOID(pthread_mutex_unlock(&LOCK_open));
-      DBUG_RETURN(0); // VIEW
+      goto end_null; // VIEW
     }
     DBUG_PRINT("info", ("inserting table '%s'.'%s' 0x%lx into the cache",
                         table->s->db.str, table->s->table_name.str,
@@ -3008,11 +3009,16 @@ TABLE *open_table(THD *thd, TABLE_LIST *
   check_unused();				// Debugging call
 
   VOID(pthread_mutex_unlock(&LOCK_open));
-  if (refresh)
-  {
-    table->next=thd->open_tables;		/* Link into simple list */
-    thd->open_tables=table;
-  }
+
+  /*
+    Link into simple list
+    Note that the table is added to the THD open tables,
+    even if it's rejected by the Object_observer later.
+    This is to avoid table leaks.
+  */
+  table->next=thd->open_tables;
+  thd->open_tables=table;
+
   table->reginfo.lock_type=TL_READ;		/* Assume read */
 
  reset:
@@ -3047,7 +3053,33 @@ TABLE *open_table(THD *thd, TABLE_LIST *
   table_list->updatable= 1; // It is not derived table nor non-updatable VIEW
   table->clear_column_bitmaps();
   DBUG_ASSERT(table->key_read == 0);
+
+end_table:
+  if (thd->m_object_observer)
+  {
+    Object_version table_version;
+    table->s->make_object_version(& table_version);
+    if (thd->m_object_observer->notify(thd, & table_version))
+    {
+      *refresh= FALSE;
+      *invalidated= TRUE;
+      DBUG_RETURN(NULL);
+    }
+  }
   DBUG_RETURN(table);
+
+end_null:
+  if (thd->m_object_observer && ! *refresh && ! table_list->view)
+  {
+    Object_version table_version;
+
+    TABLE_SHARE::make_object_null_version(& table_version,
+                                          table_list->db,
+                                          table_list->table_name);
+    if (thd->m_object_observer->notify(thd, & table_version))
+      *invalidated= TRUE;
+  }
+  DBUG_RETURN(NULL);
 }
 
 
@@ -4340,6 +4372,66 @@ bool fix_merge_after_open(TABLE_LIST *ol
 }
 
 
+int recheck_all_views(THD *thd, TABLE_LIST *start)
+{
+  Object_observer *observer;
+  TABLE_LIST *tables;
+  TABLE_LIST dummy;
+  int rc;
+  Object_version view_version;
+
+  observer= thd->m_object_observer;
+
+  if (observer == NULL)
+    return 0;
+
+  /*
+    FIXME: There is no equivalent of sroutines_list for views,
+    so we have to iterate in TABLE_LIST.
+  */
+  for (tables= start; tables; tables= tables->next_global)
+  {
+    if (tables->view)
+    {
+      /*
+        WARNING: [1] and [2] are due to the implementation of views,
+        where the view logical name is found:
+        - sometime in (db, table_name) if the view has not be processed,
+        - sometime in (view_db, view_name) if the view has been processed.
+        See the comments in mysql_make_view()
+      */
+
+      /* [1] mysql_load_view_md5 uses (db, table_name) */
+      dummy.db= tables->view_db.str;
+      dummy.table_name= tables->view_name.str;
+      rc= mysql_load_view_md5(thd, &dummy);
+
+      if (rc == 0)
+      {
+        /* [2] TABLE_LIST::make_object_version uses (view_db, view_name) */
+        LEX fake_lex;
+        dummy.view_db= tables->view_db;
+        dummy.view_name= tables->view_name;
+        dummy.view= & fake_lex;
+        rc= dummy.make_object_version(& view_version);
+      }
+      else
+        rc= TABLE_LIST::make_object_null_version(& view_version,
+                                                 tables->db,
+                                                 tables->table_name);
+
+      if (rc != 0)
+        return 1;
+
+      if (observer->notify(thd, & view_version))
+        return 1;
+    }
+  }
+
+  return 0;
+}
+
+
 /*
   Open all tables in list
 
@@ -4376,6 +4468,7 @@ int open_tables(THD *thd, TABLE_LIST **s
   MEM_ROOT new_frm_mem;
   /* Also used for indicating that prelocking is need */
   TABLE_LIST **query_tables_last_own;
+  bool invalidated;
   bool safe_to_ignore_table;
 
   DBUG_ENTER("open_tables");
@@ -4391,6 +4484,12 @@ int open_tables(THD *thd, TABLE_LIST **s
   query_tables_last_own= 0;
   thd->proc_info="Opening tables";
 
+  if (recheck_all_views(thd, *start))
+  {
+    result= -1;
+    goto err;
+  }
+
   /*
     If we are not already executing prelocked statement and don't have
     statement for which table list for prelocking is already built, let
@@ -4423,6 +4522,14 @@ int open_tables(THD *thd, TABLE_LIST **s
       *start= thd->lex->query_tables;
     }
   }
+  else
+  {
+    if (sp_refresh_routines(thd, thd->lex))
+    {
+      result= -1;
+      goto err;
+    }
+  }
 
   /*
     For every table in the list of tables to open, try to find or open
@@ -4433,6 +4540,7 @@ int open_tables(THD *thd, TABLE_LIST **s
     DBUG_PRINT("tcache", ("opening table: '%s'.'%s'  item: 0x%lx",
                           tables->db, tables->table_name, (long) tables));
 
+    invalidated= FALSE;
     safe_to_ignore_table= FALSE;
 
     /*
@@ -4477,12 +4585,14 @@ int open_tables(THD *thd, TABLE_LIST **s
         */
         Prelock_error_handler prelock_handler;
         thd->push_internal_handler(& prelock_handler);
-        tables->table= open_table(thd, tables, &new_frm_mem, &refresh, flags);
+        tables->table= open_table(thd, tables, &new_frm_mem,
+                                  &refresh, &invalidated, flags);
         thd->pop_internal_handler();
         safe_to_ignore_table= prelock_handler.safely_trapped_errors();
       }
       else
-        tables->table= open_table(thd, tables, &new_frm_mem, &refresh, flags);
+        tables->table= open_table(thd, tables, &new_frm_mem,
+                                  &refresh, &invalidated, flags);
     }
     else
       DBUG_PRINT("tcache", ("referenced table: '%s'.'%s' 0x%lx",
@@ -4493,10 +4603,13 @@ int open_tables(THD *thd, TABLE_LIST **s
     {
       free_root(&new_frm_mem, MYF(MY_KEEP_PREALLOC));
 
+      if (! invalidated)
+      {
+/* TODO: tabulate the code after review */
       if (tables->view)
       {
         /* VIEW placeholder */
-	(*counter)--;
+        (*counter)--;
 
         /*
           tables->next_global list consists of two parts:
@@ -4516,7 +4629,7 @@ int open_tables(THD *thd, TABLE_LIST **s
           call destructor for this LEX.
         */
         hash_free(&tables->view->sroutines);
-	goto process_view_routines;
+        goto process_view_routines;
       }
 
       /*
@@ -4532,7 +4645,7 @@ int open_tables(THD *thd, TABLE_LIST **s
         parent_l->next_global= *parent_l->table->child_last_l;
       }
 
-      if (refresh)				// Refresh in progress
+      if (refresh)                            // Refresh in progress
       {
         /*
           We have met name-locked or old version of table. Now we have
@@ -4551,7 +4664,7 @@ int open_tables(THD *thd, TABLE_LIST **s
         if (query_tables_last_own)
           thd->lex->mark_as_requiring_prelocking(query_tables_last_own);
         close_tables_for_reopen(thd, start);
-	goto restart;
+        goto restart;
       }
 
       if (safe_to_ignore_table)
@@ -4560,6 +4673,7 @@ int open_tables(THD *thd, TABLE_LIST **s
                             tables->db, tables->alias));
         continue;
       }
+      }
 
       result= -1;				// Fatal error
       break;
@@ -4787,13 +4901,15 @@ TABLE *open_ltable(THD *thd, TABLE_LIST 
 {
   TABLE *table;
   bool refresh;
+  bool invalidated;
   DBUG_ENTER("open_ltable");
 
   thd->proc_info="Opening table";
   thd->current_tablenr= 0;
   /* open_ltable can be used only for BASIC TABLEs */
   table_list->required_type= FRMTYPE_TABLE;
-  while (!(table= open_table(thd, table_list, thd->mem_root, &refresh, 0)) &&
+  while (!(table= open_table(thd, table_list, thd->mem_root,
+                             &refresh, &invalidated, 0)) &&
          refresh)
     ;
 
@@ -8676,10 +8792,12 @@ open_system_tables_for_read(THD *thd, TA
   thd->reset_n_backup_open_tables_state(backup);
 
   uint count= 0;
-  bool not_used;
+  bool refresh_not_used;
+  bool invalidated_not_used;
   for (TABLE_LIST *tables= table_list; tables; tables= tables->next_global)
   {
-    TABLE *table= open_table(thd, tables, thd->mem_root, &not_used,
+    TABLE *table= open_table(thd, tables, thd->mem_root,
+                             &refresh_not_used, &invalidated_not_used,
                              MYSQL_LOCK_IGNORE_FLUSH);
     if (!table)
       goto error;
@@ -8699,7 +8817,7 @@ open_system_tables_for_read(THD *thd, TA
       *(ptr++)= tables->table;
 
     thd->lock= mysql_lock_tables(thd, list, count,
-                                 MYSQL_LOCK_IGNORE_FLUSH, &not_used);
+                                 MYSQL_LOCK_IGNORE_FLUSH, &refresh_not_used);
   }
   if (thd->lock)
     DBUG_RETURN(FALSE);
diff -Nrup a/sql/sql_class.cc b/sql/sql_class.cc
--- a/sql/sql_class.cc	2008-01-10 10:44:21 -07:00
+++ b/sql/sql_class.cc	2008-02-05 16:44:10 -07:00
@@ -50,6 +50,251 @@ char empty_c_string[1]= {0};    /* used 
 
 const char * const THD::DEFAULT_WHERE= "field list";
 
+Object_id::Object_id()
+{
+  m_type= NO_OBJECT_TYPE;
+  m_key[0]= '\0';
+  m_key_length= 0;
+}
+
+Object_id::Object_id(const Object_id& oid)
+{
+  m_type= oid.m_type;
+  memcpy(m_key, oid.m_key, sizeof(m_key));
+  m_key_length= oid.m_key_length;
+}
+
+bool Object_id::is_equal(const Object_id& oid) const
+{
+  return ((m_type == oid.m_type) &&
+         (m_key_length == oid.m_key_length) &&
+         (memcmp(m_key, oid.m_key, m_key_length) == 0));
+}
+
+int
+Object_id::set(const Object_id& oid)
+{
+  m_type= oid.m_type;
+  m_key_length= oid.m_key_length;
+  memcpy(m_key, oid.m_key, m_key_length);
+  return 0;
+}
+
+int
+Object_id::set_table(const char* db, const char* name)
+{
+  /* FIXME: Fix TABLE_SHARE::db, TABLE_SHARE::table_name */
+  LEX_STRING lex_db;
+  LEX_STRING lex_name;
+  lex_db.str= (char*) db;
+  lex_db.length= strlen(lex_db.str);
+  lex_name.str= (char*) name;
+  lex_name.length= strlen(lex_name.str);
+
+  return set_table(lex_db, lex_name);
+}
+
+int
+Object_id::set_key(
+  char kind, const LEX_STRING& db, const LEX_STRING& name)
+{
+  DBUG_ASSERT(db.length <= NAME_LEN);
+  DBUG_ASSERT(name.length <= NAME_LEN);
+
+  /* format: <type> <db> . <name> \0 */
+  m_key_length= sprintf(m_key, "%c%.*s.%.*s",
+                        kind,
+                        (int) db.length, db.str,
+                        (int) name.length, name.str);
+  DBUG_ASSERT(m_key_length <= sizeof(m_key));
+
+  return 0;
+}
+
+Version_id::Version_id()
+  : m_kind(NULL_VERSION),
+    m_long_value(0)
+{
+  m_md5_value[0]= 0;
+}
+
+Version_id::Version_id(const Version_id& vid)
+{
+  m_kind= vid.m_kind;
+  switch(m_kind)
+  {
+  case NULL_VERSION:
+    break;
+  case LONG_VERSION_1:
+  case LONG_VERSION_2:
+    m_long_value= vid.m_long_value;
+    break;
+  case MD5_VERSION:
+    memcpy(m_md5_value, vid.m_md5_value, sizeof(m_md5_value));
+    break;
+  }
+}
+
+Version_id::~Version_id()
+{}
+
+bool
+Version_id::is_equal(const Version_id *vid) const
+{
+  if (m_kind != vid->m_kind)
+    return false;
+
+  switch(m_kind)
+  {
+    case NULL_VERSION:
+      return true;
+    case LONG_VERSION_1:
+    case LONG_VERSION_2:
+      return (m_long_value == vid->m_long_value);
+    case MD5_VERSION:
+      return (memcmp(m_md5_value, vid->m_md5_value, sizeof(m_md5_value)) == 0);
+    default:
+      DBUG_ASSERT(false);
+  }
+}
+
+bool
+Version_id::is_null_or_equal(const Version_id *vid) const
+{
+  return is_null() || vid->is_null() || is_equal(vid);
+}
+
+bool
+Version_id::is_null() const
+{
+  return (m_kind == NULL_VERSION);
+}
+
+void
+Version_id::set_null()
+{
+  m_kind= NULL_VERSION;
+}
+
+void
+Version_id::set_long_1(longlong value)
+{
+  m_kind= LONG_VERSION_1;
+  m_long_value= value;
+}
+
+void
+Version_id::set_long_2(longlong value)
+{
+  m_kind= LONG_VERSION_2;
+  m_long_value= value;
+}
+
+void
+Version_id::set_md5(const char* md5)
+{
+  m_kind= MD5_VERSION;
+  memcpy(m_md5_value, md5, sizeof(m_md5_value));
+}
+
+extern "C" uchar*
+get_obj_version_hash_key(const uchar *buff, size_t *length,
+                         my_bool /* unused */)
+{
+  Object_version *over= (Object_version*) buff;
+  return over->m_oid.get_hash_key(length);
+}
+
+void* Object_version::operator new(size_t size, MEM_ROOT* mem_root) throw()
+{
+  void *ptr;
+  DBUG_ENTER("Object_version::operator new");
+  ptr= alloc_root(mem_root, size);
+  DBUG_RETURN(ptr);
+}
+
+void
+Object_version::operator delete(void *ptr, MEM_ROOT* mem_root) throw()
+{
+}
+
+int
+Object_version_collection::init(MEM_ROOT *mem_root)
+{
+  DBUG_ENTER("Object_version_collection::init");
+  int rc;
+
+  DBUG_ASSERT(m_mem_root == NULL);
+  m_mem_root= mem_root;
+
+  rc= hash_init(& m_hash,
+                & my_charset_bin,
+                0,                             /* initial size */
+                0,
+                0,
+                (hash_get_key) get_obj_version_hash_key,
+                NULL,                          /* Nothing to free */
+                MYF(0));
+
+  DBUG_RETURN(rc);
+}
+
+Object_version_collection::~Object_version_collection()
+{
+  if (m_mem_root)
+  {
+    (void) hash_free(& m_hash);
+    m_mem_root= NULL;
+  }
+}
+
+int
+Object_version_collection::add(
+  const Object_id& oid,
+  const Version_id& vid)
+{
+  Object_version *over;
+  size_t hash_key_length;
+  uchar* hash_key;
+
+  DBUG_ENTER("Object_version_collection::add()");
+
+  hash_key= oid.get_hash_key(& hash_key_length);
+  over= (Object_version*) hash_search(& m_hash, hash_key, hash_key_length);
+
+  if (over)
+  {
+    if (! over->m_vid.is_equal(& vid))
+      DBUG_RETURN(1);
+  }
+  else
+  {
+    over= new (m_mem_root) Object_version(oid, vid);
+    if (my_hash_insert(& m_hash, (uchar*) over))
+      DBUG_RETURN(2);
+  }
+
+  DBUG_PRINT("info",("key: %s  length: %d",
+                    hash_key, (int) hash_key_length));
+  DBUG_RETURN(0);
+}
+
+int
+Object_version_collection::find(
+  const Object_id& oid,
+  const Object_version ** over) const
+{
+  Object_version *v;
+  size_t hash_key_length;
+  uchar* hash_key;
+
+  hash_key= oid.get_hash_key(& hash_key_length);
+  v= (Object_version*) hash_search(& m_hash, hash_key, hash_key_length);
+
+  *over= v;
+  return 0;
+}
+
 
 /*****************************************************************************
 ** Instansiate templates
@@ -493,7 +738,8 @@ THD::THD()
    bootstrap(0),
    derived_tables_processing(FALSE),
    spcont(NULL),
-   m_lip(NULL)
+   m_lip(NULL),
+   m_object_observer(NULL)
 {
   ulong tmp;
 
@@ -606,11 +852,7 @@ THD::THD()
 
 void THD::push_internal_handler(Internal_error_handler *handler)
 {
-  /*
-    TODO: The current implementation is limited to 1 handler at a time only.
-    THD and sp_rcontext need to be modified to use a common handler stack.
-  */
-  DBUG_ASSERT(m_internal_handler == NULL);
+  handler->m_next= m_internal_handler;
   m_internal_handler= handler;
 }
 
@@ -618,19 +860,24 @@ void THD::push_internal_handler(Internal
 bool THD::handle_error(uint sql_errno, const char *message,
                        MYSQL_ERROR::enum_warning_level level)
 {
-  if (m_internal_handler)
+  Internal_error_handler *current= m_internal_handler;
+
+  while (current != NULL)
   {
-    return m_internal_handler->handle_error(sql_errno, message, level, this);
+    if (current->handle_error(sql_errno, message, level, this))
+      return TRUE;
+
+    current= current->m_next;
   }
 
-  return FALSE;                                 // 'FALSE', as per coding style
+  return FALSE;
 }
 
 
 void THD::pop_internal_handler()
 {
   DBUG_ASSERT(m_internal_handler != NULL);
-  m_internal_handler= NULL;
+  m_internal_handler= m_internal_handler->m_next;
 }
 
 extern "C"
diff -Nrup a/sql/sql_class.h b/sql/sql_class.h
--- a/sql/sql_class.h	2008-01-19 12:32:43 -07:00
+++ b/sql/sql_class.h	2008-02-05 16:44:10 -07:00
@@ -23,6 +23,224 @@
 #include "log.h"
 #include "rpl_tblmap.h"
 
+#define MD5_CHAR_LENGTH 32
+
+/**
+  The type of a MySQL object.
+*/
+enum Object_type
+{
+  NO_OBJECT_TYPE= 0,
+  /**
+    A table in the general sense: a temporary table,
+    a base table, or a view.
+  */
+  OBJECT_TYPE_TABLE= 1,
+  /** A stored procedure. */
+  OBJECT_TYPE_PROCEDURE= 2,
+  /** A stored function. */
+  OBJECT_TYPE_FUNCTION= 3
+
+  /*
+    TODO: To be extended:
+    - OBJECT_TYPE_TRIGGER,
+    - OBJECT_TYPE_UDF,
+    - OBJECT_TYPE_EVENT,
+    - OBJECT_TYPE_USER,
+    - OBJECT_TYPE_TABLESPACE,
+    - OBJECT_TYPE_PARTITION,
+    etc, as needed.
+  */
+};
+
+/*
+  Format: <type> <NAME> <.> <NAME> <\0>
+*/
+#define MAX_OBJ_ID_KEY_LEN (2*NAME_LEN + 3)
+
+class Object_id
+{
+public:
+  Object_id();
+  Object_id(const Object_id& oid);
+  ~Object_id() {}
+
+  bool is_equal(const Object_id& oid) const;
+
+  Object_type get_type() const
+  { return m_type; }
+
+  int set(const Object_id& oid);
+
+  int set_table(const char* db, const char* name);
+
+  int set_table(const LEX_STRING& db, const LEX_STRING& name)
+  {
+    m_type= OBJECT_TYPE_TABLE;
+    return set_key('T', db, name);
+  }
+
+  int set_procedure(const LEX_STRING& db, const LEX_STRING& name)
+  {
+    m_type= OBJECT_TYPE_PROCEDURE;
+    return set_key('P', db, name);
+  }
+
+  int set_function(const LEX_STRING& db, const LEX_STRING& name)
+  {
+    m_type= OBJECT_TYPE_FUNCTION;
+    return set_key('F', db, name);
+  }
+
+  uchar* get_hash_key(size_t *length) const
+  {
+    *length= m_key_length;
+    return (uchar*) & m_key[0];
+  }
+
+  const char* get_printable_key() const
+  {
+    return & m_key[0];
+  }
+
+private:
+  int set_key(char kind, const LEX_STRING& db, const LEX_STRING& name);
+
+private:
+  Object_type m_type;
+  char m_key[MAX_OBJ_ID_KEY_LEN];
+  uint m_key_length;
+
+private: // Not implemented, use set()
+  Object_id& operator = (const Object_id&);
+};
+
+/**
+  A Version_id identifies a version of a given object.
+  Different objects (TABLE, VIEW, FUNCTION, PROCEDURE, ...)
+  can use version ids of different spaces (MD5, timestamp, counter, ...),
+  so that a Version_id is an heterogeneous type.
+  Versions can be compared for equality, but don't define any order.
+*/
+
+class Version_id
+{
+public:
+  Version_id();
+  Version_id(const Version_id& vid);
+  ~Version_id();
+
+  bool is_null() const;
+  /**
+    Test for equality.
+    Equality is defined by:
+    - having the same namespace
+    - having the same value within that namespace
+  */
+  bool is_equal(const Version_id *vid) const;
+  bool is_null_or_equal(const Version_id *vid) const;
+
+  void set_null();
+
+  void set_long_1(longlong value);
+
+  void set_long_2(longlong value);
+
+  void set_md5(const char* md5);
+
+private:
+  enum kind {
+    NULL_VERSION,
+    LONG_VERSION_1,
+    LONG_VERSION_2,
+    MD5_VERSION
+  };
+
+  kind m_kind;
+  longlong m_long_value;
+  char m_md5_value[MD5_CHAR_LENGTH];
+
+private: // Non implemented
+  Version_id& operator = (const Version_id&);
+};
+
+
+class Object_version
+{
+public:
+  static void* operator new(size_t size, MEM_ROOT* mem_root) throw();
+  static void operator delete(void *ptr, MEM_ROOT* mem_root) throw();
+
+  Object_version()
+  {}
+
+  Object_version(const Object_id& oid, const Version_id& vid)
+   : m_oid(oid), m_vid(vid)
+  {}
+
+  ~Object_version() {}
+
+  Object_id m_oid;
+  Version_id m_vid;
+
+private: // Non implemented
+  Object_version(const Object_version&);
+  Object_version& operator = (const Object_version&);
+};
+
+
+class Object_version_collection
+{
+public:
+  Object_version_collection()
+    : m_mem_root(NULL)
+  {}
+
+  ~Object_version_collection();
+
+  int init(MEM_ROOT *mem_root);
+  int add(const Object_id& oid, const Version_id & vid);
+  int find(const Object_id& oid, const Object_version ** over) const;
+
+private:
+  HASH m_hash;
+  MEM_ROOT *m_mem_root;
+
+private: // Non implemented
+  Object_version_collection(const Object_version_collection&);
+  Object_version_collection& operator=(const Object_version_collection&);
+};
+
+/**
+  Interface class for observers, used to inspect objects referenced
+  by a statement.
+  An Object_observer can inspect existing objects,
+  as well as get notified that some objects used in a statement are missing.
+  Observers can cause the current operation to fail, by returning an error
+  from the notification methods.
+*/
+
+class Object_observer
+{
+protected:
+  Object_observer() {}
+  virtual ~Object_observer() {}
+
+public:
+  /**
+    Notify that an object is used in a statement.
+    @param [in] thd Current thread
+    @param [in] found object version found during open
+    @return An error status
+      @retval 0 Success
+  */
+  virtual int notify(THD *thd, const Object_version *found) = 0;
+
+private: // Non implemented
+  Object_observer(const Object_observer&);
+  Object_observer& operator = (const Object_observer&);
+};
+
 class Relay_log_info;
 
 class Query_log_event;
@@ -402,6 +620,7 @@ typedef struct system_status_var
   ulong filesort_scan_count;
   /* Prepared statements and binary protocol */
   ulong com_stmt_prepare;
+  ulong com_stmt_reprepare;
   ulong com_stmt_execute;
   ulong com_stmt_send_long_data;
   ulong com_stmt_fetch;
@@ -450,7 +669,7 @@ public:
   bool is_backup_arena; /* True if this arena is used for backup. */
 #endif
   /*
-    The states relfects three diffrent life cycles for three
+    The states reflects three different life cycles for three
     different types of statements:
     Prepared statement: INITIALIZED -> PREPARED -> EXECUTED.
     Stored procedure:   INITIALIZED_FOR_SP -> EXECUTED.
@@ -938,7 +1157,10 @@ enum enum_thread_type
 class Internal_error_handler
 {
 protected:
-  Internal_error_handler() {}
+  Internal_error_handler()
+   : m_next(NULL)
+  {}
+
   virtual ~Internal_error_handler() {}
 
 public:
@@ -971,6 +1193,10 @@ public:
                             const char *message,
                             MYSQL_ERROR::enum_warning_level level,
                             THD *thd) = 0;
+
+private:
+  friend class THD;
+  Internal_error_handler *m_next;
 };
 
 
@@ -1674,6 +1900,8 @@ public:
     and may point to invalid memory after that.
   */
   Lex_input_stream *m_lip;
+
+  Object_observer *m_object_observer;
 
 #ifdef WITH_PARTITION_STORAGE_ENGINE
   partition_info *work_part_info;
diff -Nrup a/sql/sql_insert.cc b/sql/sql_insert.cc
--- a/sql/sql_insert.cc	2008-01-24 07:40:13 -07:00
+++ b/sql/sql_insert.cc	2008-02-05 16:44:10 -07:00
@@ -3405,7 +3405,10 @@ static TABLE *create_table_from_items(TH
       }
       else
       {
-        if (!(table= open_table(thd, create_table, thd->mem_root, (bool*) 0,
+        bool refresh_not_used;
+        bool invalidated_not_used;
+        if (!(table= open_table(thd, create_table, thd->mem_root,
+                                &refresh_not_used, &invalidated_not_used,
                                 MYSQL_OPEN_TEMPORARY_ONLY)) &&
             !create_info->table_existed)
         {
diff -Nrup a/sql/sql_prepare.cc b/sql/sql_prepare.cc
--- a/sql/sql_prepare.cc	2007-12-12 08:20:56 -07:00
+++ b/sql/sql_prepare.cc	2008-02-05 16:44:10 -07:00
@@ -91,6 +91,16 @@ When one supplies long data for a placeh
 #include <mysql_com.h>
 #endif
 
+/*
+  FIXME: PROTOTYPING
+  #undef to make sure refactoring alone does not cause regressions
+  #define to test re-prepare itself
+*/
+#define HAVE_VALIDATION
+#define HAVE_RE_PREPARE
+#define HAVE_RSP
+#define HAVE_REBIND
+
 /* A result class used to send cursor rows using the binary protocol. */
 
 class Select_fetch_protocol_binary: public select_send
@@ -109,8 +119,445 @@ public:
 #endif
 };
 
+/**
+  Collect the version number of all the objects seen during PREPARE.
+  The list of object versions recorded is stored with a prepared statement,
+  and is used during EXECUTE to re-validate the statement.
+*/
+class Prepare_observer : public Object_observer
+{
+public:
+  Prepare_observer(Object_version_collection* coll)
+    : m_coll(coll)
+  {}
+
+  virtual ~Prepare_observer() {}
+
+  virtual int notify(THD *thd, const Object_version* found);
+
+
+private:
+  Object_version_collection *m_coll;
+};
+
+/**
+  Enforce that the objects used during EXECUTE are valid.
+  This class enforces integrity constraints, and guarantees that the content
+  of a prepared statement is still valid and can be used to EXECUTE the
+  statement.
+*/
+class Execute_observer : public Object_observer
+{
+public:
+  Execute_observer(Object_version_collection* coll)
+    : m_coll(coll)
+  {}
+
+  virtual ~Execute_observer() {}
+
+  virtual int notify(THD *thd, const Object_version* found);
+
+private:
+  bool is_safe_table_operation(LEX *lex) const;
+  bool is_safe_sp_operation(LEX *lex) const;
+  int notify_table_or_view(THD *thd, const Object_version *found);
+  int notify_function_or_procedure(THD *thd, const Object_version *found);
+
+private:
+  Object_version_collection *m_coll;
+};
+
+class Reprepare_handler: public Internal_error_handler
+{
+public:
+  Reprepare_handler()
+    : m_recoverable_errors(0), m_fatal_errors(0)
+  {}
+
+  virtual ~Reprepare_handler() {}
+
+  virtual bool handle_error(uint sql_errno, const char *message,
+                            MYSQL_ERROR::enum_warning_level level,
+                            THD *thd);
+
+  bool need_reprepare();
+
+private:
+  int m_recoverable_errors;
+  int m_fatal_errors;
+};
+
+bool
+Reprepare_handler::handle_error(uint sql_errno,
+                                const char * /* message */,
+                                MYSQL_ERROR::enum_warning_level /* level */,
+                                THD * /* thd */)
+{
+  if (sql_errno == ER_NEED_REPREPARE)
+  {
+    m_recoverable_errors++;
+  }
+
+  if (m_recoverable_errors)
+#ifdef HAVE_RE_PREPARE
+    return TRUE;
+#else
+    return FALSE;
+#endif
+
+  m_fatal_errors++;
+  return FALSE;
+}
+
+bool
+Reprepare_handler::need_reprepare()
+{
+  return ((m_recoverable_errors > 0) && (m_fatal_errors == 0));
+}
+
+int
+Prepare_observer::notify(THD *thd, const Object_version *found)
+{
+  int rc;
+
+  DBUG_ENTER("Prepare_observer::notify");
+
+  DBUG_PRINT("info", ("key= %s",
+                      found->m_oid.get_printable_key()));
+
+  switch(found->m_oid.get_type())
+  {
+  case OBJECT_TYPE_TABLE:
+  case OBJECT_TYPE_PROCEDURE:
+  case OBJECT_TYPE_FUNCTION:
+    rc= m_coll->add(found->m_oid, found->m_vid);
+  default:
+    rc= 0;
+  }
+
+  DBUG_RETURN(rc);
+}
+
+/**
+  Indicate if DDL performed on a table is safe for a prepared statement.
+  Some statements can be applied to different tables at each execution,
+  and the re-validation code should allow them.
+*/
+bool
+Execute_observer::is_safe_table_operation(LEX *lex) const
+{
+  switch(lex->sql_command)
+  {
+  case SQLCOM_ALTER_TABLE:
+  case SQLCOM_REPAIR:
+  case SQLCOM_ANALYZE:
+  case SQLCOM_OPTIMIZE:
+    return TRUE;
+
+  case SQLCOM_SHOW_CREATE: // safe for tables, not views
+  default:
+    return FALSE;
+  }
+}
+
+/**
+  Indicate if DDL performed on a procedure or function is safe for a
+  prepared statement.
+  Some statements can be applied to different SP/SF at each execution,
+  and the re-validation code should allow them.
+*/
+bool
+Execute_observer::is_safe_sp_operation(LEX *lex) const
+{
+  switch(lex->sql_command)
+  {
+  case SQLCOM_SHOW_CREATE_PROC:
+  case SQLCOM_SHOW_CREATE_FUNC:
+    return TRUE;
+
+  default:
+    return FALSE;
+  }
+}
+
+int
+Execute_observer::notify(THD *thd, const Object_version *found)
+{
+  int rc;
+
+  DBUG_ENTER("Execute_observer::notify()");
+
+  DBUG_PRINT("info", ("key= %s",
+                      found->m_oid.get_printable_key()));
+
+#ifdef HAVE_VALIDATION
+  switch(found->m_oid.get_type())
+  {
+  case OBJECT_TYPE_TABLE:
+    rc= notify_table_or_view(thd, found);
+    break;
+  case OBJECT_TYPE_PROCEDURE:
+  case OBJECT_TYPE_FUNCTION:
+    rc= notify_function_or_procedure(thd, found);
+    break;
+  case NO_OBJECT_TYPE:
+  default:
+    rc= 0;
+    break;
+  }
+#else
+  rc= 0;
+#endif
+
+  DBUG_RETURN(rc);
+}
+
+int
+Execute_observer::notify_table_or_view(THD *thd, const Object_version *found)
+{
+  const Object_version *cached;
+  int rc;
+
+  DBUG_ENTER("Execute_observer::notify_table_or_view");
+
+  rc= m_coll->find(found->m_oid, & cached);
+  if (rc != 0)
+    goto err;
+
+  if (cached)
+  {
+    if (! cached->m_vid.is_equal(& found->m_vid))
+    {
+      if (! is_safe_table_operation(thd->lex))
+      {
+        my_error(ER_NEED_REPREPARE, MYF(0));
+        rc= 1;
+      }
+    }
+  }
+  else
+  {
+    /*
+      Here, the Prepared statement execute code is discovering
+      an object that was never found during the prepare phase.
+      For some statements, the prepare phase does not open and lock
+      tables (which is ok, performances), so that this is a normal case.
+      Example of such statements are:
+      - SHOW COLUMNS FROM <table>
+        --> open the table <table>
+      - INSTALL PLUGIN ... SONAME ...
+        --> open the table mysql.plugin
+      - SHOW CREATE TRIGGER t1_bi
+        --> open the table t1 (that the trigger relates to)
+      - SHOW COLUMNS FROM <view>
+        --> open the view <view>
+      Once a real object (version not null) is found by the first
+      execute(), it's added to the prepared statement internal state.
+      This is to properly detect further DDL changes for these late found
+      dependencies.
+      This is critical, since until Bug#27011 is fixed, the internal
+      state of the statement can contain a copy of view DDL,
+      which needs to be checked for changes later.
+    */
+    if (! found->m_vid.is_null())
+      rc= m_coll->add(found->m_oid, found->m_vid);
+  }
+
+err:
+  DBUG_RETURN(rc);
+}
+
+int
+Execute_observer::notify_function_or_procedure(THD *thd,
+                                               const Object_version *found)
+{
+  const Object_version *cached;
+  int rc;
+
+  DBUG_ENTER("Execute_observer::notify_function_or_procedure");
+
+  rc= m_coll->find(found->m_oid, & cached);
+  if (rc != 0)
+    goto err;
+
+  if (cached)
+  {
+    if (! cached->m_vid.is_equal(& found->m_vid))
+    {
+      if (! is_safe_sp_operation(thd->lex))
+      {
+        /*
+          For these objects, we do require an exact match:
+          - Version_id::is_equal() means that:
+            - either the object did not exist, and still does not exist
+            - or the object existed and is unchanged.
+        */
+        my_error(ER_NEED_REPREPARE, MYF(0));
+        rc= 1;
+      }
+    }
+  }
+  else
+  {
+    rc= m_coll->add(found->m_oid, found->m_vid);
+  }
+
+err:
+  DBUG_RETURN(rc);
+}
+
 /****************************************************************************/
 
+class Prepared_statement;
+
+class Parameter_setter
+{
+public:
+  int set(Prepared_statement *stmt, String *expanded_query);
+
+protected:
+  virtual int set_with_log(Prepared_statement *stmt,
+                           String *expanded_query) = 0;
+  virtual int set_no_log(Prepared_statement *stmt) = 0;
+
+  Parameter_setter()
+  {}
+
+  virtual ~Parameter_setter()
+  {}
+};
+
+static void reset_stmt_params(Prepared_statement *stmt);
+
+class User_vars_parameter_setter: public Parameter_setter
+{
+public:
+  User_vars_parameter_setter(List<LEX_STRING>& varnames)
+    : m_varnames(varnames)
+  {}
+
+  ~User_vars_parameter_setter()
+  {}
+
+protected:
+  virtual int set_with_log(Prepared_statement *stmt,
+                           String *expanded_query);
+  virtual int set_no_log(Prepared_statement *stmt);
+
+private:
+  List<LEX_STRING>& m_varnames;
+};
+
+#ifndef EMBEDDED_LIBRARY
+static bool setup_conversion_functions(Prepared_statement *stmt,
+                                       uchar **data, uchar *data_end);
+
+class Packet_parameter_setter: public Parameter_setter
+{
+public:
+  Packet_parameter_setter(uchar* packet_null_array, uchar* packet_end)
+  : m_packet_null_array(packet_null_array),
+    m_packet_end(packet_end)
+  {}
+
+  ~Packet_parameter_setter()
+  {}
+
+protected:
+  virtual int set_with_log(Prepared_statement *stmt,
+                           String *expanded_query);
+  virtual int set_no_log(Prepared_statement *stmt);
+
+private:
+  uchar* m_packet_null_array;
+  uchar* m_packet_end;
+};
+#endif
+
+#ifdef EMBEDDED_LIBRARY
+class Embedded_parameter_setter: public Parameter_setter
+{
+public:
+  Embedded_parameter_setter()
+  {}
+
+  ~Embedded_parameter_setter()
+  {}
+
+protected:
+  virtual int set_with_log(Prepared_statement *stmt,
+                           String *expanded_query);
+  virtual int set_no_log(Prepared_statement *stmt);
+};
+#endif
+
+/* TODO: Sp_head_parameter_setter, to use sp_head local variables */
+
+class Result_set_processor
+{
+public:
+  virtual bool process(Prepared_statement *stmt,
+                       select_result *result, List<Item> *fields) = 0;
+
+protected:
+  Result_set_processor()
+  {}
+
+  virtual ~Result_set_processor()
+  {}
+};
+
+class Prepare_RS_processor: public Result_set_processor
+{
+protected:
+  Prepare_RS_processor()
+  {}
+
+  ~Prepare_RS_processor()
+  {}
+
+  bool record_metadata(Prepared_statement *stmt, List<Item> *fields);
+};
+
+class Text_RS_processor : public Prepare_RS_processor
+{
+public:
+  Text_RS_processor()
+  {}
+
+  ~Text_RS_processor()
+  {}
+
+  virtual bool process(Prepared_statement *stmt,
+                       select_result *result, List<Item> *fields);
+};
+
+class Binary_RS_processor : public Prepare_RS_processor
+{
+public:
+  Binary_RS_processor()
+  {}
+
+  ~Binary_RS_processor()
+  {}
+
+  virtual bool process(Prepared_statement *stmt,
+                       select_result *result, List<Item> *fields);
+};
+
+class Reprepare_RS_processor : public Result_set_processor
+{
+public:
+  Reprepare_RS_processor()
+  {}
+
+  ~Reprepare_RS_processor()
+  {}
+
+  virtual bool process(Prepared_statement *stmt,
+                       select_result *result, List<Item> *fields);
+};
+
 /**
   @brief Prepared_statement: a statement that can contain placeholders
 */
@@ -131,28 +578,37 @@ public:
   uint last_errno;
   uint flags;
   char last_error[MYSQL_ERRMSG_SIZE];
-#ifndef EMBEDDED_LIBRARY
-  bool (*set_params)(Prepared_statement *st, uchar *data, uchar *data_end,
-                     uchar *read_pos, String *expanded_query);
-#else
-  bool (*set_params_data)(Prepared_statement *st, String *expanded_query);
-#endif
-  bool (*set_params_from_vars)(Prepared_statement *stmt,
-                               List<LEX_STRING>& varnames,
-                               String *expanded_query);
+
 public:
   Prepared_statement(THD *thd_arg, Protocol *protocol_arg);
+  Prepared_statement(Prepared_statement *model);
   virtual ~Prepared_statement();
-  void setup_set_params();
   virtual Query_arena::Type type() const;
   virtual void cleanup_stmt();
   bool set_name(LEX_STRING *name);
   inline void close_cursor() { delete cursor; cursor= 0; }
 
-  bool prepare(const char *packet, uint packet_length);
-  bool execute(String *expanded_query, bool open_cursor);
+  static bool execute_loop(THD *thd, Prepared_statement **stmt_ptr,
+                           Parameter_setter *setter, bool open_cursor);
+
+  bool prepare(Result_set_processor *rsp,
+               const char *packet, uint packet_length);
+  bool reprepare(const char *packet, uint packet_length);
+  bool prep(Result_set_processor *rsp, const char *packet, uint packet_length);
+  bool execute(Parameter_setter *setter, bool open_cursor,
+               bool *need_reprepare);
   /* Destroy this statement */
   bool deallocate();
+
+  bool set_column_count(uint count);
+  bool check_column_count(uint count);
+
+  bool set_column_metadata(uint col, Item* metadata);
+  bool check_column_metadata(uint col, Item* metadata);
+
+  bool clone_state(Prepared_statement *model);
+  bool clone_column_metadata(Send_field *col, Send_field *model);
+
 private:
   /**
     Store the parsed tree of a prepared statement here.
@@ -163,6 +619,20 @@ private:
     SELECT_LEX and other classes).
   */
   MEM_ROOT main_mem_root;
+
+  /**
+    Collection of all objects versions this prepared statement depends on.
+    The prepared statement internal state contains optimizations based on
+    the objects seen during prepare. Should any of the objects listed change
+    between prepare() and execute(), the prepared statement will be declared
+    invalidated (with some exceptions, see Execute_observer).
+  */
+  Object_version_collection m_versions;
+
+  ulong m_sql_mode;
+
+  uint m_column_count;
+  Send_field *m_columns_metadata;
 };
 
 
@@ -767,6 +1237,23 @@ static bool insert_params_with_log(Prepa
   DBUG_RETURN(0);
 }
 
+int Packet_parameter_setter::set_with_log(Prepared_statement *stmt,
+                                          String *expanded_query)
+{
+  uchar *parsed_packet= m_packet_null_array;
+
+  DBUG_ENTER("Packet_parameter_setter::set_with_log");
+
+  if (setup_conversion_functions(stmt, &parsed_packet, m_packet_end) ||
+      insert_params_with_log(stmt, m_packet_null_array, parsed_packet,
+                             m_packet_end, expanded_query))
+  {
+    DBUG_RETURN(1);
+  }
+
+  DBUG_RETURN(0);
+}
+
 
 static bool insert_params(Prepared_statement *stmt, uchar *null_array,
                           uchar *read_pos, uchar *data_end,
@@ -799,6 +1286,20 @@ static bool insert_params(Prepared_state
   DBUG_RETURN(0);
 }
 
+int Packet_parameter_setter::set_no_log(Prepared_statement *stmt)
+{
+  DBUG_ENTER("Packet_parameter_setter::set_no_log");
+  uchar *parsed_packet= m_packet_null_array;
+
+  if (setup_conversion_functions(stmt, &parsed_packet, m_packet_end) ||
+      insert_params(stmt, m_packet_null_array, parsed_packet, m_packet_end, NULL))
+  {
+    DBUG_RETURN(1);
+  }
+
+  DBUG_RETURN(0);
+}
+
 
 static bool setup_conversion_functions(Prepared_statement *stmt,
                                        uchar **data, uchar *data_end)
@@ -883,6 +1384,13 @@ static bool emb_insert_params(Prepared_s
   DBUG_RETURN(0);
 }
 
+int Embedded_parameter_setter::set_no_log(Prepared_statement *stmt)
+{
+  int result;
+  DBUG_ENTER("Embedded_parameter_setter::set_no_log");
+  result= emb_insert_params(stmt, NULL);
+  DBUG_RETURN(result);
+}
 
 static bool emb_insert_params_with_log(Prepared_statement *stmt,
                                        String *query)
@@ -933,6 +1441,15 @@ static bool emb_insert_params_with_log(P
   DBUG_RETURN(0);
 }
 
+int Embedded_parameter_setter::set_with_log(Prepared_statement *stmt,
+                                            String *expanded_query)
+{
+  int result;
+  DBUG_ENTER("Embedded_parameter_setter::set_with_log");
+  result= emb_insert_params_with_log(stmt, expanded_query);
+  DBUG_RETURN(result);
+}
+
 #endif /*!EMBEDDED_LIBRARY*/
 
 
@@ -972,6 +1489,13 @@ static bool insert_params_from_vars(Prep
   DBUG_RETURN(0);
 }
 
+int User_vars_parameter_setter::set_no_log(Prepared_statement *stmt)
+{
+  int result;
+  DBUG_ENTER("User_vars_parameter_setter::set_no_log");
+  result= insert_params_from_vars(stmt, m_varnames, NULL);
+  DBUG_RETURN(result);
+}
 
 /*
   Do the same as insert_params_from_vars but also construct query text for
@@ -1032,6 +1556,15 @@ static bool insert_params_from_vars_with
   DBUG_RETURN(0);
 }
 
+int User_vars_parameter_setter::set_with_log(Prepared_statement *stmt,
+                                             String *expanded_query)
+{
+  int result;
+  DBUG_ENTER("User_vars_parameter_setter::set_with_log");
+  result= insert_params_from_vars_with_log(stmt, m_varnames, expanded_query);
+  DBUG_RETURN(result);
+}
+
 /*
   Validate INSERT statement.
 
@@ -1260,6 +1793,7 @@ error:
 */
 
 static int mysql_test_select(Prepared_statement *stmt,
+                             Result_set_processor *rsp,
                              TABLE_LIST *tables, bool text_protocol)
 {
   THD *thd= stmt->thd;
@@ -1296,6 +1830,8 @@ static int mysql_test_select(Prepared_st
   */
   if (unit->prepare(thd, 0, 0))
     goto error;
+
+#ifndef HAVE_RSP
   if (!lex->describe && !text_protocol)
   {
     /* Make copy of item list, as change_columns may change it */
@@ -1306,7 +1842,7 @@ static int mysql_test_select(Prepared_st
       goto error;
 
     /*
-      We can use lex->result as it should've been prepared in
+      We can use lex->result as it should have been prepared in
       unit->prepare call above.
     */
     if (send_prep_stmt(stmt, lex->result->field_count(fields)) ||
@@ -1315,6 +1851,28 @@ static int mysql_test_select(Prepared_st
       goto error;
     DBUG_RETURN(2);
   }
+#endif
+
+#ifdef HAVE_RSP
+  if (!lex->describe)
+  {
+    /* Make copy of item list, as change_columns may change it */
+    List<Item> fields(lex->select_lex.item_list);
+
+    /* Change columns if a procedure like analyse() */
+    if (unit->last_procedure && unit->last_procedure->change_columns(fields))
+      goto error;
+
+    /*
+      We can use lex->result as it should have been prepared in
+      unit->prepare call above.
+    */
+    if (rsp->process(stmt, lex->result, &fields))
+      goto error;
+    DBUG_RETURN(2);
+  }
+#endif
+
   DBUG_RETURN(0);
 error:
   DBUG_RETURN(1);
@@ -1514,7 +2072,7 @@ static bool mysql_test_create_table(Prep
     res= select_like_stmt_test(stmt, 0, 0);
   }
 
-  /* put tables back for PS rexecuting */
+  /* put tables back for PS re-executing */
   lex->link_first_table_back(create_table, link_to_local);
   DBUG_RETURN(res);
 }
@@ -1679,9 +2237,12 @@ static bool mysql_test_insert_select(Pre
 */
 
 static bool check_prepared_statement(Prepared_statement *stmt,
+                                     Result_set_processor *rsp,
                                      bool text_protocol)
 {
+#ifndef HAVE_RSP
   THD *thd= stmt->thd;
+#endif
   LEX *lex= stmt->lex;
   SELECT_LEX *select_lex= &lex->select_lex;
   TABLE_LIST *tables;
@@ -1722,7 +2283,7 @@ static bool check_prepared_statement(Pre
     break;
 
   case SQLCOM_SELECT:
-    res= mysql_test_select(stmt, tables, text_protocol);
+    res= mysql_test_select(stmt, rsp, tables, text_protocol);
     if (res == 2)
     {
       /* Statement and field info has already been sent */
@@ -1835,9 +2396,18 @@ static bool check_prepared_statement(Pre
     }
     break;
   }
+
+#ifndef HAVE_RSP
   if (res == 0)
     DBUG_RETURN(text_protocol? FALSE : (send_prep_stmt(stmt, 0) ||
                                         thd->protocol->flush()));
+#endif
+
+#ifdef HAVE_RSP
+  if (res == 0)
+    DBUG_RETURN(rsp->process(stmt, NULL, NULL));
+#endif
+
 error:
   DBUG_RETURN(TRUE);
 }
@@ -1909,6 +2479,7 @@ static bool init_param_array(Prepared_st
 
 void mysql_stmt_prepare(THD *thd, const char *packet, uint packet_length)
 {
+  Binary_RS_processor rsp;
   Prepared_statement *stmt;
   bool error;
   DBUG_ENTER("mysql_stmt_prepare");
@@ -1938,7 +2509,7 @@ void mysql_stmt_prepare(THD *thd, const 
   if (!(specialflag & SPECIAL_NO_PRIOR))
     my_pthread_setprio(pthread_self(),QUERY_PRIOR);
 
-  error= stmt->prepare(packet, packet_length);
+  error= stmt->prepare(&rsp, packet, packet_length);
 
   if (!(specialflag & SPECIAL_NO_PRIOR))
     my_pthread_setprio(pthread_self(),WAIT_PRIOR);
@@ -2077,6 +2648,7 @@ static void init_stmt_after_parse(LEX *l
 
 void mysql_sql_stmt_prepare(THD *thd)
 {
+  Text_RS_processor rsp;
   LEX *lex= thd->lex;
   LEX_STRING *name= &lex->prepared_stmt_name;
   Prepared_statement *stmt;
@@ -2115,7 +2687,7 @@ void mysql_sql_stmt_prepare(THD *thd)
     DBUG_VOID_RETURN;
   }
 
-  if (stmt->prepare(query, query_len))
+  if (stmt->prepare(&rsp, query, query_len))
   {
     /* Statement map deletes the statement on erase */
     thd->stmt_map.erase(stmt);
@@ -2275,8 +2847,6 @@ void mysql_stmt_execute(THD *thd, char *
   uchar *packet= (uchar*)packet_arg; // GCC 4.0.1 workaround
   ulong stmt_id= uint4korr(packet);
   ulong flags= (ulong) packet[4];
-  /* Query text for binary, general or slow log, if any of them is open */
-  String expanded_query;
 #ifndef EMBEDDED_LIBRARY
   uchar *packet_end= packet + packet_length;
 #endif
@@ -2298,24 +2868,6 @@ void mysql_stmt_execute(THD *thd, char *
   sp_cache_flush_obsolete(&thd->sp_proc_cache);
   sp_cache_flush_obsolete(&thd->sp_func_cache);
 
-#ifndef EMBEDDED_LIBRARY
-  if (stmt->param_count)
-  {
-    uchar *null_array= packet;
-    if (setup_conversion_functions(stmt, &packet, packet_end) ||
-        stmt->set_params(stmt, null_array, packet, packet_end,
-                         &expanded_query))
-      goto set_params_data_err;
-  }
-#else
-  /*
-    In embedded library we re-install conversion routines each time
-    we set params, and also we don't need to parse packet.
-    So we do it in one function.
-  */
-  if (stmt->param_count && stmt->set_params_data(stmt, &expanded_query))
-    goto set_params_data_err;
-#endif
   if (!(specialflag & SPECIAL_NO_PRIOR))
     my_pthread_setprio(pthread_self(),QUERY_PRIOR);
 
@@ -2326,16 +2878,18 @@ void mysql_stmt_execute(THD *thd, char *
   */
   DBUG_ASSERT(thd->free_list == NULL);
 
-  error= stmt->execute(&expanded_query,
-                       test(flags & (ulong) CURSOR_TYPE_READ_ONLY));
+#ifndef EMBEDDED_LIBRARY
+  Packet_parameter_setter setter(packet, packet_end);
+#else
+  Embedded_parameter_setter setter;
+#endif
+
+  bool open_cursor= test(flags & (ulong) CURSOR_TYPE_READ_ONLY);
+  error= Prepared_statement::execute_loop(thd, &stmt, &setter, open_cursor);
+
   if (!(specialflag & SPECIAL_NO_PRIOR))
     my_pthread_setprio(pthread_self(), WAIT_PRIOR);
   DBUG_VOID_RETURN;
-
-set_params_data_err:
-  my_error(ER_WRONG_ARGUMENTS, MYF(0), "mysql_stmt_execute");
-  reset_stmt_params(stmt);
-  DBUG_VOID_RETURN;
 }
 
 
@@ -2364,8 +2918,6 @@ void mysql_sql_stmt_execute(THD *thd)
   LEX *lex= thd->lex;
   Prepared_statement *stmt;
   LEX_STRING *name= &lex->prepared_stmt_name;
-  /* Query text for binary, general or slow log, if any of them is open */
-  String expanded_query;
   DBUG_ENTER("mysql_sql_stmt_execute");
   DBUG_PRINT("info", ("EXECUTE: %.*s\n", (int) name->length, name->str));
 
@@ -2391,17 +2943,9 @@ void mysql_sql_stmt_execute(THD *thd)
   */
   DBUG_ASSERT(thd->free_list == NULL);
 
-  if (stmt->set_params_from_vars(stmt, lex->prepared_stmt_params,
-                                 &expanded_query))
-    goto set_params_data_err;
+  User_vars_parameter_setter setter(lex->prepared_stmt_params);
+  (void) Prepared_statement::execute_loop(thd, &stmt, &setter, FALSE);
 
-  (void) stmt->execute(&expanded_query, FALSE);
-
-  DBUG_VOID_RETURN;
-
-set_params_data_err:
-  my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE");
-  reset_stmt_params(stmt);
   DBUG_VOID_RETURN;
 }
 
@@ -2706,47 +3250,55 @@ Prepared_statement::Prepared_statement(T
   param_array(0),
   param_count(0),
   last_errno(0),
-  flags((uint) IS_IN_USE)
+  flags((uint) IS_IN_USE),
+  m_versions(),
+  m_column_count(0),
+  m_columns_metadata(NULL)
 {
   init_sql_alloc(&main_mem_root, thd_arg->variables.query_alloc_block_size,
                   thd_arg->variables.query_prealloc_size);
   *last_error= '\0';
 }
 
+Prepared_statement::Prepared_statement(Prepared_statement *model)
+  :Statement(&main_lex, &main_mem_root,
+             INITIALIZED, model->id),
+  thd(model->thd),
+  result(model->thd),
+  protocol(model->protocol),
+  param_array(0),
+  param_count(0),
+  last_errno(0),
+  flags((uint) IS_IN_USE),
+  m_versions(),
+  m_column_count(0),
+  m_columns_metadata(NULL)
+{
+  init_sql_alloc(&main_mem_root, thd->variables.query_alloc_block_size,
+                  thd->variables.query_prealloc_size);
+  *last_error= '\0';
+}
 
-void Prepared_statement::setup_set_params()
+int
+Parameter_setter::set(Prepared_statement *stmt, String *expanded_query)
 {
-  /*
-    Note: BUG#25843 applies here too (query cache lookup uses thd->db, not
-    db from "prepare" time).
-  */
-  if (query_cache_maybe_disabled(thd)) // we won't expand the query
-    lex->safe_to_cache_query= FALSE;   // so don't cache it at Execution
+  LEX *lex= stmt->lex;
+  THD *thd= stmt->thd;
+
+  if (stmt->param_count == 0)
+    return 0;
 
   /*
     Decide if we have to expand the query (because we must write it to logs or
     because we want to look it up in the query cache) or not.
   */
-  if (mysql_bin_log.is_open() && is_update_query(lex->sql_command) ||
+  if ((mysql_bin_log.is_open() && is_update_query(lex->sql_command)) ||
       opt_log || opt_slow_log ||
-      query_cache_is_cacheable_query(lex))
-  {
-    set_params_from_vars= insert_params_from_vars_with_log;
-#ifndef EMBEDDED_LIBRARY
-    set_params= insert_params_with_log;
-#else
-    set_params_data= emb_insert_params_with_log;
-#endif
-  }
-  else
-  {
-    set_params_from_vars= insert_params_from_vars;
-#ifndef EMBEDDED_LIBRARY
-    set_params= insert_params;
-#else
-    set_params_data= emb_insert_params;
-#endif
-  }
+      (query_cache_is_cacheable_query(lex) &&
+       ! query_cache_maybe_disabled(thd)))
+    return set_with_log(stmt, expanded_query);
+
+  return set_no_log(stmt);
 }
 
 
@@ -2812,6 +3364,88 @@ bool Prepared_statement::set_name(LEX_ST
   global THD state management to the caller.
 ***************************************************************************/
 
+bool Prepared_statement::prepare(Result_set_processor *rsp,
+                                 const char *packet, uint packet_len)
+{
+  bool error;
+  DBUG_ENTER("Prepared_statement::prepare");
+
+  /*
+    If this is an SQLCOM_PREPARE, we also increase Com_prepare_sql.
+    However, it seems handy if com_stmt_prepare is increased always,
+    no matter what kind of prepare is processed.
+  */
+  status_var_increment(thd->status_var.com_stmt_prepare);
+
+  /* Remember the current database. */
+
+  if (thd->db && thd->db_length)
+  {
+    db= this->strmake(thd->db, thd->db_length);
+    db_length= thd->db_length;
+  }
+  else
+  {
+    db= NULL;
+    db_length= 0;
+  }
+
+  /* Remember the SQL_MODE */
+
+  m_sql_mode= thd->variables.sql_mode;
+
+  error= prep(rsp, packet, packet_len);
+  DBUG_RETURN(error);
+}
+
+bool Prepared_statement::reprepare(const char *packet, uint packet_len)
+{
+  Reprepare_RS_processor rsp;
+  bool error;
+  char saved_cur_db_name_buf[NAME_LEN+1];
+  LEX_STRING saved_cur_db_name=
+    { saved_cur_db_name_buf, sizeof(saved_cur_db_name_buf) };
+  bool cur_db_changed;
+  LEX_STRING stmt_db_name= { db, db_length };
+  ulong save_sql_mode;
+
+  DBUG_ENTER("Prepared_statement::reprepare");
+
+  status_var_increment(thd->status_var.com_stmt_reprepare);
+
+  /*
+    Save the current database,
+    set the database active during PREPARE as current.
+  */
+
+  if (mysql_opt_change_db(thd, &stmt_db_name, &saved_cur_db_name, TRUE,
+                          &cur_db_changed))
+    DBUG_RETURN(TRUE);
+
+  /*
+    Save the current SQL_MODE,
+    set the SQL_MODE active during PREPARE as current.
+  */
+  save_sql_mode= thd->variables.sql_mode;
+  thd->variables.sql_mode= m_sql_mode;
+
+  error= prep(& rsp, packet, packet_len);
+
+  /*
+    Restore the current database.
+  */
+
+  if (cur_db_changed)
+    mysql_change_db(thd, &saved_cur_db_name, TRUE);
+
+  /*
+    Restore the current SQL_MODE.
+  */
+  thd->variables.sql_mode= save_sql_mode;
+
+  DBUG_RETURN(error);
+}
+
 /*
   Parse statement text, validate the statement, and prepare it for execution.
 
@@ -2837,18 +3471,16 @@ bool Prepared_statement::set_name(LEX_ST
     thd->mem_root contains unused memory allocated during validation.
 */
 
-bool Prepared_statement::prepare(const char *packet, uint packet_len)
+bool Prepared_statement::prep(Result_set_processor *rsp,
+                              const char *packet, uint packet_len)
 {
   bool error;
   Statement stmt_backup;
   Query_arena *old_stmt_arena;
-  DBUG_ENTER("Prepared_statement::prepare");
-  /*
-    If this is an SQLCOM_PREPARE, we also increase Com_prepare_sql.
-    However, it seems handy if com_stmt_prepare is increased always,
-    no matter what kind of prepare is processed.
-  */
-  status_var_increment(thd->status_var.com_stmt_prepare);
+  DBUG_ENTER("Prepared_statement::prep");
+
+  if (m_versions.init(& main_mem_root))
+    DBUG_RETURN(TRUE);
 
   /*
     alloc_query() uses thd->memroot && thd->query, so we should call
@@ -2871,6 +3503,8 @@ bool Prepared_statement::prepare(const c
   lip.stmt_prepare_mode= TRUE;
   lex_start(thd);
 
+  DBUG_ASSERT(thd->lex == & main_lex);
+
   error= parse_sql(thd, &lip, NULL) ||
          thd->is_error() ||
          init_param_array(this);
@@ -2906,6 +3540,10 @@ bool Prepared_statement::prepare(const c
   */
   DBUG_ASSERT(thd->change_list.is_empty());
 
+  Prepare_observer observer(& m_versions);
+  Object_observer *save_observer= thd->m_object_observer;
+  thd->m_object_observer= & observer;
+
   /* 
    The only case where we should have items in the thd->free_list is
    after stmt->set_params_from_vars(), which may in some cases create
@@ -2913,7 +3551,9 @@ bool Prepared_statement::prepare(const c
   */
 
   if (error == 0)
-    error= check_prepared_statement(this, name.str != 0);
+    error= check_prepared_statement(this, rsp, name.str != 0);
+
+  thd->m_object_observer= save_observer;
 
   /*
     Currently CREATE PROCEDURE/TRIGGER/EVENT are prohibited in prepared
@@ -2934,7 +3574,6 @@ bool Prepared_statement::prepare(const c
 
   if (error == 0)
   {
-    setup_set_params();
     init_stmt_after_parse(lex);
     state= Query_arena::PREPARED;
     flags&= ~ (uint) IS_IN_USE;
@@ -2960,6 +3599,58 @@ bool Prepared_statement::prepare(const c
   DBUG_RETURN(error);
 }
 
+bool Prepared_statement::execute_loop(THD *thd,
+                                      Prepared_statement **stmt_ptr,
+                                      Parameter_setter *setter,
+                                      bool open_cursor)
+{
+  int count= 0;
+  Prepared_statement *stmt1= *stmt_ptr;
+#ifndef HAVE_RE_PREPARE
+  bool dummy;
+  return stmt1->execute(setter, open_cursor, & dummy);
+#else
+  bool need_reprepare;
+  bool error;
+  Prepared_statement *stmt2;
+
+  error= stmt1->execute(setter, open_cursor, & need_reprepare);
+
+  while (error && need_reprepare && thd->killed == THD::NOT_KILLED)
+  {
+    count++;
+    DBUG_ASSERT(count <= 100); // FIXME, debugging
+
+    thd->clear_error();
+    need_reprepare= FALSE;
+
+    stmt2= new Prepared_statement(stmt1);
+    if (stmt2)
+    {
+      error= stmt2->clone_state(stmt1);
+      if (! error)
+      {
+        error= stmt2->reprepare(stmt1->query, stmt1->query_length);
+        if (! error)
+        {
+          error= stmt2->execute(setter, open_cursor, & need_reprepare);
+          if (! error)
+          {
+            /* Destroys stmt1 */
+            thd->stmt_map.insert(thd, stmt2);
+            *stmt_ptr= stmt2;
+          }
+        }
+      }
+    }
+    else
+      error= TRUE;
+  }
+
+  return error;
+#endif
+}
+
 /*
   Execute a prepared statement.
 
@@ -2985,11 +3676,15 @@ bool Prepared_statement::prepare(const c
     TRUE		Error
 */
 
-bool Prepared_statement::execute(String *expanded_query, bool open_cursor)
+bool Prepared_statement::execute(Parameter_setter *setter, bool open_cursor,
+                                 bool *need_reprepare)
 {
   Statement stmt_backup;
   Query_arena *old_stmt_arena;
   bool error= TRUE;
+  /* Query text for binary, general or slow log, if any of them is open */
+  String expanded_query;
+  Reprepare_handler reprepare;
 
   char saved_cur_db_name_buf[NAME_LEN+1];
   LEX_STRING saved_cur_db_name=
@@ -3000,6 +3695,15 @@ bool Prepared_statement::execute(String 
 
   status_var_increment(thd->status_var.com_stmt_execute);
 
+  *need_reprepare= FALSE;
+
+  if (setter->set(this, &expanded_query))
+  {
+    my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE");
+    reset_stmt_params(this);
+    goto error;
+  }
+
   /* Check if we got an error when sending long data */
   if (state == Query_arena::ERROR)
   {
@@ -3061,11 +3765,11 @@ bool Prepared_statement::execute(String 
 
   /* Allocate query. */
 
-  if (expanded_query->length() &&
-      alloc_query(thd, (char*) expanded_query->ptr(),
-                  expanded_query->length()))
+  if (expanded_query.length() &&
+      alloc_query(thd, (char*) expanded_query.ptr(),
+                  expanded_query.length()))
   {
-    my_error(ER_OUTOFMEMORY, 0, expanded_query->length());
+    my_error(ER_OUTOFMEMORY, 0, expanded_query.length());
     goto error;
   }
   /*
@@ -3091,11 +3795,16 @@ bool Prepared_statement::execute(String 
 
   /* Go! */
 
+  DBUG_ASSERT(thd->lex == & main_lex);
+
   if (open_cursor)
     error= mysql_open_cursor(thd, (uint) ALWAYS_MATERIALIZED_CURSOR,
                              &result, &cursor);
   else
   {
+    /* Assumption in query_cache_send_result_to_client() */
+    DBUG_ASSERT(thd->lex == this->lex);
+
     /*
       Try to find it in the query cache, if not, execute it.
       Note that multi-statements cannot exist here (they are not supported in
@@ -3104,7 +3813,16 @@ bool Prepared_statement::execute(String 
     if (query_cache_send_result_to_client(thd, thd->query,
                                           thd->query_length) <= 0)
     {
+      Execute_observer observer(& m_versions);
+      Object_observer *save_observer= thd->m_object_observer;
+      thd->m_object_observer= & observer;
+      thd->push_internal_handler(& reprepare);
+
       error= mysql_execute_command(thd);
+
+      thd->pop_internal_handler();
+      thd->m_object_observer= save_observer;
+      *need_reprepare= reprepare.need_reprepare();
     }
   }
 
@@ -3156,6 +3874,9 @@ bool Prepared_statement::execute(String 
 
 error:
   flags&= ~ (uint) IS_IN_USE;
+
+  /* If we need re prepare, an error should be returned. */
+  DBUG_ASSERT(! *need_reprepare || error);
   return error;
 }
 
@@ -3175,3 +3896,228 @@ bool Prepared_statement::deallocate()
   thd->stmt_map.erase(this);
   return FALSE;
 }
+
+bool Prepared_statement::set_column_count(uint count)
+{
+  DBUG_ASSERT(m_column_count == 0);
+  DBUG_ASSERT(m_columns_metadata == NULL);
+
+  m_column_count= count;
+  if (count)
+  {
+    size_t size= m_column_count * sizeof(Send_field);
+    m_columns_metadata= (Send_field *)
+                        alloc_root(&main_mem_root, size);
+
+    if (m_columns_metadata == NULL)
+      return TRUE;
+
+    memset(m_columns_metadata, 0, size);
+  }
+
+  return FALSE;
+}
+
+bool Prepared_statement::set_column_metadata(uint col, Item* item)
+{
+  DBUG_ASSERT(col < m_column_count);
+
+  Send_field *column= &m_columns_metadata[col];
+
+  Send_field dummy;
+  item->make_field(& dummy);
+
+  return clone_column_metadata(column, &dummy);
+}
+
+bool Prepared_statement::clone_state(Prepared_statement *model)
+{
+  /* Copy the name */
+
+  if (model->name.str)
+  {
+    name.str= (char*) memdup_root(&main_mem_root,
+                                  model->name.str,
+                                  model->name.length);
+    if (name.str == NULL)
+      return TRUE;
+    name.length= model->name.length;
+  }
+
+  /* Copy the current database */
+
+  db_length= model->db_length;
+  if (db_length)
+  {
+    db= (char*) memdup_root(&main_mem_root, model->db, db_length);
+    if (db == NULL)
+      return TRUE;
+  }
+  else
+    db= NULL;
+
+  /* Copy the SQL_MODE */
+
+  m_sql_mode= model->m_sql_mode;
+
+  /* Copy the result set metadata */
+
+  m_column_count= model->m_column_count;
+
+  if (m_column_count)
+  {
+    uint col;
+    size_t size= m_column_count * sizeof(Send_field);
+    m_columns_metadata= (Send_field *)
+                        alloc_root(&main_mem_root, size);
+
+    if (m_columns_metadata == NULL)
+      return TRUE;
+
+    for (col=0; col < m_column_count; col++)
+    {
+      if (clone_column_metadata(& m_columns_metadata[col],
+                                & model->m_columns_metadata[col]))
+        return TRUE;
+    }
+  }
+
+  return FALSE;
+}
+
+bool Prepared_statement::clone_column_metadata(Send_field *col,
+                                               Send_field *model)
+{
+  col->db_name= strdup_root(&main_mem_root, model->db_name);
+  col->table_name= strdup_root(&main_mem_root, model->table_name);
+  col->org_table_name= strdup_root(&main_mem_root, model->org_table_name);
+  col->col_name= strdup_root(&main_mem_root, model->col_name);
+  col->org_col_name= strdup_root(&main_mem_root, model->org_col_name);
+  col->length= model->length;
+  col->charsetnr= model->charsetnr;
+  col->flags= model->flags;
+  col->decimals= model->decimals;
+  col->type= model->type;
+
+  return FALSE;
+}
+
+bool Prepare_RS_processor::record_metadata(Prepared_statement *stmt,
+                                           List<Item> *fields)
+{
+  if (fields == NULL)
+    return stmt->set_column_count(0);
+
+  uint col;
+  uint columns= fields->elements;
+  List_iterator<Item> iter(*fields);
+
+  if (stmt->set_column_count(columns))
+    return TRUE;
+
+  for (col= 0; col < columns; col++)
+  {
+    if (stmt->set_column_metadata(col, iter++))
+      return TRUE;
+  }
+
+  return FALSE;
+}
+
+bool Text_RS_processor::process(Prepared_statement *stmt,
+                                select_result *result, List<Item> *fields)
+{
+  return record_metadata(stmt, fields);
+}
+
+bool Binary_RS_processor::process(Prepared_statement *stmt,
+                                  select_result *result, List<Item> *fields)
+{
+  if (record_metadata(stmt, fields))
+    return TRUE;
+
+  if (result && fields)
+  {
+    uint columns= result->field_count(*fields);
+    return (send_prep_stmt(stmt, columns) ||
+            result->send_fields(*fields, Protocol::SEND_EOF) ||
+            stmt->thd->protocol->flush());
+  }
+
+  return (send_prep_stmt(stmt, 0) ||
+          stmt->thd->protocol->flush());
+}
+
+bool Prepared_statement::check_column_count(uint count)
+{
+  if (m_column_count != count)
+  {
+    my_error(ER_PS_REBIND, MYF(0));
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+bool Prepared_statement::check_column_metadata(uint col, Item* item)
+{
+  const uint FLAGS_TO_CHECK= NOT_NULL_FLAG |
+    BLOB_FLAG |
+    UNSIGNED_FLAG |
+    ZEROFILL_FLAG |
+    BINARY_FLAG |
+    ENUM_FLAG |
+    TIMESTAMP_FLAG |
+    SET_FLAG |
+    NUM_FLAG
+    ;
+
+  DBUG_ASSERT(col < m_column_count);
+
+  Send_field *column= &m_columns_metadata[col];
+
+  Send_field dummy;
+  item->make_field(& dummy);
+
+  if ((strcmp(column->db_name, dummy.db_name) != 0) ||
+      (strcmp(column->table_name, dummy.table_name) != 0) ||
+      /* (strcmp(column->org_table_name, dummy.org_table_name) != 0) || */
+      (strcmp(column->col_name, dummy.col_name) != 0) ||
+      /* (strcmp(column->org_col_name, dummy.org_col_name) != 0) || */
+      (column->length != dummy.length) ||
+      (column->charsetnr != dummy.charsetnr) ||
+      ((column->flags & FLAGS_TO_CHECK) != (dummy.flags & FLAGS_TO_CHECK)) ||
+      (column->decimals != dummy.decimals) ||
+      (column->type != dummy.type))
+  {
+    my_error(ER_PS_REBIND, MYF(0));
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+bool Reprepare_RS_processor::process(Prepared_statement *stmt,
+                                     select_result *result, List<Item> *fields)
+{
+#ifdef HAVE_REBIND
+  if (fields == NULL)
+    return stmt->check_column_count(0);
+
+  uint col;
+  uint columns= fields->elements;
+  List_iterator<Item> iter(*fields);
+
+  if (stmt->check_column_count(columns))
+    return TRUE;
+
+  for (col= 0; col < columns; col++)
+  {
+    if (stmt->check_column_metadata(col, iter++))
+      return TRUE;
+  }
+#endif
+
+  return FALSE;
+}
+
diff -Nrup a/sql/sql_table.cc b/sql/sql_table.cc
--- a/sql/sql_table.cc	2008-01-19 12:32:45 -07:00
+++ b/sql/sql_table.cc	2008-02-05 16:44:10 -07:00
@@ -6474,12 +6474,15 @@ view_err:
   {
     if (table->s->tmp_table)
     {
+      bool refresh_not_used;
+      bool invalidated_not_used;
       TABLE_LIST tbl;
       bzero((void*) &tbl, sizeof(tbl));
       tbl.db= new_db;
       tbl.table_name= tbl.alias= tmp_name;
       /* Table is in thd->temporary_tables */
-      new_table= open_table(thd, &tbl, thd->mem_root, (bool*) 0,
+      new_table= open_table(thd, &tbl, thd->mem_root,
+                            &refresh_not_used, &invalidated_not_used,
                             MYSQL_LOCK_IGNORE_FLUSH);
     }
     else
diff -Nrup a/sql/sql_view.cc b/sql/sql_view.cc
--- a/sql/sql_view.cc	2007-10-30 11:08:13 -06:00
+++ b/sql/sql_view.cc	2008-02-05 16:44:10 -07:00
@@ -178,11 +178,14 @@ static bool
 fill_defined_view_parts (THD *thd, TABLE_LIST *view)
 {
   LEX *lex= thd->lex;
-  bool not_used;
+  bool refresh_not_used;
+  bool invalidated_not_used;
   TABLE_LIST decoy;
 
   memcpy (&decoy, view, sizeof (TABLE_LIST));
-  if (!open_table(thd, &decoy, thd->mem_root, &not_used, OPEN_VIEW_NO_PARSE) &&
+  if (!open_table(thd, &decoy, thd->mem_root,
+                  &refresh_not_used, &invalidated_not_used,
+                  OPEN_VIEW_NO_PARSE) &&
       !decoy.view)
   {
     /* It's a table */
@@ -674,6 +677,19 @@ static File_option view_parameters[]=
   FILE_OPTIONS_STRING}
 };
 
+/* Short parsing, only to read MD5 */
+static File_option view_md5_parameters[]=
+{{{ C_STRING_WITH_LEN("query")},
+  my_offsetof(TABLE_LIST, select_stmt),
+  FILE_OPTIONS_ESTRING},
+ {{ C_STRING_WITH_LEN("md5")},
+  my_offsetof(TABLE_LIST, md5),
+  FILE_OPTIONS_STRING},
+ {{NullS, 0},			0,
+  FILE_OPTIONS_STRING}
+};
+
+
 static LEX_STRING view_file_type[]= {{(char*) STRING_WITH_LEN("VIEW") }};
 
 
@@ -944,6 +960,7 @@ bool mysql_make_view(THD *thd, File_pars
     {
       DBUG_RETURN(1);
     }
+
     DBUG_PRINT("info",
                ("VIEW %s.%s is already processed on previous PS/SP execution",
                 table->view_db.str, table->view_name.str));
@@ -1001,6 +1018,26 @@ bool mysql_make_view(THD *thd, File_pars
                     required_view_parameters, &file_parser_dummy_hook))
     goto err;
 
+
+  if (thd->m_object_observer)
+  {
+    Object_version version;
+
+    if (version.m_oid.set_table(table->db, table->table_name))
+    {
+      result= TRUE;
+      goto end;
+    }
+    version.m_vid.set_md5(table->md5.str);
+
+    if (thd->m_object_observer->notify(thd, & version))
+    {
+      result= TRUE;
+      goto end;
+    }
+  }
+
+
   /*
     check old format view .frm
   */
@@ -1440,6 +1477,44 @@ err:
   table->view= 0;	// now it is not VIEW placeholder
   result= 1;
   goto end;
+}
+
+int mysql_load_view_md5(THD *thd, TABLE_LIST *view)
+{
+  int rc;
+  LEX_STRING pathstr;
+  File_parser *parser;
+  char path_buff[FN_REFLEN];
+  TABLE_LIST dummy;
+
+  DBUG_ENTER("mysql_load_view_md5");
+  DBUG_PRINT("info", ("view: (%s.%s)", view->db, view->table_name));
+
+  bzero(& dummy, sizeof(dummy));
+
+  pathstr.str= (char *) path_buff;
+  pathstr.length= build_table_filename(path_buff, sizeof(path_buff) - 1,
+                                       view->db, view->table_name,
+                                       reg_ext, 0);
+
+  parser= sql_parse_prepare(&pathstr, thd->mem_root, 0);
+  if (parser &&
+      parser->ok() &&
+      is_equal(&view_type, parser->type()) &&
+      parser->parse((uchar*) &dummy,
+                    thd->mem_root,
+                    view_md5_parameters,
+                    array_elements(view_md5_parameters)-1,
+                    &file_parser_dummy_hook) == 0)
+  {
+    view->md5.str= dummy.md5.str;
+    view->md5.length= dummy.md5.length;
+    rc= 0;
+  }
+  else
+    rc= 1;
+
+  DBUG_RETURN(rc);
 }
 
 
diff -Nrup a/sql/sql_view.h b/sql/sql_view.h
--- a/sql/sql_view.h	2006-12-23 12:19:56 -07:00
+++ b/sql/sql_view.h	2008-02-05 16:44:11 -07:00
@@ -31,6 +31,8 @@ frm_type_enum mysql_frm_type(THD *thd, c
 
 int view_checksum(THD *thd, TABLE_LIST *view);
 
+int mysql_load_view_md5(THD *thd, TABLE_LIST *view);
+
 extern TYPELIB updatable_views_with_limit_typelib;
 
 bool check_duplicate_names(List<Item>& item_list, bool gen_unique_view_names);
diff -Nrup a/sql/table.cc b/sql/table.cc
--- a/sql/table.cc	2007-12-17 06:28:05 -07:00
+++ b/sql/table.cc	2008-02-05 16:44:11 -07:00
@@ -250,6 +250,41 @@ TABLE_CATEGORY get_table_category(const 
   return TABLE_CATEGORY_USER;
 }
 
+int TABLE_SHARE::make_object_version(Object_version * version)
+{
+  int rc;
+
+  rc= version->m_oid.set_table(db, table_name);
+
+  if ((tmp_table == INTERNAL_TMP_TABLE) ||
+      (tmp_table == NON_TRANSACTIONAL_TMP_TABLE))
+  {
+    /*
+      table_map_id is THD::query_id.
+      The version number is not persistent,
+      but the table is not persistent either,
+      so using table_map_id is ok here.
+    */
+    version->m_vid.set_long_1(table_map_id);
+  }
+  else
+  {
+    version->m_vid.set_long_2(table_map_id);
+  }
+
+  return rc;
+}
+
+int TABLE_SHARE::make_object_null_version(
+  Object_version * version, const char* db, const char* name)
+{
+  int rc;
+
+  rc= version->m_oid.set_table(db, name);
+  version->m_vid.set_null();
+
+  return rc;
+}
 
 /*
   Allocate a setup TABLE_SHARE structure
@@ -2934,6 +2969,28 @@ void st_table::reset_item_list(List<Item
     DBUG_ASSERT(item_field != 0);
     item_field->reset_field(*ptr);
   }
+}
+
+int TABLE_LIST::make_object_version(Object_version * version)
+{
+  int rc;
+
+  DBUG_ASSERT(view);
+  rc= version->m_oid.set_table(view_db, view_name);
+  version->m_vid.set_md5(md5.str);
+
+  return rc;
+}
+
+int TABLE_LIST::make_object_null_version(
+  Object_version * version, const char* db, const char* name)
+{
+  int rc;
+
+  rc= version->m_oid.set_table(db, name);
+  version->m_vid.set_null();
+
+  return rc;
 }
 
 /*
diff -Nrup a/sql/table.h b/sql/table.h
--- a/sql/table.h	2007-12-14 12:46:34 -07:00
+++ b/sql/table.h	2008-02-05 16:44:11 -07:00
@@ -24,6 +24,7 @@ class st_select_lex;
 class partition_info;
 class COND_EQUAL;
 class Security_context;
+class Object_version;
 
 /*************************************************************************/
 
@@ -437,6 +438,9 @@ typedef struct st_table_share
     return table_map_id;
   }
 
+  int make_object_version(Object_version * version);
+  static int make_object_null_version(
+    Object_version * version, const char* db, const char* name);
 } TABLE_SHARE;
 
 
@@ -892,6 +896,10 @@ class Index_hint;
 struct TABLE_LIST
 {
   TABLE_LIST() {}                          /* Remove gcc warning */
+
+  int make_object_version(Object_version * version);
+  static int make_object_null_version(
+    Object_version * version, const char* db, const char* name);
 
   /**
     Prepare TABLE_LIST that consists of one table instance to use in
diff -Nrup a/tests/mysql_client_test.c b/tests/mysql_client_test.c
--- a/tests/mysql_client_test.c	2008-01-10 18:04:30 -07:00
+++ b/tests/mysql_client_test.c	2008-02-05 16:44:11 -07:00
@@ -2475,6 +2475,7 @@ static void test_ps_query_cache()
 
   for (iteration= TEST_QCACHE_ON; iteration <= TEST_QCACHE_ON_OFF; iteration++)
   {
+    fprintf(stdout, "\n Iteration %d", iteration);
 
     switch (iteration)
     {
@@ -2567,10 +2568,10 @@ static void test_ps_query_cache()
     hits2= query_cache_hits(mysql);
     switch(iteration) {
     case TEST_QCACHE_ON_WITH_OTHER_CONN:
+    case TEST_QCACHE_OFF_ON:
     case TEST_QCACHE_ON:                 /* should have hit */
       DIE_UNLESS(hits2-hits1 == 1);
       break;
-    case TEST_QCACHE_OFF_ON:
     case TEST_QCACHE_ON_OFF:             /* should not have hit */
       DIE_UNLESS(hits2-hits1 == 0);
       break;
@@ -2604,15 +2605,13 @@ static void test_ps_query_cache()
     mysql_stmt_close(stmt);
 
     switch(iteration) {
+    case TEST_QCACHE_OFF_ON:
+    case TEST_QCACHE_ON_WITH_OTHER_CONN:
     case TEST_QCACHE_ON:                 /* should have hit */
       DIE_UNLESS(hits2-hits1 == 1);
       break;
-    case TEST_QCACHE_OFF_ON:
     case TEST_QCACHE_ON_OFF:             /* should not have hit */
       DIE_UNLESS(hits2-hits1 == 0);
-      break;
-    case TEST_QCACHE_ON_WITH_OTHER_CONN: /* should have hit */
-      DIE_UNLESS(hits2-hits1 == 1);
       break;
     }
 
Thread
bk commit into 5.1 tree (malff:1.2661) BUG#12093marc.alff6 Feb