List:Internals« Previous MessageNext Message »
From:sanja Date:April 29 2005 1:44am
Subject:bk commit into 5.0 tree (bell:1.1849) BUG#10041
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of bell. When bell does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1849 05/04/29 02:43:56 bell@stripped +4 -0
  if outer refernce (identifier) was resolved with help of cache all subqueries and
resolved item itseld have to be correctly marked as dependent
  (BUG#10041)

  sql/sql_base.cc
    1.236 05/04/29 02:43:09 bell@stripped +8 -0
    if outer refernce (identifier) was resolved with help of cache all subqueries and
resolved item itseld have to be correctly marked as dependent

  sql/item_subselect.h
    1.69 05/04/29 02:43:09 bell@stripped +3 -0
    function to mark range of SELECTs as dependent (used if item was resolved with PS
cache of resolving identifiers)

  sql/item.h
    1.116 05/04/29 02:43:09 bell@stripped +6 -0
    function to mark range of SELECTs as dependent (used if item was resolved with PS
cache of resolving identifiers)

  sql/item.cc
    1.111 05/04/29 02:43:09 bell@stripped +67 -1
    depended_from shoudl be cleaned
    layout fixed
    function to mark range of SELECTs as dependent (used if item was resolved with PS
cache of resolving identifiers)

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	bell
# Host:	sanja.is.com.ua
# Root:	/home/bell/mysql/bk/work-test-5.0

--- 1.110/sql/item.cc	Sat Apr 16 06:34:44 2005
+++ 1.111/sql/item.cc	Fri Apr 29 02:43:09 2005
@@ -454,6 +454,7 @@
   db_name= orig_db_name; 
   table_name= orig_table_name;
   field_name= orig_field_name;
+  depended_from= 0;
   DBUG_VOID_RETURN;
 }
 
@@ -2334,7 +2335,7 @@
 */
 
 static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
-			      Item_ident *resolved_item,
+                              Item_ident *resolved_item,
                               Item_ident *mark_item)
 {
   const char *db_name= (resolved_item->db_name ?
@@ -2359,6 +2360,71 @@
 }
 
 
+/*
+  Mark range of selects and resolved identifier (field/reference) item as
+  dependent
+
+  SYNOPSIS
+    mark_select_range_as_dependent()
+    thd           - thread handler
+    current_sel   - current select (select where resolved_item was placed)
+    last_select   - select where resolved_item was resolved
+    found_field   - field which was found during resolving
+    found_item    - Item which was found during resolving (if resolved
+                    identifier belongs to VIEW)
+    resolved_item - Identifier which was resolved
+
+  NOTE:
+    We have to mark all items between current_sel (including) and
+    last_select (excluding) as dependend (select before last_select should
+    be marked with actual table mask used by resolved item, all other with
+    OUTER_REF_TABLE_BIT) and also write dependence information to Item of
+    resolved identifier.
+*/
+
+void mark_select_range_as_dependent(THD *thd,
+                                    SELECT_LEX *current_sel,
+                                    SELECT_LEX *last_select,
+                                    Field *found_field, Item *found_item,
+                                    Item_ident *resolved_item)
+{
+  /*
+    Go from current SELECT to SELECT where field was resolved (it
+    have to be reachable from current SELECT, because it was already
+    done once when we resolved this field and cached result of
+    resolving)
+  */
+  SELECT_LEX *previous_select= current_sel;
+  for(;
+      previous_select->outer_select() != last_select;
+      previous_select= previous_select->outer_select())
+  {
+    Item_subselect *prev_subselect_item=
+      previous_select->master_unit()->item;
+    prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
+    prev_subselect_item->const_item_cache= 0;
+  }
+  {
+    Item_subselect *prev_subselect_item=
+      previous_select->master_unit()->item;
+    Item_ident *dependent= resolved_item;
+    if (found_field == view_ref_found)
+    {
+      Item::Type type= found_item->type();
+      prev_subselect_item->used_tables_cache|=
+        found_item->used_tables();
+      dependent= ((type == Item::REF_ITEM || type == Item::FIELD_ITEM) ?
+                  (Item_ident*) found_item :
+                  0);
+    }
+    else
+      prev_subselect_item->used_tables_cache|=
+        found_field->table->map;
+    prev_subselect_item->const_item_cache= 0;
+    mark_as_dependent(thd, last_select, current_sel, resolved_item,
+                      dependent);
+  }
+}
 
 
 /*

--- 1.115/sql/item.h	Sat Apr 16 08:35:22 2005
+++ 1.116/sql/item.h	Fri Apr 29 02:43:09 2005
@@ -1795,6 +1795,12 @@
   static enum_field_types get_real_type(Item *);
 };
 
+class st_select_lex;
+void mark_select_range_as_dependent(THD *thd,
+                                    st_select_lex *current_sel,
+                                    st_select_lex *last_select,
+                                    Field *found_field, Item *found_item,
+                                    Item_ident *resolved_item);
 
 extern Item_buff *new_Item_buff(Item *item);
 extern Item_result item_cmp_type(Item_result a,Item_result b);

--- 1.235/sql/sql_base.cc	Thu Apr 14 08:54:50 2005
+++ 1.236/sql/sql_base.cc	Fri Apr 29 02:43:09 2005
@@ -2689,6 +2689,14 @@
     {
       if (found == WRONG_GRANT)
 	return (Field*) 0;
+      {
+        SELECT_LEX *current_sel= thd->lex->current_select;
+        SELECT_LEX *last_select= item->cached_table->select_lex;
+        /* check that field was resolved in outer query */
+        if (current_sel != last_select)
+          mark_select_range_as_dependent(thd, current_sel, last_select,
+                                         found, *ref, item);
+      }
       return found;
     }
   }

--- 1.68/sql/item_subselect.h	Sat Apr 16 08:05:34 2005
+++ 1.69/sql/item_subselect.h	Fri Apr 29 02:43:09 2005
@@ -122,6 +122,9 @@
   friend bool Item_field::fix_fields(THD *, TABLE_LIST *, Item **);
   friend bool Item_ref::fix_fields(THD *, TABLE_LIST *, Item **);
   friend bool Item_param::fix_fields(THD *, TABLE_LIST *, Item **);
+  friend void mark_select_range_as_dependent(THD*,
+                                             st_select_lex*, st_select_lex*,
+                                             Field*, Item*, Item_ident*);
 };
 
 /* single value subselect */
Thread
bk commit into 5.0 tree (bell:1.1849) BUG#10041sanja29 Apr