List:Commits« Previous MessageNext Message »
From:Chad MILLER Date:June 13 2006 9:33pm
Subject:bk commit into 5.1 tree (cmiller:1.2188)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of cmiller. When cmiller 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.2188 06/06/13 15:33:17 cmiller@zippy.(none) +7 -0
  Merge bk-internal.mysql.com:/home/bk/mysql-5.1
  into  zippy.(none):/home/cmiller/work/mysql/merge/mysql-5.1-new

  storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp
    1.39 06/06/13 15:33:09 cmiller@zippy.(none) +0 -0
    Auto merged

  sql/sql_acl.cc
    1.195 06/06/13 15:33:08 cmiller@zippy.(none) +0 -0
    Auto merged

  sql/opt_range.cc
    1.220 06/06/13 15:33:08 cmiller@zippy.(none) +0 -0
    Auto merged

  sql/mysqld.cc
    1.554 06/06/13 15:33:08 cmiller@zippy.(none) +0 -0
    Auto merged

  sql/item.h
    1.202 06/06/13 15:33:08 cmiller@zippy.(none) +0 -0
    Auto merged

  sql/item.cc
    1.193 06/06/13 15:33:07 cmiller@zippy.(none) +0 -0
    Auto merged

  include/my_sys.h
    1.199 06/06/13 15:33:07 cmiller@zippy.(none) +0 -0
    Auto merged

# 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:	cmiller
# Host:	zippy.(none)
# Root:	/home/cmiller/work/mysql/merge/mysql-5.1-new/RESYNC

--- 1.192/sql/item.cc	2006-05-26 12:10:28 -04:00
+++ 1.193/sql/item.cc	2006-06-13 15:33:07 -04:00
@@ -551,6 +551,23 @@ bool Item_field::find_item_in_field_list
 }
 
 
+/*
+  Mark field in read_map
+
+  NOTES
+    This is used by filesort to register used fields in a a temporary
+    column read set or to register used fields in a view
+*/
+
+bool Item_field::register_field_in_read_map(byte *arg)
+{
+  TABLE *table= (TABLE *) arg;
+  if (field->table == table || !table)
+    bitmap_set_bit(field->table->read_set, field->field_index);
+  return 0;
+}
+
+
 bool Item::check_cols(uint c)
 {
   if (c != 1)
@@ -790,14 +807,25 @@ CHARSET_INFO *Item::default_charset()
 }
 
 
+/*
+  Save value in field, but don't give any warnings
+
+  NOTES
+   This is used to temporary store and retrieve a value in a column,
+   for example in opt_range to adjust the key value to fit the column.
+*/
+
 int Item::save_in_field_no_warnings(Field *field, bool no_conversions)
 {
   int res;
-  THD *thd= field->table->in_use;
+  TABLE *table= field->table;
+  THD *thd= table->in_use;
   enum_check_fields tmp= thd->count_cuted_fields;
+  my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
   thd->count_cuted_fields= CHECK_FIELD_IGNORE;
   res= save_in_field(field, no_conversions);
   thd->count_cuted_fields= tmp;
+  dbug_tmp_restore_column_map(table->write_set, old_map);
   return res;
 }
 
@@ -2366,7 +2394,8 @@ bool Item_param::set_from_user_var(THD *
       CHARSET_INFO *tocs= thd->variables.collation_connection;
       uint32 dummy_offset;
 
-      value.cs_info.character_set_of_placeholder= fromcs;
+      value.cs_info.character_set_of_placeholder= 
+        value.cs_info.character_set_client= fromcs;
       /*
         Setup source and destination character sets so that they
         are different only if conversion is necessary: this will
@@ -3569,7 +3598,8 @@ bool Item_field::fix_fields(THD *thd, It
         Item** res= find_item_in_list(this, thd->lex->current_select->item_list,
                                       &counter, REPORT_EXCEPT_NOT_FOUND,
                                       &not_used);
-        if (res != (Item **)not_found_item && (*res)->type() ==
Item::FIELD_ITEM)
+        if (res != (Item **)not_found_item &&
+            (*res)->type() == Item::FIELD_ITEM)
         {
           set_field((*((Item_field**)res))->field);
           return 0;
@@ -3588,7 +3618,7 @@ bool Item_field::fix_fields(THD *thd, It
       if it is not expression from merged VIEW we will set this field.
 
       We can leave expression substituted from view for next PS/SP rexecution
-      (i.e. do not register this substitution for reverting on cleupup()
+      (i.e. do not register this substitution for reverting on cleanup()
       (register_item_tree_changing())), because this subtree will be
       fix_field'ed during setup_tables()->setup_underlying() (i.e. before
       all other expressions of query, and references on tables which do
@@ -3600,13 +3630,13 @@ bool Item_field::fix_fields(THD *thd, It
       return FALSE;
 
     if (!outer_fixed && cached_table && cached_table->select_lex
&&
-          context->select_lex &&
-          cached_table->select_lex != context->select_lex)
+        context->select_lex &&
+        cached_table->select_lex != context->select_lex)
     {
       int ret;
       if ((ret= fix_outer_field(thd, &from_field, reference)) < 0)
         goto error;
-      else if (!ret)
+      if (!ret)
         return FALSE;
     }
 
@@ -3617,17 +3647,28 @@ bool Item_field::fix_fields(THD *thd, It
       set_if_bigger(thd->lex->in_sum_func->max_arg_level,
                     thd->lex->current_select->nest_level);
   }
-  else if (thd->set_query_id)
+  else if (thd->mark_used_columns != MARK_COLUMNS_NONE)
   {
     TABLE *table= field->table;
-    table->file->ha_set_bit_in_rw_set(field->fieldnr,
-                                      (bool)(thd->set_query_id-1));
-    if (field->query_id != thd->query_id)
-    {
-      /* We only come here in unions */
-      field->query_id=thd->query_id;
-      table->used_fields++;
-      table->used_keys.intersect(field->part_of_key);
+    MY_BITMAP *current_bitmap, *other_bitmap;
+    if (thd->mark_used_columns == MARK_COLUMNS_READ)
+    {
+      current_bitmap= table->read_set;
+      other_bitmap=   table->write_set;
+    }
+    else
+    {
+      current_bitmap= table->write_set;
+      other_bitmap=   table->read_set;
+    }
+    if (!bitmap_fast_test_and_set(current_bitmap, field->field_index))
+    {
+      if (!bitmap_is_set(other_bitmap, field->field_index))
+      {
+        /* First usage of column */
+        table->used_fields++;                     // Used to optimize loops
+        table->used_keys.intersect(field->part_of_key);
+      }
     }
   }
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
@@ -5398,17 +5439,17 @@ void Item_insert_value::print(String *st
 void Item_trigger_field::setup_field(THD *thd, TABLE *table,
                                      GRANT_INFO *table_grant_info)
 {
-  bool save_set_query_id= thd->set_query_id;
+  enum_mark_columns save_mark_used_columns= thd->mark_used_columns;
 
   /* TODO: Think more about consequences of this step. */
-  thd->set_query_id= 0;
+  thd->mark_used_columns= MARK_COLUMNS_NONE;
   /*
     Try to find field by its name and if it will be found
     set field_idx properly.
   */
   (void)find_field_in_table(thd, table, field_name, (uint) strlen(field_name),
                             0, &field_idx);
-  thd->set_query_id= save_set_query_id;
+  thd->mark_used_columns= save_mark_used_columns;
   triggers= table->triggers;
   table_grants= table_grant_info;
 }

--- 1.219/sql/opt_range.cc	2006-05-19 08:45:30 -04:00
+++ 1.220/sql/opt_range.cc	2006-06-13 15:33:08 -04:00
@@ -374,6 +374,12 @@ public:
     keys_map.clear_all();
     bzero((char*) keys,sizeof(keys));
   }
+  /*
+    Note: there may exist SEL_TREE objects with sel_tree->type=KEY and
+    keys[i]=0 for all i. (SergeyP: it is not clear whether there is any
+    merit in range analyzer functions (e.g. get_mm_parts) returning a
+    pointer to such SEL_TREE instead of NULL)
+  */
   SEL_ARG *keys[MAX_KEY];
   key_map keys_map;        /* bitmask of non-NULL elements in keys */
 
@@ -822,6 +828,10 @@ QUICK_RANGE_SELECT::QUICK_RANGE_SELECT(T
                                        bool no_alloc, MEM_ROOT *parent_alloc)
   :dont_free(0),error(0),free_file(0),in_range(0),cur_range(NULL),range(0)
 {
+  my_bitmap_map *bitmap;
+  DBUG_ENTER("QUICK_RANGE_SELECT::QUICK_RANGE_SELECT");
+
+  in_ror_merged_scan= 0;
   sorted= 0;
   index= key_nr;
   head=  table;
@@ -845,6 +855,19 @@ QUICK_RANGE_SELECT::QUICK_RANGE_SELECT(T
     bzero((char*) &alloc,sizeof(alloc));
   file= head->file;
   record= head->record[0];
+  save_read_set= head->read_set;
+  save_write_set= head->write_set;
+
+  /* Allocate a bitmap for used columns */
+  if (!(bitmap= (my_bitmap_map*) my_malloc(head->s->column_bitmap_size,
+                                           MYF(MY_WME))))
+  {
+    column_bitmap.bitmap= 0;
+    error= 1;
+  }
+  else
+    bitmap_init(&column_bitmap, bitmap, head->s->fields, FALSE);
+  DBUG_VOID_RETURN;
 }
 
 
@@ -874,24 +897,26 @@ QUICK_RANGE_SELECT::~QUICK_RANGE_SELECT(
     if (file) 
     {
       range_end();
-      file->extra(HA_EXTRA_NO_KEYREAD);
       if (free_file)
       {
         DBUG_PRINT("info", ("Freeing separate handler %p (free=%d)", file,
                             free_file));
-        file->ha_reset();
         file->ha_external_lock(current_thd, F_UNLCK);
         file->close();
         delete file;
       }
+      else
+      {
+        file->extra(HA_EXTRA_NO_KEYREAD);
+      }
     }
     delete_dynamic(&ranges); /* ranges are allocated in alloc */
     free_root(&alloc,MYF(0));
+    my_free((char*) column_bitmap.bitmap, MYF(MY_ALLOW_ZERO_PTR));
   }
-  if (multi_range)
-    my_free((char*) multi_range, MYF(0));
-  if (multi_range_buff)
-    my_free((char*) multi_range_buff, MYF(0));
+  head->column_bitmaps_set(save_read_set, save_write_set);
+  x_free(multi_range);
+  x_free(multi_range_buff);
   DBUG_VOID_RETURN;
 }
 
@@ -1011,20 +1036,21 @@ int QUICK_ROR_INTERSECT_SELECT::init()
 
 int QUICK_RANGE_SELECT::init_ror_merged_scan(bool reuse_handler)
 {
-  handler *save_file= file;
+  handler *save_file= file, *org_file;
   THD *thd;
+  MY_BITMAP *bitmap;
   DBUG_ENTER("QUICK_RANGE_SELECT::init_ror_merged_scan");
 
+  in_ror_merged_scan= 1;
   if (reuse_handler)
   {
-    DBUG_PRINT("info", ("Reusing handler %p", file));
-    if (file->extra(HA_EXTRA_KEYREAD) ||
-        file->ha_retrieve_all_pk() ||
-        init() || reset())
+    DBUG_PRINT("info", ("Reusing handler 0x%lx", (long) file));
+    if (init() || reset())
     {
       DBUG_RETURN(1);
     }
-    DBUG_RETURN(0);
+    head->column_bitmaps_set(&column_bitmap, &column_bitmap);
+    goto end;
   }
 
   /* Create a separate handler object for this quick select */
@@ -1037,19 +1063,20 @@ int QUICK_RANGE_SELECT::init_ror_merged_
   thd= head->in_use;
   if (!(file= get_new_handler(head->s, thd->mem_root, head->s->db_type)))
     goto failure;
-  DBUG_PRINT("info", ("Allocated new handler %p", file));
+  DBUG_PRINT("info", ("Allocated new handler 0x%lx", (long) file));
   if (file->ha_open(head, head->s->normalized_path.str, head->db_stat,
                     HA_OPEN_IGNORE_IF_LOCKED))
   {
     /* Caller will free the memory */
     goto failure;
   }
+
+  head->column_bitmaps_set(&column_bitmap, &column_bitmap);
+
   if (file->ha_external_lock(thd, F_RDLCK))
     goto failure;
 
-  if (file->extra(HA_EXTRA_KEYREAD) ||
-      file->ha_retrieve_all_pk() ||
-      init() || reset())
+  if (init() || reset())
   {
     file->ha_external_lock(thd, F_UNLCK);
     file->close();
@@ -1057,11 +1084,28 @@ int QUICK_RANGE_SELECT::init_ror_merged_
   }
   free_file= TRUE;
   last_rowid= file->ref;
+
+end:
+  /*
+    We are only going to read key fields and call position() on 'file'
+    The following sets head->tmp_set to only use this key and then updates
+    head->read_set and head->write_set to use this bitmap.
+    The now bitmap is stored in 'column_bitmap' which is used in ::get_next()
+  */
+  org_file= head->file;
+  head->file= file;
+  /* We don't have to set 'head->keyread' here as the 'file' is unique */
+  head->mark_columns_used_by_index(index);
+  head->prepare_for_position();
+  head->file= org_file;
+  bitmap_copy(&column_bitmap, head->read_set);
+  head->column_bitmaps_set(&column_bitmap, &column_bitmap);
+
   DBUG_RETURN(0);
 
 failure:
-  if (file)
-    delete file;
+  head->column_bitmaps_set(save_read_set, save_write_set);
+  delete file;
   file= save_file;
   DBUG_RETURN(1);
 }
@@ -1766,32 +1810,26 @@ public:
 static int fill_used_fields_bitmap(PARAM *param)
 {
   TABLE *table= param->table;
-  param->fields_bitmap_size= bitmap_buffer_size(table->s->fields+1);
-  uint32 *tmp;
+  my_bitmap_map *tmp;
   uint pk;
-  if (!(tmp= (uint32*) alloc_root(param->mem_root,param->fields_bitmap_size)) ||
-      bitmap_init(&param->needed_fields, tmp, param->fields_bitmap_size*8,
-                  FALSE))
+  param->fields_bitmap_size= table->s->column_bitmap_size;
+  if (!(tmp= (my_bitmap_map*) alloc_root(param->mem_root,
+                                  param->fields_bitmap_size)) ||
+      bitmap_init(&param->needed_fields, tmp, table->s->fields, FALSE))
     return 1;
 
-  bitmap_clear_all(&param->needed_fields);
-  for (uint i= 0; i < table->s->fields; i++)
-  {
-    if (param->thd->query_id == table->field[i]->query_id)
-      bitmap_set_bit(&param->needed_fields, i+1);
-  }
+  bitmap_copy(&param->needed_fields, table->read_set);
+  bitmap_union(&param->needed_fields, table->write_set);
 
   pk= param->table->s->primary_key;
-  if (param->table->file->primary_key_is_clustered() && pk != MAX_KEY)
+  if (pk != MAX_KEY && param->table->file->primary_key_is_clustered())
   {
     /* The table uses clustered PK and it is not internally generated */
     KEY_PART_INFO *key_part= param->table->key_info[pk].key_part;
     KEY_PART_INFO *key_part_end= key_part +
                                  param->table->key_info[pk].key_parts;
     for (;key_part != key_part_end; ++key_part)
-    {
-      bitmap_clear_bit(&param->needed_fields, key_part->fieldnr);
-    }
+      bitmap_clear_bit(&param->needed_fields, key_part->fieldnr-1);
   }
   return 0;
 }
@@ -1843,7 +1881,7 @@ int SQL_SELECT::test_quick_select(THD *t
   DBUG_PRINT("enter",("keys_to_use: %lu  prev_tables: %lu  const_tables: %lu",
 		      keys_to_use.to_ulonglong(), (ulong) prev_tables,
 		      (ulong) const_tables));
-  DBUG_PRINT("info", ("records=%lu", (ulong)head->file->records));
+  DBUG_PRINT("info", ("records: %lu", (ulong) head->file->stats.records));
   delete quick;
   quick=0;
   needed_reg.clear_all();
@@ -1853,7 +1891,7 @@ int SQL_SELECT::test_quick_select(THD *t
     DBUG_RETURN(0); /* purecov: inspected */
   if (keys_to_use.is_clear_all())
     DBUG_RETURN(0);
-  records= head->file->records;
+  records= head->file->stats.records;
   if (!records)
     records++;					/* purecov: inspected */
   scan_time= (double) records / TIME_FOR_COMPARE + 1;
@@ -1878,7 +1916,7 @@ int SQL_SELECT::test_quick_select(THD *t
 
     /* set up parameter that is passed to all functions */
     param.thd= thd;
-    param.baseflag=head->file->table_flags();
+    param.baseflag=head->file->ha_table_flags();
     param.prev_tables=prev_tables | const_tables;
     param.read_tables=read_tables;
     param.current_table= head->map;
@@ -2296,6 +2334,7 @@ bool prune_partitions(THD *thd, TABLE *t
   PART_PRUNE_PARAM prune_param;
   MEM_ROOT alloc;
   RANGE_OPT_PARAM  *range_par= &prune_param.range_param;
+  my_bitmap_map *old_read_set, *old_write_set;
 
   prune_param.part_info= part_info;
   init_sql_alloc(&alloc, thd->variables.range_alloc_block_size, 0);
@@ -2309,6 +2348,8 @@ bool prune_partitions(THD *thd, TABLE *t
     DBUG_RETURN(FALSE);
   }
   
+  old_write_set= dbug_tmp_use_all_columns(table, table->write_set);
+  old_read_set=  dbug_tmp_use_all_columns(table, table->read_set);
   range_par->thd= thd;
   range_par->table= table;
   /* range_par->cond doesn't need initialization */
@@ -2398,6 +2439,8 @@ all_used:
   retval= FALSE; // some partitions are used
   mark_all_partitions_as_used(prune_param.part_info);
 end:
+  dbug_tmp_restore_column_map(table->write_set, old_write_set);
+  dbug_tmp_restore_column_map(table->read_set,  old_read_set);
   thd->no_errors=0;
   thd->mem_root= range_par->old_root;
   free_root(&alloc,MYF(0));			// Return memory & allocator
@@ -2424,6 +2467,8 @@ end:
 void store_key_image_to_rec(Field *field, char *ptr, uint len)
 {
   /* Do the same as print_key() does */ 
+  my_bitmap_map *old_map;
+
   if (field->real_maybe_null())
   {
     if (*ptr)
@@ -2434,7 +2479,10 @@ void store_key_image_to_rec(Field *field
     field->set_notnull();
     ptr++;
   }    
+  old_map= dbug_tmp_use_all_columns(field->table,
+                                    field->table->write_set);
   field->set_key_image(ptr, len); 
+  dbug_tmp_restore_column_map(field->table->write_set, old_map);
 }
 
 
@@ -2514,11 +2562,11 @@ static int find_used_partitions_imerge_l
 {
   MY_BITMAP all_merges;
   uint bitmap_bytes;
-  uint32 *bitmap_buf;
+  my_bitmap_map *bitmap_buf;
   uint n_bits= ppar->part_info->used_partitions.n_bits;
   bitmap_bytes= bitmap_buffer_size(n_bits);
-  if (!(bitmap_buf= (uint32*)alloc_root(ppar->range_param.mem_root,
-                                        bitmap_bytes)))
+  if (!(bitmap_buf= (my_bitmap_map*) alloc_root(ppar->range_param.mem_root,
+                                                bitmap_bytes)))
   {
     /*
       Fallback, process just the first SEL_IMERGE. This can leave us with more
@@ -2580,7 +2628,8 @@ int find_used_partitions_imerge(PART_PRU
     ppar->cur_part_fields= 0;
     ppar->cur_subpart_fields= 0;
     init_all_partitions_iterator(ppar->part_info, &ppar->part_iter);
-    if (-1 == (res |= find_used_partitions(ppar, (*ptree)->keys[0])))
+    SEL_ARG *key_tree= (*ptree)->keys[0];
+    if (!key_tree || (-1 == (res |= find_used_partitions(ppar, key_tree))))
       return -1;
   }
   return res;
@@ -2764,7 +2813,8 @@ int find_used_partitions(PART_PRUNE_PARA
         
       uint32 subpart_id;
       bitmap_clear_all(&ppar->subparts_bitmap);
-      while ((subpart_id= subpart_iter.get_next(&subpart_iter)) !=
NOT_A_PARTITION_ID)
+      while ((subpart_id= subpart_iter.get_next(&subpart_iter)) !=
+             NOT_A_PARTITION_ID)
         bitmap_set_bit(&ppar->subparts_bitmap, subpart_id);
 
       /* Mark each partition as used in each subpartition.  */
@@ -2870,7 +2920,8 @@ process_next_key_part:
       /* Got "full range" for subpartitioning fields */
       uint32 part_id;
       bool found= FALSE;
-      while ((part_id= ppar->part_iter.get_next(&ppar->part_iter)) !=
NOT_A_PARTITION_ID)
+      while ((part_id= ppar->part_iter.get_next(&ppar->part_iter)) !=
+             NOT_A_PARTITION_ID)
       {
         ppar->mark_full_partition_used(ppar->part_info, part_id);
         found= TRUE;
@@ -3017,11 +3068,12 @@ static bool create_partition_index_descr
  
   if (ppar->subpart_fields)
   {
-    uint32 *buf;
+    my_bitmap_map *buf;
     uint32 bufsize= bitmap_buffer_size(ppar->part_info->no_subparts);
-    if (!(buf= (uint32*)alloc_root(alloc, bufsize)))
+    if (!(buf= (my_bitmap_map*) alloc_root(alloc, bufsize)))
       return TRUE;
-    bitmap_init(&ppar->subparts_bitmap, buf, ppar->part_info->no_subparts,
FALSE);
+    bitmap_init(&ppar->subparts_bitmap, buf, ppar->part_info->no_subparts,
+                FALSE);
   }
   range_par->key_parts= key_part;
   Field **field= (ppar->part_fields)? part_info->part_field_array :
@@ -3188,7 +3240,8 @@ double get_sweep_read_cost(const PARAM *
   else
   {
     double n_blocks=
-      ceil(ulonglong2double(param->table->file->data_file_length) / IO_SIZE);
+      ceil(ulonglong2double(param->table->file->stats.data_file_length) /
+           IO_SIZE);
     double busy_blocks=
       n_blocks * (1.0 - pow(1.0 - 1.0/n_blocks, rows2double(records)));
     if (busy_blocks < 1.0)
@@ -3357,7 +3410,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick
 
   DBUG_PRINT("info", ("index_merge scans cost=%g", imerge_cost));
   if (imerge_too_expensive || (imerge_cost > read_time) ||
-      (non_cpk_scan_records+cpk_scan_records >= param->table->file->records)
&&
+      (non_cpk_scan_records+cpk_scan_records >=
param->table->file->stats.records) &&
       read_time != DBL_MAX)
   {
     /*
@@ -3415,7 +3468,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick
       imerge_trp->read_cost= imerge_cost;
       imerge_trp->records= non_cpk_scan_records + cpk_scan_records;
       imerge_trp->records= min(imerge_trp->records,
-                               param->table->file->records);
+                               param->table->file->stats.records);
       imerge_trp->range_scans= range_scans;
       imerge_trp->range_scans_end= range_scans + n_child_scans;
       read_time= imerge_cost;
@@ -3476,7 +3529,7 @@ skip_to_ror_scan:
         ((TRP_ROR_INTERSECT*)(*cur_roru_plan))->index_scan_costs;
     roru_total_records += (*cur_roru_plan)->records;
     roru_intersect_part *= (*cur_roru_plan)->records /
-                           param->table->file->records;
+                           param->table->file->stats.records;
   }
 
   /*
@@ -3486,7 +3539,7 @@ skip_to_ror_scan:
     in disjunction do not share key parts.
   */
   roru_total_records -= (ha_rows)(roru_intersect_part*
-                                  param->table->file->records);
+                                  param->table->file->stats.records);
   /* ok, got a ROR read plan for each of the disjuncts
     Calculate cost:
     cost(index_union_scan(scan_1, ... scan_n)) =
@@ -3547,7 +3600,7 @@ static double get_index_only_read_time(c
                                        int keynr)
 {
   double read_time;
-  uint keys_per_block= (param->table->file->block_size/2/
+  uint keys_per_block= (param->table->file->stats.block_size/2/
 			(param->table->key_info[keynr].key_length+
 			 param->table->file->ref_length) + 1);
   read_time=((double) (records+keys_per_block-1)/
@@ -3599,7 +3652,7 @@ static
 ROR_SCAN_INFO *make_ror_scan(const PARAM *param, int idx, SEL_ARG *sel_arg)
 {
   ROR_SCAN_INFO *ror_scan;
-  uint32 *bitmap_buf;
+  my_bitmap_map *bitmap_buf;
   uint keynr;
   DBUG_ENTER("make_ror_scan");
 
@@ -3614,12 +3667,12 @@ ROR_SCAN_INFO *make_ror_scan(const PARAM
   ror_scan->sel_arg= sel_arg;
   ror_scan->records= param->table->quick_rows[keynr];
 
-  if (!(bitmap_buf= (uint32*)alloc_root(param->mem_root,
-                                        param->fields_bitmap_size)))
+  if (!(bitmap_buf= (my_bitmap_map*) alloc_root(param->mem_root,
+                                                param->fields_bitmap_size)))
     DBUG_RETURN(NULL);
 
   if (bitmap_init(&ror_scan->covered_fields, bitmap_buf,
-                  param->fields_bitmap_size*8, FALSE))
+                  param->table->s->fields, FALSE))
     DBUG_RETURN(NULL);
   bitmap_clear_all(&ror_scan->covered_fields);
 
@@ -3628,8 +3681,8 @@ ROR_SCAN_INFO *make_ror_scan(const PARAM
                                param->table->key_info[keynr].key_parts;
   for (;key_part != key_part_end; ++key_part)
   {
-    if (bitmap_is_set(&param->needed_fields, key_part->fieldnr))
-      bitmap_set_bit(&ror_scan->covered_fields, key_part->fieldnr);
+    if (bitmap_is_set(&param->needed_fields, key_part->fieldnr-1))
+      bitmap_set_bit(&ror_scan->covered_fields, key_part->fieldnr-1);
   }
   ror_scan->index_read_cost=
     get_index_only_read_time(param, param->table->quick_rows[ror_scan->keynr],
@@ -3729,21 +3782,21 @@ static
 ROR_INTERSECT_INFO* ror_intersect_init(const PARAM *param)
 {
   ROR_INTERSECT_INFO *info;
-  uint32* buf;
+  my_bitmap_map* buf;
   if (!(info= (ROR_INTERSECT_INFO*)alloc_root(param->mem_root,
                                               sizeof(ROR_INTERSECT_INFO))))
     return NULL;
   info->param= param;
-  if (!(buf= (uint32*)alloc_root(param->mem_root,
-                                 param->fields_bitmap_size)))
+  if (!(buf= (my_bitmap_map*) alloc_root(param->mem_root,
+                                         param->fields_bitmap_size)))
     return NULL;
-  if (bitmap_init(&info->covered_fields, buf, param->fields_bitmap_size*8,
+  if (bitmap_init(&info->covered_fields, buf, param->table->s->fields,
                   FALSE))
     return NULL;
   info->is_covering= FALSE;
   info->index_scan_costs= 0.0;
   info->index_records= 0;
-  info->out_rows= param->table->file->records;
+  info->out_rows= param->table->file->stats.records;
   bitmap_clear_all(&info->covered_fields);
   return info;
 }
@@ -3862,14 +3915,14 @@ static double ror_scan_selectivity(const
   SEL_ARG *sel_arg, *tuple_arg= NULL;
   bool cur_covered;
   bool prev_covered= test(bitmap_is_set(&info->covered_fields,
-                                        key_part->fieldnr));
+                                        key_part->fieldnr-1));
   key_range min_range;
   key_range max_range;
   min_range.key= (byte*) key_val;
   min_range.flag= HA_READ_KEY_EXACT;
   max_range.key= (byte*) key_val;
   max_range.flag= HA_READ_AFTER_KEY;
-  ha_rows prev_records= info->param->table->file->records;
+  ha_rows prev_records= info->param->table->file->stats.records;
   DBUG_ENTER("ror_intersect_selectivity");
 
   for (sel_arg= scan->sel_arg; sel_arg;
@@ -3877,7 +3930,7 @@ static double ror_scan_selectivity(const
   {
     DBUG_PRINT("info",("sel_arg step"));
     cur_covered= test(bitmap_is_set(&info->covered_fields,
-                                    key_part[sel_arg->part].fieldnr));
+                                    key_part[sel_arg->part].fieldnr-1));
     if (cur_covered != prev_covered)
     {
       /* create (part1val, ..., part{n-1}val) tuple. */
@@ -4006,15 +4059,15 @@ static bool ror_intersect_add(ROR_INTERS
   }
 
   info->total_cost= info->index_scan_costs;
-  DBUG_PRINT("info", ("info->total_cost= %g", info->total_cost));
+  DBUG_PRINT("info", ("info->total_cost: %g", info->total_cost));
   if (!info->is_covering)
   {
     info->total_cost += 
       get_sweep_read_cost(info->param, double2rows(info->out_rows));
     DBUG_PRINT("info", ("info->total_cost= %g", info->total_cost));
   }
-  DBUG_PRINT("info", ("New out_rows= %g", info->out_rows));
-  DBUG_PRINT("info", ("New cost= %g, %scovering", info->total_cost,
+  DBUG_PRINT("info", ("New out_rows: %g", info->out_rows));
+  DBUG_PRINT("info", ("New cost: %g, %scovering", info->total_cost,
                       info->is_covering?"" : "non-"));
   DBUG_RETURN(TRUE);
 }
@@ -4093,7 +4146,7 @@ TRP_ROR_INTERSECT *get_best_ror_intersec
   double min_cost= DBL_MAX;
   DBUG_ENTER("get_best_ror_intersect");
 
-  if ((tree->n_ror_scans < 2) || !param->table->file->records)
+  if ((tree->n_ror_scans < 2) || !param->table->file->stats.records)
     DBUG_RETURN(NULL);
 
   /*
@@ -4262,7 +4315,8 @@ TRP_ROR_INTERSECT *get_best_ror_intersec
     F=set of all fields to cover
     S={}
 
-    do {
+    do
+    {
       Order I by (#covered fields in F desc,
                   #components asc,
                   number of first not covered component asc);
@@ -4280,7 +4334,6 @@ TRP_ROR_INTERSECT *get_best_covering_ror
   ROR_SCAN_INFO **ror_scan_mark;
   ROR_SCAN_INFO **ror_scans_end= tree->ror_scans_end;
   DBUG_ENTER("get_best_covering_ror_intersect");
-  uint nbits= param->fields_bitmap_size*8;
 
   for (ROR_SCAN_INFO **scan= tree->ror_scans; scan != ror_scans_end; ++scan)
     (*scan)->key_components=
@@ -4294,9 +4347,9 @@ TRP_ROR_INTERSECT *get_best_covering_ror
   /*I=set of all covering indexes */
   ror_scan_mark= tree->ror_scans;
 
-  uint32 int_buf[MAX_KEY/32+1];
+  my_bitmap_map int_buf[MAX_KEY/(sizeof(my_bitmap_map)*8)+1];
   MY_BITMAP covered_fields;
-  if (bitmap_init(&covered_fields, int_buf, nbits, FALSE))
+  if (bitmap_init(&covered_fields, int_buf, param->table->s->fields, FALSE))
     DBUG_RETURN(0);
   bitmap_clear_all(&covered_fields);
 
@@ -4545,7 +4598,8 @@ QUICK_SELECT_I *TRP_ROR_INTERSECT::make_
 
   if ((quick_intrsect=
          new QUICK_ROR_INTERSECT_SELECT(param->thd, param->table,
-                                        retrieve_full_rows? (!is_covering):FALSE,
+                                        (retrieve_full_rows? (!is_covering) :
+                                         FALSE),
                                         parent_alloc)))
   {
     DBUG_EXECUTE("info", print_ror_scans_arr(param->table,
@@ -5104,7 +5158,7 @@ get_mm_parts(RANGE_OPT_PARAM *param, CON
       tree->keys_map.set_bit(key_part->key);
     }
   }
-
+  
   DBUG_RETURN(tree);
 }
 
@@ -7218,7 +7272,7 @@ QUICK_RANGE_SELECT *get_quick_select_for
     goto err;
   quick->records= records;
 
-  if (cp_buffer_from_ref(thd,ref) && thd->is_fatal_error ||
+  if (cp_buffer_from_ref(thd, table, ref) && thd->is_fatal_error ||
       !(range= new(alloc) QUICK_RANGE()))
     goto err;                                   // out of memory
 
@@ -7281,10 +7335,9 @@ err:
   rowids into Unique, get the sorted sequence and destroy the Unique.
   
   If table has a clustered primary key that covers all rows (TRUE for bdb
-     and innodb currently) and one of the index_merge scans is a scan on PK,
-  then
-    rows that will be retrieved by PK scan are not put into Unique and 
-    primary key scan is not performed here, it is performed later separately.
+  and innodb currently) and one of the index_merge scans is a scan on PK,
+  then rows that will be retrieved by PK scan are not put into Unique and 
+  primary key scan is not performed here, it is performed later separately.
 
   RETURN
     0     OK
@@ -7297,21 +7350,17 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_
   QUICK_RANGE_SELECT* cur_quick;
   int result;
   Unique *unique;
-  DBUG_ENTER("QUICK_INDEX_MERGE_SELECT::prepare_unique");
+  MY_BITMAP *save_read_set, *save_write_set;
+  handler *file= head->file;
+  DBUG_ENTER("QUICK_INDEX_MERGE_SELECT::read_keys_and_merge");
 
   /* We're going to just read rowids. */
-  if (head->file->extra(HA_EXTRA_KEYREAD))
-    DBUG_RETURN(1);
-
-  /*
-    Make innodb retrieve all PK member fields, so
-     * ha_innobase::position (which uses them) call works.
-     * We can filter out rows that will be retrieved by clustered PK.
-    (This also creates a deficiency - it is possible that we will retrieve
-     parts of key that are not used by current query at all.)
-  */
-  if (head->file->ha_retrieve_all_pk())
-    DBUG_RETURN(1);
+  save_read_set=  head->read_set;
+  save_write_set= head->write_set;
+  file->extra(HA_EXTRA_KEYREAD);
+  bitmap_clear_all(&head->tmp_set);
+  head->column_bitmaps_set(&head->tmp_set, &head->tmp_set);
+  head->prepare_for_position();
 
   cur_quick_it.rewind();
   cur_quick= cur_quick_it++;
@@ -7324,8 +7373,8 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_
   if (cur_quick->init() || cur_quick->reset())
     DBUG_RETURN(1);
 
-  unique= new Unique(refpos_order_cmp, (void *)head->file,
-                     head->file->ref_length,
+  unique= new Unique(refpos_order_cmp, (void *)file,
+                     file->ref_length,
                      thd->variables.sortbuff_size);
   if (!unique)
     DBUG_RETURN(1);
@@ -7368,15 +7417,16 @@ int QUICK_INDEX_MERGE_SELECT::read_keys_
 
   }
 
+  DBUG_PRINT("info", ("ok"));
   /* ok, all row ids are in Unique */
   result= unique->get(head);
   delete unique;
   doing_pk_scan= FALSE;
+  /* index_merge currently doesn't support "using index" at all */
+  file->extra(HA_EXTRA_NO_KEYREAD);
+  head->column_bitmaps_set(save_read_set, save_write_set);
   /* start table scan */
   init_read_record(&read_record, thd, head, (SQL_SELECT*) 0, 1, 1);
-  /* index_merge currently doesn't support "using index" at all */
-  head->file->extra(HA_EXTRA_NO_KEYREAD);
-
   DBUG_RETURN(result);
 }
 
@@ -7398,9 +7448,7 @@ int QUICK_INDEX_MERGE_SELECT::get_next()
   if (doing_pk_scan)
     DBUG_RETURN(pk_quick_select->get_next());
 
-  result= read_record.read_record(&read_record);
-
-  if (result == -1)
+  if ((result= read_record.read_record(&read_record)) == -1)
   {
     result= HA_ERR_END_OF_FILE;
     end_read_record(&read_record);
@@ -7408,7 +7456,8 @@ int QUICK_INDEX_MERGE_SELECT::get_next()
     if (pk_quick_select)
     {
       doing_pk_scan= TRUE;
-      if ((result= pk_quick_select->init()) || (result= pk_quick_select->reset()))
+      if ((result= pk_quick_select->init()) ||
+          (result= pk_quick_select->reset()))
         DBUG_RETURN(result);
       DBUG_RETURN(pk_quick_select->get_next());
     }
@@ -7450,16 +7499,12 @@ int QUICK_ROR_INTERSECT_SELECT::get_next
   {
     /* Get a rowid for first quick and save it as a 'candidate' */
     quick= quick_it++;
+    error= quick->get_next();
     if (cpk_quick)
     {
-      do
-      {
+      while (!error && !cpk_quick->row_in_ranges())
         error= quick->get_next();
-      }while (!error && !cpk_quick->row_in_ranges());
     }
-    else
-      error= quick->get_next();
-
     if (error)
       DBUG_RETURN(error);
 
@@ -7505,7 +7550,7 @@ int QUICK_ROR_INTERSECT_SELECT::get_next
       }
     }
 
-    /* We get here iff we got the same row ref in all scans. */
+    /* We get here if we got the same row ref in all scans. */
     if (need_to_fetch_row)
       error= head->file->rnd_pos(head->record[0], last_rowid);
   } while (error == HA_ERR_RECORD_DELETED);
@@ -7578,6 +7623,7 @@ int QUICK_ROR_UNION_SELECT::get_next()
   DBUG_RETURN(error);
 }
 
+
 int QUICK_RANGE_SELECT::reset()
 {
   uint  mrange_bufsiz;
@@ -7617,7 +7663,7 @@ int QUICK_RANGE_SELECT::reset()
   }
 
   /* Allocate the handler buffer if necessary.  */
-  if (file->table_flags() & HA_NEED_READ_RANGE_BUFFER)
+  if (file->ha_table_flags() & HA_NEED_READ_RANGE_BUFFER)
   {
     mrange_bufsiz= min(multi_range_bufsiz,
                        (QUICK_SELECT_I::records + 1)* head->s->reclength);
@@ -7682,6 +7728,15 @@ int QUICK_RANGE_SELECT::get_next()
               (cur_range >= (QUICK_RANGE**) ranges.buffer) &&
               (cur_range <= (QUICK_RANGE**) ranges.buffer + ranges.elements));
 
+  if (in_ror_merged_scan)
+  {
+    /*
+      We don't need to signal the bitmap change as the bitmap is always the
+      same for this head->file
+    */
+    head->column_bitmaps_set_no_signal(&column_bitmap, &column_bitmap);
+  }
+
   for (;;)
   {
     if (in_range)
@@ -7689,10 +7744,7 @@ int QUICK_RANGE_SELECT::get_next()
       /* We did already start to read this key. */
       result= file->read_multi_range_next(&mrange);
       if (result != HA_ERR_END_OF_FILE)
-      {
-        in_range= ! result;
-	DBUG_RETURN(result);
-      }
+        goto end;
     }
 
     uint count= min(multi_range_length, ranges.elements -
@@ -7701,6 +7753,8 @@ int QUICK_RANGE_SELECT::get_next()
     {
       /* Ranges have already been used up before. None is left for read. */
       in_range= FALSE;
+      if (in_ror_merged_scan)
+        head->column_bitmaps_set_no_signal(save_read_set, save_write_set);
       DBUG_RETURN(HA_ERR_END_OF_FILE);
     }
     KEY_MULTI_RANGE *mrange_slot, *mrange_end;
@@ -7732,12 +7786,18 @@ int QUICK_RANGE_SELECT::get_next()
     result= file->read_multi_range_first(&mrange, multi_range, count,
                                          sorted, multi_range_buff);
     if (result != HA_ERR_END_OF_FILE)
-    {
-      in_range= ! result;
-      DBUG_RETURN(result);
-    }
+      goto end;
     in_range= FALSE; /* No matching rows; go to next set of ranges. */
   }
+
+end:
+  in_range= ! result;
+  if (in_ror_merged_scan)
+  {
+    /* Restore bitmaps set on entry */
+    head->column_bitmaps_set_no_signal(save_read_set, save_write_set);
+  }
+  DBUG_RETURN(result);
 }
 
 
@@ -7914,7 +7974,7 @@ bool QUICK_RANGE_SELECT::row_in_ranges()
 
 QUICK_SELECT_DESC::QUICK_SELECT_DESC(QUICK_RANGE_SELECT *q,
                                      uint used_key_parts)
- : QUICK_RANGE_SELECT(*q), rev_it(rev_ranges)
+ :QUICK_RANGE_SELECT(*q), rev_it(rev_ranges)
 {
   QUICK_RANGE *r;
 
@@ -8390,9 +8450,10 @@ cost_group_min_max(TABLE* table, KEY *in
            groups, and thus can be applied after the grouping.
     GA4. There are no expressions among G_i, just direct column references.
     NGA1.If in the index I there is a gap between the last GROUP attribute G_k,
-         and the MIN/MAX attribute C, then NGA must consist of exactly the index
-         attributes that constitute the gap. As a result there is a permutation
-         of NGA that coincides with the gap in the index <B_1, ..., B_m>.
+         and the MIN/MAX attribute C, then NGA must consist of exactly the
+         index attributes that constitute the gap. As a result there is a
+         permutation of NGA that coincides with the gap in the index
+         <B_1, ..., B_m>.
     NGA2.If BA <> {}, then the WHERE clause must contain a conjunction EQ of
          equality conditions for all NG_i of the form (NG_i = const) or
          (const = NG_i), such that each NG_i is referenced in exactly one
@@ -8400,9 +8461,10 @@ cost_group_min_max(TABLE* table, KEY *in
          gap in the index.
     WA1. There are no other attributes in the WHERE clause except the ones
          referenced in predicates RNG, PA, PC, EQ defined above. Therefore
-         WA is subset of (GA union NGA union C) for GA,NGA,C that pass the above
-         tests. By transitivity then it also follows that each WA_i participates
-         in the index I (if this was already tested for GA, NGA and C).
+         WA is subset of (GA union NGA union C) for GA,NGA,C that pass the
+         above tests. By transitivity then it also follows that each WA_i
+         participates in the index I (if this was already tested for GA, NGA
+         and C).
 
     C) Overall query form:
        SELECT EXPR([A_1,...,A_k], [B_1,...,B_m], [MIN(C)], [MAX(C)])
@@ -8464,12 +8526,12 @@ get_best_group_min_max(PARAM *param, SEL
   TABLE *table= param->table;
   bool have_min= FALSE;              /* TRUE if there is a MIN function. */
   bool have_max= FALSE;              /* TRUE if there is a MAX function. */
-  Item_field *min_max_arg_item= NULL;/* The argument of all MIN/MAX functions.*/
+  Item_field *min_max_arg_item= NULL; // The argument of all MIN/MAX functions
   KEY_PART_INFO *min_max_arg_part= NULL; /* The corresponding keypart. */
   uint group_prefix_len= 0; /* Length (in bytes) of the key prefix. */
   KEY *index_info= NULL;    /* The index chosen for data access. */
   uint index= 0;            /* The id of the chosen index. */
-  uint group_key_parts= 0;  /* Number of index key parts in the group prefix. */
+  uint group_key_parts= 0;  // Number of index key parts in the group prefix.
   uint used_key_parts= 0;   /* Number of index key parts used for access. */
   byte key_infix[MAX_KEY_LENGTH]; /* Constants from equality predicates.*/
   uint key_infix_len= 0;          /* Length of key_infix. */
@@ -8587,28 +8649,19 @@ get_best_group_min_max(PARAM *param, SEL
       we check that all query fields are indeed covered by 'cur_index'.
     */
     if (pk < MAX_KEY && cur_index != pk &&
-        (table->file->table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX))
+        (table->file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX))
     {
       /* For each table field */
       for (uint i= 0; i < table->s->fields; i++)
       {
         Field *cur_field= table->field[i];
         /*
-          If the field is used in the current query, check that the
-          field is covered by some keypart of the current index.
+          If the field is used in the current query ensure that it's
+          part of 'cur_index'
         */
-        if (thd->query_id == cur_field->query_id)
-        {
-          KEY_PART_INFO *key_part= cur_index_info->key_part;
-          KEY_PART_INFO *key_part_end= key_part + cur_index_info->key_parts;
-          for (;;)
-          {
-            if (key_part->field == cur_field)
-              break;
-            if (++key_part == key_part_end)
-              goto next_index;                  // Field was not part of key
-          }
-        }
+        if (bitmap_is_set(table->read_set, cur_field->field_index) &&
+            !cur_field->part_of_key_not_clustered.is_set(cur_index))
+          goto next_index;                  // Field was not part of key
       }
     }
 
@@ -8762,7 +8815,7 @@ get_best_group_min_max(PARAM *param, SEL
         key_part_range[1]= last_part;
 
         /* Check if cur_part is referenced in the WHERE clause. */
-        if (join->conds->walk(&Item::find_item_in_field_list_processor,
+        if (join->conds->walk(&Item::find_item_in_field_list_processor, 0,
                               (byte*) key_part_range))
           goto next_index;
       }
@@ -8776,7 +8829,7 @@ get_best_group_min_max(PARAM *param, SEL
     {
       for (cur_part= first_non_infix_part; cur_part != last_part; cur_part++)
       {
-        if (cur_part->field->query_id == thd->query_id)
+        if (bitmap_is_set(table->read_set, cur_part->field->field_index))
           goto next_index;
       }
     }
@@ -9240,8 +9293,8 @@ void cost_group_min_max(TABLE* table, KE
   double cpu_cost= 0; /* TODO: CPU cost of index_read calls? */
   DBUG_ENTER("cost_group_min_max");
 
-  table_records= table->file->records;
-  keys_per_block= (table->file->block_size / 2 /
+  table_records= table->file->stats.records;
+  keys_per_block= (table->file->stats.block_size / 2 /
                    (index_info->key_length + table->file->ref_length)
                         + 1);
   num_blocks= (table_records / keys_per_block) + 1;
@@ -10414,6 +10467,10 @@ print_key(KEY_PART *key_part,const char 
   const char *key_end= key+used_length;
   String tmp(buff,sizeof(buff),&my_charset_bin);
   uint store_length;
+  TABLE *table= key_part->field->table;
+  my_bitmap_map *old_write_set, *old_read_set;
+  old_write_set= dbug_tmp_use_all_columns(table, table->write_set);
+  old_read_set=  dbug_tmp_use_all_columns(table, table->read_set);
 
   for (; key < key_end; key+=store_length, key_part++)
   {
@@ -10439,18 +10496,28 @@ print_key(KEY_PART *key_part,const char 
     if (key+store_length < key_end)
       fputc('/',DBUG_FILE);
   }
+  dbug_tmp_restore_column_map(table->write_set, old_write_set);
+  dbug_tmp_restore_column_map(table->read_set, old_read_set);
 }
 
 
 static void print_quick(QUICK_SELECT_I *quick, const key_map *needed_reg)
 {
   char buf[MAX_KEY/8+1];
+  TABLE *table;
+  my_bitmap_map *old_read_map, *old_write_map;
   DBUG_ENTER("print_quick");
   if (!quick)
     DBUG_VOID_RETURN;
   DBUG_LOCK_FILE;
 
+  table= quick->head;
+  old_read_map=  dbug_tmp_use_all_columns(table, table->read_set);
+  old_write_map= dbug_tmp_use_all_columns(table, table->write_set);
   quick->dbug_dump(0, TRUE);
+  dbug_tmp_restore_column_map(table->read_set, old_read_map);
+  dbug_tmp_restore_column_map(table->write_set, old_write_map);
+
   fprintf(DBUG_FILE,"other_keys: 0x%s:\n", needed_reg->print(buf));
 
   DBUG_UNLOCK_FILE;

--- 1.194/sql/sql_acl.cc	2006-05-26 12:10:28 -04:00
+++ 1.195/sql/sql_acl.cc	2006-06-13 15:33:08 -04:00
@@ -323,6 +323,7 @@ static my_bool acl_load(THD *thd, TABLE_
 
   init_sql_alloc(&mem, ACL_ALLOC_BLOCK_SIZE, 0);
   init_read_record(&read_record_info,thd,table= tables[0].table,NULL,1,0);
+  table->use_all_columns();
   VOID(my_init_dynamic_array(&acl_hosts,sizeof(ACL_HOST),20,50));
   while (!(read_record_info.read_record(&read_record_info)))
   {
@@ -342,7 +343,8 @@ static my_bool acl_load(THD *thd, TABLE_
                           "case that has been forced to lowercase because "
                           "lower_case_table_names is set. It will not be "
                           "possible to remove this privilege using REVOKE.",
-                          host.host.hostname, host.db);
+                          host.host.hostname ? host.host.hostname : "",
+                          host.db ? host.db : "");
     }
     host.access= get_access(table,2);
     host.access= fix_rights_for_db(host.access);
@@ -351,7 +353,8 @@ static my_bool acl_load(THD *thd, TABLE_
     {
       sql_print_warning("'host' entry '%s|%s' "
 		      "ignored in --skip-name-resolve mode.",
-		      host.host.hostname, host.db?host.db:"");
+			host.host.hostname ? host.host.hostname : "",
+			host.db ? host.db : "");
       continue;
     }
 #ifndef TO_BE_REMOVED
@@ -369,6 +372,7 @@ static my_bool acl_load(THD *thd, TABLE_
   freeze_size(&acl_hosts);
 
   init_read_record(&read_record_info,thd,table=tables[1].table,NULL,1,0);
+  table->use_all_columns();
   VOID(my_init_dynamic_array(&acl_users,sizeof(ACL_USER),50,100));
   password_length= table->field[2]->field_length /
     table->field[2]->charset()->mbmaxlen;
@@ -421,7 +425,8 @@ static my_bool acl_load(THD *thd, TABLE_
     {
       sql_print_warning("'user' entry '%s@%s' "
                         "ignored in --skip-name-resolve mode.",
-		      user.user, user.host.hostname);
+			user.user ? user.user : "",
+			user.host.hostname ? user.host.hostname : "");
       continue;
     }
 
@@ -544,8 +549,8 @@ static my_bool acl_load(THD *thd, TABLE_
 #endif
       }
       VOID(push_dynamic(&acl_users,(gptr) &user));
-      if (!user.host.hostname || user.host.hostname[0] == wild_many &&
-          !user.host.hostname[1])
+      if (!user.host.hostname ||
+	  (user.host.hostname[0] == wild_many && !user.host.hostname[1]))
         allow_all_hosts=1;			// Anyone can connect
     }
   }
@@ -555,6 +560,7 @@ static my_bool acl_load(THD *thd, TABLE_
   freeze_size(&acl_users);
 
   init_read_record(&read_record_info,thd,table=tables[2].table,NULL,1,0);
+  table->use_all_columns();
   VOID(my_init_dynamic_array(&acl_dbs,sizeof(ACL_DB),50,100));
   while (!(read_record_info.read_record(&read_record_info)))
   {
@@ -571,7 +577,9 @@ static my_bool acl_load(THD *thd, TABLE_
     {
       sql_print_warning("'db' entry '%s %s@%s' "
 		        "ignored in --skip-name-resolve mode.",
-		        db.db, db.user, db.host.hostname);
+		        db.db,
+			db.user ? db.user : "",
+			db.host.hostname ? db.host.hostname : "");
       continue;
     }
     db.access=get_access(table,3);
@@ -590,7 +598,9 @@ static my_bool acl_load(THD *thd, TABLE_
                           "case that has been forced to lowercase because "
                           "lower_case_table_names is set. It will not be "
                           "possible to remove this privilege using REVOKE.",
-		          db.db, db.user, db.host.hostname, db.host.hostname);
+		          db.db,
+			  db.user ? db.user : "",
+			  db.host.hostname ? db.host.hostname : "");
       }
     }
     db.sort=get_sort(3,db.host.hostname,db.db,db.user);
@@ -1088,6 +1098,8 @@ bool acl_getroot_no_password(Security_co
 
   sctx->master_access= 0;
   sctx->db_access= 0;
+  sctx->priv_user= (char *) "";
+  *sctx->priv_host= 0;
 
   /*
      Find acl entry in user database.
@@ -1162,8 +1174,7 @@ static void acl_update_user(const char *
   {
     ACL_USER *acl_user=dynamic_element(&acl_users,i,ACL_USER*);
     if (!acl_user->user && !user[0] ||
-	acl_user->user &&
-	!strcmp(user,acl_user->user))
+	acl_user->user && !strcmp(user,acl_user->user))
     {
       if (!acl_user->host.hostname && !host[0] ||
 	  acl_user->host.hostname &&
@@ -1226,8 +1237,8 @@ static void acl_insert_user(const char *
   set_user_salt(&acl_user, password, password_len);
 
   VOID(push_dynamic(&acl_users,(gptr) &acl_user));
-  if (!acl_user.host.hostname || acl_user.host.hostname[0] == wild_many
-      && !acl_user.host.hostname[1])
+  if (!acl_user.host.hostname ||
+      (acl_user.host.hostname[0] == wild_many && !acl_user.host.hostname[1]))
     allow_all_hosts=1;		// Anyone can connect /* purecov: tested */
   qsort((gptr) dynamic_element(&acl_users,0,ACL_USER*),acl_users.elements,
 	sizeof(ACL_USER),(qsort_cmp) acl_compare);
@@ -1287,7 +1298,7 @@ static void acl_insert_db(const char *us
   ACL_DB acl_db;
   safe_mutex_assert_owner(&acl_cache->lock);
   acl_db.user=strdup_root(&mem,user);
-  update_hostname(&acl_db.host,strdup_root(&mem,host));
+  update_hostname(&acl_db.host, *host ? strdup_root(&mem,host) : 0);
   acl_db.db=strdup_root(&mem,db);
   acl_db.access=privileges;
   acl_db.sort=get_sort(3,acl_db.host.hostname,acl_db.db,acl_db.user);
@@ -1674,11 +1685,10 @@ find_acl_user(const char *host, const ch
   {
     ACL_USER *acl_user=dynamic_element(&acl_users,i,ACL_USER*);
     DBUG_PRINT("info",("strcmp('%s','%s'), compare_hostname('%s','%s'),",
-		       user,
-		       acl_user->user ? acl_user->user : "",
-		       host,
-		       acl_user->host.hostname ? acl_user->host.hostname :
-		       ""));
+                       user, acl_user->user ? acl_user->user : "",
+                       host,
+                       acl_user->host.hostname ? acl_user->host.hostname :
+                       ""));
     if (!acl_user->user && !user[0] ||
 	acl_user->user && !strcmp(user,acl_user->user))
     {
@@ -1728,7 +1738,7 @@ static const char *calc_ip(const char *i
 
 static void update_hostname(acl_host_and_ip *host, const char *hostname)
 {
-  host->hostname=(char*) hostname;		// This will not be modified!
+  host->hostname=(char*) hostname;             // This will not be modified!
   if (!hostname ||
       (!(hostname=calc_ip(hostname,&host->ip,'/')) ||
        !(hostname=calc_ip(hostname+1,&host->ip_mask,'\0'))))
@@ -1748,8 +1758,8 @@ static bool compare_hostname(const acl_h
   }
   return (!host->hostname ||
 	  (hostname && !wild_case_compare(system_charset_info,
-                                          hostname,host->hostname)) ||
-	  (ip && !wild_compare(ip,host->hostname,0)));
+                                          hostname, host->hostname)) ||
+	  (ip && !wild_compare(ip, host->hostname, 0)));
 }
 
 bool hostname_requires_resolving(const char *hostname)
@@ -1795,14 +1805,15 @@ static bool update_user_table(THD *thd, 
   DBUG_ENTER("update_user_table");
   DBUG_PRINT("enter",("user: %s  host: %s",user,host));
 
+  table->use_all_columns();
   table->field[0]->store(host,(uint) strlen(host), system_charset_info);
   table->field[1]->store(user,(uint) strlen(user), system_charset_info);
   key_copy((byte *) user_key, table->record[0], table->key_info,
            table->key_info->key_length);
 
-  table->file->ha_retrieve_all_cols();
   if (table->file->index_read_idx(table->record[0], 0,
-				  (byte *) user_key, table->key_info->key_length,
+				  (byte *) user_key,
+                                  table->key_info->key_length,
 				  HA_READ_KEY_EXACT))
   {
     my_message(ER_PASSWORD_NO_MATCH, ER(ER_PASSWORD_NO_MATCH),
@@ -1885,12 +1896,14 @@ static int replace_user_table(THD *thd, 
     password=combo.password.str;
   }
 
-  table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
-  table->field[1]->store(combo.user.str,combo.user.length, system_charset_info);
+  table->use_all_columns();
+  table->field[0]->store(combo.host.str,combo.host.length,
+                         system_charset_info);
+  table->field[1]->store(combo.user.str,combo.user.length,
+                         system_charset_info);
   key_copy(user_key, table->record[0], table->key_info,
            table->key_info->key_length);
 
-  table->file->ha_retrieve_all_cols();
   if (table->file->index_read_idx(table->record[0], 0,
                                   user_key, table->key_info->key_length,
                                   HA_READ_KEY_EXACT))
@@ -2026,7 +2039,6 @@ static int replace_user_table(THD *thd, 
       We should NEVER delete from the user table, as a uses can still
       use mysqld even if he doesn't have any privileges in the user table!
     */
-    table->file->ha_retrieve_all_cols();
     if (cmp_record(table,record[1]) &&
 	(error=table->file->ha_update_row(table->record[1],table->record[0])))
     {						// This should never happen
@@ -2102,13 +2114,15 @@ static int replace_db_table(TABLE *table
     DBUG_RETURN(-1);
   }
 
-  table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
+  table->use_all_columns();
+  table->field[0]->store(combo.host.str,combo.host.length,
+                         system_charset_info);
   table->field[1]->store(db,(uint) strlen(db), system_charset_info);
-  table->field[2]->store(combo.user.str,combo.user.length, system_charset_info);
+  table->field[2]->store(combo.user.str,combo.user.length,
+                         system_charset_info);
   key_copy(user_key, table->record[0], table->key_info,
            table->key_info->key_length);
 
-  table->file->ha_retrieve_all_cols();
   if (table->file->index_read_idx(table->record[0],0,
                                   user_key, table->key_info->key_length,
                                   HA_READ_KEY_EXACT))
@@ -2120,9 +2134,11 @@ static int replace_db_table(TABLE *table
     }
     old_row_exists = 0;
     restore_record(table, s->default_values);
-    table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
+    table->field[0]->store(combo.host.str,combo.host.length,
+                           system_charset_info);
     table->field[1]->store(db,(uint) strlen(db), system_charset_info);
-    table->field[2]->store(combo.user.str,combo.user.length, system_charset_info);
+    table->field[2]->store(combo.user.str,combo.user.length,
+                           system_charset_info);
   }
   else
   {
@@ -2144,18 +2160,17 @@ static int replace_db_table(TABLE *table
     /* update old existing row */
     if (rights)
     {
-      table->file->ha_retrieve_all_cols();
-      if ((error=table->file->ha_update_row(table->record[1],
-                                            table->record[0])))
+      if ((error= table->file->ha_update_row(table->record[1],
+                                             table->record[0])))
 	goto table_error;			/* purecov: deadcode */
     }
     else	/* must have been a revoke of all privileges */
     {
-      if ((error = table->file->ha_delete_row(table->record[1])))
+      if ((error= table->file->ha_delete_row(table->record[1])))
 	goto table_error;			/* purecov: deadcode */
     }
   }
-  else if (rights &&
(error=table->file->ha_write_row(table->record[0])))
+  else if (rights && (error=
table->file->ha_write_row(table->record[0])))
   {
     if (error && error != HA_ERR_FOUND_DUPP_KEY) /* purecov: inspected */
       goto table_error; /* purecov: deadcode */
@@ -2311,7 +2326,8 @@ GRANT_TABLE::GRANT_TABLE(TABLE *form, TA
     uint key_prefix_len;
     KEY_PART_INFO *key_part= col_privs->key_info->key_part;
     col_privs->field[0]->store(host.hostname,
-                               host.hostname ? (uint) strlen(host.hostname) : 0,
+                               host.hostname ? (uint) strlen(host.hostname) :
+                               0,
                                system_charset_info);
     col_privs->field[1]->store(db,(uint) strlen(db), system_charset_info);
     col_privs->field[2]->store(user,(uint) strlen(user), system_charset_info);
@@ -2397,7 +2413,8 @@ static GRANT_NAME *name_hash_search(HASH
   {
     if (exact)
     {
-      if ((host &&
+      if (!grant_name->host.hostname ||
+          (host &&
 	   !my_strcasecmp(system_charset_info, host,
                           grant_name->host.hostname)) ||
 	  (ip && !strcmp(ip, grant_name->host.hostname)))
@@ -2452,6 +2469,7 @@ static int replace_column_table(GRANT_TA
   KEY_PART_INFO *key_part= table->key_info->key_part;
   DBUG_ENTER("replace_column_table");
 
+  table->use_all_columns();
   table->field[0]->store(combo.host.str,combo.host.length,
                          system_charset_info);
   table->field[1]->store(db,(uint) strlen(db),
@@ -2487,7 +2505,6 @@ static int replace_column_table(GRANT_TA
     key_copy(user_key, table->record[0], table->key_info,
              table->key_info->key_length);
 
-    table->file->ha_retrieve_all_cols();
     if (table->file->index_read(table->record[0], user_key,
 				table->key_info->key_length,
                                 HA_READ_KEY_EXACT))
@@ -2565,7 +2582,6 @@ static int replace_column_table(GRANT_TA
     key_copy(user_key, table->record[0], table->key_info,
              key_prefix_length);
 
-    table->file->ha_retrieve_all_cols();
     if (table->file->index_read(table->record[0], user_key,
 				key_prefix_length,
                                 HA_READ_KEY_EXACT))
@@ -2655,16 +2671,19 @@ static int replace_table_table(THD *thd,
     DBUG_RETURN(-1);				/* purecov: deadcode */
   }
 
+  table->use_all_columns();
   restore_record(table, s->default_values);     // Get empty record
-  table->field[0]->store(combo.host.str,combo.host.length, system_charset_info);
+  table->field[0]->store(combo.host.str,combo.host.length,
+                         system_charset_info);
   table->field[1]->store(db,(uint) strlen(db), system_charset_info);
-  table->field[2]->store(combo.user.str,combo.user.length, system_charset_info);
-  table->field[3]->store(table_name,(uint) strlen(table_name),
system_charset_info);
+  table->field[2]->store(combo.user.str,combo.user.length,
+                         system_charset_info);
+  table->field[3]->store(table_name,(uint) strlen(table_name),
+                         system_charset_info);
   store_record(table,record[1]);			// store at pos 1
   key_copy(user_key, table->record[0], table->key_info,
            table->key_info->key_length);
 
-  table->file->ha_retrieve_all_cols();
   if (table->file->index_read_idx(table->record[0], 0,
                                   user_key, table->key_info->key_length,
 				  HA_READ_KEY_EXACT))
@@ -2777,6 +2796,7 @@ static int replace_routine_table(THD *th
     DBUG_RETURN(-1);
   }
 
+  table->use_all_columns();
   restore_record(table, s->default_values);		// Get empty record
   table->field[0]->store(combo.host.str,combo.host.length, &my_charset_latin1);
   table->field[1]->store(db,(uint) strlen(db), &my_charset_latin1);
@@ -3473,10 +3493,14 @@ static my_bool grant_load(TABLE_LIST *ta
 		   0,0);
   init_sql_alloc(&memex, ACL_ALLOC_BLOCK_SIZE, 0);
 
-  t_table = tables[0].table; c_table = tables[1].table;
+  t_table = tables[0].table;
+  c_table = tables[1].table;
   p_table= tables[2].table;
   t_table->file->ha_index_init(0, 1);
   p_table->file->ha_index_init(0, 1);
+  t_table->use_all_columns();
+  c_table->use_all_columns();
+  p_table->use_all_columns();
   if (!t_table->file->index_first(t_table->record[0]))
   {
     memex_ptr= &memex;
@@ -3484,7 +3508,7 @@ static my_bool grant_load(TABLE_LIST *ta
     do
     {
       GRANT_TABLE *mem_check;
-      if (!(mem_check=new GRANT_TABLE(t_table,c_table)))
+      if (!(mem_check=new (memex_ptr) GRANT_TABLE(t_table,c_table)))
       {
 	/* This could only happen if we are out memory */
 	grant_option= FALSE;
@@ -3497,8 +3521,10 @@ static my_bool grant_load(TABLE_LIST *ta
 	{
           sql_print_warning("'tables_priv' entry '%s %s@%s' "
                             "ignored in --skip-name-resolve mode.",
-                            mem_check->tname, mem_check->user,
-                            mem_check->host, mem_check->host);
+                            mem_check->tname,
+                            mem_check->user ? mem_check->user : "",
+                            mem_check->host.hostname ?
+                            mem_check->host.hostname : "");
 	  continue;
 	}
       }
@@ -3522,7 +3548,7 @@ static my_bool grant_load(TABLE_LIST *ta
     {
       GRANT_NAME *mem_check;
       HASH *hash;
-      if (!(mem_check=new GRANT_NAME(p_table)))
+      if (!(mem_check=new (&memex) GRANT_NAME(p_table)))
       {
 	/* This could only happen if we are out memory */
 	grant_option= FALSE;
@@ -3536,7 +3562,8 @@ static my_bool grant_load(TABLE_LIST *ta
           sql_print_warning("'procs_priv' entry '%s %s@%s' "
                             "ignored in --skip-name-resolve mode.",
                             mem_check->tname, mem_check->user,
-                            mem_check->host);
+                            mem_check->host.hostname ?
+                            mem_check->host.hostname : "");
 	  continue;
 	}
       }
@@ -3692,6 +3719,7 @@ bool check_grant(THD *thd, ulong want_ac
   TABLE_LIST *table, *first_not_own_table= thd->lex->first_not_own_table();
   Security_context *sctx= thd->security_ctx;
   uint i;
+  ulong orig_want_access= want_access;
   DBUG_ENTER("check_grant");
   DBUG_ASSERT(number > 0);
 
@@ -3713,18 +3741,22 @@ bool check_grant(THD *thd, ulong want_ac
     table->grant.orig_want_privilege= (want_access & ~SHOW_VIEW_ACL);
   }
 
-  want_access&= ~sctx->master_access;
-  if (!want_access)
-    DBUG_RETURN(0);                             // ok
-
   rw_rdlock(&LOCK_grant);
   for (table= tables;
        table && number-- && table != first_not_own_table;
        table= table->next_global)
   {
     GRANT_TABLE *grant_table;
+    sctx = test(table->security_ctx) ?
+      table->security_ctx : thd->security_ctx;
+
+    want_access= orig_want_access;
+    want_access&= ~sctx->master_access;
+    if (!want_access)
+      continue;                                 // ok
+
     if (!(~table->grant.privilege & want_access) || 
-        table->derived || table->schema_table || table->belong_to_view)
+        table->derived || table->schema_table)
     {
       /*
         It is subquery in the FROM clause. VIEW set table->derived after
@@ -4243,11 +4275,6 @@ bool mysql_show_grants(THD *thd,LEX_USER
     DBUG_RETURN(TRUE);
   }
 
-  if (!lex_user->host.str)
-  {
-    lex_user->host.str= (char*) "%";
-    lex_user->host.length=1;
-  }
   if (lex_user->host.length > HOSTNAME_LENGTH ||
       lex_user->user.length > USERNAME_LENGTH)
   {
@@ -4457,16 +4484,17 @@ bool mysql_show_grants(THD *thd,LEX_USER
   /* Add table & column access */
   for (index=0 ; index < column_priv_hash.records ; index++)
   {
-    const char *user;
+    const char *user, *host;
     GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&column_priv_hash,
 							  index);
 
     if (!(user=grant_table->user))
       user= "";
+    if (!(host= grant_table->host.hostname))
+      host= "";
 
     if (!strcmp(lex_user->user.str,user) &&
-	!my_strcasecmp(system_charset_info, lex_user->host.str,
-                       grant_table->host.hostname))
+	!my_strcasecmp(system_charset_info, lex_user->host.str, host))
     {
       ulong table_access= grant_table->privs;
       if ((table_access | grant_table->cols) != 0)
@@ -4593,15 +4621,16 @@ static int show_routine_grants(THD* thd,
   /* Add routine access */
   for (index=0 ; index < hash->records ; index++)
   {
-    const char *user;
+    const char *user, *host;
     GRANT_NAME *grant_proc= (GRANT_NAME*) hash_element(hash, index);
 
     if (!(user=grant_proc->user))
       user= "";
+    if (!(host= grant_proc->host.hostname))
+      host= "";
 
     if (!strcmp(lex_user->user.str,user) &&
-	!my_strcasecmp(system_charset_info, lex_user->host.str,
-                       grant_proc->host.hostname))
+	!my_strcasecmp(system_charset_info, lex_user->host.str, host))
     {
       ulong proc_access= grant_proc->privs;
       if (proc_access != 0)
@@ -4877,6 +4906,7 @@ static int handle_grant_table(TABLE_LIST
   uint key_prefix_length;
   DBUG_ENTER("handle_grant_table");
 
+  table->use_all_columns();
   if (! table_no) // mysql.user table
   {
     /*
@@ -5055,39 +5085,37 @@ static int handle_grant_struct(uint stru
   {
     /*
       Get a pointer to the element.
-      Unfortunaltely, the host default differs for the structures.
     */
     switch (struct_no) {
     case 0:
       acl_user= dynamic_element(&acl_users, idx, ACL_USER*);
       user= acl_user->user;
-      if (!(host= acl_user->host.hostname))
-        host= "%";
-      break;
+      host= acl_user->host.hostname;
+    break;
 
     case 1:
       acl_db= dynamic_element(&acl_dbs, idx, ACL_DB*);
       user= acl_db->user;
-      if (!(host= acl_db->host.hostname))
-        host= "%";
+      host= acl_db->host.hostname;
       break;
 
     case 2:
       grant_name= (GRANT_NAME*) hash_element(&column_priv_hash, idx);
       user= grant_name->user;
-      if (!(host= grant_name->host.hostname))
-        host= "%";
+      host= grant_name->host.hostname;
       break;
 
     case 3:
       grant_name= (GRANT_NAME*) hash_element(&proc_priv_hash, idx);
       user= grant_name->user;
-      if (!(host= grant_name->host.hostname))
-        host= "%";
+      host= grant_name->host.hostname;
       break;
     }
     if (! user)
       user= "";
+    if (! host)
+      host= "";
+
 #ifdef EXTRA_DEBUG
     DBUG_PRINT("loop",("scan struct: %u  index: %u  user: '%s'  host: '%s'",
                        struct_no, idx, user, host));
@@ -5526,7 +5554,8 @@ bool mysql_revoke_all(THD *thd,  List <L
 	if (!strcmp(lex_user->user.str,user) &&
 	    !my_strcasecmp(system_charset_info, lex_user->host.str, host))
 	{
-	  if (!replace_db_table(tables[1].table, acl_db->db, *lex_user, ~(ulong)0, 1))
+	  if (!replace_db_table(tables[1].table, acl_db->db, *lex_user,
+                                ~(ulong)0, 1))
 	  {
 	    /*
 	      Don't increment counter as replace_db_table deleted the
@@ -5671,8 +5700,10 @@ bool sp_revoke_privileges(THD *thd, cons
         LEX_USER lex_user;
 	lex_user.user.str= grant_proc->user;
 	lex_user.user.length= strlen(grant_proc->user);
-	lex_user.host.str= grant_proc->host.hostname;
-	lex_user.host.length= strlen(grant_proc->host.hostname);
+	lex_user.host.str= grant_proc->host.hostname ?
+	  grant_proc->host.hostname : (char*)"";
+	lex_user.host.length= grant_proc->host.hostname ?
+	  strlen(grant_proc->host.hostname) : 0;
 	if (!replace_routine_table(thd,grant_proc,tables[4].table,lex_user,
 				   grant_proc->db, grant_proc->tname,
                                    is_proc, ~(ulong)0, 1))
@@ -5979,16 +6010,17 @@ int fill_schema_table_privileges(THD *th
 
   for (index=0 ; index < column_priv_hash.records ; index++)
   {
-    const char *user, *is_grantable= "YES";
+    const char *user, *host, *is_grantable= "YES";
     GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&column_priv_hash,
 							  index);
     if (!(user=grant_table->user))
       user= "";
+    if (!(host= grant_table->host.hostname))
+      host= "";
 
     if (no_global_access &&
         (strcmp(thd->security_ctx->priv_user, user) ||
-         my_strcasecmp(system_charset_info, curr_host,
-                       grant_table->host.hostname)))
+         my_strcasecmp(system_charset_info, curr_host, host)))
       continue;
 
     ulong table_access= grant_table->privs;
@@ -6004,7 +6036,7 @@ int fill_schema_table_privileges(THD *th
       if (!(table_access & GRANT_ACL))
         is_grantable= "NO";
 
-      strxmov(buff,"'",user,"'@'",grant_table->host.hostname,"'",NullS);
+      strxmov(buff, "'", user, "'@'", host, "'", NullS);
       if (!test_access)
         update_schema_privilege(table, buff, grant_table->db, grant_table->tname,
                                 0, 0, STRING_WITH_LEN("USAGE"), is_grantable);
@@ -6046,16 +6078,17 @@ int fill_schema_column_privileges(THD *t
 
   for (index=0 ; index < column_priv_hash.records ; index++)
   {
-    const char *user, *is_grantable= "YES";
+    const char *user, *host, *is_grantable= "YES";
     GRANT_TABLE *grant_table= (GRANT_TABLE*) hash_element(&column_priv_hash,
 							  index);
     if (!(user=grant_table->user))
       user= "";
+    if (!(host= grant_table->host.hostname))
+      host= "";
 
     if (no_global_access &&
         (strcmp(thd->security_ctx->priv_user, user) ||
-         my_strcasecmp(system_charset_info, curr_host,
-                       grant_table->host.hostname)))
+         my_strcasecmp(system_charset_info, curr_host, host)))
       continue;
 
     ulong table_access= grant_table->cols;
@@ -6065,7 +6098,7 @@ int fill_schema_column_privileges(THD *t
         is_grantable= "NO";
 
       ulong test_access= table_access & ~GRANT_ACL;
-      strxmov(buff,"'",user,"'@'",grant_table->host.hostname,"'",NullS);
+      strxmov(buff, "'", user, "'@'", host, "'", NullS);
       if (!test_access)
         continue;
       else

--- 1.38/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp	2006-06-08 09:55:09 -04:00
+++ 1.39/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp	2006-06-13 15:33:09 -04:00
@@ -1839,8 +1839,7 @@ int Dbtup::interpreterNextLab(Signal* si
 	    /* ------------------------------------------------------------- */
 	    TregMemBuffer[theRegister]= 0x50;
             // arithmetic conversion if big-endian
-            * (Int64*)(TregMemBuffer+theRegister+2)=
-                                       TregMemBuffer[theRegister+1];
+            * (Int64*)(TregMemBuffer+theRegister+2)= TregMemBuffer[theRegister+1];
 	  } else if (TnoDataRW == 3) {
 	    /* ------------------------------------------------------------- */
 	    // Three words read means that we get the instruction plus two 
Thread
bk commit into 5.1 tree (cmiller:1.2188)Chad MILLER13 Jun