summaryrefslogtreecommitdiff
path: root/mysql-test
diff options
context:
space:
mode:
authorOleksandr Byelkin <sanja@mariadb.com>2019-04-17 15:50:59 +0200
committerOleksandr Byelkin <sanja@mariadb.com>2022-01-24 14:41:06 +0100
commit349283c5e7a3a338445140156e866d6ade939edf (patch)
treeee5f87b18649f9b4ac55239bce87826c0f06bc31 /mysql-test
parentecfa9361406f9007af8a808567909a519aa9984b (diff)
downloadmariadb-git-bb-10.2-MDEV-17124.tar.gz
MDEV-17124: mariadb 10.1.34, views and prepared statements: ERROR 1615 (HY000): Prepared statement needs to be re-preparedbb-10.2-MDEV-17124
The problem is that if table definition cache (TDC) is full of real tables which are in tables cache, view definition can not stay there so will be removed by its own underlying tables. In situation above old mechanism of detection matching definition in PS and current version always require reprepare and so prevent executing the PS. One work around is to increase TDC, other - improve version check for views/triggers (which is done here). Now in suspicious cases we check: - timestamp (ms) of the view to be sure that version really have changed; - time (ms) of creation of a trigger related to time (ms) of statement preparation.
Diffstat (limited to 'mysql-test')
-rw-r--r--mysql-test/r/ps_ddl.result20
-rw-r--r--mysql-test/r/view.result28
-rw-r--r--mysql-test/t/ps_ddl.test15
-rw-r--r--mysql-test/t/view.test40
4 files changed, 88 insertions, 15 deletions
diff --git a/mysql-test/r/ps_ddl.result b/mysql-test/r/ps_ddl.result
index e69c6e06193..005c78a0319 100644
--- a/mysql-test/r/ps_ddl.result
+++ b/mysql-test/r/ps_ddl.result
@@ -214,7 +214,7 @@ new trigger: 10
drop trigger t1_bd;
set @val=11;
execute stmt using @val;
-call p_verify_reprepare_count(1);
+call p_verify_reprepare_count(0);
SUCCESS
select @message;
@@ -224,7 +224,7 @@ Test 6-e: removing a relevant trigger
drop trigger t1_bi;
set @val=12;
execute stmt using @val;
-call p_verify_reprepare_count(1);
+call p_verify_reprepare_count(0);
SUCCESS
select @message;
@@ -384,7 +384,7 @@ a
flush table t1;
set @var=9;
execute stmt using @var;
-call p_verify_reprepare_count(1);
+call p_verify_reprepare_count(0);
SUCCESS
select * from t2;
@@ -831,8 +831,8 @@ a b c
20 40 100
30 60 150
call p_verify_reprepare_count(1);
-SUCCESS
-
+ERROR
+Expected: 1, actual: 0
# Check that we properly handle ALTER VIEW statements.
execute stmt;
a b c
@@ -882,9 +882,9 @@ a b c
10 50 60
20 100 120
30 150 180
-call p_verify_reprepare_count(1);
-SUCCESS
-
+call p_verify_reprepare_count(0);
+ERROR
+Expected: 0, actual: 1
execute stmt;
a b c
10 50 60
@@ -1206,7 +1206,7 @@ drop trigger v2_bi;
set @message=null;
set @var=9;
execute stmt using @var;
-call p_verify_reprepare_count(1);
+call p_verify_reprepare_count(0);
SUCCESS
select @message;
@@ -2578,7 +2578,7 @@ SELECT * FROM t1;
a
2048
1025
-1024
+2048
DROP TABLE t1;
#
# End of 10.1 tests
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 4edbabf11cc..1340a48fb83 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -6862,5 +6862,33 @@ r
drop view v1;
drop table t1;
#
+# MDEV-17124: mariadb 10.1.34, views and prepared statements:
+# ERROR 1615 (HY000): Prepared statement needs to be re-prepared
+#
+set @tdc= @@table_definition_cache, @tc= @@table_open_cache;
+set global table_definition_cache= 400, table_open_cache= 400;
+create table tt (a int, primary key(a)) engine=MyISAM;
+create view v as select * from tt;
+insert into tt values(1),(2),(3),(4);
+prepare stmt from 'select * from tt';
+#fill table definition cache
+execute stmt;
+a
+1
+2
+3
+4
+prepare stmt from 'select * from v';
+execute stmt;
+a
+1
+2
+3
+4
+drop database db;
+drop view v;
+drop table tt;
+set global table_definition_cache= @tdc, table_open_cache= @tc;
+#
# End of 10.2 tests
#
diff --git a/mysql-test/t/ps_ddl.test b/mysql-test/t/ps_ddl.test
index 90226d379bf..fc1bd8d3752 100644
--- a/mysql-test/t/ps_ddl.test
+++ b/mysql-test/t/ps_ddl.test
@@ -250,7 +250,8 @@ drop trigger t1_bd;
set @val=11;
execute stmt using @val;
-call p_verify_reprepare_count(1);
+# No trigger in opened table => nothing to check => no reprepare
+call p_verify_reprepare_count(0);
select @message;
--echo Test 6-e: removing a relevant trigger
@@ -259,7 +260,8 @@ drop trigger t1_bi;
set @val=12;
execute stmt using @val;
-call p_verify_reprepare_count(1);
+# No trigger in opened table => nothing to check => no reprepare
+call p_verify_reprepare_count(0);
select @message;
set @val=13;
execute stmt using @val;
@@ -374,7 +376,8 @@ select * from t3;
flush table t1;
set @var=9;
execute stmt using @var;
-call p_verify_reprepare_count(1);
+# flush tables now do not mean reprepare
+call p_verify_reprepare_count(0);
select * from t2;
select * from t3;
drop view v1;
@@ -763,7 +766,8 @@ flush tables; # empty TDC
create view t1 as select a, 5*a as b, 6*a as c from t2;
lock tables t1 read, t2 read;
execute stmt;
-call p_verify_reprepare_count(1);
+# flush tables now do not mean reprepare
+call p_verify_reprepare_count(0);
execute stmt;
call p_verify_reprepare_count(0);
execute stmt;
@@ -967,7 +971,8 @@ drop trigger v2_bi;
set @message=null;
set @var=9;
execute stmt using @var;
-call p_verify_reprepare_count(1);
+# No trigger in opened table => nothing to check => no reprepare
+call p_verify_reprepare_count(0);
select @message;
create trigger v2_bi after insert on v2 for each row set @message="v2_ai";
set @var= 10;
diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test
index 6265a514783..6914c80f635 100644
--- a/mysql-test/t/view.test
+++ b/mysql-test/t/view.test
@@ -6598,5 +6598,45 @@ drop view v1;
drop table t1;
--echo #
+--echo # MDEV-17124: mariadb 10.1.34, views and prepared statements:
+--echo # ERROR 1615 (HY000): Prepared statement needs to be re-prepared
+--echo #
+
+set @tdc= @@table_definition_cache, @tc= @@table_open_cache;
+set global table_definition_cache= 400, table_open_cache= 400;
+
+create table tt (a int, primary key(a)) engine=MyISAM;
+create view v as select * from tt;
+insert into tt values(1),(2),(3),(4);
+
+prepare stmt from 'select * from tt';
+--echo #fill table definition cache
+--disable_query_log
+--disable_result_log
+create database db;
+use db;
+--let $tables=401
+while ($tables)
+{
+ --eval create table t$tables (i int) engine=MyISAM
+ --eval select * from t$tables
+ --dec $tables
+}
+
+use test;
+
+--enable_query_log
+--enable_result_log
+execute stmt;
+prepare stmt from 'select * from v';
+execute stmt;
+
+# Cleanup
+drop database db;
+drop view v;
+drop table tt;
+set global table_definition_cache= @tdc, table_open_cache= @tc;
+
+--echo #
--echo # End of 10.2 tests
--echo #