Skip to content

Commit 10a83b3

Browse files
Dyre TjeldvollDyre Tjeldvoll
Dyre Tjeldvoll
authored and
Dyre Tjeldvoll
committed
BUG#19770958: WRONG RESULTS WITH STORED PROGRAMS AND NULLABLE SYSTEM
VARIABLES null_value was not being reset between invocations of Item_func_get_system_var::val_str(). When a stored procedure evaluates a system variable it calls sp_eval_expr() which in turn calls Item::save_in_field(). Item::save_in_field() calls Item_func_get_system_var::val_str() but ignores the returned value if null_value is true. As a result it continued to return NULL even if the value of the system variable had been updated. Normal execution was not affected because Item::send() does not call Item::save_in_field(), but calls val_str() directly and ignores the null_value variable. Patch modifies Item_func_get_system_var::val_str() so that null_value is reset to FALSE before checking if the variable value is NULL.
1 parent 712d895 commit 10a83b3

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

mysql-test/r/sp-vars.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,3 +1204,20 @@ CALL vctest();
12041204
Warnings:
12051205
Warning 1292 Truncated incorrect DOUBLE value: 'string'
12061206
DROP PROCEDURE vctest;
1207+
1208+
---------------------------------------------------------------
1209+
BUG#19770958
1210+
---------------------------------------------------------------
1211+
1212+
CREATE TABLE t (a INT PRIMARY KEY, b TEXT, FULLTEXT(b)) ENGINE=InnoDB;
1213+
CREATE FUNCTION f() RETURNS TEXT RETURN @@GLOBAL.innodb_ft_aux_table;
1214+
SELECT @@GLOBAL.innodb_ft_aux_table, f();
1215+
@@GLOBAL.innodb_ft_aux_table f()
1216+
NULL NULL
1217+
SET GLOBAL innodb_ft_aux_table="test/t";
1218+
SELECT @@GLOBAL.innodb_ft_aux_table, f();
1219+
@@GLOBAL.innodb_ft_aux_table f()
1220+
test/t test/t
1221+
SET GLOBAL innodb_ft_aux_table= default;
1222+
DROP FUNCTION f;
1223+
DROP TABLE t;

mysql-test/t/sp-vars.test

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,3 +1476,28 @@ DELIMITER ;|
14761476

14771477
CALL vctest();
14781478
DROP PROCEDURE vctest;
1479+
1480+
1481+
###########################################################################
1482+
#
1483+
# Test case for BUG#19770958 WRONG RESULTS WITH STORED PROGRAMS AND
1484+
# NULLABLE SYSTEM VARIABLES: Create a function which returns a system
1485+
# variable which initially is NULL. Then update the variable and call function
1486+
# again to see that it returns the updated value.
1487+
#
1488+
###########################################################################
1489+
1490+
--echo
1491+
--echo ---------------------------------------------------------------
1492+
--echo BUG#19770958
1493+
--echo ---------------------------------------------------------------
1494+
--echo
1495+
1496+
CREATE TABLE t (a INT PRIMARY KEY, b TEXT, FULLTEXT(b)) ENGINE=InnoDB;
1497+
CREATE FUNCTION f() RETURNS TEXT RETURN @@GLOBAL.innodb_ft_aux_table;
1498+
SELECT @@GLOBAL.innodb_ft_aux_table, f();
1499+
SET GLOBAL innodb_ft_aux_table="test/t";
1500+
SELECT @@GLOBAL.innodb_ft_aux_table, f();
1501+
SET GLOBAL innodb_ft_aux_table= default;
1502+
DROP FUNCTION f;
1503+
DROP TABLE t;

sql/item_func.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7122,6 +7122,7 @@ String* Item_func_get_system_var::val_str(String* str)
71227122
}
71237123

71247124
str= &cached_strval;
7125+
null_value= FALSE;
71257126
switch (var->show_type())
71267127
{
71277128
case SHOW_CHAR:
@@ -7167,7 +7168,7 @@ String* Item_func_get_system_var::val_str(String* str)
71677168

71687169
default:
71697170
my_error(ER_VAR_CANT_BE_READ, MYF(0), var->name.str);
7170-
str= NULL;
7171+
str= error_str();
71717172
break;
71727173
}
71737174

0 commit comments

Comments
 (0)