~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/join.cc

  • Committer: tdavies
  • Date: 2010-10-31 07:38:13 UTC
  • mto: (1897.2.4 merge)
  • mto: This revision was merged to the branch mainline in revision 1899.
  • Revision ID: tdavies@molly-20101031073813-mmu12nqc0bwezxny
struct order_st changed and renamed to c++ class named:Order

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
 
72
72
/** Declarations of static functions used in this source file. */
73
73
static bool make_group_fields(Join *main_join, Join *curr_join);
74
 
static void calc_group_buffer(Join *join,order_st *group);
75
 
static bool alloc_group_fields(Join *join,order_st *group);
 
74
static void calc_group_buffer(Join *join, Order *group);
 
75
static bool alloc_group_fields(Join *join, Order *group);
76
76
static uint32_t cache_record_length(Join *join, uint32_t index);
77
77
static double prev_record_reads(Join *join, uint32_t idx, table_map found_ref);
78
78
static bool get_best_combination(Join *join);
102
102
static bool make_join_select(Join *join, optimizer::SqlSelect *select,COND *item);
103
103
static bool make_join_readinfo(Join *join);
104
104
static void update_depend_map(Join *join);
105
 
static void update_depend_map(Join *join, order_st *order);
106
 
static order_st *remove_constants(Join *join,order_st *first_order,COND *cond, bool change_list, bool *simple_order);
 
105
static void update_depend_map(Join *join, Order *order);
 
106
static Order *remove_constants(Join *join,Order *first_order,COND *cond, bool change_list, bool *simple_order);
107
107
static int return_zero_rows(Join *join,
108
108
                            select_result *res,
109
109
                            TableList *tables,
121
121
                               List<Item> &fields,
122
122
                               List<Item> &all_fields,
123
123
                               COND **conds,
124
 
                               order_st *order,
125
 
                               order_st *group,
 
124
                               Order *order,
 
125
                               Order *group,
126
126
                               bool *hidden_group_fields);
127
127
static bool make_join_statistics(Join *join, TableList *leaves, COND *conds, DYNAMIC_ARRAY *keyuse);
128
128
static uint32_t build_bitmap_for_nested_joins(List<TableList> *join_list, uint32_t first_unused);
129
 
static Table *get_sort_by_table(order_st *a,order_st *b,TableList *tables);
 
129
static Table *get_sort_by_table(Order *a, Order *b,TableList *tables);
130
130
static void reset_nj_counters(List<TableList> *join_list);
131
 
static bool test_if_subpart(order_st *a,order_st *b);
 
131
static bool test_if_subpart(Order *a,Order *b);
132
132
static void restore_prev_nj_state(JoinTable *last);
133
133
static bool add_ref_to_table_cond(Session *session, JoinTable *join_tab);
134
134
static void free_blobs(Field **ptr); /* Rename this method...conflicts with another in global namespace... */
150
150
                  uint32_t wild_num,
151
151
                  COND *conds_init,
152
152
                  uint32_t og_num,
153
 
                  order_st *order_init,
154
 
                  order_st *group_init,
 
153
                  Order *order_init,
 
154
                  Order *group_init,
155
155
                  Item *having_init,
156
156
                  Select_Lex *select_lex_arg,
157
157
                  Select_Lex_Unit *unit_arg)
288
288
 
289
289
  if (order)
290
290
  {
291
 
    order_st *ord;
 
291
    Order *ord;
292
292
    for (ord= order; ord; ord= ord->next)
293
293
    {
294
294
      Item *item= *ord->item;
333
333
  {
334
334
    /* Caclulate the number of groups */
335
335
    send_group_parts= 0;
336
 
    for (order_st *group_tmp= group_list ; group_tmp ; group_tmp= group_tmp->next)
 
336
    for (Order *group_tmp= group_list ; group_tmp ; group_tmp= group_tmp->next)
337
337
      send_group_parts++;
338
338
  }
339
339
 
653
653
 
654
654
  /* Optimize distinct away if possible */
655
655
  {
656
 
    order_st *org_order= order;
 
656
    Order *org_order= order;
657
657
    order= remove_constants(this, order,conds,1, &simple_order);
658
658
    if (session->is_error())
659
659
    {
787
787
  }
788
788
  simple_group= 0;
789
789
  {
790
 
    order_st *old_group_list;
 
790
    Order *old_group_list;
791
791
    group_list= remove_constants(this, (old_group_list= group_list), conds,
792
792
                                 rollup.state == ROLLUP::STATE_NONE,
793
793
                                 &simple_group);
937
937
        Force using of tmp table if sorting by a SP or UDF function due to
938
938
        their expensive and probably non-deterministic nature.
939
939
      */
940
 
      for (order_st *tmp_order= order; tmp_order ; tmp_order=tmp_order->next)
 
940
      for (Order *tmp_order= order; tmp_order ; tmp_order=tmp_order->next)
941
941
      {
942
942
        Item *item= *tmp_order->item;
943
943
        if (item->is_expensive())
981
981
 
982
982
    tmp_table_param.hidden_field_count= (all_fields.elements -
983
983
           fields_list.elements);
984
 
    order_st *tmp_group= ((!simple_group && 
 
984
    Order *tmp_group= ((!simple_group &&
985
985
                           ! (test_flags.test(TEST_NO_KEY_GROUP))) ? group_list :
986
 
                                                                     (order_st*) 0);
 
986
                                                                     (Order*) 0);
987
987
    /*
988
988
      Pushing LIMIT to the temporary table creation is not applicable
989
989
      when there is ORDER BY or GROUP BY or there is no GROUP BY, but
1430
1430
              exec_tmp_table2= create_tmp_table(session,
1431
1431
                                                &curr_join->tmp_table_param,
1432
1432
                                                *curr_all_fields,
1433
 
                                                (order_st*) 0,
 
1433
                                                (Order*) 0,
1434
1434
                                                curr_join->select_distinct &&
1435
1435
                                                !curr_join->group_list,
1436
1436
                                                1, curr_join->select_options,
1990
1990
    */
1991
1991
    if (order)
1992
1992
    {
1993
 
      order_st *ord;
 
1993
      Order *ord;
1994
1994
      for (ord= order; ord; ord= ord->next)
1995
1995
        group_parts++;
1996
1996
    }
2100
2100
  Item *item;
2101
2101
  while ((item= it++))
2102
2102
  {
2103
 
    order_st *group_tmp;
 
2103
    Order *group_tmp;
2104
2104
    bool found_in_group= 0;
2105
2105
 
2106
2106
    for (group_tmp= group_list; group_tmp; group_tmp= group_tmp->next)
2129
2129
            return 1;
2130
2130
          new_item->fix_fields(session, (Item **) 0);
2131
2131
          session->change_item_tree(it.ref(), new_item);
2132
 
          for (order_st *tmp= group_tmp; tmp; tmp= tmp->next)
 
2132
          for (Order *tmp= group_tmp; tmp; tmp= tmp->next)
2133
2133
          {
2134
2134
            if (*tmp->item == item)
2135
2135
              session->change_item_tree(tmp->item, new_item);
2204
2204
    Item *item;
2205
2205
    List_iterator<Item> new_it(rollup.fields[pos]);
2206
2206
    Item **ref_array_start= rollup.ref_pointer_arrays[pos];
2207
 
    order_st *start_group;
 
2207
    Order *start_group;
2208
2208
 
2209
2209
    /* Point to first hidden field */
2210
2210
    Item **ref_array= ref_array_start + fields_arg.elements-1;
2246
2246
      else
2247
2247
      {
2248
2248
        /* Check if this is something that is part of this group by */
2249
 
        order_st *group_tmp;
 
2249
        Order *group_tmp;
2250
2250
        for (group_tmp= start_group, i= pos ;
2251
2251
                  group_tmp ; group_tmp= group_tmp->next, i++)
2252
2252
        {
2847
2847
enum_nested_loop_state end_update(Join *join, JoinTable *, bool end_of_records)
2848
2848
{
2849
2849
  Table *table= join->tmp_table;
2850
 
  order_st *group;
 
2850
  Order *group;
2851
2851
  int   error;
2852
2852
 
2853
2853
  if (end_of_records)
2984
2984
/**
2985
2985
  calc how big buffer we need for comparing group entries.
2986
2986
*/
2987
 
static void calc_group_buffer(Join *join,order_st *group)
 
2987
static void calc_group_buffer(Join *join, Order *group)
2988
2988
{
2989
2989
  uint32_t key_length=0, parts=0, null_parts=0;
2990
2990
 
3063
3063
 
3064
3064
  Groups are saved in reverse order for easyer check loop.
3065
3065
*/
3066
 
static bool alloc_group_fields(Join *join,order_st *group)
 
3066
static bool alloc_group_fields(Join *join, Order *group)
3067
3067
{
3068
3068
  if (group)
3069
3069
  {
4944
4944
}
4945
4945
 
4946
4946
/** Update the dependency map for the sort order. */
4947
 
static void update_depend_map(Join *join, order_st *order)
 
4947
static void update_depend_map(Join *join, Order *order)
4948
4948
{
4949
4949
  for (; order ; order=order->next)
4950
4950
  {
4982
4982
  @return
4983
4983
    Returns new sort order
4984
4984
*/
4985
 
static order_st *remove_constants(Join *join,order_st *first_order, COND *cond, bool change_list, bool *simple_order)
 
4985
static Order *remove_constants(Join *join,Order *first_order, COND *cond, bool change_list, bool *simple_order)
4986
4986
{
4987
4987
  if (join->tables == join->const_tables)
4988
4988
    return change_list ? 0 : first_order;               // No need to sort
4989
4989
 
4990
 
  order_st *order,**prev_ptr;
 
4990
  Order *order,**prev_ptr;
4991
4991
  table_map first_table= join->join_tab[join->const_tables].table->map;
4992
4992
  table_map not_const_tables= ~join->const_table_map;
4993
4993
  table_map ref;
5428
5428
                               List<Item> &fields,
5429
5429
                               List<Item> &all_fields,
5430
5430
                               COND **conds,
5431
 
                               order_st *order,
5432
 
                               order_st *group,
 
5431
                               Order *order,
 
5432
                               Order *group,
5433
5433
                               bool *hidden_group_fields)
5434
5434
{
5435
5435
  int res;
5940
5940
  Return table number if there is only one table in sort order
5941
5941
  and group and order is compatible, else return 0.
5942
5942
*/
5943
 
static Table *get_sort_by_table(order_st *a,order_st *b,TableList *tables)
 
5943
static Table *get_sort_by_table(Order *a, Order *b,TableList *tables)
5944
5944
{
5945
5945
  table_map map= (table_map) 0;
5946
5946
 
5995
5995
  If first parts has different direction, change it to second part
5996
5996
  (group is sorted like order)
5997
5997
*/
5998
 
static bool test_if_subpart(order_st *a,order_st *b)
 
5998
static bool test_if_subpart(Order *a, Order *b)
5999
5999
{
6000
6000
  for (; a && b; a=a->next,b=b->next)
6001
6001
  {