summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2022-01-28 22:32:56 +0400
committerAlexander Barkov <bar@mariadb.com>2022-01-28 22:32:56 +0400
commit059a8fd87eb900a5a12185b1963e5623df874c21 (patch)
treec941e055a8d088a2da04832718dfd9f822b8f833
parentfb8fea3490b79b9b92e188f6bb4ca84f8636efc3 (diff)
downloadmariadb-git-059a8fd87eb900a5a12185b1963e5623df874c21.tar.gz
MDEV-27668 Assertion `item->type_handler()->is_traditional_scalar_type() || item->type_handler() == type_handler()' failed in Field_inet6::can_optimize_keypart_ref
-rw-r--r--plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.result21
-rw-r--r--plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.test18
-rw-r--r--plugin/type_inet/sql_type_inet.cc8
-rw-r--r--sql/sql_type.h5
4 files changed, 50 insertions, 2 deletions
diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.result b/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.result
index eb35a9a09ca..2b6603a51c3 100644
--- a/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.result
+++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.result
@@ -40,3 +40,24 @@ ERROR HY000: Illegal parameter data types inet6 and longblob/json for operation
SELECT a+c FROM t1;
ERROR HY000: Illegal parameter data types inet6 and longblob for operation '+'
DROP TABLE t1;
+#
+# MDEV-27668 Assertion `item->type_handler()->is_traditional_scalar_type() || item->type_handler() == type_handler()' failed in Field_inet6::can_optimize_keypart_ref
+#
+CREATE TABLE t1 (i INET6 PRIMARY KEY);
+CREATE TABLE t2 (a VARCHAR(40) CHECK (JSON_VALID(a)));
+SELECT * FROM t1 JOIN t2 ON (i = a);
+i a
+INSERT INTO t1 VALUES ('::'),('ffff::ffff');
+INSERT INTO t2 VALUES ('{}'),('[]');
+SELECT * FROM t1 JOIN t2 ON (i = a);
+i a
+DROP TABLE t1, t2;
+CREATE TABLE t1 (i INET6 PRIMARY KEY);
+SELECT * FROM t1 WHERE i<JSON_OBJECT('c','b');
+i
+INSERT INTO t1 VALUES ('::'),('ffff::ffff');
+SELECT * FROM t1 WHERE i<JSON_OBJECT('c','b');
+i
+Warnings:
+Warning 1292 Incorrect inet6 value: '{"c": "b"}'
+DROP TABLE t1;
diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.test b/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.test
index a7aac1ecf00..74a91ff9a05 100644
--- a/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.test
+++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.test
@@ -48,3 +48,21 @@ SELECT a+b FROM t1;
SELECT a+c FROM t1;
DROP TABLE t1;
+
+--echo #
+--echo # MDEV-27668 Assertion `item->type_handler()->is_traditional_scalar_type() || item->type_handler() == type_handler()' failed in Field_inet6::can_optimize_keypart_ref
+--echo #
+
+CREATE TABLE t1 (i INET6 PRIMARY KEY);
+CREATE TABLE t2 (a VARCHAR(40) CHECK (JSON_VALID(a)));
+SELECT * FROM t1 JOIN t2 ON (i = a);
+INSERT INTO t1 VALUES ('::'),('ffff::ffff');
+INSERT INTO t2 VALUES ('{}'),('[]');
+SELECT * FROM t1 JOIN t2 ON (i = a);
+DROP TABLE t1, t2;
+
+CREATE TABLE t1 (i INET6 PRIMARY KEY);
+SELECT * FROM t1 WHERE i<JSON_OBJECT('c','b');
+INSERT INTO t1 VALUES ('::'),('ffff::ffff');
+SELECT * FROM t1 WHERE i<JSON_OBJECT('c','b');
+DROP TABLE t1;
diff --git a/plugin/type_inet/sql_type_inet.cc b/plugin/type_inet/sql_type_inet.cc
index 9832a84a1b9..26be505ac65 100644
--- a/plugin/type_inet/sql_type_inet.cc
+++ b/plugin/type_inet/sql_type_inet.cc
@@ -936,8 +936,11 @@ public:
Mixing of two different non-traditional types is currently prevented.
This may change in the future. For example, INET4 and INET6
data types can be made comparable.
+ But we allow mixing INET6 to a data type directly inherited from
+ a traditional type, e.g. INET6=VARCHAR/JSON.
*/
- DBUG_ASSERT(item->type_handler()->is_traditional_scalar_type() ||
+ DBUG_ASSERT(item->type_handler()->type_handler_base_or_self()->
+ is_traditional_scalar_type() ||
item->type_handler() == type_handler());
return true;
}
@@ -951,7 +954,8 @@ public:
bool is_eq_func) const override
{
// See the DBUG_ASSERT comment in can_optimize_keypart_ref()
- DBUG_ASSERT(item->type_handler()->is_traditional_scalar_type() ||
+ DBUG_ASSERT(item->type_handler()->type_handler_base_or_self()->
+ is_traditional_scalar_type() ||
item->type_handler() == type_handler());
return true;
}
diff --git a/sql/sql_type.h b/sql/sql_type.h
index 8ea5b9ddde1..a2e21d81894 100644
--- a/sql/sql_type.h
+++ b/sql/sql_type.h
@@ -3773,6 +3773,11 @@ public:
{
return NULL;
}
+ const Type_handler *type_handler_base_or_self() const
+ {
+ const Type_handler *res= type_handler_base();
+ return res ? res : this;
+ }
virtual const Type_handler *type_handler_for_comparison() const= 0;
virtual const Type_handler *type_handler_for_native_format() const
{