~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Mark Atwood
  • Date: 2011-06-27 19:01:37 UTC
  • mfrom: (2318.6.90 refactor16)
  • Revision ID: me@mark.atwood.name-20110627190137-iflt3vku0kw77l8a
mergeĀ lp:~olafvdspek/drizzle/refactor17

Show diffs side-by-side

added added

removed removed

Lines of Context:
2551
2551
  true   otherwise
2552
2552
*/
2553
2553
 
2554
 
static bool
2555
 
set_new_item_local_context(Session *session, Item_ident *item, TableList *table_ref)
 
2554
static void set_new_item_local_context(Session *session, Item_ident *item, TableList *table_ref)
2556
2555
{
2557
 
  Name_resolution_context *context;
2558
 
  if (!(context= new (session->mem_root) Name_resolution_context))
2559
 
    return true;
 
2556
  Name_resolution_context* context= new (session->mem_root) Name_resolution_context;
2560
2557
  context->init();
2561
 
  context->first_name_resolution_table=
2562
 
    context->last_name_resolution_table= table_ref;
 
2558
  context->first_name_resolution_table= context->last_name_resolution_table= table_ref;
2563
2559
  item->context= context;
2564
 
  return false;
2565
2560
}
2566
2561
 
2567
2562
 
2691
2686
      Item *item_2=   nj_col_2->create_item(session);
2692
2687
      Field *field_1= nj_col_1->field();
2693
2688
      Field *field_2= nj_col_2->field();
2694
 
      Item_ident *item_ident_1, *item_ident_2;
2695
 
      Item_func_eq *eq_cond;
2696
 
 
 
2689
 
2697
2690
      if (!item_1 || !item_2)
2698
2691
        return(result); // out of memory
2699
2692
 
2710
2703
        We need to cast item_1,2 to Item_ident, because we need to hook name
2711
2704
        resolution contexts specific to each item.
2712
2705
      */
2713
 
      item_ident_1= (Item_ident*) item_1;
2714
 
      item_ident_2= (Item_ident*) item_2;
 
2706
      Item_ident* item_ident_1= (Item_ident*) item_1;
 
2707
      Item_ident* item_ident_2= (Item_ident*) item_2;
2715
2708
      /*
2716
2709
        Create and hook special name resolution contexts to each item in the
2717
2710
        new join condition . We need this to both speed-up subsequent name
2718
2711
        resolution of these items, and to enable proper name resolution of
2719
2712
        the items during the execute phase of PS.
2720
2713
      */
2721
 
      if (set_new_item_local_context(session, item_ident_1, nj_col_1->table_ref) ||
2722
 
          set_new_item_local_context(session, item_ident_2, nj_col_2->table_ref))
2723
 
        return(result);
 
2714
      set_new_item_local_context(session, item_ident_1, nj_col_1->table_ref);
 
2715
      set_new_item_local_context(session, item_ident_2, nj_col_2->table_ref);
2724
2716
 
2725
 
      if (!(eq_cond= new Item_func_eq(item_ident_1, item_ident_2)))
2726
 
        return(result);                               /* Out of memory. */
 
2717
      Item_func_eq* eq_cond= new Item_func_eq(item_ident_1, item_ident_2);
2727
2718
 
2728
2719
      /*
2729
2720
        Add the new equi-join condition to the ON clause. Notice that
2767
2758
    we check for this error in store_natural_using_join_columns() when
2768
2759
    (found_using_fields < length(join_using_fields)).
2769
2760
  */
2770
 
  result= false;
2771
 
 
2772
 
  return(result);
 
2761
  return false;
2773
2762
}
2774
2763
 
2775
2764
 
2820
2809
  Field_iterator_table_ref it_1, it_2;
2821
2810
  Natural_join_column *nj_col_1, *nj_col_2;
2822
2811
  bool result= true;
2823
 
  List<Natural_join_column> *non_join_columns;
2824
2812
 
2825
2813
  assert(!natural_using_join->join_columns);
2826
2814
 
2827
 
  if (!(non_join_columns= new List<Natural_join_column>) ||
2828
 
      !(natural_using_join->join_columns= new List<Natural_join_column>))
2829
 
  {
2830
 
    return(result);
2831
 
  }
 
2815
  List<Natural_join_column>* non_join_columns= new List<Natural_join_column>;
 
2816
  natural_using_join->join_columns= new List<Natural_join_column>;
2832
2817
 
2833
2818
  /* Append the columns of the first join operand. */
2834
2819
  for (it_1.set(table_ref_1); !it_1.end_of_fields(); it_1.next())
2851
2836
  */
2852
2837
  if (using_fields && found_using_fields < using_fields->size())
2853
2838
  {
2854
 
    String *using_field_name;
2855
2839
    List<String>::iterator using_fields_it(using_fields->begin());
2856
 
    while ((using_field_name= using_fields_it++))
 
2840
    while (String* using_field_name= using_fields_it++)
2857
2841
    {
2858
2842
      const char *using_field_name_ptr= using_field_name->c_ptr();
2859
 
      List<Natural_join_column>::iterator
2860
 
        it(natural_using_join->join_columns->begin());
2861
 
      Natural_join_column *common_field;
2862
 
 
 
2843
      List<Natural_join_column>::iterator  it(natural_using_join->join_columns->begin());
2863
2844
      for (;;)
2864
2845
      {
2865
2846
        /* If reached the end of fields, and none was found, report error. */
2866
 
        if (!(common_field= it++))
 
2847
        Natural_join_column* common_field= it++;
 
2848
        if (not common_field)
2867
2849
        {
2868
 
          my_error(ER_BAD_FIELD_ERROR, MYF(0), using_field_name_ptr,
2869
 
                   session->where());
2870
 
          return(result);
 
2850
          my_error(ER_BAD_FIELD_ERROR, MYF(0), using_field_name_ptr, session->where());
 
2851
          return result;
2871
2852
        }
2872
 
        if (!my_strcasecmp(system_charset_info,
2873
 
                           common_field->name(), using_field_name_ptr))
 
2853
        if (!my_strcasecmp(system_charset_info, common_field->name(), using_field_name_ptr))
2874
2854
          break;                                // Found match
2875
2855
      }
2876
2856
    }
2893
2873
    natural_using_join->join_columns->concat(non_join_columns);
2894
2874
  natural_using_join->is_join_columns_complete= true;
2895
2875
 
2896
 
  result= false;
2897
 
 
2898
 
  return(result);
 
2876
  return false;
2899
2877
}
2900
2878
 
2901
2879
 
3055
3033
    else
3056
3034
      table_ref->next_name_resolution_table= NULL;
3057
3035
  }
3058
 
  result= false; /* All is OK. */
3059
 
 
3060
 
  return(result);
 
3036
  return false;
3061
3037
}
3062
3038
 
3063
3039
 
3105
3081
  {
3106
3082
    table_ref= left_neighbor;
3107
3083
    left_neighbor= table_ref_it++;
3108
 
    if (store_top_level_join_columns(session, table_ref,
3109
 
                                     left_neighbor, right_neighbor))
 
3084
    if (store_top_level_join_columns(session, table_ref, left_neighbor, right_neighbor))
3110
3085
      return true;
3111
3086
    if (left_neighbor)
3112
3087
    {
3201
3176
                  List<Item> &fields, enum_mark_columns mark_used_columns,
3202
3177
                  List<Item> *sum_func_list, bool allow_sum_func)
3203
3178
{
3204
 
  register Item *item;
 
3179
  Item *item;
3205
3180
  enum_mark_columns save_mark_used_columns= session->mark_used_columns;
3206
3181
  nesting_map save_allow_sum_func= session->lex().allow_sum_func;
3207
3182
  List<Item>::iterator it(fields.begin());