Skip to content

Commit ec1f195

Browse files
committed
MDEV-15955 Assertion `field_types == 0 || field_types[field_pos] == MYSQL_TYPE_LONGLONG' failed in Protocol_text::store_longlong
1 parent 1217e4a commit ec1f195

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

mysql-test/r/type_int.result

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# Start of 5.5 tests
3+
#
4+
#
5+
# MDEV-15955 Assertion `field_types == 0 || field_types[field_pos] == MYSQL_TYPE_LONGLONG' failed in Protocol_text::store_longlong
6+
#
7+
CREATE TABLE t1 (a INT);
8+
INSERT INTO t1 VALUES (1),(2);
9+
SELECT @a := 1 FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
10+
@a := 1
11+
1
12+
SELECT COALESCE(1) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
13+
COALESCE(1)
14+
1
15+
SELECT COALESCE(@a:=1) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
16+
COALESCE(@a:=1)
17+
1
18+
SELECT COALESCE(@a) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
19+
COALESCE(@a)
20+
1
21+
DROP TABLE t1;
22+
#
23+
# End of 5.5 tests
24+
#

mysql-test/t/type_int.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--echo #
2+
--echo # Start of 5.5 tests
3+
--echo #
4+
5+
--echo #
6+
--echo # MDEV-15955 Assertion `field_types == 0 || field_types[field_pos] == MYSQL_TYPE_LONGLONG' failed in Protocol_text::store_longlong
7+
--echo #
8+
9+
CREATE TABLE t1 (a INT);
10+
INSERT INTO t1 VALUES (1),(2);
11+
SELECT @a := 1 FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
12+
SELECT COALESCE(1) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
13+
SELECT COALESCE(@a:=1) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
14+
SELECT COALESCE(@a) FROM t1 ORDER BY STRCMP(STDDEV_SAMP(a), 'bar');
15+
DROP TABLE t1;
16+
17+
--echo #
18+
--echo # End of 5.5 tests
19+
--echo #

sql/sql_select.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14762,6 +14762,28 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
1476214762
if (item->cmp_type() == TIME_RESULT ||
1476314763
item->field_type() == MYSQL_TYPE_GEOMETRY)
1476414764
new_field= item->tmp_table_field_from_field_type(table, 1);
14765+
else if (item->type() == Item::FUNC_ITEM &&
14766+
static_cast<Item_func*>(item)->functype() == Item_func::SUSERVAR_FUNC)
14767+
{
14768+
/*
14769+
A temporary solution for versions 5.5 .. 10.3.
14770+
This change should be null-merged to 10.4.
14771+
14772+
Item_func_set_user_var is special. It overrides make_field().
14773+
by adding a special branch `if (result_field)...`.
14774+
So it's important to preserve the exact data type here,
14775+
to avoid type mismatch in Protocol_text::store_longlong()
14776+
See MDEV-15955.
14777+
14778+
Other Item_func descendants are not affected by MDEV-15955.
14779+
They don't override make_field() so they don't use result_field
14780+
when initializing Send_field.
14781+
14782+
This is properly fixed in 10.4 in the method
14783+
Item_func_user_var::create_tmp_field_ex().
14784+
*/
14785+
new_field= item->tmp_table_field_from_field_type(table, false);
14786+
}
1476514787
else
1476614788
switch (item->result_type()) {
1476714789
case REAL_RESULT:

0 commit comments

Comments
 (0)