File tree Expand file tree Collapse file tree 4 files changed +87
-2
lines changed Expand file tree Collapse file tree 4 files changed +87
-2
lines changed Original file line number Diff line number Diff line change @@ -2120,3 +2120,42 @@ t2 CREATE TABLE `t2` (
21202120) ENGINE=MyISAM DEFAULT CHARSET=latin1
21212121DROP TABLE t2;
21222122DROP TABLE t1;
2123+ #
2124+ # MDEV-22758 Assertion `!item->null_value' failed in Type_handler_inet6::make_sort_key_part
2125+ #
2126+ CREATE TABLE t1 (c INET6);
2127+ INSERT INTO t1 VALUES ('::'),(NULL);
2128+ SELECT * FROM t1 ORDER BY IFNULL(c, 'foo');
2129+ c
2130+ NULL
2131+ ::
2132+ Warnings:
2133+ Warning 1292 Incorrect inet6 value: 'foo'
2134+ DROP TABLE t1;
2135+ CREATE TABLE t1 (c INET6);
2136+ INSERT INTO t1 VALUES ('::'),(NULL);
2137+ CREATE TABLE t2 AS SELECT IFNULL(c, 'foo') FROM t1;
2138+ Warnings:
2139+ Warning 1292 Incorrect inet6 value: 'foo'
2140+ SHOW CREATE TABLE t2;
2141+ Table Create Table
2142+ t2 CREATE TABLE `t2` (
2143+ `IFNULL(c, 'foo')` inet6 DEFAULT NULL
2144+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1
2145+ SELECT * FROM t2;
2146+ IFNULL(c, 'foo')
2147+ ::
2148+ NULL
2149+ DROP TABLE t2;
2150+ CREATE TABLE t2 AS SELECT IFNULL(c, '::1') FROM t1;
2151+ SHOW CREATE TABLE t2;
2152+ Table Create Table
2153+ t2 CREATE TABLE `t2` (
2154+ `IFNULL(c, '::1')` inet6 NOT NULL
2155+ ) ENGINE=MyISAM DEFAULT CHARSET=latin1
2156+ SELECT * FROM t2;
2157+ IFNULL(c, '::1')
2158+ ::
2159+ ::1
2160+ DROP TABLE t2;
2161+ DROP TABLE t1;
Original file line number Diff line number Diff line change @@ -1560,3 +1560,29 @@ SHOW CREATE TABLE t2;
15601560DROP TABLE t2;
15611561
15621562DROP TABLE t1;
1563+
1564+ --echo #
1565+ --echo # MDEV-22758 Assertion `!item->null_value' failed in Type_handler_inet6::make_sort_key_part
1566+ --echo #
1567+
1568+ CREATE TABLE t1 (c INET6);
1569+ INSERT INTO t1 VALUES ('::'),(NULL);
1570+ SELECT * FROM t1 ORDER BY IFNULL(c, 'foo');
1571+ DROP TABLE t1;
1572+
1573+ CREATE TABLE t1 (c INET6);
1574+ INSERT INTO t1 VALUES ('::'),(NULL);
1575+
1576+ # Expect a NULL column
1577+ CREATE TABLE t2 AS SELECT IFNULL(c, 'foo') FROM t1;
1578+ SHOW CREATE TABLE t2;
1579+ SELECT * FROM t2;
1580+ DROP TABLE t2;
1581+
1582+ # Expect a NOT NULL column
1583+ CREATE TABLE t2 AS SELECT IFNULL(c, '::1') FROM t1;
1584+ SHOW CREATE TABLE t2;
1585+ SELECT * FROM t2;
1586+ DROP TABLE t2;
1587+
1588+ DROP TABLE t1;
Original file line number Diff line number Diff line change @@ -720,7 +720,17 @@ class Type_handler_inet6: public Type_handler
720720 {
721721 attr->Type_std_attributes ::operator =(Type_std_attributes_inet6 ());
722722 h->set_handler (this );
723- for (uint i= 0 ; i < nitems; i++)
723+ /*
724+ If some of the arguments cannot be safely converted to "INET6 NOT NULL",
725+ then mark the entire function nullability as NULL-able.
726+ Otherwise, keep the generic nullability calculated by earlier stages:
727+ - either by the most generic way in Item_func::fix_fields()
728+ - or by Item_func_xxx::fix_length_and_dec() before the call of
729+ Item_hybrid_func_fix_attributes()
730+ IFNULL() is special. It does not need to test args[0].
731+ */
732+ uint first= dynamic_cast <Item_func_ifnull*>(attr) ? 1 : 0 ;
733+ for (uint i= first; i < nitems; i++)
724734 {
725735 if (Inet6::fix_fields_maybe_null_on_conversion_to_inet6 (items[i]))
726736 {
Original file line number Diff line number Diff line change @@ -1117,9 +1117,19 @@ class Item_func_ifnull :public Item_func_case_abbreviation2
11171117 bool native_op (THD *thd, Native *to);
11181118 bool fix_length_and_dec ()
11191119 {
1120+ /*
1121+ Set nullability from args[1] by default.
1122+ Note, some type handlers may reset maybe_null
1123+ in Item_hybrid_func_fix_attributes() if args[1]
1124+ is NOT NULL but cannot always be converted to
1125+ the data type of "this" safely.
1126+ E.g. Type_handler_inet6 does:
1127+ IFNULL(inet6_not_null_expr, 'foo') -> INET6 NULL
1128+ IFNULL(inet6_not_null_expr, '::1') -> INET6 NOT NULL
1129+ */
1130+ maybe_null= args[1 ]->maybe_null ;
11201131 if (Item_func_case_abbreviation2::fix_length_and_dec2 (args))
11211132 return TRUE ;
1122- maybe_null= args[1 ]->maybe_null ;
11231133 return FALSE ;
11241134 }
11251135 const char *func_name () const { return " ifnull" ; }
You can’t perform that action at this time.
0 commit comments