Skip to content

Commit

Permalink
MDEV-12238 Add Type_handler::Item_func_{plus|minus|mul|div|mod}_fix_l…
Browse files Browse the repository at this point in the history
…ength_and_dec()
  • Loading branch information
Alexander Barkov committed Apr 13, 2017
1 parent 949faa2 commit 45730fb
Show file tree
Hide file tree
Showing 8 changed files with 811 additions and 103 deletions.
53 changes: 53 additions & 0 deletions mysql-test/r/gis-debug.result
Expand Up @@ -352,3 +352,56 @@ Note 1105 DBUG: types_compatible=yes bisect=yes
DROP TABLE t1;
SET SESSION debug_dbug="-d,Predicant_to_list_comparator";
SET SESSION debug_dbug="-d,Item_func_in";
#
# MDEV-12238 Add Type_handler::Item_func_{plus|minus|mul|div|mod}_fix_length_and_dec()
#
SET debug_dbug='+d,num_op';
CREATE TABLE t1 AS SELECT
POINT(0,0)+POINT(0,0),
POINT(0,0)-POINT(0,0),
POINT(0,0)*POINT(0,0),
POINT(0,0)/POINT(0,0),
POINT(0,0) MOD POINT(0,0) LIMIT 0;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`POINT(0,0)+POINT(0,0)` geometry DEFAULT NULL,
`POINT(0,0)-POINT(0,0)` geometry DEFAULT NULL,
`POINT(0,0)*POINT(0,0)` geometry DEFAULT NULL,
`POINT(0,0)/POINT(0,0)` geometry DEFAULT NULL,
`POINT(0,0) MOD POINT(0,0)` geometry DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
CREATE TABLE t1 AS SELECT
POINT(0,0)+'0',
POINT(0,0)-'0',
POINT(0,0)*'0',
POINT(0,0)/'0',
POINT(0,0) MOD '0' LIMIT 0;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`POINT(0,0)+'0'` longtext DEFAULT NULL,
`POINT(0,0)-'0'` longtext DEFAULT NULL,
`POINT(0,0)*'0'` longtext DEFAULT NULL,
`POINT(0,0)/'0'` longtext DEFAULT NULL,
`POINT(0,0) MOD '0'` longtext DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
CREATE TABLE t1 AS SELECT
'0'+POINT(0,0),
'0'*POINT(0,0) LIMIT 0;
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`'0'+POINT(0,0)` longtext DEFAULT NULL,
`'0'*POINT(0,0)` longtext DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
CREATE TABLE t1 AS SELECT '0'-POINT(0,0) LIMIT 0;
ERROR HY000: Illegal parameter data types varchar and geometry for operation '-'
CREATE TABLE t1 AS SELECT '0'/POINT(0,0) LIMIT 0;
ERROR HY000: Illegal parameter data types varchar and geometry for operation '/'
CREATE TABLE t1 AS SELECT '0' MOD POINT(0,0) LIMIT 0;
ERROR HY000: Illegal parameter data types varchar and geometry for operation '%'
SET debug_dbug='-d,num_op';
65 changes: 65 additions & 0 deletions mysql-test/r/gis.result
Expand Up @@ -3837,5 +3837,70 @@ SELECT LENGTH(CAST(COALESCE(a) AS BINARY)) FROM t1;
LENGTH(CAST(COALESCE(a) AS BINARY))
DROP TABLE t1;
#
# MDEV-12238 Add Type_handler::Item_func_{plus|minus|mul|div|mod}_fix_length_and_dec()
#
CREATE TABLE t1 (a GEOMETRY);
SELECT POINT(1,1) + 1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '+'
SELECT POINT(1,1) - 1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '-'
SELECT POINT(1,1) * 1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '*'
SELECT POINT(1,1) / 1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '/'
SELECT POINT(1,1) MOD 1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '%'
SELECT 1 + POINT(1,1);
ERROR HY000: Illegal parameter data types bigint and geometry for operation '+'
SELECT 1 - POINT(1,1);
ERROR HY000: Illegal parameter data types bigint and geometry for operation '-'
SELECT 1 * POINT(1,1);
ERROR HY000: Illegal parameter data types bigint and geometry for operation '*'
SELECT 1 / POINT(1,1);
ERROR HY000: Illegal parameter data types bigint and geometry for operation '/'
SELECT 1 MOD POINT(1,1);
ERROR HY000: Illegal parameter data types bigint and geometry for operation '%'
SELECT a + 1 FROM t1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '+'
SELECT a - 1 FROM t1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '-'
SELECT a * 1 FROM t1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '*'
SELECT a / 1 FROM t1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '/'
SELECT a MOD 1 FROM t1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '%'
SELECT 1 + a FROM t1;
ERROR HY000: Illegal parameter data types bigint and geometry for operation '+'
SELECT 1 - a FROM t1;
ERROR HY000: Illegal parameter data types bigint and geometry for operation '-'
SELECT 1 * a FROM t1;
ERROR HY000: Illegal parameter data types bigint and geometry for operation '*'
SELECT 1 / a FROM t1;
ERROR HY000: Illegal parameter data types bigint and geometry for operation '/'
SELECT 1 MOD a FROM t1;
ERROR HY000: Illegal parameter data types bigint and geometry for operation '%'
SELECT COALESCE(a) + 1 FROM t1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '+'
SELECT COALESCE(a) - 1 FROM t1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '-'
SELECT COALESCE(a) * 1 FROM t1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '*'
SELECT COALESCE(a) / 1 FROM t1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '/'
SELECT COALESCE(a) MOD 1 FROM t1;
ERROR HY000: Illegal parameter data types geometry and bigint for operation '%'
SELECT 1 + COALESCE(a) FROM t1;
ERROR HY000: Illegal parameter data types bigint and geometry for operation '+'
SELECT 1 - COALESCE(a) FROM t1;
ERROR HY000: Illegal parameter data types bigint and geometry for operation '-'
SELECT 1 * COALESCE(a) FROM t1;
ERROR HY000: Illegal parameter data types bigint and geometry for operation '*'
SELECT 1 / COALESCE(a) FROM t1;
ERROR HY000: Illegal parameter data types bigint and geometry for operation '/'
SELECT 1 MOD COALESCE(a) FROM t1;
ERROR HY000: Illegal parameter data types bigint and geometry for operation '%'
DROP TABLE t1;
#
# End of 10.3 tests
#
65 changes: 65 additions & 0 deletions mysql-test/t/gis-debug.test
Expand Up @@ -46,3 +46,68 @@ DROP TABLE t1;

SET SESSION debug_dbug="-d,Predicant_to_list_comparator";
SET SESSION debug_dbug="-d,Item_func_in";


--echo #
--echo # MDEV-12238 Add Type_handler::Item_func_{plus|minus|mul|div|mod}_fix_length_and_dec()
--echo #

# This tests is to check that operators '+' and '*' are commutative,
# while operators '/', '-' and 'MOD' are not commutative.
#
# It forces substitution of type_aggregator_for_{plus|minus|mul|div|mod} to
# type_aggregator_for_result / type_aggregator_non_commutative_test,
# which have pairs:
# (GEOMETRY,GEOMETRY)->GEOMETRY
# (GEOMETRY,VARCHAR)->GEOMETRY
# Note, they don't not have a pair:
# (VARCHAR,GEOMETRY)->GEOMETRY
#
# Commutative operators should work for all these argument type combinations:
# (GEOMETRY,GEOMETRY), (GEOMETRY,VARCHAR), (VARCHAR,GEOMETRY).
# Non-commutative operators should work for:
# (GEOMETRY,GEOMETRY), (GEOMETRY,VARCHAR),
# but should fail for (VARCHAR,GEOMETRY).
#
# Note, LIMIT 0 is needed to avoid calling str_op(), which does DBUG_ASSERT(0).

SET debug_dbug='+d,num_op';

# (GEOMETRY,GEOMETRY) gives GEOMETRY for all operators
CREATE TABLE t1 AS SELECT
POINT(0,0)+POINT(0,0),
POINT(0,0)-POINT(0,0),
POINT(0,0)*POINT(0,0),
POINT(0,0)/POINT(0,0),
POINT(0,0) MOD POINT(0,0) LIMIT 0;
SHOW CREATE TABLE t1;
DROP TABLE t1;

# (GEOMETRY,VARCHAR) gives GEOMETRY for all operators
CREATE TABLE t1 AS SELECT
POINT(0,0)+'0',
POINT(0,0)-'0',
POINT(0,0)*'0',
POINT(0,0)/'0',
POINT(0,0) MOD '0' LIMIT 0;
SHOW CREATE TABLE t1;
DROP TABLE t1;

# (VARCHAR,GEOMETRY) gives GEOMETRY for commutative operators
CREATE TABLE t1 AS SELECT
'0'+POINT(0,0),
'0'*POINT(0,0) LIMIT 0;
SHOW CREATE TABLE t1;
DROP TABLE t1;

# (VARCHAR,GEOMETRY) gives an error for non-commutative operators
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CREATE TABLE t1 AS SELECT '0'-POINT(0,0) LIMIT 0;

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CREATE TABLE t1 AS SELECT '0'/POINT(0,0) LIMIT 0;

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
CREATE TABLE t1 AS SELECT '0' MOD POINT(0,0) LIMIT 0;

SET debug_dbug='-d,num_op';
75 changes: 75 additions & 0 deletions mysql-test/t/gis.test
Expand Up @@ -2016,6 +2016,81 @@ SELECT LENGTH(CAST(COALESCE(a) AS BINARY)) FROM t1;

DROP TABLE t1;

--echo #
--echo # MDEV-12238 Add Type_handler::Item_func_{plus|minus|mul|div|mod}_fix_length_and_dec()
--echo #

CREATE TABLE t1 (a GEOMETRY);

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT POINT(1,1) + 1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT POINT(1,1) - 1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT POINT(1,1) * 1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT POINT(1,1) / 1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT POINT(1,1) MOD 1;

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 + POINT(1,1);
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 - POINT(1,1);
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 * POINT(1,1);
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 / POINT(1,1);
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 MOD POINT(1,1);

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT a + 1 FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT a - 1 FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT a * 1 FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT a / 1 FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT a MOD 1 FROM t1;

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 + a FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 - a FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 * a FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 / a FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 MOD a FROM t1;

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT COALESCE(a) + 1 FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT COALESCE(a) - 1 FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT COALESCE(a) * 1 FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT COALESCE(a) / 1 FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT COALESCE(a) MOD 1 FROM t1;

--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 + COALESCE(a) FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 - COALESCE(a) FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 * COALESCE(a) FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 / COALESCE(a) FROM t1;
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
SELECT 1 MOD COALESCE(a) FROM t1;

DROP TABLE t1;


--echo #
--echo # End of 10.3 tests
--echo #

0 comments on commit 45730fb

Please sign in to comment.