Commit f22093ad authored by Alexander Barkov's avatar Alexander Barkov

MDEV-22764 Crash with a stored aggregate function returning INET6

Item_sum_sp did not override val_native(). So the reported script
crashed in the default implementation in Item::val_native() on DBUG_ASSERT().

Implementing a correct Item_sum_sp::val_native().
parent dec3f8ca
......@@ -1986,3 +1986,38 @@ ERROR HY000: Illegal parameter data type inet6 for operation 'extract(day)'
DROP TABLE t1;
SELECT EXTRACT(DAY FROM CAST('::' AS INET6));
ERROR HY000: Illegal parameter data type inet6 for operation 'extract(day)'
#
# MDEV-22764 Crash with a stored aggregate function returning INET6
#
CREATE OR REPLACE AGGREGATE FUNCTION aggregate_min_inet6(x INET6) RETURNS INET6
BEGIN
DECLARE res INET6 DEFAULT NULL;
DECLARE CONTINUE HANDLER FOR NOT FOUND
RETURN res;
LOOP
FETCH GROUP NEXT ROW;
IF (res IS NULL) OR (res > x) THEN
SET res= x;
END IF;
END LOOP;
END;
$$
CREATE OR REPLACE TABLE t1 (name CHAR(30), val INET6);
INSERT INTO t1 VALUES ('a', '::05');
INSERT INTO t1 VALUES ('a', '::03');
INSERT INTO t1 VALUES ('b', '::01');
INSERT INTO t1 VALUES ('b', '::02');
INSERT INTO t1 VALUES ('b', '::05');
SELECT name, aggregate_min_inet6(val) pc FROM t1 GROUP BY name;
name pc
a ::3
b ::1
CREATE OR REPLACE TABLE t2 (name CHAR(30), val INET6);
INSERT INTO t2 SELECT name, aggregate_min_inet6(val) pc FROM t1 GROUP BY name;
SELECT * FROM t2;
name val
a ::3
b ::1
DROP TABLE t2;
DROP TABLE t1;
DROP FUNCTION aggregate_min_inet6;
......@@ -1457,3 +1457,40 @@ SELECT EXTRACT(DAY FROM a) FROM t1;
DROP TABLE t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
SELECT EXTRACT(DAY FROM CAST('::' AS INET6));
--echo #
--echo # MDEV-22764 Crash with a stored aggregate function returning INET6
--echo #
DELIMITER $$;
CREATE OR REPLACE AGGREGATE FUNCTION aggregate_min_inet6(x INET6) RETURNS INET6
BEGIN
DECLARE res INET6 DEFAULT NULL;
DECLARE CONTINUE HANDLER FOR NOT FOUND
RETURN res;
LOOP
FETCH GROUP NEXT ROW;
IF (res IS NULL) OR (res > x) THEN
SET res= x;
END IF;
END LOOP;
END;
$$
DELIMITER ;$$
CREATE OR REPLACE TABLE t1 (name CHAR(30), val INET6);
INSERT INTO t1 VALUES ('a', '::05');
INSERT INTO t1 VALUES ('a', '::03');
INSERT INTO t1 VALUES ('b', '::01');
INSERT INTO t1 VALUES ('b', '::02');
INSERT INTO t1 VALUES ('b', '::05');
SELECT name, aggregate_min_inet6(val) pc FROM t1 GROUP BY name;
CREATE OR REPLACE TABLE t2 (name CHAR(30), val INET6);
INSERT INTO t2 SELECT name, aggregate_min_inet6(val) pc FROM t1 GROUP BY name;
SELECT * FROM t2;
DROP TABLE t2;
DROP TABLE t1;
DROP FUNCTION aggregate_min_inet6;
......@@ -1407,6 +1407,11 @@ class Item_sum_sp :public Item_sum,
return sp_result_field->val_decimal(dec_buf);
}
bool val_native(THD *thd, Native *to)
{
return null_value= execute() || sp_result_field->val_native(to);
}
String *val_str(String *str)
{
String buf;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment