summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/main/gis.result7
-rw-r--r--mysql-test/main/gis.test9
-rw-r--r--mysql-test/main/row.result13
-rw-r--r--mysql-test/main/row.test18
-rw-r--r--plugin/type_inet/mysql-test/type_inet/type_inet6.result9
-rw-r--r--plugin/type_inet/mysql-test/type_inet/type_inet6.test12
-rw-r--r--sql/item_timefunc.cc15
-rw-r--r--sql/item_timefunc.h1
-rw-r--r--sql/sql_type.cc5
-rw-r--r--sql/sql_type.h1
10 files changed, 90 insertions, 0 deletions
diff --git a/mysql-test/main/gis.result b/mysql-test/main/gis.result
index 95f4a3f2f79..f6d582c42a6 100644
--- a/mysql-test/main/gis.result
+++ b/mysql-test/main/gis.result
@@ -5308,5 +5308,12 @@ def COALESCE(gc,gc) 255 (type=geometrycollection) 4294967295 0 Y 128 0 63
COALESCE(gc,p) COALESCE(gc,ls) COALESCE(gc,pl) COALESCE(gc,mp) COALESCE(gc,mls) COALESCE(gc,mpl) COALESCE(gc,g) COALESCE(gc,gc)
DROP TABLE t1;
#
+# MDEV-20809 EXTRACT from INET6 value does not produce any warnings
+#
+CREATE TABLE t1 (a GEOMETRY);
+SELECT EXTRACT(DAY FROM a) FROM t1;
+ERROR HY000: Illegal parameter data type geometry for operation 'extract(day)'
+DROP TABLE t1;
+#
# End of 10.5 tests
#
diff --git a/mysql-test/main/gis.test b/mysql-test/main/gis.test
index c18966bc0fb..6ece15bd235 100644
--- a/mysql-test/main/gis.test
+++ b/mysql-test/main/gis.test
@@ -3310,5 +3310,14 @@ FROM t1;
DROP TABLE t1;
--echo #
+--echo # MDEV-20809 EXTRACT from INET6 value does not produce any warnings
+--echo #
+
+CREATE TABLE t1 (a GEOMETRY);
+--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
+SELECT EXTRACT(DAY FROM a) FROM t1;
+DROP TABLE t1;
+
+--echo #
--echo # End of 10.5 tests
--echo #
diff --git a/mysql-test/main/row.result b/mysql-test/main/row.result
index 40d3e2640f0..12ab4208c11 100644
--- a/mysql-test/main/row.result
+++ b/mysql-test/main/row.result
@@ -545,3 +545,16 @@ SELECT (1,null) NOT IN ((2,2),(3,3)), (1,null) NOT IN ((2,2)), (1,null) NOT IN (
#
# End of 10.1 tests
#
+#
+# Start of 10.5 tests
+#
+#
+# MDEV-20809 EXTRACT from INET6 value does not produce any warnings
+#
+CREATE TABLE t1 (a GEOMETRY);
+SELECT EXTRACT(DAY FROM a) FROM t1;
+ERROR HY000: Illegal parameter data type geometry for operation 'extract(day)'
+DROP TABLE t1;
+#
+# End of 10.5 tests
+#
diff --git a/mysql-test/main/row.test b/mysql-test/main/row.test
index 80c61c414bf..d78d61b078a 100644
--- a/mysql-test/main/row.test
+++ b/mysql-test/main/row.test
@@ -314,3 +314,21 @@ SELECT (1,null) NOT IN ((2,2),(3,3)), (1,null) NOT IN ((2,2)), (1,null) NOT IN (
--echo #
--echo # End of 10.1 tests
--echo #
+
+
+--echo #
+--echo # Start of 10.5 tests
+--echo #
+
+--echo #
+--echo # MDEV-20809 EXTRACT from INET6 value does not produce any warnings
+--echo #
+
+CREATE TABLE t1 (a GEOMETRY);
+--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
+SELECT EXTRACT(DAY FROM a) FROM t1;
+DROP TABLE t1;
+
+--echo #
+--echo # End of 10.5 tests
+--echo #
diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6.result b/plugin/type_inet/mysql-test/type_inet/type_inet6.result
index 15c8dbf8ca9..edcdc64dade 100644
--- a/plugin/type_inet/mysql-test/type_inet/type_inet6.result
+++ b/plugin/type_inet/mysql-test/type_inet/type_inet6.result
@@ -1977,3 +1977,12 @@ SELECT MIN(a), MAX(a) FROM t1 GROUP BY id;
MIN(a) MAX(a)
fff:: 8888::
DROP TABLE t1;
+#
+# MDEV-20809 EXTRACT from INET6 value does not produce any warnings
+#
+CREATE TABLE t1 (a INET6);
+SELECT EXTRACT(DAY FROM a) FROM t1;
+ERROR HY000: Illegal parameter data type inet6 for operation 'extract(day)'
+DROP TABLE t1;
+SELECT EXTRACT(DAY FROM CAST('::' AS INET6));
+ERROR HY000: Illegal parameter data type inet6 for operation 'extract(day)'
diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6.test b/plugin/type_inet/mysql-test/type_inet/type_inet6.test
index 8559748c7dd..92ca0d95644 100644
--- a/plugin/type_inet/mysql-test/type_inet/type_inet6.test
+++ b/plugin/type_inet/mysql-test/type_inet/type_inet6.test
@@ -1445,3 +1445,15 @@ CREATE TABLE t1 (id INT, a INET6) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1, 'fff::'),(1, '8888::');
SELECT MIN(a), MAX(a) FROM t1 GROUP BY id;
DROP TABLE t1;
+
+
+--echo #
+--echo # MDEV-20809 EXTRACT from INET6 value does not produce any warnings
+--echo #
+
+CREATE TABLE t1 (a INET6);
+--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
+SELECT EXTRACT(DAY FROM a) FROM t1;
+DROP TABLE t1;
+--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION
+SELECT EXTRACT(DAY FROM CAST('::' AS INET6));
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index a1377af08e6..e47d4fa7f0e 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -2109,6 +2109,21 @@ void Item_extract::print(String *str, enum_query_type query_type)
str->append(')');
}
+
+bool Item_extract::check_arguments() const
+{
+ if (!args[0]->type_handler()->can_return_extract_source(int_type))
+ {
+ char tmp[64];
+ my_snprintf(tmp, sizeof(tmp), "extract(%s)", interval_names[int_type]);
+ my_error(ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION, MYF(0),
+ args[0]->type_handler()->name().ptr(), tmp);
+ return true;
+ }
+ return false;
+}
+
+
bool Item_extract::fix_length_and_dec()
{
maybe_null=1; // If wrong date
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index 5d5f3bd4681..c9a493f8efc 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -1002,6 +1002,7 @@ class Item_extract :public Item_int_func,
longlong val_int();
enum Functype functype() const { return EXTRACT_FUNC; }
const char *func_name() const { return "extract"; }
+ bool check_arguments() const;
bool fix_length_and_dec();
bool eq(const Item *item, bool binary_cmp) const;
void print(String *str, enum_query_type query_type);
diff --git a/sql/sql_type.cc b/sql/sql_type.cc
index cbf620e85d1..cb4d9fb1de5 100644
--- a/sql/sql_type.cc
+++ b/sql/sql_type.cc
@@ -8994,6 +8994,11 @@ bool Type_handler::partition_field_append_value(
}
+bool Type_handler::can_return_extract_source(interval_type int_type) const
+{
+ return type_collection() == &type_collection_std;
+}
+
/***************************************************************************/
LEX_CSTRING Charset::collation_specific_name() const
diff --git a/sql/sql_type.h b/sql/sql_type.h
index c3a6a5f4ff5..2f1063a20f6 100644
--- a/sql/sql_type.h
+++ b/sql/sql_type.h
@@ -3616,6 +3616,7 @@ public:
virtual bool can_return_text() const { return true; }
virtual bool can_return_date() const { return true; }
virtual bool can_return_time() const { return true; }
+ virtual bool can_return_extract_source(interval_type type) const;
virtual bool is_bool_type() const { return false; }
virtual bool is_general_purpose_string_type() const { return false; }
virtual uint Item_time_precision(THD *thd, Item *item) const;