Skip to content

Commit 0bb924e

Browse files
committed
MDEV-17830 Server crashes in Item_null_result::field_type upon SELECT with CHARSET(date) and ROLLUP
1 parent 409dddf commit 0bb924e

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

mysql-test/r/olap.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,5 +786,19 @@ t COUNT(*)
786786
12:12:13 1
787787
DROP TABLE t1;
788788
#
789+
# MDEV-17830 Server crashes in Item_null_result::field_type upon SELECT with CHARSET(date) and ROLLUP
790+
#
791+
# Note, returning "latin1" in the first row vs "binary" in the second row is wrong here.
792+
# Both lines should return equal values.
793+
# The point in this test is to make sure it does not crash.
794+
# Bad result will be fixed in a later version.
795+
CREATE TABLE t (d DATE) ENGINE=MyISAM;
796+
INSERT INTO t VALUES ('2018-12-12');
797+
SELECT CHARSET(d) AS f FROM t GROUP BY d WITH ROLLUP;
798+
f
799+
latin1
800+
binary
801+
DROP TABLE t;
802+
#
789803
# End of 10.1 tests
790804
#

mysql-test/t/olap.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,21 @@ SELECT t, COUNT(*) FROM t1 GROUP BY t WITH ROLLUP HAVING t > '00:00:00';
424424
DROP TABLE t1;
425425

426426

427+
--echo #
428+
--echo # MDEV-17830 Server crashes in Item_null_result::field_type upon SELECT with CHARSET(date) and ROLLUP
429+
--echo #
430+
431+
--echo # Note, returning "latin1" in the first row vs "binary" in the second row is wrong here.
432+
--echo # Both lines should return equal values.
433+
--echo # The point in this test is to make sure it does not crash.
434+
--echo # Bad result will be fixed in a later version.
435+
436+
CREATE TABLE t (d DATE) ENGINE=MyISAM;
437+
INSERT INTO t VALUES ('2018-12-12');
438+
SELECT CHARSET(d) AS f FROM t GROUP BY d WITH ROLLUP;
439+
DROP TABLE t;
440+
441+
427442
--echo #
428443
--echo # End of 10.1 tests
429444
--echo #

sql/item.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2618,6 +2618,10 @@ class Item_null_result :public Item_null
26182618
{
26192619
return result_field->type();
26202620
}
2621+
CHARSET_INFO *charset_for_protocol(void) const
2622+
{
2623+
return collation.collation;
2624+
}
26212625
#else
26222626
const Type_handler *type_handler() const
26232627
{
@@ -3942,6 +3946,12 @@ class Item_ref :public Item_ident
39423946
void save_org_in_field(Field *field, fast_field_copier optimizer_data);
39433947
fast_field_copier setup_fast_field_copier(Field *field)
39443948
{ return (*ref)->setup_fast_field_copier(field); }
3949+
#if MARIADB_VERSION_ID < 100300
3950+
CHARSET_INFO *charset_for_protocol(void) const
3951+
{
3952+
return (*ref)->charset_for_protocol();
3953+
}
3954+
#endif
39453955
enum Item_result result_type () const { return (*ref)->result_type(); }
39463956
enum_field_types field_type() const { return (*ref)->field_type(); }
39473957
Field *get_tmp_table_field()

0 commit comments

Comments
 (0)