Skip to content
Permalink
Browse files
MDEV-29159 Patch for MDEV-28918 introduces more inconsistency than it…
… solves, breaks usability

1. Store assignment failures on incompatible data types now raise errors if:
- STRICT_ALL_TABLES or STRICT_TRANS_TABLES sql_mode is used, and
- IGNORE is not used

Otherwise, only a warning is raised and the statement continues.

2. Changing the error/warning test as follows:

-ERROR HY000: Illegal parameter data types inet6 and int for operation 'SET'
+ERROR HY000: Cannot cast 'int' as 'inet6' in assignment of `db`.`t`.`col`

so in case of a big table it's easier to see which column has the problem.
The new error text is also applied to SP variables.
  • Loading branch information
abarkov committed Aug 5, 2022
1 parent 97d16c7 commit 3ebbfd8
Show file tree
Hide file tree
Showing 43 changed files with 1,599 additions and 613 deletions.
@@ -1,5 +1,9 @@
--echo # Start of type_store_assignment_incompatible.inc

--disable_abort_on_error

SET @sql_mode_save= @@sql_mode;

SET @source_type= (SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME='source'
AND TABLE_NAME='t1'
@@ -10,8 +14,15 @@ SET @target_type= (SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
AND TABLE_NAME='t1'
AND TABLE_SCHEMA='test');

# 'IGNORE' -> ' IGNORE'
SET @ignore= CASE WHEN @ignore IS NULL OR @ignore = '' THEN ''
WHEN @ignore NOT LIKE ' %' THEN CONCAT(' ',@ignore)
ELSE @ignore
END;

let $source_type= `(SELECT @source_type)`;
let $target_type= `(SELECT @target_type)`;
let $ignore=`(SELECT @ignore)`;

CREATE TABLE t2 LIKE t1;
ALTER TABLE t2 ADD id INT NOT NULL PRIMARY KEY FIRST;
@@ -23,8 +34,7 @@ SHOW CREATE TABLE t2;
#

CREATE TABLE t3 LIKE t2;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
INSERT INTO t3 VALUES
eval INSERT$ignore INTO t3 VALUES
(1,
(SELECT source FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1));
@@ -52,8 +62,7 @@ EXECUTE IMMEDIATE
IF(@source_type='geometry','AsText(source)','source'), ' AS source ',
' FROM t3');

--error 0,ER_CANT_CREATE_GEOMETRY_OBJECT
INSERT INTO t3 VALUES
eval INSERT$ignore INTO t3 VALUES
(1,
(SELECT target FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1)),
@@ -64,8 +73,7 @@ SELECT * FROM v3;
TRUNCATE TABLE t3;

SET sql_mode=STRICT_ALL_TABLES;
--error ER_TRUNCATED_WRONG_VALUE, ER_TRUNCATED_WRONG_VALUE_FOR_FIELD, WARN_DATA_TRUNCATED, ER_CANT_CREATE_GEOMETRY_OBJECT
INSERT INTO t3 VALUES
eval INSERT$ignore INTO t3 VALUES
(1,
(SELECT target FROM t2 ORDER BY id LIMIT 1),
(SELECT source FROM t2 ORDER BY id LIMIT 1)),
@@ -74,7 +82,7 @@ INSERT INTO t3 VALUES
(SELECT source FROM t2 ORDER BY id LIMIT 1));
SELECT * FROM v3;
TRUNCATE TABLE t3;
SET sql_mode=DEFAULT;
SET sql_mode=@sql_mode_save;
DROP TABLE t3;
DROP VIEW v3;

@@ -83,55 +91,46 @@ DROP VIEW v3;
#

CREATE TABLE t3 LIKE t2;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
INSERT INTO t3 SELECT id,source,source FROM t2;
eval INSERT$ignore INTO t3 SELECT id,source,source FROM t2;

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
INSERT INTO t3 (id,target,source) SELECT id,source,source FROM t2;
eval INSERT$ignore INTO t3 (id,target,source) SELECT id,source,source FROM t2;

#
# INSERT .. VALUES .. ON DUPLICATE KEY UPDATE target=source
#

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
INSERT INTO t3 VALUES (1,DEFAULT,DEFAULT) ON DUPLICATE KEY UPDATE target=source;
eval INSERT$ignore INTO t3 VALUES (1,DEFAULT,DEFAULT) ON DUPLICATE KEY UPDATE target=source;

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
INSERT INTO t3 (id,target,source) VALUES (1,DEFAULT,DEFAULT) ON DUPLICATE KEY UPDATE target=source;
eval INSERT$ignore INTO t3 (id,target,source) VALUES (1,DEFAULT,DEFAULT) ON DUPLICATE KEY UPDATE target=source;

#
# INSERT .. SELECT .. ON DUPLICATE KEY UPDATE target=source
#

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
INSERT INTO t3 SELECT 1,DEFAULT(t2.target),DEFAULT(t2.source) FROM t2 ON DUPLICATE KEY UPDATE t3.target=t2.source;
eval INSERT$ignore INTO t3 SELECT 1,DEFAULT(t2.target),DEFAULT(t2.source) FROM t2 ON DUPLICATE KEY UPDATE t3.target=t2.source;

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
INSERT INTO t3 (id,target,source) SELECT 1,DEFAULT(t2.target),DEFAULT(t2.source) FROM t2 ON DUPLICATE KEY UPDATE t3.target=t2.source;
eval INSERT$ignore INTO t3 (id,target,source) SELECT 1,DEFAULT(t2.target),DEFAULT(t2.source) FROM t2 ON DUPLICATE KEY UPDATE t3.target=t2.source;


#
# UPDATE
#
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
UPDATE t3 SET target=source;
eval UPDATE$ignore t3 SET target=source;


#
# UPDATE, multi-table
#

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
UPDATE t2, t3 SET t3.target=t2.source WHERE t2.id=t3.id;
eval UPDATE$ignore t2, t3 SET t3.target=t2.source WHERE t2.id=t3.id;


#
# ALTER
#

SET @alter=CONCAT('ALTER TABLE t3 MODIFY target ', @source_type);
SET @alter=CONCAT('ALTER', @ignore, ' TABLE t3 MODIFY target ', @source_type);
SELECT @alter;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
EXECUTE IMMEDIATE @alter;


@@ -154,7 +153,6 @@ BEGIN
END;
$$
DELIMITER ;$$
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p1;
DROP PROCEDURE p1;

@@ -163,12 +161,10 @@ DROP PROCEDURE p1;
#

--eval CREATE FUNCTION f1(a $target_type) RETURNS INT RETURN NULL;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT f1((SELECT source FROM t1 ORDER BY source LIMIT 1));
DROP FUNCTION f1;

--eval CREATE PROCEDURE p1(a $target_type) BEGIN END;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p1((SELECT source FROM t1 ORDER BY source LIMIT 1));
DROP PROCEDURE p1;

@@ -190,7 +186,6 @@ BEGIN
END;
$$
DELIMITER ;$$
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p2();
SHOW WARNINGS;
DROP PROCEDURE p2;
@@ -209,7 +204,6 @@ BEGIN
END;
$$
DELIMITER ;$$
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT f1();
DROP FUNCTION f1;

@@ -227,7 +221,6 @@ BEGIN
END;
$$
DELIMITER ;$$
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p1();
DROP PROCEDURE p1;

@@ -249,10 +242,11 @@ BEGIN
END;
$$
DELIMITER ;$$
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CALL p1();
DROP PROCEDURE p1;

DROP TABLE t2;

--enable_abort_on_error

--echo # End of type_store_assignment_incompatible.inc
@@ -1152,11 +1152,11 @@ SELECT @var62, @var63;
@var62 @var63
1 NULL
INSERT INTO t1 SELECT id2, val2, p2 from t2;
ERROR HY000: Illegal parameter data types double and point for operation 'SET'
ERROR HY000: Cannot cast 'point' as 'double' in assignment of `test`.`t1`.`d1`
GET DIAGNOSTICS CONDITION 1 @var64= ROW_NUMBER;
GET DIAGNOSTICS CONDITION 2 @var65= ROW_NUMBER;
Warnings:
Error 4078 Illegal parameter data types double and point for operation 'SET'
Error 4078 Cannot cast 'point' as 'double' in assignment of `test`.`t1`.`d1`
Error 1758 Invalid condition number
SELECT @var64, @var65;
@var64 @var65
@@ -1396,11 +1396,11 @@ SELECT @var103, @var104;
@var103 @var104
1 NULL
INSERT INTO t1 SELECT id2, val2, p2 from t2;
ERROR HY000: Illegal parameter data types double and point for operation 'SET'
ERROR HY000: Cannot cast 'point' as 'double' in assignment of `test`.`t1`.`d1`
GET DIAGNOSTICS CONDITION 1 @var105= ROW_NUMBER;
GET DIAGNOSTICS CONDITION 2 @var106= ROW_NUMBER;
Warnings:
Error 4078 Illegal parameter data types double and point for operation 'SET'
Error 4078 Cannot cast 'point' as 'double' in assignment of `test`.`t1`.`d1`
Error 1758 Invalid condition number
SELECT @var105, @var106;
@var105 @var106
@@ -688,9 +688,9 @@ object_id geometrytype(geo) ISSIMPLE(GEO) ASTEXT(centroid(geo))
drop table t1;
create table t1 (fl geometry not null);
insert into t1 values (1);
ERROR HY000: Illegal parameter data types geometry and int for operation 'SET'
ERROR HY000: Cannot cast 'int' as 'geometry' in assignment of `test`.`t1`.`fl`
insert into t1 values (1.11);
ERROR HY000: Illegal parameter data types geometry and decimal for operation 'SET'
ERROR HY000: Cannot cast 'decimal' as 'geometry' in assignment of `test`.`t1`.`fl`
insert into t1 values ("qwerty");
ERROR 22003: Cannot get geometry object from data you send to the GEOMETRY field
insert into t1 values (pointfromtext('point(1,1)'));
@@ -20,7 +20,7 @@ RETURN a;
END;
$$
SELECT f1(ROW(10,20));
ERROR HY000: Illegal parameter data types int and row for operation 'SET'
ERROR HY000: Cannot cast 'row' as 'int' in assignment of `f1(ROW(10,20))`
DROP FUNCTION f1;
#
# ROW as an SP parameter
@@ -236,7 +236,7 @@ SELECT f1(a);
END;
$$
CALL p1();
ERROR HY000: Illegal parameter data types int and row for operation 'SET'
ERROR HY000: Cannot cast 'row' as 'int' in assignment of `a`
DROP PROCEDURE p1;
DROP FUNCTION f1;
#
@@ -286,7 +286,7 @@ RETURN rec;
END;
$$
SELECT f1(10);
ERROR HY000: Illegal parameter data types int and row for operation 'SET'
ERROR HY000: Cannot cast 'row' as 'int' in assignment of `f1(10)`
DROP FUNCTION f1;
#
# Using the entire ROW in SELECT..CREATE
@@ -1026,11 +1026,11 @@ BEGIN
SELECT arg;
END|
CALL p1((1, 2));
ERROR HY000: Illegal parameter data types tinyint and row for operation 'SET'
ERROR 21000: Operand should contain 1 column(s)
CALL p1((SELECT * FROM t1 LIMIT 1));
ERROR HY000: Illegal parameter data types tinyint and row for operation 'SET'
ERROR 21000: Operand should contain 1 column(s)
CALL p1((SELECT col1, col2 FROM t1 LIMIT 1));
ERROR HY000: Illegal parameter data types tinyint and row for operation 'SET'
ERROR 21000: Operand should contain 1 column(s)
DROP PROCEDURE p1;
DROP TABLE t1;

@@ -1221,13 +1221,13 @@ BEGIN
END|
delimiter ;|

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
--error ER_OPERAND_COLUMNS
CALL p1((1, 2));

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
--error ER_OPERAND_COLUMNS
CALL p1((SELECT * FROM t1 LIMIT 1));

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
--error ER_OPERAND_COLUMNS
CALL p1((SELECT col1, col2 FROM t1 LIMIT 1));

#
@@ -255,7 +255,7 @@ return i+1|
call sub1("sub1a", (select 7))|
call sub1("sub1b", (select max(i) from t2))|
call sub1("sub1c", (select i,d from t2 limit 1))|
ERROR HY000: Illegal parameter data types int and row for operation 'SET'
ERROR HY000: Cannot cast 'row' as 'int' in assignment of `x`
call sub1("sub1d", (select 1 from (select 1) a))|
call sub2("sub2")|
select * from t1 order by id|

0 comments on commit 3ebbfd8

Please sign in to comment.