Skip to content

Commit 3330929

Browse files
committed
Bug #25451180 SPLIT ITEM_FUNC_SPATIAL_OPERATION
Split class Item_func_spatial_operation into one class per SQL function it computes. Preserve Item_func_spatial_operation as a base class that contains only the GIS computations and val_int(). Add "m_" prefix to member variables of Item_func_spatial_operation. Change BG_geometry_collection::merge_one_run() to take an Item_func_st_union pointer as parameter, since that's the only spatial operation used by this function. Change-Id: I8e10ae0304898bd017023670eb19f4b70f4be395
1 parent 8113ef1 commit 3330929

File tree

4 files changed

+138
-149
lines changed

4 files changed

+138
-149
lines changed

sql/item_create.cc

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -627,29 +627,6 @@ using Mbr_within_instantiator=
627627
using Mbr_crosses_instantiator=
628628
Mbr_rel_instantiator<Item_func::SP_CROSSES_FUNC>;
629629

630-
template<Item_func_spatial_operation::op_type Op_type>
631-
class Spatial_instantiator
632-
{
633-
public:
634-
static const uint Min_argcount= 2;
635-
static const uint Max_argcount= 2;
636-
637-
Item *instantiate(THD *thd, PT_item_list *args)
638-
{
639-
return new (thd->mem_root)
640-
Item_func_spatial_operation(POS(), (*args)[0], (*args)[1], Op_type);
641-
}
642-
};
643-
644-
using Intersection_instantiator=
645-
Spatial_instantiator<Item_func_spatial_operation::op_intersection>;
646-
using Difference_instantiator=
647-
Spatial_instantiator<Item_func_spatial_operation::op_difference>;
648-
using Union_instantiator=
649-
Spatial_instantiator<Item_func_spatial_operation::op_union>;
650-
using Symdifference_instantiator=
651-
Spatial_instantiator<Item_func_spatial_operation::op_symdifference>;
652-
653630

654631
template<Item_func::Functype Functype>
655632
using Spatial_rel_instantiator=
@@ -1778,7 +1755,7 @@ static const std::pair<const char *, Create_func *> func_array[]=
17781755
{ "ST_CONTAINS", SQL_FACTORY(St_contains_instantiator) },
17791756
{ "ST_CONVEXHULL", SQL_FN(Item_func_convex_hull, 1) },
17801757
{ "ST_CROSSES", SQL_FACTORY(St_crosses_instantiator) },
1781-
{ "ST_DIFFERENCE", SQL_FACTORY(Difference_instantiator) },
1758+
{ "ST_DIFFERENCE", SQL_FN(Item_func_st_difference, 2) },
17821759
{ "ST_DIMENSION", SQL_FN(Item_func_dimension, 1) },
17831760
{ "ST_DISJOINT", SQL_FACTORY(St_disjoint_instantiator) },
17841761
{ "ST_DISTANCE", SQL_FN_LIST(Item_func_distance, 2) },
@@ -1802,7 +1779,7 @@ static const std::pair<const char *, Create_func *> func_array[]=
18021779
{ "ST_GEOMFROMWKB", SQL_FACTORY(Geomfromwkb_instantiator) },
18031780
{ "ST_INTERIORRINGN", SQL_FACTORY(Sp_interiorringn_instantiator) },
18041781
{ "ST_INTERSECTS", SQL_FACTORY(St_intersects_instantiator) },
1805-
{ "ST_INTERSECTION", SQL_FACTORY(Intersection_instantiator) },
1782+
{ "ST_INTERSECTION", SQL_FN(Item_func_st_intersection, 2) },
18061783
{ "ST_ISCLOSED", SQL_FN(Item_func_isclosed, 1) },
18071784
{ "ST_ISEMPTY", SQL_FN(Item_func_isempty, 1) },
18081785
{ "ST_ISSIMPLE", SQL_FN(Item_func_issimple, 1) },
@@ -1843,10 +1820,10 @@ static const std::pair<const char *, Create_func *> func_array[]=
18431820
{ "ST_SIMPLIFY", SQL_FN(Item_func_simplify, 2) },
18441821
{ "ST_SRID", SQL_FACTORY(Srid_instantiator) },
18451822
{ "ST_STARTPOINT", SQL_FACTORY(Startpoint_instantiator) },
1846-
{ "ST_SYMDIFFERENCE", SQL_FACTORY(Symdifference_instantiator) },
1823+
{ "ST_SYMDIFFERENCE", SQL_FN(Item_func_st_symdifference, 2) },
18471824
{ "ST_SWAPXY", SQL_FN(Item_func_swap_xy, 1) },
18481825
{ "ST_TOUCHES", SQL_FACTORY(St_touches_instantiator) },
1849-
{ "ST_UNION", SQL_FACTORY(Union_instantiator) },
1826+
{ "ST_UNION", SQL_FN(Item_func_st_union, 2) },
18501827
{ "ST_VALIDATE", SQL_FN(Item_func_validate, 1) },
18511828
{ "ST_WITHIN", SQL_FACTORY(St_within_instantiator) },
18521829
{ "ST_X", SQL_FACTORY(X_instantiator) },

sql/item_geofunc.h

Lines changed: 67 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class BG_result_buf_mgr
127127
};
128128

129129

130-
class Item_func_spatial_operation;
130+
class Item_func_st_union;
131131

132132
/**
133133
A utility class to flatten any hierarchy of geometry collection into one
@@ -197,7 +197,7 @@ class BG_geometry_collection
197197
void merge_components(bool *pnull_value);
198198
private:
199199
template<typename Coordsys>
200-
bool merge_one_run(Item_func_spatial_operation *ifso,
200+
bool merge_one_run(Item_func_st_union *ifsu,
201201
bool *pnull_value);
202202
bool store_geometry(const Geometry *geo, bool break_multi_geom);
203203
Geometry *store(const Geometry *geo);
@@ -1064,9 +1064,25 @@ class Item_func_spatial_rel final : public Item_bool_func2
10641064
/**
10651065
Spatial operations
10661066
*/
1067-
class Item_func_spatial_operation final : public Item_geometry_func
1067+
class Item_func_spatial_operation : public Item_geometry_func
10681068
{
1069+
public:
1070+
String *val_str(String *) override;
1071+
10691072
protected:
1073+
enum op_type
1074+
{
1075+
op_union= 0x10000000,
1076+
op_intersection= 0x20000000,
1077+
op_symdifference= 0x30000000,
1078+
op_difference= 0x40000000,
1079+
};
1080+
1081+
Item_func_spatial_operation(const POS &pos, Item *a, Item *b, op_type sp_op)
1082+
: Item_geometry_func(pos, a, b), m_spatial_op(sp_op)
1083+
{}
1084+
1085+
private:
10701086
// It will call the protected member functions in this class,
10711087
// no data member accessed directly.
10721088
template<typename Geotypes>
@@ -1089,9 +1105,6 @@ class Item_func_spatial_operation final : public Item_geometry_func
10891105

10901106
Geometry *empty_result(String *str, uint32 srid);
10911107

1092-
String tmp_value1,tmp_value2;
1093-
BG_result_buf_mgr bg_resbuf_mgr;
1094-
10951108
bool assign_result(Geometry *geo, String *result);
10961109

10971110
template <typename Geotypes>
@@ -1118,34 +1131,56 @@ class Item_func_spatial_operation final : public Item_geometry_func
11181131
Geometry *geocol_union(const BG_geometry_collection &bggc1,
11191132
const BG_geometry_collection &bggc2,
11201133
String *result);
1121-
public:
1122-
enum op_type
1123-
{
1124-
op_shape= 0,
1125-
op_not= 0x80000000,
1126-
op_union= 0x10000000,
1127-
op_intersection= 0x20000000,
1128-
op_symdifference= 0x30000000,
1129-
op_difference= 0x40000000,
1130-
op_backdifference= 0x50000000,
1131-
op_any= 0x70000000
1132-
};
11331134

1134-
Item_func_spatial_operation(const POS &pos, Item *a, Item *b,
1135-
Item_func_spatial_operation::op_type sp_op) :
1136-
Item_geometry_func(pos, a, b), spatial_op(sp_op)
1137-
{
1138-
}
1139-
virtual ~Item_func_spatial_operation();
1140-
String *val_str(String *) override;
1141-
const char *func_name() const override;
1142-
void print(String *str, enum_query_type query_type) override
1143-
{
1144-
Item_func::print(str, query_type);
1145-
}
1146-
private:
1147-
op_type spatial_op;
1135+
op_type m_spatial_op;
11481136
String m_result_buffer;
1137+
String m_tmp_value1;
1138+
String m_tmp_value2;
1139+
BG_result_buf_mgr m_bg_resbuf_mgr;
1140+
};
1141+
1142+
1143+
class Item_func_st_difference final : public Item_func_spatial_operation
1144+
{
1145+
public:
1146+
Item_func_st_difference(const POS &pos, Item *a, Item *b)
1147+
: Item_func_spatial_operation(pos, a, b, op_difference)
1148+
{}
1149+
const char *func_name() const override
1150+
{ return "st_difference"; }
1151+
};
1152+
1153+
1154+
class Item_func_st_intersection final : public Item_func_spatial_operation
1155+
{
1156+
public:
1157+
Item_func_st_intersection(const POS &pos, Item *a, Item *b)
1158+
: Item_func_spatial_operation(pos, a, b, op_intersection)
1159+
{}
1160+
const char *func_name() const override
1161+
{ return "st_intersection"; }
1162+
};
1163+
1164+
1165+
class Item_func_st_symdifference final : public Item_func_spatial_operation
1166+
{
1167+
public:
1168+
Item_func_st_symdifference(const POS &pos, Item *a, Item *b)
1169+
: Item_func_spatial_operation(pos, a, b, op_symdifference)
1170+
{}
1171+
const char *func_name() const override
1172+
{ return "st_symdifference"; }
1173+
};
1174+
1175+
1176+
class Item_func_st_union final : public Item_func_spatial_operation
1177+
{
1178+
public:
1179+
Item_func_st_union(const POS &pos, Item *a, Item *b)
1180+
: Item_func_spatial_operation(pos, a, b, op_union)
1181+
{}
1182+
const char *func_name() const override
1183+
{ return "st_union"; }
11491184
};
11501185

11511186

sql/item_geofunc_internal.cc

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License as published by
@@ -163,8 +163,7 @@ merge_components(bool *pnull_value)
163163
return;
164164

165165
POS pos;
166-
Item_func_spatial_operation ifso(pos, NULL, NULL,
167-
Item_func_spatial_operation::op_union);
166+
Item_func_st_union ifsu(pos, NULL, NULL);
168167
bool do_again= true;
169168
uint32 last_composition[6]= {0}, num_unchanged_composition= 0;
170169
size_t last_num_geos= 0;
@@ -201,7 +200,7 @@ merge_components(bool *pnull_value)
201200
*/
202201
while (!*pnull_value && do_again)
203202
{
204-
do_again= merge_one_run<Coordsys>(&ifso, pnull_value);
203+
do_again= merge_one_run<Coordsys>(&ifsu, pnull_value);
205204
if (!*pnull_value && do_again)
206205
{
207206
const size_t num_geos= m_geos.size();
@@ -392,13 +391,13 @@ class Rtree_entry_compare
392391
393392
@tparam Coordsys Coordinate system type, specified using those defined in
394393
boost::geometry::cs.
395-
@param ifso the Item_func_spatial_operation object, we here rely on it to
394+
@param ifsu the Item_func_spatial_operation object, we here rely on it to
396395
do union operation.
397396
@param[out] pnull_value takes back null_value set during the operation.
398397
@return whether need another call of this function.
399398
*/
400399
template<typename Coordsys>
401-
bool BG_geometry_collection::merge_one_run(Item_func_spatial_operation *ifso,
400+
bool BG_geometry_collection::merge_one_run(Item_func_st_union *ifsu,
402401
bool *pnull_value)
403402
{
404403
Geometry *gres= NULL;
@@ -538,9 +537,9 @@ bool BG_geometry_collection::merge_one_run(Item_func_spatial_operation *ifso,
538537
break;
539538
}
540539

541-
gres= ifso->bg_geo_set_op<Coordsys>(*i, geom2,
540+
gres= ifsu->bg_geo_set_op<Coordsys>(*i, geom2,
542541
&wkbres);
543-
null_value= ifso->null_value;
542+
null_value= ifsu->null_value;
544543

545544
if (null_value)
546545
{

0 commit comments

Comments
 (0)