From: Alexander Barkov Date: October 15 2012 2:16pm Subject: bzr push into mysql-5.6 branch (alexander.barkov:4461 to 4462) List-Archive: http://lists.mysql.com/commits/145043 Message-Id: <201210151428.q9FES4Q3009748@acsmt358.oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 4462 Alexander Barkov 2012-10-15 Small refactoting to make GIS debugging easier: - Adding "uint Gcalc_dyn_list::Item::m_item_id" with public method item_id(). Item IDs exist only in DBUG mode. IDs are genereted consequently, starting from 1. With help of m_item_id it's much easier to identify items (e.g. res_point's and active_thread's) when debugging in gdb. Also, item_id() can be used DBUG_PRINT, to produce an easeir-to-read trace log. - Encapsulation: Renaming res_point::outer_poly to "m_outer_poly". Moving it into the private section. Adding access methods: set_outer_poly() and get_outer_poly(). This helps to set breakpoints when outer_poly is read or set. - Moving setting of res_point::intersection_point and pes_point::pi inside Gcalc_operation_reducer::add_res_point(), to reduce code duplication. - Introducing Gcalc_operation_reducer::add_res_i_point(), and moving setting of insersection_point, pi, x, y inside this method, to reduce code duplication. - Introducing Gcalc_operation_reducer::add_res_single_point(), and moving setting of intesection_point, pi, x,y inside the method, to reduce code duplication. - Moving new_res_point() from public to private section, as it's now used only inside the class any more. - Moving DBUG_PRINT's inside add_res_point(), add_res_i_point(), and add_res_single_point(), to reduce code duplication. Adding printing of item_id(), to get an easeir-to-read trace log. modified: sql/gcalc_slicescan.cc sql/gcalc_slicescan.h sql/gcalc_tools.cc sql/gcalc_tools.h 4461 Norvald H. Ryeng 2012-10-15 Bug#14601664 ASSERTION FAILED: *REF && (*REF)->FIXED, FILE ITEM.CC Post push fix. Define is_fixed_or_outer_ref() only in debug builds. modified: sql/item.cc === modified file 'sql/gcalc_slicescan.cc' --- a/sql/gcalc_slicescan.cc 2012-09-27 12:28:25 +0000 +++ b/sql/gcalc_slicescan.cc 2012-10-15 14:15:49 +0000 @@ -39,6 +39,9 @@ typedef int (*sc_compare_func)(const voi Gcalc_dyn_list::Gcalc_dyn_list(size_t blk_size, size_t sizeof_item): +#ifndef DBUG_OFF + m_last_item_id(0), +#endif m_blk_size(blk_size - ALLOC_ROOT_MIN_BLOCK_SIZE), m_sizeof_item(ALIGN_SIZE(sizeof_item)), m_points_per_blk((m_blk_size - PH_DATA_OFFSET) / m_sizeof_item), === modified file 'sql/gcalc_slicescan.h' --- a/sql/gcalc_slicescan.h 2012-07-02 11:13:50 +0000 +++ b/sql/gcalc_slicescan.h 2012-10-15 14:15:49 +0000 @@ -30,9 +30,18 @@ class Gcalc_dyn_list { +#ifndef DBUG_OFF + uint m_last_item_id; +#endif public: class Item { +#ifndef DBUG_OFF + uint m_item_id; + public: + uint item_id() const { return m_item_id; } + void set_item_id(uint id) { m_item_id= id; } +#endif public: Item *next; }; @@ -49,6 +58,9 @@ public: result= m_free; m_free= m_free->next; +#ifndef DBUG_OFF + result->set_item_id(++m_last_item_id); +#endif result->next= NULL; return result; } === modified file 'sql/gcalc_tools.cc' --- a/sql/gcalc_tools.cc 2012-09-27 12:22:02 +0000 +++ b/sql/gcalc_tools.cc 2012-10-15 14:15:49 +0000 @@ -584,16 +584,13 @@ inline int Gcalc_operation_reducer::cont const Gcalc_heap::Info *p) { DBUG_ENTER("Gcalc_operation_reducer::continue_range"); - DBUG_PRINT("info", ("p=(%g,%g,#%u)", p->x, p->y, p->shape)); DBUG_ASSERT(t->result_range); - res_point *rp= add_res_point(); + res_point *rp= add_res_point(p); if (!rp) DBUG_RETURN(1); rp->glue= NULL; rp->down= t->rp; t->rp->up= rp; - rp->intersection_point= false; - rp->pi= p; t->rp= rp; DBUG_RETURN(0); } @@ -604,18 +601,13 @@ inline int Gcalc_operation_reducer::cont double x, double y) { DBUG_ENTER("Gcalc_operation_reducer::continue_i_range"); - DBUG_PRINT("info", ("p=(%g,%g,#%u) xy=(%g,%g)", p->x, p->y, p->shape, x, y)); DBUG_ASSERT(t->result_range); - res_point *rp= add_res_point(); + res_point *rp= add_res_i_point(p, x, y); if (!rp) DBUG_RETURN(1); rp->glue= NULL; rp->down= t->rp; t->rp->up= rp; - rp->intersection_point= true; - rp->x= x; - rp->pi= p; - rp->y= y; t->rp= rp; DBUG_RETURN(0); } @@ -624,13 +616,10 @@ inline int Gcalc_operation_reducer::star const Gcalc_heap::Info *p) { DBUG_ENTER("Gcalc_operation_reducer::start_range"); - DBUG_PRINT("info", ("p=(%g,%g,#%u)", p->x, p->y, p->shape)); - res_point *rp= add_res_point(); + res_point *rp= add_res_point(p); if (!rp) DBUG_RETURN(1); rp->glue= rp->down= NULL; - rp->intersection_point= false; - rp->pi= p; t->result_range= 1; t->rp= rp; DBUG_RETURN(0); @@ -641,15 +630,10 @@ inline int Gcalc_operation_reducer::star double x, double y) { DBUG_ENTER("Gcalc_operation_reducer::start_i_range"); - DBUG_PRINT("info", ("p=(%g,%g,#%u) xy=(%g,%g)", p->x, p->y, p->shape, x, y)); - res_point *rp= add_res_point(); + res_point *rp= add_res_i_point(p, x, y); if (!rp) DBUG_RETURN(1); rp->glue= rp->down= NULL; - rp->intersection_point= true; - rp->x= x; - rp->y= y; - rp->pi= p; t->result_range= 1; t->rp= rp; DBUG_RETURN(0); @@ -659,14 +643,11 @@ inline int Gcalc_operation_reducer::end_ const Gcalc_heap::Info *p) { DBUG_ENTER("Gcalc_operation_reducer::end_range"); - DBUG_PRINT("info", ("p=(%g,%g,#%u)", p->x, p->y, p->shape)); - res_point *rp= add_res_point(); + res_point *rp= add_res_point(p); if (!rp) DBUG_RETURN(1); rp->glue= rp->up= NULL; rp->down= t->rp; - rp->intersection_point= false; - rp->pi= p; t->rp->up= rp; t->result_range= 0; DBUG_RETURN(0); @@ -677,16 +658,11 @@ inline int Gcalc_operation_reducer::end_ double x, double y) { DBUG_ENTER("Gcalc_operation_reducer::end_i_range"); - DBUG_PRINT("info", ("p=(%g,%g,#%u) xy=(%g,%g)", p->x, p->y, p->shape, x, y)); - res_point *rp= add_res_point(); + res_point *rp= add_res_i_point(p, x, y); if (!rp) DBUG_RETURN(1); rp->glue= rp->up= NULL; rp->down= t->rp; - rp->intersection_point= true; - rp->x= x; - rp->pi= p; - rp->y= y; t->rp->up= rp; t->result_range= 0; DBUG_RETURN(0); @@ -697,24 +673,22 @@ int Gcalc_operation_reducer::start_coupl const active_thread *prev_range) { DBUG_ENTER("Gcalc_operation_reducer::start_couple"); - DBUG_PRINT("info", ("p=(%g,%g,#%u)", p->x, p->y, p->shape)); res_point *rp0, *rp1; - if (!(rp0= add_res_point()) || !(rp1= add_res_point())) + if (!(rp0= add_res_point(p)) || !(rp1= add_res_point(p))) DBUG_RETURN(1); rp0->glue= rp1; rp1->glue= rp0; - rp0->intersection_point= rp1->intersection_point= false; rp0->down= rp1->down= NULL; - rp0->pi= rp1->pi= p; t0->rp= rp0; t1->rp= rp1; if (prev_range) { - rp0->outer_poly= t1->thread_start= prev_range->thread_start; + rp0->set_outer_poly(prev_range->thread_start); + t1->thread_start= prev_range->thread_start; } else { - rp0->outer_poly= 0; + rp0->set_outer_poly(NULL); t0->thread_start= rp0; } DBUG_RETURN(0); @@ -727,29 +701,23 @@ int Gcalc_operation_reducer::start_i_cou const active_thread *prev_range) { DBUG_ENTER("Gcalc_operation_reducer::start_i_couple"); - DBUG_PRINT("info", ("p0=(%g,%g,#%u) p1=(%g,%g,#%u) xy=(%g,%g)", - p0->x, p0->y, p0->shape, p1->x, p1->y, p1->shape, x, y)); res_point *rp0, *rp1; - if (!(rp0= add_res_point()) || !(rp1= add_res_point())) + if (!(rp0= add_res_i_point(p0, x, y)) || !(rp1= add_res_i_point(p1, x, y))) DBUG_RETURN(1); rp0->glue= rp1; rp1->glue= rp0; - rp0->pi= p0; - rp1->pi= p1; - rp0->intersection_point= rp1->intersection_point= true; rp0->down= rp1->down= NULL; - rp0->x= rp1->x= x; - rp0->y= rp1->y= y; t0->result_range= t1->result_range= 1; t0->rp= rp0; t1->rp= rp1; if (prev_range) { - rp0->outer_poly= t1->thread_start= prev_range->thread_start; + rp0->set_outer_poly(prev_range->thread_start); + t1->thread_start= prev_range->thread_start; } else { - rp0->outer_poly= 0; + rp0->set_outer_poly(NULL); t0->thread_start= rp0; } DBUG_RETURN(0); @@ -759,10 +727,9 @@ int Gcalc_operation_reducer::end_couple( const Gcalc_heap::Info *p) { DBUG_ENTER("Gcalc_operation_reducer::end_couple"); - DBUG_PRINT("info", ("p=(%g,%g,#%u)", p->x, p->y, p->shape)); res_point *rp0, *rp1; DBUG_ASSERT(t1->result_range); - if (!(rp0= add_res_point()) || !(rp1= add_res_point())) + if (!(rp0= add_res_point(p)) || !(rp1= add_res_point(p))) DBUG_RETURN(1); rp0->down= t0->rp; rp1->down= t1->rp; @@ -771,8 +738,6 @@ int Gcalc_operation_reducer::end_couple( rp0->up= rp1->up= NULL; t0->rp->up= rp0; t1->rp->up= rp1; - rp0->intersection_point= rp1->intersection_point= false; - rp0->pi= rp1->pi= p; t0->result_range= t1->result_range= 0; DBUG_RETURN(0); } @@ -783,21 +748,14 @@ int Gcalc_operation_reducer::end_i_coupl double x, double y) { DBUG_ENTER("Gcalc_operation_reducer::end_i_couple"); - DBUG_PRINT("info", ("p0=(%g,%g,#%u) p1=(%g,%g,#%u) xy=(%g,%g)", - p0->x, p0->y, p0->shape, p1->x, p1->y, p1->shape, x, y)); res_point *rp0, *rp1; - if (!(rp0= add_res_point()) || !(rp1= add_res_point())) + if (!(rp0= add_res_i_point(p0, x, y)) || !(rp1= add_res_i_point(p1, x, y))) DBUG_RETURN(1); rp0->down= t0->rp; rp1->down= t1->rp; - rp0->pi= p0; - rp1->pi= p1; rp1->glue= rp0; rp0->glue= rp1; rp0->up= rp1->up= NULL; - rp0->intersection_point= rp1->intersection_point= true; - rp0->x= rp1->x= x; - rp0->y= rp1->y= y; t0->result_range= t1->result_range= 0; t0->rp->up= rp0; t1->rp->up= rp1; @@ -807,15 +765,10 @@ int Gcalc_operation_reducer::end_i_coupl int Gcalc_operation_reducer::add_single_point(const Gcalc_heap::Info *p) { DBUG_ENTER("Gcalc_operation_reducer::add_single_point"); - DBUG_PRINT("info", ("p=(%g,%g,#%u)", p->x, p->y, p->shape)); - res_point *rp= add_res_point(); + res_point *rp= add_res_single_point(p); if (!rp) DBUG_RETURN(1); rp->glue= rp->up= rp->down= NULL; - rp->intersection_point= false; - rp->pi= p; - rp->x= p->x; - rp->y= p->y; DBUG_RETURN(0); } @@ -823,15 +776,10 @@ int Gcalc_operation_reducer::add_i_singl double x, double y) { DBUG_ENTER("Gcalc_operation_reducer::add_i_single_point"); - DBUG_PRINT("info", ("p=(%g,%g,#%u) xy=(%g,%g)", p->x, p->y, p->shape, x, y)); - res_point *rp= add_res_point(); + res_point *rp= add_res_i_point(p, x, y); if (!rp) DBUG_RETURN(1); rp->glue= rp->up= rp->down= NULL; - rp->intersection_point= true; - rp->x= x; - rp->pi= p; - rp->y= y; DBUG_RETURN(0); } @@ -1336,9 +1284,9 @@ int Gcalc_operation_reducer::get_result( if (shape == Gcalc_function::shape_polygon) { polygons_found= true; - if (m_result->outer_poly) // Inner ring (hole) + if (m_result->get_outer_poly()) // Inner ring (hole) { - chunk.first_point= m_result->outer_poly; + chunk.first_point= m_result->get_outer_poly(); chunk.is_poly_hole= true; shape= Gcalc_function::shape_hole; } === modified file 'sql/gcalc_tools.h' --- a/sql/gcalc_tools.h 2012-07-21 06:56:07 +0000 +++ b/sql/gcalc_tools.h 2012-10-15 14:15:49 +0000 @@ -249,6 +249,7 @@ public: class res_point : public Gcalc_dyn_list::Item { + res_point *m_outer_poly; public: bool intersection_point; double x,y; @@ -260,9 +261,16 @@ public: const Gcalc_heap::Info *pi; // is valid before get_result_thread() res_point *first_poly_node; // is valid after get_result_thread() }; - res_point *outer_poly; Gcalc_dyn_list::Item **prev_hook; res_point *get_next() { return (res_point *)next; } + void set_outer_poly(res_point *p) + { + m_outer_poly= p; + DBUG_PRINT("info", ("setting outer_poly of #%u to #%u", + item_id(), + m_outer_poly ? m_outer_poly->item_id() : 0)); + } + res_point *get_outer_poly() { return m_outer_poly; } }; class active_thread : public Gcalc_dyn_list::Item @@ -288,13 +296,38 @@ protected: res_point *result_heap; active_thread *m_first_active_thread; - res_point *add_res_point() + res_point *add_res_point(const Gcalc_heap::Info *pi) { - res_point *result= (res_point *)new_item(); - *m_res_hook= result; - result->prev_hook= m_res_hook; - m_res_hook= &result->next; - return result; + res_point *rp= new_res_point(pi, false); + if (!rp) + return NULL; + DBUG_PRINT("info", ("add_res_point #%u: pi=(%g,%g,#%u)", + rp->item_id(), pi->x, pi->y, pi->shape)); + return rp; + } + + res_point *add_res_i_point(const Gcalc_heap::Info *pi, double x, double y) + { + res_point *rp= new_res_point(pi, true); + if (!rp) + return NULL; + DBUG_PRINT("info", ("add_res_i_point #%u: pi=(%g,%g,#%u) xy=(%g,%g)", + rp->item_id(), pi->x, pi->y, pi->shape, x, y)); + rp->x= x; + rp->y= y; + return rp; + } + + res_point *add_res_single_point(const Gcalc_heap::Info *pi) + { + res_point *rp= new_res_point(pi, false); + if (!rp) + return NULL; + DBUG_PRINT("info", ("add_res_single_point #%u: pi=(%g,%g,#%u)", + rp->item_id(), pi->x, pi->y, pi->shape)); + rp->x= pi->x; + rp->y= pi->y; + return rp; } active_thread *new_active_thread() @@ -306,6 +339,19 @@ protected: } private: + + res_point *new_res_point(const Gcalc_heap::Info *pi, + bool intersection_point) + { + res_point *result= (res_point *) new_item(); + *m_res_hook= result; + result->prev_hook= m_res_hook; + m_res_hook= &result->next; + result->pi= pi; + result->intersection_point= intersection_point; + return result; + } + int continue_range(active_thread *t, const Gcalc_heap::Info *p); int continue_i_range(active_thread *t, const Gcalc_heap::Info *p, double x, double y); No bundle (reason: useless for push emails).