Skip to content

Commit 001f93d

Browse files
committed
MDEV-12668 SRID is not preserved in UNION, VIEW, MIN, MAX
Fixing the problem that an operation involving a mix of two or more GEOMETRY operands did not preserve their SRIDs. Now SRIDs are preserved by hybrid functions, subqueries, TVCs, UNIONs, VIEWs. Incompatible change: An attempt to mix two different SRIDs now raises an error. Details: - Adding a new class Type_extra_attributes. It's a generic container which can store very specific data type attributes. For now it can store one uint32 and one const pointer attribute (for GEOMETRY's SRID and for ENUM/SET TYPELIB respectively). In the future it can grow as needed. Type_extra_attributes will also be reused soon to store "const Type_zone*" pointers for the TIMESTAMP's "WITH TIME ZONE 'tz'" attribute (a timestamp data type with a fixed time zone independent from @@time_zone). The time zone attribute will be stored in exactly the same way like a TYPELIB pointer is stored by ENUM/SET. - Removing Column_definition_attributes members "interval" and "srid". Deriving Column_definition_attributes from the generic attribute container Type_extra_attributes instead. - Adding a new class Type_typelib_attributes, to store the TYPELIB of the ENUM and SET data types. Deriving Field_enum from it. Removing the member Field_enum::typelib. - Adding a new class Type_geom_attributes, to store the GEOMETRY related attributes. Deriving Field_geom from it. Removing the member Field_geom::srid. - Removing virtual methods: Field::get_typelib() Type_all_attributes::get_typelib() and Type_all_attributes::set_typelib() They were very specific to TYPELIB. Adding more generic virtual methods instead: * Field::type_extra_attributes() - to get extra attributes * Type_all_attributes::type_extra_attributes() - to get extra attributes * Type_all_attributes::type_extra_attributes_addr() - to set extra attributes - Removing Item_type_holder::enum_set_typelib. Deriving Item_type_holder from the generic attribute container Type_extra_attributes instead. This makes it possible for UNION to preserve SRID (in addition to preserving TYPELIB). - Deriving Item_hybrid_func from Type_extra_attributes. This makes it possible for hybrid functions (e.g. CASE, COALESCE, LEAST, GREATEST etc) to preserve SRID. - Deriving Item_singlerow_subselect from Type_extra_attributes and overriding methods: * Item_cache::type_extra_attributes() * subselect_single_select_engine::fix_length_and_dec() * Item_singlerow_subselect::type_extra_attributes() * Item_singlerow_subselect::type_extra_attributes_addr() This is needed to preserve SRID in subqueries and TVCs - Cleanup: fixing the data type of members * Binlog_type_info::m_enum_typelib * Binlog_type_info::m_set_typelib from "TYPELIB *" to "const TYPELIB *"
1 parent 486d42d commit 001f93d

21 files changed

+502
-153
lines changed

mysql-test/main/gis.result

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5437,3 +5437,69 @@ DROP TABLE t1;
54375437
#
54385438
# End of 10.5 tests
54395439
#
5440+
#
5441+
# Start of 11.5 tests
5442+
#
5443+
#
5444+
# MDEV-12668 SRID is not preserved in UNION, VIEW, MIN, MAX
5445+
#
5446+
CREATE TABLE t1 (a POINT REF_SYSTEM_ID=0, b POINT REF_SYSTEM_ID=102);
5447+
SELECT a FROM t1 UNION SELECT b FROM t1;
5448+
ERROR HY000: Illegal parameter data types `point ref_system_id=0` and `point ref_system_id=102` for operation 'UNION'
5449+
DROP TABLE t1;
5450+
CREATE TABLE t1 (a POINT REF_SYSTEM_ID=101, b POINT REF_SYSTEM_ID=102);
5451+
SELECT a FROM t1 UNION SELECT b FROM t1;
5452+
ERROR HY000: Illegal parameter data types `point ref_system_id=101` and `point ref_system_id=102` for operation 'UNION'
5453+
DROP TABLE t1;
5454+
CREATE TABLE t1 (a POINT REF_SYSTEM_ID=101, b POINT REF_SYSTEM_ID=101);
5455+
CREATE TABLE t2 AS SELECT a, b FROM t1;
5456+
CREATE VIEW v2 AS SELECT a, b FROM t1;
5457+
CREATE TABLE t3 AS SELECT a FROM t1 UNION SELECT b FROM t1;
5458+
CREATE VIEW v3 AS SELECT a FROM t1 UNION SELECT b FROM t1;
5459+
CREATE TABLE t4 AS SELECT COALESCE(a,b) AS a FROM t1;
5460+
CREATE VIEW v4 AS SELECT COALESCE(a,b) AS a FROM t1;
5461+
CREATE TABLE t5 AS SELECT LEAST(a,b) AS a FROM t1;
5462+
CREATE VIEW v5 AS SELECT LEAST(a,b) AS a FROM t1;
5463+
CREATE TABLE t6 AS SELECT MIN(a) AS a FROM t1;
5464+
CREATE VIEW v6 AS SELECT MIN(a) AS a FROM t1;
5465+
CREATE TABLE t7 AS SELECT MIN(a) AS a FROM t1 UNION SELECT b FROM v2;
5466+
CREATE VIEW v7 AS SELECT MIN(a) AS a FROM t1 UNION SELECT b FROM v2;
5467+
CREATE TABLE t8 AS SELECT (SELECT a FROM t1) AS a;
5468+
CREATE VIEW v8 AS SELECT (SELECT a FROM t1) AS a;
5469+
CREATE TABLE t9 AS VALUES ((SELECT MAX(a) FROM t1)),(((SELECT MIN(b) FROM t1)));
5470+
CREATE VIEW v9 AS VALUES ((SELECT MAX(a) FROM t1)),(((SELECT MIN(b) FROM t1)));
5471+
SELECT
5472+
G_TABLE_NAME, G_GEOMETRY_COLUMN, SRID
5473+
FROM
5474+
INFORMATION_SCHEMA.GEOMETRY_COLUMNS
5475+
WHERE
5476+
F_TABLE_SCHEMA='test'
5477+
ORDER
5478+
BY G_TABLE_NAME, G_GEOMETRY_COLUMN;
5479+
G_TABLE_NAME G_GEOMETRY_COLUMN SRID
5480+
t1 a 101
5481+
t1 b 101
5482+
t2 a 101
5483+
t2 b 101
5484+
t3 a 101
5485+
t4 a 101
5486+
t5 a 101
5487+
t6 a 101
5488+
t7 a 101
5489+
t8 a 101
5490+
t9 (SELECT MAX(a) FROM t1) 101
5491+
v2 a 101
5492+
v2 b 101
5493+
v3 a 101
5494+
v4 a 101
5495+
v5 a 101
5496+
v6 a 101
5497+
v7 a 101
5498+
v8 a 101
5499+
v9 (select max(`test`.`t1`.`a`) from `test`.`t1`) 101
5500+
DROP TABLE t2,t3,t4,t5,t6,t7,t8,t9;
5501+
DROP VIEW v2,v3,v4,v5,v6,v7,v8,v9;
5502+
DROP TABLE t1;
5503+
#
5504+
# End of 11.5 tests
5505+
#

mysql-test/main/gis.test

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3441,3 +3441,64 @@ DROP TABLE t1;
34413441
--echo #
34423442
--echo # End of 10.5 tests
34433443
--echo #
3444+
3445+
--echo #
3446+
--echo # Start of 11.5 tests
3447+
--echo #
3448+
3449+
--echo #
3450+
--echo # MDEV-12668 SRID is not preserved in UNION, VIEW, MIN, MAX
3451+
--echo #
3452+
3453+
CREATE TABLE t1 (a POINT REF_SYSTEM_ID=0, b POINT REF_SYSTEM_ID=102);
3454+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
3455+
SELECT a FROM t1 UNION SELECT b FROM t1;
3456+
DROP TABLE t1;
3457+
3458+
CREATE TABLE t1 (a POINT REF_SYSTEM_ID=101, b POINT REF_SYSTEM_ID=102);
3459+
--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION
3460+
SELECT a FROM t1 UNION SELECT b FROM t1;
3461+
DROP TABLE t1;
3462+
3463+
CREATE TABLE t1 (a POINT REF_SYSTEM_ID=101, b POINT REF_SYSTEM_ID=101);
3464+
3465+
CREATE TABLE t2 AS SELECT a, b FROM t1;
3466+
CREATE VIEW v2 AS SELECT a, b FROM t1;
3467+
3468+
CREATE TABLE t3 AS SELECT a FROM t1 UNION SELECT b FROM t1;
3469+
CREATE VIEW v3 AS SELECT a FROM t1 UNION SELECT b FROM t1;
3470+
3471+
CREATE TABLE t4 AS SELECT COALESCE(a,b) AS a FROM t1;
3472+
CREATE VIEW v4 AS SELECT COALESCE(a,b) AS a FROM t1;
3473+
3474+
CREATE TABLE t5 AS SELECT LEAST(a,b) AS a FROM t1;
3475+
CREATE VIEW v5 AS SELECT LEAST(a,b) AS a FROM t1;
3476+
3477+
CREATE TABLE t6 AS SELECT MIN(a) AS a FROM t1;
3478+
CREATE VIEW v6 AS SELECT MIN(a) AS a FROM t1;
3479+
3480+
CREATE TABLE t7 AS SELECT MIN(a) AS a FROM t1 UNION SELECT b FROM v2;
3481+
CREATE VIEW v7 AS SELECT MIN(a) AS a FROM t1 UNION SELECT b FROM v2;
3482+
3483+
CREATE TABLE t8 AS SELECT (SELECT a FROM t1) AS a;
3484+
CREATE VIEW v8 AS SELECT (SELECT a FROM t1) AS a;
3485+
3486+
CREATE TABLE t9 AS VALUES ((SELECT MAX(a) FROM t1)),(((SELECT MIN(b) FROM t1)));
3487+
CREATE VIEW v9 AS VALUES ((SELECT MAX(a) FROM t1)),(((SELECT MIN(b) FROM t1)));
3488+
3489+
SELECT
3490+
G_TABLE_NAME, G_GEOMETRY_COLUMN, SRID
3491+
FROM
3492+
INFORMATION_SCHEMA.GEOMETRY_COLUMNS
3493+
WHERE
3494+
F_TABLE_SCHEMA='test'
3495+
ORDER
3496+
BY G_TABLE_NAME, G_GEOMETRY_COLUMN;
3497+
3498+
DROP TABLE t2,t3,t4,t5,t6,t7,t8,t9;
3499+
DROP VIEW v2,v3,v4,v5,v6,v7,v8,v9;
3500+
DROP TABLE t1;
3501+
3502+
--echo #
3503+
--echo # End of 11.5 tests
3504+
--echo #

0 commit comments

Comments
 (0)