diff --git a/mysql-test/main/spatial_utility_function_collect.result b/mysql-test/main/spatial_utility_function_collect.result index 5dd14a953091d..d74f5987645fa 100644 --- a/mysql-test/main/spatial_utility_function_collect.result +++ b/mysql-test/main/spatial_utility_function_collect.result @@ -122,3 +122,16 @@ GEOMETRYCOLLECTION(MULTIPOINT(5 0),MULTIPOINT(6 0)) GEOMETRYCOLLECTION(MULTIPOINT(6 0),GEOMETRYCOLLECTION EMPTY) GEOMETRYCOLLECTION(GEOMETRYCOLLECTION EMPTY,GEOMETRYCOLLECTION EMPTY) DROP TABLE simple_table; +# +# MDEV-35102 CREATE TABLE AS SELECT ST_collect ... does not work +# +SELECT ST_astext(ST_collect(( POINTFROMTEXT(' POINT( 4 1 ) ') ))); +ST_astext(ST_collect(( POINTFROMTEXT(' POINT( 4 1 ) ') ))) +MULTIPOINT(4 1) +CREATE TABLE tb1 AS SELECT (ST_collect(( POINTFROMTEXT(' POINT( 4 1 ) ') )) ); +SHOW CREATE TABLE tb1; +Table Create Table +tb1 CREATE TABLE `tb1` ( + `(ST_collect(( POINTFROMTEXT(' POINT( 4 1 ) ') )) )` geometry DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +DROP TABLE tb1; diff --git a/mysql-test/main/spatial_utility_function_collect.test b/mysql-test/main/spatial_utility_function_collect.test index 5a68e02ebcdf8..3e638d1d4e081 100644 --- a/mysql-test/main/spatial_utility_function_collect.test +++ b/mysql-test/main/spatial_utility_function_collect.test @@ -189,3 +189,11 @@ PRECEDING AND CURRENT ROW)) AS geocollect FROM simple_table; # SELECT CAST(ST_COLLECT(geo) AS DECIMAL ) FROM simple_table; DROP TABLE simple_table; + +--echo # +--echo # MDEV-35102 CREATE TABLE AS SELECT ST_collect ... does not work +--echo # +SELECT ST_astext(ST_collect(( POINTFROMTEXT(' POINT( 4 1 ) ') ))); +CREATE TABLE tb1 AS SELECT (ST_collect(( POINTFROMTEXT(' POINT( 4 1 ) ') )) ); +SHOW CREATE TABLE tb1; +DROP TABLE tb1; diff --git a/sql/item_sum.cc b/sql/item_sum.cc index d119a57ddcfd9..befcbb7138ee3 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -35,6 +35,7 @@ #include "sql_parse.h" #include "sp_head.h" #include "item_sum.h" +#include "sql_type_geom.h" /** Calculate the affordable RAM limit for structures like TREE or Unique @@ -4803,6 +4804,20 @@ String *Item_func_collect::val_str(String *str) } -Item *Item_func_collect::copy_or_same(THD *thd) { +Item *Item_func_collect::copy_or_same(THD *thd) +{ return new (thd->mem_root) Item_func_collect(thd, is_distinct, this); } + + +const Type_handler *Item_func_collect::type_handler() const +{ + return &type_handler_geometry; +} + + +bool Item_func_collect::fix_fields_impl(THD *thd,Item **) +{ + max_length= UINT_MAX32; + return FALSE; +} diff --git a/sql/item_sum.h b/sql/item_sum.h index cd3a4108644e7..61c96361ce33c 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -2169,8 +2169,7 @@ class Item_func_collect : public Item_sum_str { return GEOMETRY_COLLECT_FUNC; } - const Type_handler *type_handler() const override - { return &type_handler_string; } + const Type_handler *type_handler() const override; String *val_str(String*str) override; LEX_CSTRING func_name_cstring() const override { @@ -2185,10 +2184,7 @@ class Item_func_collect : public Item_sum_str return true; } - bool fix_fields_impl(THD *,Item **) override - { - return FALSE; - } + bool fix_fields_impl(THD *thd,Item **) override; public: Item_func_collect(THD *thd, bool is_distinct, Item *item_par);