[MDEV-21634] Inconsistency in data type conversion with GIS columns Created: 2020-02-02  Updated: 2023-04-27

Status: Open
Project: MariaDB Server
Component/s: Data types, GIS
Affects Version/s: 10.3, 10.4
Fix Version/s: 10.4

Type: Bug Priority: Minor
Reporter: Elena Stepanova Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-21635 Assertion `!is_set() || (m_status == ... Closed

 Description   

It is very well possible that the change in behavior between 10.2 and 10.3 was intentional and correct, but I would want to make sure.

UPDATE in the test case below has a value of a wrong type in WHERE clause.
On 10.2, it produces an error if the column has a key on it, and works without warnings or errors if there is no key.
On 10.3 and later, it works regardless of the key, without a warning or error.

However, if we attempt to INSERT such record into the table, it causes an error on all versions, regardless the key.

sql_mode doesn't seem to anyhow affect it.

Note: All comparison was made on non-debug builds, because the debug version of 10.2 aborts with an assertion failure, filed separately as MDEV-21635.

With key

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (f POINT, KEY(f));
INSERT INTO t1 VALUES (ST_PointFromText('POINT(1 1)')),(ST_PointFromText('POINT(2 2)'));
UPDATE t1 SET f = NULL WHERE f IN ( 'x', ST_PointFromText('POINT(1 1)') );

Without key

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (f POINT);
INSERT INTO t1 VALUES (ST_PointFromText('POINT(1 1)')),(ST_PointFromText('POINT(2 2)'));
UPDATE t1 SET f = NULL WHERE f IN ( 'x', ST_PointFromText('POINT(1 1)') );

10.2 256994ef

MariaDB [test]> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected (0.137 sec)
 
MariaDB [test]> CREATE TABLE t1 (f POINT, KEY(f));
Query OK, 0 rows affected (0.201 sec)
 
MariaDB [test]> INSERT INTO t1 VALUES (ST_PointFromText('POINT(1 1)')),(ST_PointFromText('POINT(2 2)'));
Query OK, 2 rows affected (0.037 sec)
Records: 2  Duplicates: 0  Warnings: 0
 
MariaDB [test]> UPDATE t1 SET f = NULL WHERE f IN ( 'x', ST_PointFromText('POINT(1 1)') );
ERROR 1416 (22003): Cannot get geometry object from data you send to the GEOMETRY field
 
MariaDB [test]> CREATE TABLE t1 (f POINT);
Query OK, 0 rows affected (0.184 sec)
 
MariaDB [test]> INSERT INTO t1 VALUES (ST_PointFromText('POINT(1 1)')),(ST_PointFromText('POINT(2 2)'));
Query OK, 2 rows affected (0.037 sec)
Records: 2  Duplicates: 0  Warnings: 0
 
MariaDB [test]> UPDATE t1 SET f = NULL WHERE f IN ( 'x', ST_PointFromText('POINT(1 1)') );
Query OK, 1 row affected (0.066 sec)
Rows matched: 1  Changed: 1  Warnings: 0

10.3 c8bd8d5c

MariaDB [test]> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected (0.135 sec)
 
MariaDB [test]> CREATE TABLE t1 (f POINT, KEY(f));
Query OK, 0 rows affected (0.209 sec)
 
MariaDB [test]> INSERT INTO t1 VALUES (ST_PointFromText('POINT(1 1)')),(ST_PointFromText('POINT(2 2)'));
Query OK, 2 rows affected (0.038 sec)
Records: 2  Duplicates: 0  Warnings: 0
 
MariaDB [test]> UPDATE t1 SET f = NULL WHERE f IN ( 'x', ST_PointFromText('POINT(1 1)') );
Query OK, 1 row affected (0.064 sec)
Rows matched: 1  Changed: 1  Warnings: 0
 
MariaDB [test]> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected (0.138 sec)
 
MariaDB [test]> CREATE TABLE t1 (f POINT);
Query OK, 0 rows affected (0.192 sec)
 
MariaDB [test]> INSERT INTO t1 VALUES (ST_PointFromText('POINT(1 1)')),(ST_PointFromText('POINT(2 2)'));
Query OK, 2 rows affected (0.037 sec)
Records: 2  Duplicates: 0  Warnings: 0
 
MariaDB [test]> UPDATE t1 SET f = NULL WHERE f IN ( 'x', ST_PointFromText('POINT(1 1)') );
Query OK, 1 row affected (0.065 sec)
Rows matched: 1  Changed: 1  Warnings: 0



 Comments   
Comment by Alexander Barkov [ 2020-02-03 ]

The difference happens because:

  • 10.2 compares string+geometry as string
  • 10.3 compares string+geometry as geometry

So in case of:

 ..WHERE f IN ('x', ST_PointFromText('POINT(1 1)') )

we have two comparison handlers for two values:

  • Type_handler_long_blob for f IN ('x')
  • Type_handler_geometry for f IN (ST_PointFromText('POINT(1 1)'))

This disables keys for IN optimization.

It's probably bad from performance point of view.

Generated at Thu Feb 08 09:08:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.