[MDEV-19923] Add type handlers for geometry sub-types Created: 2019-07-02  Updated: 2019-07-03  Resolved: 2019-07-03

Status: Closed
Project: MariaDB Server
Component/s: Data types, GIS
Fix Version/s: 10.5.0

Type: Task Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Blocks
blocks MDEV-4912 Data type plugin API version 1 Closed
blocks MDEV-17832 Protocol: extensions for Pluggable ty... Closed
is blocked by MDEV-19908 Add class Type_collection Closed
Relates
relates to MDEV-19944 Remove GIS data types from keyword li... Closed

 Description   

According to the OpenGIS specifications for SQL, geometry sub-types like POINT, LINESTRING, etc. are separate data types. Having separate type handlers Type_handler_point, Type_handler_linestring, etc (instead of a single Type_handler_geometry with a geometry type attribute) will look more natural in the code:

  • It will be easier to turn Type_handler_geometry into a plugin, e.g. in the parser. The geometry specific fields in %union in sql_yacc.yy, such as geom_type, will be removed.
  • Better error reporting, e.g. precise data type instead of GEOMETRY:

    SELECT POINT(0,0)+POINT(0,0);
    ERROR HY000: Illegal parameter data types point and point for operation '+'
    

  • It will make implementing MDEV-17832 easier (with a cleaner API).
  • It will allow to localize geometry specific things inside Type_handler_geometry, e.g.
    • move enum geometry_type from Field to Type_handler_geometry
    • remove Item::geometry_type() and Item::set_geometry_type()

To remove geometry specific tests, such as f_is_geom(), from the loop handling keys in mysql_prepare_create_table(), and to simplify adding new data typesr, lets add a few virtual methods:

virtual bool Key_part_spec_init_primary(Key_part_spec *part,
                                        const Column_definition &def,
                                        const handler *file) const;
virtual bool Key_part_spec_init_unique(Key_part_spec *part,
                                       const Column_definition &def,
                                       const handler *file,
                                       bool *has_key_needed) const;
virtual bool Key_part_spec_init_multiple(Key_part_spec *part,
                                         const Column_definition &def,
                                         const handler *file) const;
virtual bool Key_part_spec_init_foreign(Key_part_spec *part,
                                        const Column_definition &def,
                                        const handler *file) const;
virtual bool Key_part_spec_init_spatial(Key_part_spec *part,
                                        const Column_definition &def) const;

With these new methods, data type plugins will be able to decide how to handle various key types.
This also will help to move POINT specific global declaration from sql_table.h inside Type_handler_point:

/* Maximum length of GEOM_POINT Field */
#define MAX_LEN_GEOM_POINT_FIELD   25

Let's also add separate classes under Item_func_spatial_collection for all constructor-alike SQL functions, so the hierarchy looks like this:

    Item_func_spatial_collection
      Item_func_geometrycollection
      Item_func_linestring
      Item_func_polygon
      Item_func_multilinestring
      Item_func_multipoint
      Item_func_multipolygon

In the future, it will allow to remove geometry-specific code in the grammar, e.g.:

       | GEOMETRYCOLLECTION '(' expr_list ')'
         {
           $$= GEOM_NEW(thd,
                        Item_func_spatial_collection(thd, *$3,
                        Geometry::wkb_geometrycollection,
                        Geometry::wkb_point));
           $$= GEOM_NEW(thd, Item_func_geometrycollection(thd, *$3));
         }

In a separate MDEV later we'll replace it to something like this:

       | user_defined_type_handler_name '(' expr_list ')'
         {
           if (!($$= $1->make_constructor_item($3))
             MYSQL_YYABORT;
         }


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