From 539b3ca87d97d15fcf1076ce1e4a83d5b00d9c26 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 5 May 2015 09:30:17 +0400 Subject: [PATCH] - Moving Item_func_spatial_mbr_rel from Item_bool_func2 to Item_bool_func, as Item_func_spatial_mbr_rel needs nothing from Item_bool_func2. - Renaming Item_func_spacial_rel (the class that implements precise spacial relations) to Item_func_spatial_precise_rel - Adding a new abstract class Item_func_spatial_rel as a common parent for Item_func_spatial_precise_rel and Item_func_spatial_mbr_rel. --- sql/item_create.cc | 30 ++++++++++----------- sql/item_geofunc.cc | 28 ++++---------------- sql/item_geofunc.h | 63 +++++++++++++++++++++------------------------ sql/sql_yacc.yy | 4 +-- 4 files changed, 52 insertions(+), 73 deletions(-) diff --git a/sql/item_create.cc b/sql/item_create.cc index a37f61fc6aa..a55c9ef3de4 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -3560,8 +3560,8 @@ Create_func_contains Create_func_contains::s_singleton; Item* Create_func_contains::create_2_arg(THD *thd, Item *arg1, Item *arg2) { - return new (thd->mem_root) Item_func_spatial_rel(arg1, arg2, - Item_func::SP_CONTAINS_FUNC); + return new (thd->mem_root) Item_func_spatial_precise_rel(arg1, arg2, + Item_func::SP_CONTAINS_FUNC); } #endif @@ -3617,7 +3617,7 @@ Create_func_crosses Create_func_crosses::s_singleton; Item* Create_func_crosses::create_2_arg(THD *thd, Item *arg1, Item *arg2) { - return new (thd->mem_root) Item_func_spatial_rel(arg1, arg2, + return new (thd->mem_root) Item_func_spatial_precise_rel(arg1, arg2, Item_func::SP_CROSSES_FUNC); } #endif @@ -3800,8 +3800,8 @@ Create_func_disjoint Create_func_disjoint::s_singleton; Item* Create_func_disjoint::create_2_arg(THD *thd, Item *arg1, Item *arg2) { - return new (thd->mem_root) Item_func_spatial_rel(arg1, arg2, - Item_func::SP_DISJOINT_FUNC); + return new (thd->mem_root) Item_func_spatial_precise_rel(arg1, arg2, + Item_func::SP_DISJOINT_FUNC); } @@ -3931,8 +3931,8 @@ Create_func_equals Create_func_equals::s_singleton; Item* Create_func_equals::create_2_arg(THD *thd, Item *arg1, Item *arg2) { - return new (thd->mem_root) Item_func_spatial_rel(arg1, arg2, - Item_func::SP_EQUALS_FUNC); + return new (thd->mem_root) Item_func_spatial_precise_rel(arg1, arg2, + Item_func::SP_EQUALS_FUNC); } #endif @@ -4427,7 +4427,7 @@ Create_func_relate Create_func_relate::s_singleton; Item* Create_func_relate::create_3_arg(THD *thd, Item *arg1, Item *arg2, Item *matrix) { - return new (thd->mem_root) Item_func_spatial_rel(arg1, arg2, matrix); + return new (thd->mem_root) Item_func_spatial_precise_rel(arg1, arg2, matrix); } @@ -4446,8 +4446,8 @@ Create_func_intersects Create_func_intersects::s_singleton; Item* Create_func_intersects::create_2_arg(THD *thd, Item *arg1, Item *arg2) { - return new (thd->mem_root) Item_func_spatial_rel(arg1, arg2, - Item_func::SP_INTERSECTS_FUNC); + return new (thd->mem_root) Item_func_spatial_precise_rel(arg1, arg2, + Item_func::SP_INTERSECTS_FUNC); } @@ -5048,8 +5048,8 @@ Create_func_overlaps Create_func_overlaps::s_singleton; Item* Create_func_overlaps::create_2_arg(THD *thd, Item *arg1, Item *arg2) { - return new (thd->mem_root) Item_func_spatial_rel(arg1, arg2, - Item_func::SP_OVERLAPS_FUNC); + return new (thd->mem_root) Item_func_spatial_precise_rel(arg1, arg2, + Item_func::SP_OVERLAPS_FUNC); } #endif @@ -5485,7 +5485,7 @@ Create_func_touches Create_func_touches::s_singleton; Item* Create_func_touches::create_2_arg(THD *thd, Item *arg1, Item *arg2) { - return new (thd->mem_root) Item_func_spatial_rel(arg1, arg2, + return new (thd->mem_root) Item_func_spatial_precise_rel(arg1, arg2, Item_func::SP_TOUCHES_FUNC); } #endif @@ -5636,8 +5636,8 @@ Create_func_within Create_func_within::s_singleton; Item* Create_func_within::create_2_arg(THD *thd, Item *arg1, Item *arg2) { - return new (thd->mem_root) Item_func_spatial_rel(arg1, arg2, - Item_func::SP_WITHIN_FUNC); + return new (thd->mem_root) Item_func_spatial_precise_rel(arg1, arg2, + Item_func::SP_WITHIN_FUNC); } #endif diff --git a/sql/item_geofunc.cc b/sql/item_geofunc.cc index 9fc8e9d09e0..fc7367dcd67 100644 --- a/sql/item_geofunc.cc +++ b/sql/item_geofunc.cc @@ -957,8 +957,8 @@ const char *Item_func_spatial_mbr_rel::func_name() const longlong Item_func_spatial_mbr_rel::val_int() { DBUG_ASSERT(fixed == 1); - String *res1= args[0]->val_str(&cmp.value1); - String *res2= args[1]->val_str(&cmp.value2); + String *res1= args[0]->val_str(&tmp_value1); + String *res2= args[1]->val_str(&tmp_value2); Geometry_buffer buffer1, buffer2; Geometry *g1, *g2; MBR mbr1, mbr2; @@ -999,25 +999,7 @@ longlong Item_func_spatial_mbr_rel::val_int() } -Item_func_spatial_rel::Item_func_spatial_rel(Item *a,Item *b, - enum Functype sp_rel) : - Item_bool_func(a,b), collector() -{ - spatial_rel = sp_rel; -} - - -Item_func_spatial_rel::Item_func_spatial_rel(Item *a,Item *b, Item *mask) : - Item_bool_func(a,b,mask), spatial_rel(SP_RELATE_FUNC) -{} - - -Item_func_spatial_rel::~Item_func_spatial_rel() -{ -} - - -const char *Item_func_spatial_rel::func_name() const +const char *Item_func_spatial_precise_rel::func_name() const { switch (spatial_rel) { case SP_CONTAINS_FUNC: @@ -1158,9 +1140,9 @@ static int setup_relate_func(Geometry *g1, Geometry *g2, #define GIS_ZERO 0.00000000001 -longlong Item_func_spatial_rel::val_int() +longlong Item_func_spatial_precise_rel::val_int() { - DBUG_ENTER("Item_func_spatial_rel::val_int"); + DBUG_ENTER("Item_func_spatial_precise_rel::val_int"); DBUG_ASSERT(fixed == 1); String *res1; String *res2; diff --git a/sql/item_geofunc.h b/sql/item_geofunc.h index 7ba2d0487bc..2dbb2cd317f 100644 --- a/sql/item_geofunc.h +++ b/sql/item_geofunc.h @@ -272,54 +272,51 @@ public: Spatial relations */ -class Item_func_spatial_mbr_rel: public Item_bool_func2 +class Item_func_spatial_rel: public Item_bool_func { +protected: enum Functype spatial_rel; + String tmp_value1, tmp_value2; public: - Item_func_spatial_mbr_rel(Item *a,Item *b, enum Functype sp_rel) : - Item_bool_func2(a,b) { spatial_rel = sp_rel; } - longlong val_int(); - enum Functype functype() const - { - return spatial_rel; - } + Item_func_spatial_rel(Item *a, Item *b, enum Functype sp_rel) + :Item_bool_func(a, b), spatial_rel(sp_rel) + { } + Item_func_spatial_rel(Item *a, Item *b, Item *c, enum Functype sp_rel) + :Item_bool_func(a, b, c), spatial_rel(sp_rel) + { } + enum Functype functype() const { return spatial_rel; } enum Functype rev_functype() const { return spatial_rel; } - const char *func_name() const; - virtual inline void print(String *str, enum_query_type query_type) - { - Item_func::print(str, query_type); - } - void fix_length_and_dec() { maybe_null= 1; } bool is_null() { (void) val_int(); return null_value; } + optimize_type select_optimize() const { return OPTIMIZE_OP; } }; -class Item_func_spatial_rel: public Item_bool_func +class Item_func_spatial_mbr_rel: public Item_func_spatial_rel +{ +public: + Item_func_spatial_mbr_rel(Item *a, Item *b, enum Functype sp_rel) + :Item_func_spatial_rel(a, b, sp_rel) + { } + longlong val_int(); + const char *func_name() const; +}; + + +class Item_func_spatial_precise_rel: public Item_func_spatial_rel { - enum Functype spatial_rel; Gcalc_heap collector; Gcalc_scan_iterator scan_it; Gcalc_function func; - String tmp_value1,tmp_value2, tmp_matrix; + String tmp_matrix; public: - Item_func_spatial_rel(Item *a,Item *b, enum Functype sp_rel); - Item_func_spatial_rel(Item *a, Item *b, Item *matrix); - virtual ~Item_func_spatial_rel(); + Item_func_spatial_precise_rel(Item *a, Item *b, enum Functype sp_rel) + :Item_func_spatial_rel(a, b, sp_rel), collector() + { } + Item_func_spatial_precise_rel(Item *a, Item *b, Item *matrix) + :Item_func_spatial_rel(a, b, matrix, SP_RELATE_FUNC) + { } longlong val_int(); - enum Functype functype() const - { - return spatial_rel; - } - enum Functype rev_functype() const { return spatial_rel; } const char *func_name() const; - virtual inline void print(String *str, enum_query_type query_type) - { - Item_func::print(str, query_type); - } - - bool is_null() { (void) val_int(); return null_value; } - uint decimal_precision() const { return 1; } - optimize_type select_optimize() const { return OPTIMIZE_OP; } }; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index ecb3ebeaf2a..47a06ab73d5 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -9938,8 +9938,8 @@ geometry_function: CONTAINS_SYM '(' expr ',' expr ')' { $$= GEOM_NEW(thd, - Item_func_spatial_rel($3, $5, - Item_func::SP_CONTAINS_FUNC)); + Item_func_spatial_precise_rel($3, $5, + Item_func::SP_CONTAINS_FUNC)); } | GEOMETRYCOLLECTION '(' expr_list ')' {