Skip to content

Commit fa4c552

Browse files
committed
Bug #25451166 SPLIT ITEM_FUNC_SPATIAL_REL
Split class Item_func_spatial_rel into one class per SQL function it computes. Preserve Item_func_spatial_rel as a base class that contains only the GIS computations and val_int(). Remove the unnecessary template parameters to Item_func_spatial_rel::bg_geo_relation_check() and Item_func_spatial_rel::geocol_relcheck_intersect_disjoint(). Those functions are only used for Cartesian geometries. Change-Id: I544d719e83d1af573f396da0a4f596f720909694
1 parent 3330929 commit fa4c552

File tree

5 files changed

+260
-157
lines changed

5 files changed

+260
-157
lines changed

sql/item_create.cc

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -628,28 +628,6 @@ using Mbr_crosses_instantiator=
628628
Mbr_rel_instantiator<Item_func::SP_CROSSES_FUNC>;
629629

630630

631-
template<Item_func::Functype Functype>
632-
using Spatial_rel_instantiator=
633-
Instantiator_with_functype<Item_func_spatial_rel, Functype, 2>;
634-
635-
using St_contains_instantiator=
636-
Spatial_rel_instantiator<Item_func::SP_CONTAINS_FUNC>;
637-
using St_crosses_instantiator=
638-
Spatial_rel_instantiator<Item_func::SP_CROSSES_FUNC>;
639-
using St_disjoint_instantiator=
640-
Spatial_rel_instantiator<Item_func::SP_DISJOINT_FUNC>;
641-
using St_equals_instantiator=
642-
Spatial_rel_instantiator<Item_func::SP_EQUALS_FUNC>;
643-
using St_intersects_instantiator=
644-
Spatial_rel_instantiator<Item_func::SP_INTERSECTS_FUNC>;
645-
using St_overlaps_instantiator=
646-
Spatial_rel_instantiator<Item_func::SP_OVERLAPS_FUNC>;
647-
using St_touches_instantiator=
648-
Spatial_rel_instantiator<Item_func::SP_TOUCHES_FUNC>;
649-
using St_within_instantiator=
650-
Spatial_rel_instantiator<Item_func::SP_WITHIN_FUNC>;
651-
652-
653631
template<Item_func::Functype Functype>
654632
using Spatial_decomp_instantiator=
655633
Instantiator_with_functype<Item_func_spatial_decomp, Functype, 1>;
@@ -1752,17 +1730,17 @@ static const std::pair<const char *, Create_func *> func_array[]=
17521730
{ "ST_BUFFER", SQL_FN_V_LIST(Item_func_buffer, 2, 5) },
17531731
{ "ST_BUFFER_STRATEGY", SQL_FN_V_LIST(Item_func_buffer_strategy, 1, 2) },
17541732
{ "ST_CENTROID", SQL_FN(Item_func_centroid, 1) },
1755-
{ "ST_CONTAINS", SQL_FACTORY(St_contains_instantiator) },
1733+
{ "ST_CONTAINS", SQL_FN(Item_func_st_contains, 2) },
17561734
{ "ST_CONVEXHULL", SQL_FN(Item_func_convex_hull, 1) },
1757-
{ "ST_CROSSES", SQL_FACTORY(St_crosses_instantiator) },
1735+
{ "ST_CROSSES", SQL_FN(Item_func_st_crosses, 2) },
17581736
{ "ST_DIFFERENCE", SQL_FN(Item_func_st_difference, 2) },
17591737
{ "ST_DIMENSION", SQL_FN(Item_func_dimension, 1) },
1760-
{ "ST_DISJOINT", SQL_FACTORY(St_disjoint_instantiator) },
1738+
{ "ST_DISJOINT", SQL_FN(Item_func_st_disjoint, 2) },
17611739
{ "ST_DISTANCE", SQL_FN_LIST(Item_func_distance, 2) },
17621740
{ "ST_DISTANCE_SPHERE", SQL_FN_V_LIST(Item_func_distance_sphere, 2, 3) },
17631741
{ "ST_ENDPOINT", SQL_FACTORY(Endpoint_instantiator) },
17641742
{ "ST_ENVELOPE", SQL_FN(Item_func_envelope, 1) },
1765-
{ "ST_EQUALS", SQL_FACTORY(St_equals_instantiator) },
1743+
{ "ST_EQUALS", SQL_FN(Item_func_st_equals, 2) },
17661744
{ "ST_EXTERIORRING", SQL_FACTORY(Exteriorring_instantiator) },
17671745
{ "ST_GEOHASH", SQL_FN_V(Item_func_geohash, 2, 3) },
17681746
{ "ST_GEOMCOLLFROMTEXT", SQL_FACTORY(Geomcollfromtext_instantiator) },
@@ -1778,7 +1756,7 @@ static const std::pair<const char *, Create_func *> func_array[]=
17781756
{ "ST_GEOMFROMTEXT", SQL_FACTORY(Geomfromtext_instantiator) },
17791757
{ "ST_GEOMFROMWKB", SQL_FACTORY(Geomfromwkb_instantiator) },
17801758
{ "ST_INTERIORRINGN", SQL_FACTORY(Sp_interiorringn_instantiator) },
1781-
{ "ST_INTERSECTS", SQL_FACTORY(St_intersects_instantiator) },
1759+
{ "ST_INTERSECTS", SQL_FN(Item_func_st_intersects, 2) },
17821760
{ "ST_INTERSECTION", SQL_FN(Item_func_st_intersection, 2) },
17831761
{ "ST_ISCLOSED", SQL_FN(Item_func_isclosed, 1) },
17841762
{ "ST_ISEMPTY", SQL_FN(Item_func_isempty, 1) },
@@ -1808,7 +1786,7 @@ static const std::pair<const char *, Create_func *> func_array[]=
18081786
{ "ST_NUMINTERIORRING", SQL_FN(Item_func_numinteriorring, 1) },
18091787
{ "ST_NUMINTERIORRINGS", SQL_FN(Item_func_numinteriorring, 1) },
18101788
{ "ST_NUMPOINTS", SQL_FN(Item_func_numpoints, 1) },
1811-
{ "ST_OVERLAPS", SQL_FACTORY(St_overlaps_instantiator) },
1789+
{ "ST_OVERLAPS", SQL_FN(Item_func_st_overlaps, 2) },
18121790
{ "ST_POINTFROMGEOHASH", SQL_FN(Item_func_pointfromgeohash, 2) },
18131791
{ "ST_POINTFROMTEXT", SQL_FACTORY(Pointfromtext_instantiator) },
18141792
{ "ST_POINTFROMWKB", SQL_FACTORY(Pointfromwkb_instantiator) },
@@ -1822,10 +1800,10 @@ static const std::pair<const char *, Create_func *> func_array[]=
18221800
{ "ST_STARTPOINT", SQL_FACTORY(Startpoint_instantiator) },
18231801
{ "ST_SYMDIFFERENCE", SQL_FN(Item_func_st_symdifference, 2) },
18241802
{ "ST_SWAPXY", SQL_FN(Item_func_swap_xy, 1) },
1825-
{ "ST_TOUCHES", SQL_FACTORY(St_touches_instantiator) },
1803+
{ "ST_TOUCHES", SQL_FN(Item_func_st_touches, 2) },
18261804
{ "ST_UNION", SQL_FN(Item_func_st_union, 2) },
18271805
{ "ST_VALIDATE", SQL_FN(Item_func_validate, 1) },
1828-
{ "ST_WITHIN", SQL_FACTORY(St_within_instantiator) },
1806+
{ "ST_WITHIN", SQL_FN(Item_func_st_within, 2) },
18291807
{ "ST_X", SQL_FACTORY(X_instantiator) },
18301808
{ "ST_Y", SQL_FACTORY(Y_instantiator) },
18311809
{ "SUBSTRING_INDEX", SQL_FN(Item_func_substr_index, 3) },

sql/item_geofunc.h

Lines changed: 202 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -965,50 +965,21 @@ class Item_func_spatial_mbr_rel: public Item_bool_func2
965965
};
966966

967967

968-
class Item_func_spatial_rel final : public Item_bool_func2
968+
class Item_func_spatial_rel : public Item_bool_func2
969969
{
970-
enum Functype spatial_rel;
971-
String tmp_value1,tmp_value2;
972970
public:
973-
Item_func_spatial_rel(const POS &pos, Item *a,Item *b, enum Functype sp_rel);
974-
virtual ~Item_func_spatial_rel();
971+
Item_func_spatial_rel(const POS &pos, Item *a, Item *b)
972+
: Item_bool_func2(pos, a, b)
973+
{}
975974
longlong val_int() override;
976-
enum Functype functype() const override
977-
{
978-
return spatial_rel;
979-
}
980-
enum Functype rev_functype() const override
981-
{
982-
switch (spatial_rel)
983-
{
984-
case SP_CONTAINS_FUNC:
985-
return SP_WITHIN_FUNC;
986-
case SP_WITHIN_FUNC:
987-
return SP_CONTAINS_FUNC;
988-
default:
989-
return spatial_rel;
990-
}
991-
}
992975

993-
const char *func_name() const override;
994-
void print(String *str, enum_query_type query_type) override
995-
{
996-
Item_func::print(str, query_type);
997-
}
998-
999-
bool resolve_type(THD *) override
1000-
{
1001-
maybe_null= true;
1002-
return false;
1003-
}
1004-
bool is_null() override { val_int(); return null_value; }
1005-
1006-
template<typename CoordinateSystemType>
976+
// Use is not restricted to subclasses. Also used by setops,
977+
// BG_geometry_collection::merge_one_run() and
978+
// linear_areal_intersect_infinite().
1007979
static int bg_geo_relation_check(Geometry *g1, Geometry *g2,
1008980
Functype relchk_type, bool *);
1009981

1010-
protected:
1011-
982+
private:
1012983
template<typename Geom_types>
1013984
friend class BG_wrap;
1014985

@@ -1043,7 +1014,6 @@ class Item_func_spatial_rel final : public Item_bool_func2
10431014

10441015
template<typename Coordsys>
10451016
int geocol_relation_check(Geometry *g1, Geometry *g2);
1046-
template<typename Coordsys>
10471017
int geocol_relcheck_intersect_disjoint(const typename BG_geometry_collection::
10481018
Geometry_list *gv1,
10491019
const typename BG_geometry_collection::
@@ -1052,7 +1022,8 @@ class Item_func_spatial_rel final : public Item_bool_func2
10521022
int geocol_relcheck_within(const typename BG_geometry_collection::
10531023
Geometry_list *gv1,
10541024
const typename BG_geometry_collection::
1055-
Geometry_list *gv2);
1025+
Geometry_list *gv2,
1026+
Functype spatial_rel);
10561027
template<typename Coordsys>
10571028
int geocol_equals_check(const typename BG_geometry_collection::
10581029
Geometry_list *gv1,
@@ -1061,6 +1032,198 @@ class Item_func_spatial_rel final : public Item_bool_func2
10611032
};
10621033

10631034

1035+
class Item_func_st_contains final : public Item_func_spatial_rel
1036+
{
1037+
public:
1038+
Item_func_st_contains(const POS &pos, Item *a, Item *b)
1039+
: Item_func_spatial_rel(pos, a, b)
1040+
{}
1041+
enum Functype functype() const override
1042+
{ return SP_CONTAINS_FUNC; }
1043+
enum Functype rev_functype() const override
1044+
{ return SP_WITHIN_FUNC; }
1045+
const char *func_name() const override
1046+
{ return "st_contains"; }
1047+
bool resolve_type(THD *) override
1048+
{
1049+
maybe_null= true;
1050+
return false;
1051+
}
1052+
void print(String *str, enum_query_type query_type) override
1053+
{
1054+
Item_func::print(str, query_type);
1055+
}
1056+
};
1057+
1058+
1059+
class Item_func_st_crosses final : public Item_func_spatial_rel
1060+
{
1061+
public:
1062+
Item_func_st_crosses(const POS &pos, Item *a, Item *b)
1063+
: Item_func_spatial_rel(pos, a, b)
1064+
{}
1065+
enum Functype functype() const override
1066+
{ return SP_CROSSES_FUNC; }
1067+
enum Functype rev_functype() const override
1068+
{ return SP_CROSSES_FUNC; }
1069+
const char *func_name() const override
1070+
{ return "st_crosses"; }
1071+
bool resolve_type(THD *) override
1072+
{
1073+
maybe_null= true;
1074+
return false;
1075+
}
1076+
void print(String *str, enum_query_type query_type) override
1077+
{
1078+
Item_func::print(str, query_type);
1079+
}
1080+
};
1081+
1082+
1083+
class Item_func_st_disjoint final : public Item_func_spatial_rel
1084+
{
1085+
public:
1086+
Item_func_st_disjoint(const POS &pos, Item *a, Item *b)
1087+
: Item_func_spatial_rel(pos, a, b)
1088+
{}
1089+
enum Functype functype() const override
1090+
{ return SP_DISJOINT_FUNC; }
1091+
enum Functype rev_functype() const override
1092+
{ return SP_DISJOINT_FUNC; }
1093+
const char *func_name() const override
1094+
{ return "st_disjoint"; }
1095+
bool resolve_type(THD *) override
1096+
{
1097+
maybe_null= true;
1098+
return false;
1099+
}
1100+
void print(String *str, enum_query_type query_type) override
1101+
{
1102+
Item_func::print(str, query_type);
1103+
}
1104+
};
1105+
1106+
1107+
class Item_func_st_equals final : public Item_func_spatial_rel
1108+
{
1109+
public:
1110+
Item_func_st_equals(const POS &pos, Item *a, Item *b)
1111+
: Item_func_spatial_rel(pos, a, b)
1112+
{}
1113+
enum Functype functype() const override
1114+
{ return SP_EQUALS_FUNC; }
1115+
enum Functype rev_functype() const override
1116+
{ return SP_EQUALS_FUNC; }
1117+
const char *func_name() const override
1118+
{ return "st_equals"; }
1119+
bool resolve_type(THD *) override
1120+
{
1121+
maybe_null= true;
1122+
return false;
1123+
}
1124+
void print(String *str, enum_query_type query_type) override
1125+
{
1126+
Item_func::print(str, query_type);
1127+
}
1128+
};
1129+
1130+
1131+
class Item_func_st_intersects final : public Item_func_spatial_rel
1132+
{
1133+
public:
1134+
Item_func_st_intersects(const POS &pos, Item *a, Item *b)
1135+
: Item_func_spatial_rel(pos, a, b)
1136+
{}
1137+
enum Functype functype() const override
1138+
{ return SP_INTERSECTS_FUNC; }
1139+
enum Functype rev_functype() const override
1140+
{ return SP_INTERSECTS_FUNC; }
1141+
const char *func_name() const override
1142+
{ return "st_intersects"; }
1143+
bool resolve_type(THD *) override
1144+
{
1145+
maybe_null= true;
1146+
return false;
1147+
}
1148+
void print(String *str, enum_query_type query_type) override
1149+
{
1150+
Item_func::print(str, query_type);
1151+
}
1152+
};
1153+
1154+
1155+
class Item_func_st_overlaps final : public Item_func_spatial_rel
1156+
{
1157+
public:
1158+
Item_func_st_overlaps(const POS &pos, Item *a, Item *b)
1159+
: Item_func_spatial_rel(pos, a, b)
1160+
{}
1161+
enum Functype functype() const override
1162+
{ return SP_OVERLAPS_FUNC; }
1163+
enum Functype rev_functype() const override
1164+
{ return SP_OVERLAPS_FUNC; }
1165+
const char *func_name() const override
1166+
{ return "st_overlaps"; }
1167+
bool resolve_type(THD *) override
1168+
{
1169+
maybe_null= true;
1170+
return false;
1171+
}
1172+
void print(String *str, enum_query_type query_type) override
1173+
{
1174+
Item_func::print(str, query_type);
1175+
}
1176+
};
1177+
1178+
1179+
class Item_func_st_touches final : public Item_func_spatial_rel
1180+
{
1181+
public:
1182+
Item_func_st_touches(const POS &pos, Item *a, Item *b)
1183+
: Item_func_spatial_rel(pos, a, b)
1184+
{}
1185+
enum Functype functype() const override
1186+
{ return SP_TOUCHES_FUNC; }
1187+
enum Functype rev_functype() const override
1188+
{ return SP_TOUCHES_FUNC; }
1189+
const char *func_name() const override
1190+
{ return "st_touches"; }
1191+
bool resolve_type(THD *) override
1192+
{
1193+
maybe_null= true;
1194+
return false;
1195+
}
1196+
void print(String *str, enum_query_type query_type) override
1197+
{
1198+
Item_func::print(str, query_type);
1199+
}
1200+
};
1201+
1202+
1203+
class Item_func_st_within final : public Item_func_spatial_rel
1204+
{
1205+
public:
1206+
Item_func_st_within(const POS &pos, Item *a, Item *b)
1207+
: Item_func_spatial_rel(pos, a, b)
1208+
{}
1209+
enum Functype functype() const override
1210+
{ return SP_WITHIN_FUNC; }
1211+
enum Functype rev_functype() const override
1212+
{ return SP_CONTAINS_FUNC; }
1213+
const char *func_name() const override
1214+
{ return "st_within"; }
1215+
bool resolve_type(THD *) override
1216+
{
1217+
maybe_null= true;
1218+
return false;
1219+
}
1220+
void print(String *str, enum_query_type query_type) override
1221+
{
1222+
Item_func::print(str, query_type);
1223+
}
1224+
};
1225+
1226+
10641227
/**
10651228
Spatial operations
10661229
*/

0 commit comments

Comments
 (0)