3427 Raghav Kapoor 2011-09-22
BUG#12735829 - SPACE() FUNCTION WARNING REFERS TO REPEAT()
IN ER_WARN_ALLOWED_PACKET_OVERFLOWED
BACKGROUND:
Previously in the bug,the warning text was incorrect.Instead
of printing space it was printing repeat in the warning message.
FIX:
The bug has been fixed by creating a new class Item_func_space
in item_strfunc.h file and implementing fix_length_and_dec()
and val_str(String *str) functions for it in item_strfunc.cc.
Also Create_func_space now returns Item_func_space in
item_create.cc file.This patch also partially fixes the
bug#11746123 which arises because of wrong implementaion of
space() function which "caches" session character set and
collation at creation time.Test cases have been written to
demonstrate the fix for the both the bugs in func_str.test
file and the corrsponding result files have also been updated.
@ mysql-test/t/func_str.test
Test case for bug#12735829 and bug#11746123 have been written
@ sql/item_create.cc
Item_func_space is called instead of Item_func_repeat
@ sql/item_strfunc.cc
fix_length_and_dec() and val_str(String *str) functions
for item_func_space have been implemented.
@ sql/item_strfunc.h
new class item_func_space has been created
modified:
mysql-test/r/ctype_utf16.result
mysql-test/r/func_str.result
mysql-test/t/func_str.test
sql/item_create.cc
sql/item_strfunc.cc
sql/item_strfunc.h
3426 Tor Didriksen 2011-09-22
WL#4897: Add EXPLAIN INSERT/UPDATE/DELETE
Post-push fix, there was a memory leak in mysqltest,
since 'explain_re' is now a separate struct.
modified:
client/mysqltest.cc
=== modified file 'mysql-test/r/ctype_utf16.result'
--- a/mysql-test/r/ctype_utf16.result 2011-05-02 11:31:27 +0000
+++ b/mysql-test/r/ctype_utf16.result 2011-09-22 10:42:10 +0000
@@ -1131,7 +1131,7 @@ SELECT space(date_add(101, INTERVAL CHAR
space(date_add(101, INTERVAL CHAR('1' USING utf16) hour_second))
NULL
Warnings:
-Warning 1301 Result of repeat() was larger than max_allowed_packet (1048576) - truncated
+Warning 1301 Result of space() was larger than max_allowed_packet (1048576) - truncated
#
# End of 5.5 tests
#
=== modified file 'mysql-test/r/func_str.result'
--- a/mysql-test/r/func_str.result 2011-09-20 09:17:02 +0000
+++ b/mysql-test/r/func_str.result 2011-09-22 10:42:10 +0000
@@ -845,7 +845,7 @@ explain extended select concat('*',space
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
-Note 1003 /* select#1 */ select concat('*',repeat(' ',5),'*') AS `concat('*',space(5),'*')`
+Note 1003 /* select#1 */ select concat('*',space(5),'*') AS `concat('*',space(5),'*')`
explain extended select reverse('abc');
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
@@ -2084,7 +2084,7 @@ select space(4294967295);
space(4294967295)
NULL
Warnings:
-Warning 1301 Result of repeat() was larger than max_allowed_packet (1048576) - truncated
+Warning 1301 Result of space() was larger than max_allowed_packet (1048576) - truncated
select space(-4294967296);
space(-4294967296)
@@ -2092,7 +2092,7 @@ select space(4294967296);
space(4294967296)
NULL
Warnings:
-Warning 1301 Result of repeat() was larger than max_allowed_packet (1048576) - truncated
+Warning 1301 Result of space() was larger than max_allowed_packet (1048576) - truncated
select space(-4294967297);
space(-4294967297)
@@ -2100,7 +2100,7 @@ select space(4294967297);
space(4294967297)
NULL
Warnings:
-Warning 1301 Result of repeat() was larger than max_allowed_packet (1048576) - truncated
+Warning 1301 Result of space() was larger than max_allowed_packet (1048576) - truncated
select space(-18446744073709551615);
space(-18446744073709551615)
@@ -2111,7 +2111,7 @@ select space(18446744073709551615);
space(18446744073709551615)
NULL
Warnings:
-Warning 1301 Result of repeat() was larger than max_allowed_packet (1048576) - truncated
+Warning 1301 Result of space() was larger than max_allowed_packet (1048576) - truncated
select space(-18446744073709551616);
space(-18446744073709551616)
@@ -2124,7 +2124,7 @@ NULL
Warnings:
Warning 1292 Truncated incorrect DECIMAL value: ''
Warning 1292 Truncated incorrect DECIMAL value: ''
-Warning 1301 Result of repeat() was larger than max_allowed_packet (1048576) - truncated
+Warning 1301 Result of space() was larger than max_allowed_packet (1048576) - truncated
select space(-18446744073709551617);
space(-18446744073709551617)
@@ -2137,7 +2137,7 @@ NULL
Warnings:
Warning 1292 Truncated incorrect DECIMAL value: ''
Warning 1292 Truncated incorrect DECIMAL value: ''
-Warning 1301 Result of repeat() was larger than max_allowed_packet (1048576) - truncated
+Warning 1301 Result of space() was larger than max_allowed_packet (1048576) - truncated
select rpad('hello', -1, '1');
rpad('hello', -1, '1')
NULL
@@ -4407,6 +4407,20 @@ NULL
Warnings:
Warning 1301 Result of export_set() was larger than max_allowed_packet (1073741824) - truncated
SET @@global.max_allowed_packet:= @tmp_max;
+SELECT SPACE(@@global.max_allowed_packet*2);
+SPACE(@@global.max_allowed_packet*2)
+NULL
+Warnings:
+Warning 1301 Result of space() was larger than max_allowed_packet (1048576) - truncated
+SET NAMES latin1;
+PREPARE stmt FROM "SELECT COLLATION(space(2))";
+EXECUTE stmt;
+COLLATION(space(2))
+latin1_swedish_ci
+SET NAMES latin2;
+EXECUTE stmt;
+COLLATION(space(2))
+latin2_general_ci
#
# End of 5.6 tests
#
=== modified file 'mysql-test/t/func_str.test'
--- a/mysql-test/t/func_str.test 2011-09-20 09:17:02 +0000
+++ b/mysql-test/t/func_str.test 2011-09-22 10:42:10 +0000
@@ -1626,6 +1626,23 @@ SET @@global.max_allowed_packet:= @tmp_m
--disconnect newconn
+#
+# BUG #12735829: SPACE() FUNCTION WARNING REFERS TO REPEAT() IN ER_WARN_ALLOWED_PACKET_OVERFLOWED
+#
+
+SELECT SPACE(@@global.max_allowed_packet*2);
+
+
+#
+# BUG #11746123-23637: CHARSET AND COLLATION OF THE FUNCTION SPACE()
+#
+
+SET NAMES latin1;
+PREPARE stmt FROM "SELECT COLLATION(space(2))";
+EXECUTE stmt;
+SET NAMES latin2;
+EXECUTE stmt;
+
--echo #
--echo # End of 5.6 tests
--echo #
=== modified file 'sql/item_create.cc'
--- a/sql/item_create.cc 2011-07-04 00:25:46 +0000
+++ b/sql/item_create.cc 2011-09-22 10:42:10 +0000
@@ -4909,26 +4909,7 @@ Create_func_space Create_func_space::s_s
Item*
Create_func_space::create(THD *thd, Item *arg1)
{
- /**
- TODO: Fix Bug#23637
- The parsed item tree should not depend on
- <code>thd->variables.collation_connection</code>.
- */
- const CHARSET_INFO *cs= thd->variables.collation_connection;
- Item *sp;
-
- if (cs->mbminlen > 1)
- {
- uint dummy_errors;
- sp= new (thd->mem_root) Item_string("", 0, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
- sp->str_value.copy(" ", 1, &my_charset_latin1, cs, &dummy_errors);
- }
- else
- {
- sp= new (thd->mem_root) Item_string(" ", 1, cs, DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
- }
-
- return new (thd->mem_root) Item_func_repeat(sp, arg1);
+ return new (thd->mem_root) Item_func_space(arg1);
}
=== modified file 'sql/item_strfunc.cc'
--- a/sql/item_strfunc.cc 2011-07-28 10:54:44 +0000
+++ b/sql/item_strfunc.cc 2011-09-22 10:42:10 +0000
@@ -2816,6 +2816,76 @@ err:
}
+
+void Item_func_space::fix_length_and_dec()
+{
+ collation.set(default_charset(), DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII);
+ if (args[0]->const_item())
+ {
+ /* must be longlong to avoid truncation */
+ longlong count= args[0]->val_int();
+ if (args[0]->null_value)
+ goto end;
+ /*
+ Assumes that the maximum length of a String is < INT_MAX32.
+ Set here so that rest of code sees out-of-bound value as such.
+ */
+ if (count > INT_MAX32)
+ count= INT_MAX32;
+ fix_char_length_ulonglong(count);
+ return;
+ }
+
+end:
+ max_length= MAX_BLOB_WIDTH;
+ maybe_null= 1;
+}
+
+
+String *Item_func_space::val_str(String *str)
+{
+ uint tot_length;
+ longlong count= args[0]->val_int();
+ const CHARSET_INFO *cs= collation.collation;
+
+ if (args[0]->null_value)
+ goto err; // string and/or delim are null
+ null_value= 0;
+
+ if (count <= 0 && (count == 0 || !args[0]->unsigned_flag))
+ return make_empty_result();
+ /*
+ Assumes that the maximum length of a String is < INT_MAX32.
+ Bounds check on count: If this is triggered, we will error.
+ */
+ if ((ulonglong) count > INT_MAX32)
+ count= INT_MAX32;
+
+ // Safe length check
+ tot_length= (uint) count * cs->mbminlen;
+ if (tot_length > current_thd->variables.max_allowed_packet)
+ {
+ push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
+ ER_WARN_ALLOWED_PACKET_OVERFLOWED,
+ ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED),
+ func_name(),
+ current_thd->variables.max_allowed_packet);
+ goto err;
+ }
+
+ if (str->alloc(tot_length))
+ goto err;
+ str->length(tot_length);
+ str->set_charset(cs);
+ cs->cset->fill(cs, (char*) str->ptr(), tot_length, ' ');
+ return str;
+
+err:
+ null_value= 1;
+ return 0;
+}
+
+
void Item_func_rpad::fix_length_and_dec()
{
// Handle character set for args[0] and args[2].
=== modified file 'sql/item_strfunc.h'
--- a/sql/item_strfunc.h 2011-07-04 00:25:46 +0000
+++ b/sql/item_strfunc.h 2011-09-22 10:42:10 +0000
@@ -617,6 +617,16 @@ public:
};
+class Item_func_space :public Item_str_func
+{
+public:
+ Item_func_space(Item *arg1):Item_str_func(arg1) {}
+ String *val_str(String *);
+ void fix_length_and_dec();
+ const char *func_name() const { return "space"; }
+};
+
+
class Item_func_rpad :public Item_str_func
{
String tmp_value, rpad_str;
No bundle (reason: useless for push emails).
| Thread |
|---|
| • bzr push into mysql-trunk branch (raghav.kapoor:3426 to 3427) Bug#12735829 | Raghav Kapoor | 22 Sep |