summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatjana Azundris Nuernberg <tatjana.nuernberg@oracle.com>2011-07-12 06:08:52 +0100
committerTatjana Azundris Nuernberg <tatjana.nuernberg@oracle.com>2011-07-12 06:08:52 +0100
commit083a316d1f9020d48a5b9769fafbb3accad3c03a (patch)
treec68479d792db74ae20ae25ec0ef40d0dd66d2484
parentc2e8aacb3f4fa952d4a9f6757dad1654ec70f49b (diff)
downloadmariadb-git-083a316d1f9020d48a5b9769fafbb3accad3c03a.tar.gz
Bug#11758414/Bug#50614: Default storage_engine not honored when set from within a stored procedure
When CREATE TABLE wasn't given ENGINE=... it would determine the default ENGINE at parse-time rather than at execution time, leading to incorrect behaviour (namely, later changes to the default engine being ignore) when calling CREATE TABLE from a stored procedure. We now defer working out the default engine till execution of CREATE TABLE. mysql-test/r/sp_trans.result: results! mysql-test/t/sp_trans.test: Show that CREATE TABLE (called from store routine) heeds any changes after CREATE SP / parse-time. Show that explicitly requesting an ENGINE still works. sql/sql_parse.cc: If no ENGINE=... was given at parse-time, determine default engine at execution time of CREATE TABLE. sql/sql_yacc.yy: If CREATE TABLE is not given ENGINE=..., don't bother figuring out the default engine during parsing; we'll do it at execution time instead to be aware of the latest updates.
-rw-r--r--mysql-test/r/sp_trans.result46
-rw-r--r--mysql-test/t/sp_trans.test33
-rw-r--r--sql/sql_parse.cc6
-rw-r--r--sql/sql_yacc.yy4
4 files changed, 87 insertions, 2 deletions
diff --git a/mysql-test/r/sp_trans.result b/mysql-test/r/sp_trans.result
index a64f53efde7..dec37db652a 100644
--- a/mysql-test/r/sp_trans.result
+++ b/mysql-test/r/sp_trans.result
@@ -556,3 +556,49 @@ f1 bug13575(f1)
3 ccc
drop function bug13575|
drop table t3|
+SELECT @@GLOBAL.storage_engine INTO @old_engine|
+SET @@GLOBAL.storage_engine=InnoDB|
+SET @@SESSION.storage_engine=InnoDB|
+SHOW GLOBAL VARIABLES LIKE 'storage_engine'|
+Variable_name Value
+storage_engine InnoDB
+SHOW SESSION VARIABLES LIKE 'storage_engine'|
+Variable_name Value
+storage_engine InnoDB
+CREATE PROCEDURE bug11758414()
+BEGIN
+SET @@GLOBAL.storage_engine="MyISAM";
+SET @@SESSION.storage_engine="MyISAM";
+# show defaults at execution time / that setting them worked
+SHOW GLOBAL VARIABLES LIKE 'storage_engine';
+SHOW SESSION VARIABLES LIKE 'storage_engine';
+CREATE TABLE t1 (id int);
+CREATE TABLE t2 (id int) ENGINE=InnoDB;
+# show we're heeding the default (at run-time, not parse-time!)
+ SHOW CREATE TABLE t1;
+ # show that we didn't break explicit override with ENGINE=...
+SHOW CREATE TABLE t2;
+END;
+|
+CALL bug11758414|
+Variable_name Value
+storage_engine MyISAM
+Variable_name Value
+storage_engine MyISAM
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `id` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+Table Create Table
+t2 CREATE TABLE `t2` (
+ `id` int(11) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=latin1
+SHOW GLOBAL VARIABLES LIKE 'storage_engine'|
+Variable_name Value
+storage_engine MyISAM
+SHOW SESSION VARIABLES LIKE 'storage_engine'|
+Variable_name Value
+storage_engine MyISAM
+DROP PROCEDURE bug11758414|
+DROP TABLE t1, t2|
+SET @@GLOBAL.storage_engine=@old_engine|
diff --git a/mysql-test/t/sp_trans.test b/mysql-test/t/sp_trans.test
index 0b04b9d7668..2d59fb20bbd 100644
--- a/mysql-test/t/sp_trans.test
+++ b/mysql-test/t/sp_trans.test
@@ -594,6 +594,39 @@ drop table t3|
#
+# BUG#11758414: Default storage_engine not honored when set
+# from within a stored procedure
+#
+SELECT @@GLOBAL.storage_engine INTO @old_engine|
+SET @@GLOBAL.storage_engine=InnoDB|
+SET @@SESSION.storage_engine=InnoDB|
+# show defaults at define-time
+SHOW GLOBAL VARIABLES LIKE 'storage_engine'|
+SHOW SESSION VARIABLES LIKE 'storage_engine'|
+CREATE PROCEDURE bug11758414()
+BEGIN
+ SET @@GLOBAL.storage_engine="MyISAM";
+ SET @@SESSION.storage_engine="MyISAM";
+ # show defaults at execution time / that setting them worked
+ SHOW GLOBAL VARIABLES LIKE 'storage_engine';
+ SHOW SESSION VARIABLES LIKE 'storage_engine';
+ CREATE TABLE t1 (id int);
+ CREATE TABLE t2 (id int) ENGINE=InnoDB;
+ # show we're heeding the default (at run-time, not parse-time!)
+ SHOW CREATE TABLE t1;
+ # show that we didn't break explicit override with ENGINE=...
+ SHOW CREATE TABLE t2;
+END;
+|
+CALL bug11758414|
+# show that changing defaults within SP stuck
+SHOW GLOBAL VARIABLES LIKE 'storage_engine'|
+SHOW SESSION VARIABLES LIKE 'storage_engine'|
+DROP PROCEDURE bug11758414|
+DROP TABLE t1, t2|
+SET @@GLOBAL.storage_engine=@old_engine|
+
+#
# BUG#NNNN: New bug synopsis
#
#--disable_warnings
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 2eeabc2f0c1..14ad77d29fd 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -2617,6 +2617,12 @@ mysql_execute_command(THD *thd)
goto end_with_restore_list;
#endif
/*
+ If no engine type was given, work out the default now
+ rather than at parse-time.
+ */
+ if (!(create_info.used_fields & HA_CREATE_USED_ENGINE))
+ create_info.db_type= ha_default_handlerton(thd);
+ /*
If we are using SET CHARSET without DEFAULT, add an implicit
DEFAULT to not confuse old users. (This may change).
*/
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 6245f07b9cf..f4fb822b294 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -1838,7 +1838,6 @@ create:
lex->change=NullS;
bzero((char*) &lex->create_info,sizeof(lex->create_info));
lex->create_info.options=$2 | $4;
- lex->create_info.db_type= ha_default_handlerton(thd);
lex->create_info.default_table_charset= NULL;
lex->name.str= 0;
lex->name.length= 0;
@@ -1847,7 +1846,8 @@ create:
{
LEX *lex= YYTHD->lex;
lex->current_select= &lex->select_lex;
- if (!lex->create_info.db_type)
+ if ((lex->create_info.used_fields & HA_CREATE_USED_ENGINE) &&
+ !lex->create_info.db_type)
{
lex->create_info.db_type= ha_default_handlerton(YYTHD);
push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN,