← Back to team overview

maria-developers team mailing list archive

A question about JOIN re-execution by subquery code

 

Hi Sanja,

As far I understand, JOIN structure has two  "modules" to support join 
re-execution:

M1. save_join_tab() saves/restores the contents of JOIN::join_tab array, as 
    if execution process changed JOIN_TAB structures

M2. JOIN::tmp_join is used to save/restore the contents of JOIN structure
    itself.
  
What puzzles me are two questions:
Q1: Why do we have separate functions to M1 and M2, instead of one "save
everything" call, and one "restore everything" call?

Q2: Why does M1 copy the whole JOIN_TAB structures?  I've  made a patch which 
makes it to save/restore JOIN::join_tab pointer instead (attached), and it
passed all tests in the main test suite.

(I am asking all this in connection with bug MDEV-238 on MWL#182 code)

BR
 Sergei
-- 
Sergei Petrunia, Software Developer
Monty Program AB, http://askmonty.org
Blog: http://s.petrunia.net/blog
=== modified file 'sql/sql_select.cc'
--- sql/sql_select.cc	2012-04-13 21:01:15 +0000
+++ sql/sql_select.cc	2012-05-07 02:05:46 +0000
@@ -2042,8 +2042,8 @@ JOIN::reinit()
     set_items_ref_array(items0);
 
   if (join_tab_save)
-    memcpy(join_tab, join_tab_save, sizeof(JOIN_TAB) * table_count);
-
+    //psergey-test: memcpy(join_tab, join_tab_save, sizeof(JOIN_TAB) * table_count);
+    join_tab= join_tab_save;
   /* need to reset ref access state (see join_read_key) */
   if (join_tab)
   {
@@ -2108,9 +2108,12 @@ JOIN::save_join_tab()
 {
   if (!join_tab_save && select_lex->master_unit()->uncacheable)
   {
-    if (!(join_tab_save= (JOIN_TAB*)thd->memdup((uchar*) join_tab,
+    /*
+    psergey-test:if (!(join_tab_save= (JOIN_TAB*)thd->memdup((uchar*) join_tab,
 						sizeof(JOIN_TAB) * table_count)))
       return 1;
+    */
+    join_tab_save= join_tab;
   }
   return 0;
 }