diff options
author | Alexander Barkov <bar@mariadb.org> | 2017-04-22 23:47:27 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.org> | 2017-04-22 23:47:27 +0400 |
commit | 658082551ffd49a89d5473775bef5197e572d17e (patch) | |
tree | ef6e2a34d6ede0d4a0d7cae20aa2e2355e1c5195 /mysql-test/t/gis.test | |
parent | ba670edfa30a5317c4b0eebd005b83dce63d0dfc (diff) | |
download | mariadb-git-658082551ffd49a89d5473775bef5197e572d17e.tar.gz |
MDEV-12506 Split Item_func_min_max::fix_length_and_dec() into methods in Type_handler + MDEV-12497 + MDEV-12504
This patch does the following:
1. Adds a new method Type_handler_hybrid_field_type::aggregate_for_min_max()
- For non-traditional data types it uses
type_handler_data->m_type_aggregator_for_result.find_handler()
This allows pluggable data types to define in the future their
own behavior of the result data type detection for LEAST/GREATEST.
Also, this disallows expressions of the GEOMETRY data type
(and its variants such as POINT) to be mixed in with
numeric and temporal data types in LEAST/GREATEST.
- For traditional data types it reproduces the old behavior of
the result data type detection (but not attributes, see below).
2. Adds a new virtual method Type_handler::Item_func_min_max_fix_attributes()
and reuses as much as possible the code that calculates data type attributes
for CASE-alike functions (e.g. CASE..THEN, COALESCE, IF).
As the old code responsible for attributes calculation in the old
implementation of Item_func_min_max::fix_length_and_dec()
was not fully correct, this automatically fixes the following bugs:
- MDEV-12497 Wrong data type for LEAST(latin1_expr, utf8_expr)
The old fix_length_and_dec() calculated max_length before
character set aggregation. Now max_length is calculated after, in
Item_func::count_string_length() called from
Item_func::aggregate_attributes_string() called from
Type_handler_string_result::Item_hybrid_func_fix_attributes() called from
Type_handler::Item_func_min_max_fix_attributes() called from
Item_func_min_max::fix_length_and_dec().
- MDEV-12504 Wrong data type for LEAST(date_expr,time_expr)
The old fix_length_and_dec() simply used the maximum of max_length
among all arguments to set its own max_length and did not take
into account that a mixture of DATE and TIME becomes DATETIME.
Now this is correctly handled by:
Type_handler_datetime_common::Item_hybrid_func_fix_attributes() called from
Type_handler::Item_func_min_max_fix_attributes() called from
Item_func_min_max::fix_length_and_dec().
3. Removes the old implementation of Item_func_min_max::fix_length_and_dec()
and replaces it to calls of the new methods.
4. Cleanup: moves the code related to unsigned_flag processing
from Type_handler_hybrid_field_type::aggregate_for_result()
to Type_handler_int_result::Item_hybrid_func_fix_attributes().
This is done:
- to avoid code duplication in
Type_handler_hybrid_field_type::aggregate_for_min_max()
- to get rid of one more call for field_type(), which is unfriendly
to the conceipt of pluggable data types.
Diffstat (limited to 'mysql-test/t/gis.test')
-rw-r--r-- | mysql-test/t/gis.test | 73 |
1 files changed, 72 insertions, 1 deletions
diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test index 1b355b70bc6..9b3dc69a7d1 100644 --- a/mysql-test/t/gis.test +++ b/mysql-test/t/gis.test @@ -1789,7 +1789,7 @@ CALL p1('CREATE TABLE t1 (a ENUM(0x61), b Point)'); CALL p1('CREATE TABLE t1 (a SET(0x61), b Point)'); --enable_query_log ---echo # This does not preserve geometry type (MDEV-9405) +--echo # This does not preserve geometry type (MDEV-12560) CREATE TABLE t1 AS SELECT COALESCE(NULL, Point(1,1)); SHOW CREATE TABLE t1; DROP TABLE t1; @@ -1870,6 +1870,77 @@ DROP PROCEDURE p2; --echo # +--echo # MDEV-12506 Split Item_func_min_max::fix_length_and_dec() into methods in Type_handler +--echo # + +DELIMITER $$; +CREATE PROCEDURE p2(query TEXT) +BEGIN + DECLARE errcount INT DEFAULT 0; + DECLARE CONTINUE HANDLER FOR SQLEXCEPTION + BEGIN + SET errcount = errcount+1; + #SHOW WARNINGS; + GET DIAGNOSTICS CONDITION 1 @p= MESSAGE_TEXT; + SELECT @p AS `ERROR: `; + END; + SELECT query AS ``; + EXECUTE IMMEDIATE query; + IF errcount = 0 + THEN + SHOW CREATE TABLE t2; + DROP TABLE t2; + END IF; +END; +$$ +CREATE PROCEDURE p1(query TEXT) +BEGIN + SELECT query AS `-------------------------------------`; + EXECUTE IMMEDIATE query; + CALL p2('CREATE TABLE t2 AS SELECT LEAST(a,b) FROM t1'); + DROP TABLE t1; +END; +$$ +DELIMITER ;$$ + +--disable_query_log +CALL p1('CREATE TABLE t1 (a CHAR(10), b Point)'); +CALL p1('CREATE TABLE t1 (a VARCHAR(10), b Point)'); +CALL p1('CREATE TABLE t1 (a TINYTEXT, b Point)'); +CALL p1('CREATE TABLE t1 (a TEXT, b Point)'); +CALL p1('CREATE TABLE t1 (a MEDIUMTEXT, b Point)'); +CALL p1('CREATE TABLE t1 (a LONGTEXT, b Point)'); + +CALL p1('CREATE TABLE t1 (a TINYINT, b Point)'); +CALL p1('CREATE TABLE t1 (a SMALLINT, b Point)'); +CALL p1('CREATE TABLE t1 (a MEDIUMINT, b Point)'); +CALL p1('CREATE TABLE t1 (a INT, b Point)'); +CALL p1('CREATE TABLE t1 (a BIGINT, b Point)'); +CALL p1('CREATE TABLE t1 (a FLOAT, b Point)'); +CALL p1('CREATE TABLE t1 (a DOUBLE, b Point)'); +CALL p1('CREATE TABLE t1 (a DECIMAL(10,2), b Point)'); +CALL p1('CREATE TABLE t1 (a BIT(8), b Point)'); + +CALL p1('CREATE TABLE t1 (a TIME, b Point)'); +CALL p1('CREATE TABLE t1 (a DATE, b Point)'); +CALL p1('CREATE TABLE t1 (a DATETIME, b Point)'); +CALL p1('CREATE TABLE t1 (a TIMESTAMP, b Point)'); +CALL p1('CREATE TABLE t1 (a YEAR, b Point)'); + +--echo # This LEAST(ENUM,GEOMETRY) creates BLOB, but fails on error with UNION (see MDEV-12503) +CALL p1('CREATE TABLE t1 (a ENUM(0x61), b Point)'); +CALL p1('CREATE TABLE t1 (a SET(0x61), b Point)'); +--enable_query_log + +--echo # This does not preserve geometry type (MDEV-9405) +CREATE TABLE t1 AS SELECT LEAST(NULL, Point(1,1)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +DROP PROCEDURE p1; +DROP PROCEDURE p2; + +--echo # --echo # MDEV-12001 Split Item_func_round::fix_length_and_dec to virtual methods in Type_handler --echo # |