~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_select.cc

  • Committer: Brian Aker
  • Date: 2008-10-06 06:47:29 UTC
  • Revision ID: brian@tangent.org-20081006064729-2i9mhjkzyvow9xsm
RemoveĀ uint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
                                 DYNAMIC_ARRAY *keyuse);
45
45
static bool update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,
46
46
                                JOIN_TAB *join_tab,
47
 
                                uint tables, COND *conds,
 
47
                                uint32_t tables, COND *conds,
48
48
                                COND_EQUAL *cond_equal,
49
49
                                table_map table_map, SELECT_LEX *select_lex,
50
50
                                st_sargable_param **sargables);
51
51
static int sort_keyuse(KEYUSE *a,KEYUSE *b);
52
 
static void set_position(JOIN *join,uint index,JOIN_TAB *table,KEYUSE *key);
 
52
static void set_position(JOIN *join,uint32_t index,JOIN_TAB *table,KEYUSE *key);
53
53
static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, KEYUSE *org_keyuse,
54
54
                               table_map used_tables);
55
55
static bool choose_plan(JOIN *join,table_map join_tables);
56
56
 
57
57
static void best_access_path(JOIN *join, JOIN_TAB *s, THD *thd,
58
 
                             table_map remaining_tables, uint idx,
 
58
                             table_map remaining_tables, uint32_t idx,
59
59
                             double record_count, double read_time);
60
60
static void optimize_straight_join(JOIN *join, table_map join_tables);
61
61
static bool greedy_search(JOIN *join, table_map remaining_tables,
62
 
                             uint depth, uint prune_level);
 
62
                             uint32_t depth, uint32_t prune_level);
63
63
static bool best_extension_by_limited_search(JOIN *join,
64
64
                                             table_map remaining_tables,
65
 
                                             uint idx, double record_count,
66
 
                                             double read_time, uint depth,
67
 
                                             uint prune_level);
68
 
static uint determine_search_depth(JOIN* join);
 
65
                                             uint32_t idx, double record_count,
 
66
                                             double read_time, uint32_t depth,
 
67
                                             uint32_t prune_level);
 
68
static uint32_t determine_search_depth(JOIN* join);
69
69
static int join_tab_cmp(const void* ptr1, const void* ptr2);
70
70
static int join_tab_cmp_straight(const void* ptr1, const void* ptr2);
71
71
/*
72
72
  TODO: 'find_best' is here only temporarily until 'greedy_search' is
73
73
  tested and approved.
74
74
*/
75
 
static bool find_best(JOIN *join,table_map rest_tables,uint index,
 
75
static bool find_best(JOIN *join,table_map rest_tables,uint32_t index,
76
76
                      double record_count,double read_time);
77
 
static uint cache_record_length(JOIN *join,uint index);
78
 
static double prev_record_reads(JOIN *join, uint idx, table_map found_ref);
 
77
static uint32_t cache_record_length(JOIN *join,uint32_t index);
 
78
static double prev_record_reads(JOIN *join, uint32_t idx, table_map found_ref);
79
79
static bool get_best_combination(JOIN *join);
80
80
static store_key *get_store_key(THD *thd,
81
81
                                KEYUSE *keyuse, table_map used_tables,
82
82
                                KEY_PART_INFO *key_part, unsigned char *key_buff,
83
 
                                uint maybe_null);
 
83
                                uint32_t maybe_null);
84
84
static bool make_simple_join(JOIN *join,Table *tmp_table);
85
85
static void make_outerjoin_info(JOIN *join);
86
86
static bool make_join_select(JOIN *join,SQL_SELECT *select,COND *item);
87
 
static bool make_join_readinfo(JOIN *join, uint64_t options, uint no_jbuf_after);
 
87
static bool make_join_readinfo(JOIN *join, uint64_t options, uint32_t no_jbuf_after);
88
88
static bool only_eq_ref_tables(JOIN *join, order_st *order, table_map tables);
89
89
static void update_depend_map(JOIN *join);
90
90
static void update_depend_map(JOIN *join, order_st *order);
106
106
static bool check_interleaving_with_nj(JOIN_TAB *last, JOIN_TAB *next);
107
107
static void restore_prev_nj_state(JOIN_TAB *last);
108
108
static void reset_nj_counters(List<TableList> *join_list);
109
 
static uint build_bitmap_for_nested_joins(List<TableList> *join_list,
110
 
                                          uint first_unused);
 
109
static uint32_t build_bitmap_for_nested_joins(List<TableList> *join_list,
 
110
                                          uint32_t first_unused);
111
111
 
112
112
static 
113
113
void advance_sj_state(const table_map remaining_tables, const JOIN_TAB *tab);
175
175
static int remove_dup_with_compare(THD *thd, Table *entry, Field **field,
176
176
                                   ulong offset,Item *having);
177
177
static int remove_dup_with_hash_index(THD *thd,Table *table,
178
 
                                      uint field_count, Field **first_field,
 
178
                                      uint32_t field_count, Field **first_field,
179
179
 
180
180
                                      ulong key_length,Item *having);
181
 
static int join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count);
 
181
static int join_init_cache(THD *thd,JOIN_TAB *tables,uint32_t table_count);
182
182
static ulong used_blob_length(CACHE_FIELD **ptr);
183
183
static bool store_record_in_cache(JOIN_CACHE *cache);
184
184
static void reset_cache_read(JOIN_CACHE *cache);
198
198
static bool change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
199
199
                                     List<Item> &new_list1,
200
200
                                     List<Item> &new_list2,
201
 
                                     uint elements, List<Item> &items);
 
201
                                     uint32_t elements, List<Item> &items);
202
202
// Create list for using with tempory table
203
203
static bool change_refs_to_tmp_fields(THD *thd, Item **ref_pointer_array,
204
204
                                      List<Item> &new_list1,
205
205
                                      List<Item> &new_list2,
206
 
                                      uint elements, List<Item> &items);
 
206
                                      uint32_t elements, List<Item> &items);
207
207
static void init_tmptable_sum_functions(Item_sum **func);
208
208
static void update_tmptable_sum_func(Item_sum **func,Table *tmp_table);
209
209
static void copy_sum_funcs(Item_sum **func_ptr, Item_sum **end);
438
438
int
439
439
JOIN::prepare(Item ***rref_pointer_array,
440
440
              TableList *tables_init,
441
 
              uint wild_num, COND *conds_init, uint og_num,
 
441
              uint32_t wild_num, COND *conds_init, uint32_t og_num,
442
442
              order_st *order_init, order_st *group_init,
443
443
              Item *having_init,
444
444
              order_st *proc_param_init, SELECT_LEX *select_lex_arg,
779
779
    join_tab->packed_info |= TAB_INFO_USING_INDEX;
780
780
  if (where)
781
781
    join_tab->packed_info |= TAB_INFO_USING_WHERE;
782
 
  for (uint i = 0; i < join_tab->ref.key_parts; i++)
 
782
  for (uint32_t i = 0; i < join_tab->ref.key_parts; i++)
783
783
  {
784
784
    if (join_tab->ref.cond_guards[i])
785
785
    {
829
829
  if (join_tab->type == JT_EQ_REF)
830
830
  {
831
831
    Table_map_iterator it(join_tab->ref.depend_map & ~PSEUDO_TABLE_BITS);
832
 
    uint idx;
 
832
    uint32_t idx;
833
833
    while ((idx= it.next_bit())!=Table_map_iterator::BITMAP_END)
834
834
    {
835
835
      JOIN_TAB *ref_tab= join->join_tab + idx;
941
941
*/
942
942
 
943
943
static
944
 
int setup_semijoin_dups_elimination(JOIN *join, uint64_t options, uint no_jbuf_after)
 
944
int setup_semijoin_dups_elimination(JOIN *join, uint64_t options, uint32_t no_jbuf_after)
945
945
{
946
946
  table_map cur_map= join->const_table_map | PSEUDO_TABLE_BITS;
947
947
  struct {
951
951
      2 - Temptable (maybe confluent),
952
952
      3 - Temptable with join buffering
953
953
    */
954
 
    uint strategy;
955
 
    uint start_idx; /* Left range bound */
956
 
    uint end_idx;   /* Right range bound */
 
954
    uint32_t strategy;
 
955
    uint32_t start_idx; /* Left range bound */
 
956
    uint32_t end_idx;   /* Right range bound */
957
957
    /* 
958
958
      For Temptable strategy: Bitmap of all outer and correlated tables from 
959
959
      all involved join nests.
968
968
  table_map range_start_map= 0; /* table_map at current range start */
969
969
  bool dealing_with_jbuf= false; /* true <=> table within cur range uses join buf */
970
970
  int cur_range= 0;
971
 
  uint i;
 
971
  uint32_t i;
972
972
 
973
973
  /*
974
974
    First pass: locate the duplicate-generating ranges and pick the strategies.
1109
1109
    {
1110
1110
      SJ_TMP_TABLE::TAB sjtabs[MAX_TABLES];
1111
1111
      table_map cur_map= join->const_table_map | PSEUDO_TABLE_BITS;
1112
 
      uint jt_rowid_offset= 0; // # tuple bytes are already occupied (w/o NULL bytes)
1113
 
      uint jt_null_bits= 0;    // # null bits in tuple bytes
 
1112
      uint32_t jt_rowid_offset= 0; // # tuple bytes are already occupied (w/o NULL bytes)
 
1113
      uint32_t jt_null_bits= 0;    // # null bits in tuple bytes
1114
1114
      SJ_TMP_TABLE::TAB *last_tab= sjtabs;
1115
 
      uint rowid_keep_flags= JOIN_TAB::CALL_POSITION | JOIN_TAB::KEEP_ROWID;
 
1115
      uint32_t rowid_keep_flags= JOIN_TAB::CALL_POSITION | JOIN_TAB::KEEP_ROWID;
1116
1116
      JOIN_TAB *last_outer_tab= tab - 1;
1117
1117
      /*
1118
1118
        Walk through the range and remember
1144
1144
      if (jt_rowid_offset) /* Temptable has at least one rowid */
1145
1145
      {
1146
1146
        SJ_TMP_TABLE *sjtbl;
1147
 
        uint tabs_size= (last_tab - sjtabs) * sizeof(SJ_TMP_TABLE::TAB);
 
1147
        uint32_t tabs_size= (last_tab - sjtabs) * sizeof(SJ_TMP_TABLE::TAB);
1148
1148
        if (!(sjtbl= (SJ_TMP_TABLE*)thd->alloc(sizeof(SJ_TMP_TABLE))) ||
1149
1149
            !(sjtbl->tabs= (SJ_TMP_TABLE::TAB*) thd->alloc(tabs_size)))
1150
1150
          return(true);
1197
1197
  join->sj_tmp_tables= NULL;
1198
1198
}
1199
1199
 
1200
 
uint make_join_orderinfo(JOIN *join);
 
1200
uint32_t make_join_orderinfo(JOIN *join);
1201
1201
 
1202
1202
/**
1203
1203
  global select optimisation.
1627
1627
              (group_list && order) ||
1628
1628
              test(select_options & OPTION_BUFFER_RESULT)));
1629
1629
 
1630
 
  uint no_jbuf_after= make_join_orderinfo(this);
 
1630
  uint32_t no_jbuf_after= make_join_orderinfo(this);
1631
1631
  uint64_t select_opts_for_readinfo= 
1632
1632
    (select_options & (SELECT_DESCRIBE | SELECT_NO_JOIN_CACHE)) | (0);
1633
1633
 
1711
1711
  */
1712
1712
  if (need_tmp || select_distinct || group_list || order)
1713
1713
  {
1714
 
    for (uint i = const_tables; i < tables; i++)
 
1714
    for (uint32_t i = const_tables; i < tables; i++)
1715
1715
      join_tab[i].table->prepare_for_position();
1716
1716
  }
1717
1717
 
2602
2602
 
2603
2603
bool
2604
2604
mysql_select(THD *thd, Item ***rref_pointer_array,
2605
 
             TableList *tables, uint wild_num, List<Item> &fields,
2606
 
             COND *conds, uint og_num,  order_st *order, order_st *group,
 
2605
             TableList *tables, uint32_t wild_num, List<Item> &fields,
 
2606
             COND *conds, uint32_t og_num,  order_st *order, order_st *group,
2607
2607
             Item *having, order_st *proc_param, uint64_t select_options,
2608
2608
             select_result *result, SELECT_LEX_UNIT *unit,
2609
2609
             SELECT_LEX *select_lex)
2935
2935
  /*TODO: also reset the 'with_subselect' there. */
2936
2936
 
2937
2937
  /* n. Adjust the parent_join->tables counter */
2938
 
  uint table_no= parent_join->tables;
 
2938
  uint32_t table_no= parent_join->tables;
2939
2939
  /* n. Walk through child's tables and adjust table->map */
2940
2940
  for (tl= subq_lex->leaf_tables; tl; tl= tl->next_leaf, table_no++)
2941
2941
  {
2993
2993
  }
2994
2994
  else
2995
2995
  {
2996
 
    for (uint i= 0; i < subq_pred->left_expr->cols(); i++)
 
2996
    for (uint32_t i= 0; i < subq_pred->left_expr->cols(); i++)
2997
2997
    {
2998
2998
      nested_join->sj_outer_expr_list.push_back(subq_pred->left_expr->
2999
2999
                                                element_index(i));
3195
3195
bool find_eq_ref_candidate(Table *table, table_map sj_inner_tables)
3196
3196
{
3197
3197
  KEYUSE *keyuse= table->reginfo.join_tab->keyuse;
3198
 
  uint key;
 
3198
  uint32_t key;
3199
3199
 
3200
3200
  if (keyuse)
3201
3201
  {
3393
3393
{
3394
3394
  Field *field;              /* field against which to check sargability */
3395
3395
  Item **arg_value;          /* values of potential keys for lookups     */
3396
 
  uint num_values;           /* number of values in the above array      */
 
3396
  uint32_t num_values;           /* number of values in the above array      */
3397
3397
} SARGABLE_PARAM;  
3398
3398
 
3399
3399
/**
3411
3411
{
3412
3412
  int error;
3413
3413
  Table *table;
3414
 
  uint i,table_count,const_count,key;
 
3414
  uint32_t i,table_count,const_count,key;
3415
3415
  table_map found_const_table_map, all_table_map, found_ref, refs;
3416
3416
  key_map const_ref, eq_part;
3417
3417
  Table **table_vector;
3520
3520
    */
3521
3521
    for (i= 0, s= stat ; i < table_count ; i++, s++)
3522
3522
    {
3523
 
      for (uint j= 0 ; j < table_count ; j++)
 
3523
      for (uint32_t j= 0 ; j < table_count ; j++)
3524
3524
      {
3525
3525
        table= stat[j].table;
3526
3526
        if (s->dependent & table->map)
3717
3717
      key_map possible_keys= field->key_start;
3718
3718
      possible_keys.intersect(field->table->keys_in_use_for_query);
3719
3719
      bool is_const= 1;
3720
 
      for (uint j=0; j < sargables->num_values; j++)
 
3720
      for (uint32_t j=0; j < sargables->num_values; j++)
3721
3721
        is_const&= sargables->arg_value[j]->const_item();
3722
3722
      if (is_const)
3723
3723
        join_tab[0].const_keys.merge(possible_keys);
3847
3847
  */
3848
3848
  bool          null_rejecting; 
3849
3849
  bool          *cond_guard; /* See KEYUSE::cond_guard */
3850
 
  uint          sj_pred_no; /* See KEYUSE::sj_pred_no */
 
3850
  uint32_t          sj_pred_no; /* See KEYUSE::sj_pred_no */
3851
3851
} KEY_FIELD;
3852
3852
 
3853
3853
/**
3876
3876
 
3877
3877
static KEY_FIELD *
3878
3878
merge_key_fields(KEY_FIELD *start,KEY_FIELD *new_fields,KEY_FIELD *end,
3879
 
                 uint and_level)
 
3879
                 uint32_t and_level)
3880
3880
{
3881
3881
  if (start == new_fields)
3882
3882
    return start;                               // Impossible or
4003
4003
*/
4004
4004
 
4005
4005
static void
4006
 
add_key_field(KEY_FIELD **key_fields,uint and_level, Item_func *cond,
4007
 
              Field *field, bool eq_func, Item **value, uint num_values,
 
4006
add_key_field(KEY_FIELD **key_fields,uint32_t and_level, Item_func *cond,
 
4007
              Field *field, bool eq_func, Item **value, uint32_t num_values,
4008
4008
              table_map usable_tables, SARGABLE_PARAM **sargables)
4009
4009
{
4010
 
  uint exists_optimize= 0;
 
4010
  uint32_t exists_optimize= 0;
4011
4011
  if (!(field->flags & PART_KEY_FLAG))
4012
4012
  {
4013
4013
    // Don't remove column IS NULL on a LEFT JOIN table
4021
4021
  {
4022
4022
    table_map used_tables=0;
4023
4023
    bool optimizable=0;
4024
 
    for (uint i=0; i<num_values; i++)
 
4024
    for (uint32_t i=0; i<num_values; i++)
4025
4025
    {
4026
4026
      used_tables|=(value[i])->used_tables();
4027
4027
      if (!((value[i])->used_tables() & (field->table->map | RAND_TABLE_BIT)))
4057
4057
      stat[0].key_dependent|=used_tables;
4058
4058
 
4059
4059
      bool is_const=1;
4060
 
      for (uint i=0; i<num_values; i++)
 
4060
      for (uint32_t i=0; i<num_values; i++)
4061
4061
      {
4062
4062
        if (!(is_const&= value[i]->const_item()))
4063
4063
          break;
4175
4175
*/
4176
4176
 
4177
4177
static void
4178
 
add_key_equal_fields(KEY_FIELD **key_fields, uint and_level,
 
4178
add_key_equal_fields(KEY_FIELD **key_fields, uint32_t and_level,
4179
4179
                     Item_func *cond, Item_field *field_item,
4180
4180
                     bool eq_func, Item **val,
4181
 
                     uint num_values, table_map usable_tables,
 
4181
                     uint32_t num_values, table_map usable_tables,
4182
4182
                     SARGABLE_PARAM **sargables)
4183
4183
{
4184
4184
  Field *field= field_item->field;
4206
4206
}
4207
4207
 
4208
4208
static void
4209
 
add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level,
 
4209
add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint32_t *and_level,
4210
4210
               COND *cond, table_map usable_tables,
4211
4211
               SARGABLE_PARAM **sargables)
4212
4212
{
4299
4299
    if (cond_func->functype() == Item_func::BETWEEN)
4300
4300
    {
4301
4301
      values= cond_func->arguments();
4302
 
      for (uint i= 1 ; i < cond_func->argument_count() ; i++)
 
4302
      for (uint32_t i= 1 ; i < cond_func->argument_count() ; i++)
4303
4303
      {
4304
4304
        Item_field *field_item;
4305
4305
        if (cond_func->arguments()[i]->real_item()->type() == Item::FIELD_ITEM
4410
4410
static uint
4411
4411
max_part_bit(key_part_map bits)
4412
4412
{
4413
 
  uint found;
 
4413
  uint32_t found;
4414
4414
  for (found=0; bits & 1 ; found++,bits>>=1) ;
4415
4415
  return found;
4416
4416
}
4424
4424
 
4425
4425
  if (key_field->eq_func && !(key_field->optimize & KEY_OPTIMIZE_EXISTS))
4426
4426
  {
4427
 
    for (uint key= 0 ; key < form->sizeKeys() ; key++)
 
4427
    for (uint32_t key= 0 ; key < form->sizeKeys() ; key++)
4428
4428
    {
4429
4429
      if (!(form->keys_in_use_for_query.is_set(key)))
4430
4430
        continue;
4431
4431
 
4432
 
      uint key_parts= (uint) form->key_info[key].key_parts;
4433
 
      for (uint part=0 ; part <  key_parts ; part++)
 
4432
      uint32_t key_parts= (uint) form->key_info[key].key_parts;
 
4433
      for (uint32_t part=0 ; part <  key_parts ; part++)
4434
4434
      {
4435
4435
        if (field->eq(form->key_info[key].key_part[part].field))
4436
4436
        {
4507
4507
*/
4508
4508
 
4509
4509
static void add_key_fields_for_nj(JOIN *join, TableList *nested_join_table,
4510
 
                                  KEY_FIELD **end, uint *and_level,
 
4510
                                  KEY_FIELD **end, uint32_t *and_level,
4511
4511
                                  SARGABLE_PARAM **sargables)
4512
4512
{
4513
4513
  List_iterator<TableList> li(nested_join_table->nested_join->join_list);
4565
4565
 
4566
4566
static bool
4567
4567
update_ref_and_keys(THD *thd, DYNAMIC_ARRAY *keyuse,JOIN_TAB *join_tab,
4568
 
                    uint tables, COND *cond,
 
4568
                    uint32_t tables, COND *cond,
4569
4569
                    COND_EQUAL *cond_equal __attribute__((unused)),
4570
4570
                    table_map normal_tables, SELECT_LEX *select_lex,
4571
4571
                    SARGABLE_PARAM **sargables)
4572
4572
{
4573
4573
  uint  and_level,i,found_eq_constant;
4574
4574
  KEY_FIELD *key_fields, *end, *field;
4575
 
  uint sz;
4576
 
  uint m= cmax(select_lex->max_equal_elems,(uint32_t)1);
 
4575
  uint32_t sz;
 
4576
  uint32_t m= cmax(select_lex->max_equal_elems,(uint32_t)1);
4577
4577
  
4578
4578
  /* 
4579
4579
    We use the same piece of memory to store both  KEY_FIELD 
4736
4736
        (map= (keyuse->used_tables & ~join->const_table_map &
4737
4737
               ~OUTER_REF_TABLE_BIT)))
4738
4738
    {
4739
 
      uint tablenr;
 
4739
      uint32_t tablenr;
4740
4740
      for (tablenr=0 ; ! (map & 1) ; map>>=1, tablenr++) ;
4741
4741
      if (map == 1)                     // Only one table
4742
4742
      {
4823
4823
/** Save const tables first as used tables. */
4824
4824
 
4825
4825
static void
4826
 
set_position(JOIN *join,uint idx,JOIN_TAB *table,KEYUSE *key)
 
4826
set_position(JOIN *join,uint32_t idx,JOIN_TAB *table,KEYUSE *key)
4827
4827
{
4828
4828
  join->positions[idx].table= table;
4829
4829
  join->positions[idx].key=key;
4865
4865
{
4866
4866
  List_iterator<Item> li(sj_nest->nested_join->sj_outer_expr_list);
4867
4867
  Item *item;
4868
 
  uint i= 0;
 
4868
  uint32_t i= 0;
4869
4869
  uint64_t res= 0;
4870
4870
  while ((item= li++))
4871
4871
  {
4914
4914
                 JOIN_TAB  *s,
4915
4915
                 THD       *thd,
4916
4916
                 table_map remaining_tables,
4917
 
                 uint      idx,
 
4917
                 uint32_t      idx,
4918
4918
                 double    record_count,
4919
4919
                 double    read_time __attribute__((unused)))
4920
4920
{
4921
4921
  KEYUSE *best_key=         0;
4922
 
  uint best_max_key_part=   0;
 
4922
  uint32_t best_max_key_part=   0;
4923
4923
  bool found_constraint= 0;
4924
4924
  double best=              DBL_MAX;
4925
4925
  double best_time=         DBL_MAX;
4927
4927
  table_map best_ref_depends_map= 0;
4928
4928
  double tmp;
4929
4929
  ha_rows rec;
4930
 
  uint best_is_sj_inside_out=    0;
 
4930
  uint32_t best_is_sj_inside_out=    0;
4931
4931
 
4932
4932
  if (s->keyuse)
4933
4933
  {                                            /* Use key if possible */
4965
4965
    {
4966
4966
      key_part_map found_part= 0;
4967
4967
      table_map found_ref= 0;
4968
 
      uint key= keyuse->key;
 
4968
      uint32_t key= keyuse->key;
4969
4969
      KEY *keyinfo= table->key_info+key;
4970
4970
      /* Bitmap of keyparts where the ref access is over 'keypart=const': */
4971
4971
      key_part_map const_part= 0;
4979
4979
 
4980
4980
      do /* For each keypart */
4981
4981
      {
4982
 
        uint keypart= keyuse->keypart;
 
4982
        uint32_t keypart= keyuse->keypart;
4983
4983
        table_map best_part_found_ref= 0;
4984
4984
        double best_prev_record_reads= DBL_MAX;
4985
4985
        
5055
5055
            (handled_sj_equalities | bound_sj_equalities) ==     // (1)
5056
5056
            PREV_BITS(uint64_t, s->emb_sj_nest->sj_in_exprs)) // (1)
5057
5057
        {
5058
 
          uint n_fixed_parts= max_part_bit(found_part);
 
5058
          uint32_t n_fixed_parts= max_part_bit(found_part);
5059
5059
          if (n_fixed_parts != keyinfo->key_parts &&
5060
5060
              (PREV_BITS(uint, n_fixed_parts) | sj_insideout_map) ==
5061
5061
               PREV_BITS(uint, keyinfo->key_parts))
5536
5536
static bool
5537
5537
choose_plan(JOIN *join, table_map join_tables)
5538
5538
{
5539
 
  uint search_depth= join->thd->variables.optimizer_search_depth;
5540
 
  uint prune_level=  join->thd->variables.optimizer_prune_level;
 
5539
  uint32_t search_depth= join->thd->variables.optimizer_search_depth;
 
5540
  uint32_t prune_level=  join->thd->variables.optimizer_prune_level;
5541
5541
  bool straight_join= test(join->select_options & SELECT_STRAIGHT_JOIN);
5542
5542
 
5543
5543
  join->cur_embedding_map= 0;
5671
5671
 
5672
5672
  @todo
5673
5673
    this value should be determined dynamically, based on statistics:
5674
 
    uint max_tables_for_exhaustive_opt= 7;
 
5674
    uint32_t max_tables_for_exhaustive_opt= 7;
5675
5675
 
5676
5676
  @todo
5677
5677
    this value could be determined by some mapping of the form:
5686
5686
static uint
5687
5687
determine_search_depth(JOIN *join)
5688
5688
{
5689
 
  uint table_count=  join->tables - join->const_tables;
5690
 
  uint search_depth;
 
5689
  uint32_t table_count=  join->tables - join->const_tables;
 
5690
  uint32_t search_depth;
5691
5691
  /* TODO: this value should be determined dynamically, based on statistics: */
5692
 
  uint max_tables_for_exhaustive_opt= 7;
 
5692
  uint32_t max_tables_for_exhaustive_opt= 7;
5693
5693
 
5694
5694
  if (table_count <= max_tables_for_exhaustive_opt)
5695
5695
    search_depth= table_count+1; // use exhaustive for small number of tables
5731
5731
optimize_straight_join(JOIN *join, table_map join_tables)
5732
5732
{
5733
5733
  JOIN_TAB *s;
5734
 
  uint idx= join->const_tables;
 
5734
  uint32_t idx= join->const_tables;
5735
5735
  double    record_count= 1.0;
5736
5736
  double    read_time=    0.0;
5737
5737
 
5841
5841
static bool
5842
5842
greedy_search(JOIN      *join,
5843
5843
              table_map remaining_tables,
5844
 
              uint      search_depth,
5845
 
              uint      prune_level)
 
5844
              uint32_t      search_depth,
 
5845
              uint32_t      prune_level)
5846
5846
{
5847
5847
  double    record_count= 1.0;
5848
5848
  double    read_time=    0.0;
5849
 
  uint      idx= join->const_tables; // index into 'join->best_ref'
5850
 
  uint      best_idx;
5851
 
  uint      size_remain;    // cardinality of remaining_tables
 
5849
  uint32_t      idx= join->const_tables; // index into 'join->best_ref'
 
5850
  uint32_t      best_idx;
 
5851
  uint32_t      size_remain;    // cardinality of remaining_tables
5852
5852
  POSITION  best_pos;
5853
5853
  JOIN_TAB  *best_table; // the next plan node to be added to the curr QEP
5854
5854
 
6021
6021
static bool
6022
6022
best_extension_by_limited_search(JOIN      *join,
6023
6023
                                 table_map remaining_tables,
6024
 
                                 uint      idx,
 
6024
                                 uint32_t      idx,
6025
6025
                                 double    record_count,
6026
6026
                                 double    read_time,
6027
 
                                 uint      search_depth,
6028
 
                                 uint      prune_level)
 
6027
                                 uint32_t      search_depth,
 
6028
                                 uint32_t      prune_level)
6029
6029
{
6030
6030
  THD *thd= join->thd;
6031
6031
  if (thd->killed)  // Abort
6149
6149
    true        Fatal error
6150
6150
*/
6151
6151
static bool
6152
 
find_best(JOIN *join,table_map rest_tables,uint idx,double record_count,
 
6152
find_best(JOIN *join,table_map rest_tables,uint32_t idx,double record_count,
6153
6153
          double read_time)
6154
6154
{
6155
6155
  THD *thd= join->thd;
6226
6226
static void calc_used_field_length(THD *thd __attribute__((unused)),
6227
6227
                                   JOIN_TAB *join_tab)
6228
6228
{
6229
 
  uint null_fields,blobs,fields,rec_length;
 
6229
  uint32_t null_fields,blobs,fields,rec_length;
6230
6230
  Field **f_ptr,*field;
6231
6231
  MY_BITMAP *read_set= join_tab->table->read_set;;
6232
6232
 
6235
6235
  {
6236
6236
    if (bitmap_is_set(read_set, field->field_index))
6237
6237
    {
6238
 
      uint flags=field->flags;
 
6238
      uint32_t flags=field->flags;
6239
6239
      fields++;
6240
6240
      rec_length+=field->pack_length();
6241
6241
      if (flags & BLOB_FLAG)
6250
6250
    rec_length+=sizeof(bool);
6251
6251
  if (blobs)
6252
6252
  {
6253
 
    uint blob_length=(uint) (join_tab->table->file->stats.mean_rec_length-
 
6253
    uint32_t blob_length=(uint) (join_tab->table->file->stats.mean_rec_length-
6254
6254
                             (join_tab->table->getRecordLength()- rec_length));
6255
6255
    rec_length+=(uint) cmax((uint)4,blob_length);
6256
6256
  }
6261
6261
 
6262
6262
 
6263
6263
static uint
6264
 
cache_record_length(JOIN *join,uint idx)
 
6264
cache_record_length(JOIN *join,uint32_t idx)
6265
6265
{
6266
 
  uint length=0;
 
6266
  uint32_t length=0;
6267
6267
  JOIN_TAB **pos,**end;
6268
6268
  THD *thd=join->thd;
6269
6269
 
6332
6332
*/
6333
6333
 
6334
6334
static double
6335
 
prev_record_reads(JOIN *join, uint idx, table_map found_ref)
 
6335
prev_record_reads(JOIN *join, uint32_t idx, table_map found_ref)
6336
6336
{
6337
6337
  double found=1.0;
6338
6338
  POSITION *pos_end= join->positions - 1;
6372
6372
static bool
6373
6373
get_best_combination(JOIN *join)
6374
6374
{
6375
 
  uint i,tablenr;
 
6375
  uint32_t i,tablenr;
6376
6376
  table_map used_tables;
6377
6377
  JOIN_TAB *join_tab,*j;
6378
6378
  KEYUSE *keyuse;
6379
 
  uint table_count;
 
6379
  uint32_t table_count;
6380
6380
  THD *thd=join->thd;
6381
6381
 
6382
6382
  table_count=join->tables;
6426
6426
{
6427
6427
  KEYUSE *keyuse=org_keyuse;
6428
6428
  THD  *thd= join->thd;
6429
 
  uint keyparts,length,key;
 
6429
  uint32_t keyparts,length,key;
6430
6430
  Table *table;
6431
6431
  KEY *keyinfo;
6432
6432
 
6437
6437
 
6438
6438
  {
6439
6439
    keyparts=length=0;
6440
 
    uint found_part_ref_or_null= 0;
 
6440
    uint32_t found_part_ref_or_null= 0;
6441
6441
    /*
6442
6442
      Calculate length for the used key
6443
6443
      Stop if there is a missing key part or when we find second key_part
6482
6482
  unsigned char *key_buff=j->ref.key_buff, *null_ref_key= 0;
6483
6483
  bool keyuse_uses_no_tables= true;
6484
6484
  {
6485
 
    uint i;
 
6485
    uint32_t i;
6486
6486
    for (i=0 ; i < keyparts ; keyuse++,i++)
6487
6487
    {
6488
6488
      while (keyuse->keypart != i ||
6489
6489
             ((~used_tables) & keyuse->used_tables))
6490
6490
        keyuse++;                               /* Skip other parts */
6491
6491
 
6492
 
      uint maybe_null= test(keyinfo->key_part[i].null_bit);
 
6492
      uint32_t maybe_null= test(keyinfo->key_part[i].null_bit);
6493
6493
      j->ref.items[i]=keyuse->val;              // Save for cond removal
6494
6494
      j->ref.cond_guards[i]= keyuse->cond_guard;
6495
6495
      if (keyuse->null_rejecting) 
6551
6551
 
6552
6552
static store_key *
6553
6553
get_store_key(THD *thd, KEYUSE *keyuse, table_map used_tables,
6554
 
              KEY_PART_INFO *key_part, unsigned char *key_buff, uint maybe_null)
 
6554
              KEY_PART_INFO *key_part, unsigned char *key_buff, uint32_t maybe_null)
6555
6555
{
6556
6556
  if (!((~used_tables) & keyuse->used_tables))          // if const item
6557
6557
  {
6748
6748
 
6749
6749
static void add_not_null_conds(JOIN *join)
6750
6750
{
6751
 
  for (uint i=join->const_tables ; i < join->tables ; i++)
 
6751
  for (uint32_t i=join->const_tables ; i < join->tables ; i++)
6752
6752
  {
6753
6753
    JOIN_TAB *tab=join->join_tab+i;
6754
6754
    if ((tab->type == JT_REF || tab->type == JT_EQ_REF || 
6755
6755
         tab->type == JT_REF_OR_NULL) &&
6756
6756
        !tab->table->maybe_null)
6757
6757
    {
6758
 
      for (uint keypart= 0; keypart < tab->ref.key_parts; keypart++)
 
6758
      for (uint32_t keypart= 0; keypart < tab->ref.key_parts; keypart++)
6759
6759
      {
6760
6760
        if (tab->ref.null_rejecting & (1 << keypart))
6761
6761
        {
6868
6868
static void
6869
6869
make_outerjoin_info(JOIN *join)
6870
6870
{
6871
 
  for (uint i=join->const_tables ; i < join->tables ; i++)
 
6871
  for (uint32_t i=join->const_tables ; i < join->tables ; i++)
6872
6872
  {
6873
6873
    JOIN_TAB *tab=join->join_tab+i;
6874
6874
    Table *table=tab->table;
6970
6970
    }
6971
6971
    used_tables=((select->const_tables=join->const_table_map) |
6972
6972
                 OUTER_REF_TABLE_BIT | RAND_TABLE_BIT);
6973
 
    for (uint i=join->const_tables ; i < join->tables ; i++)
 
6973
    for (uint32_t i=join->const_tables ; i < join->tables ; i++)
6974
6974
    {
6975
6975
      JOIN_TAB *tab=join->join_tab+i;
6976
6976
      /*
7094
7094
          }
7095
7095
          tab->quick=0;
7096
7096
        }
7097
 
        uint ref_key=(uint) sel->head->reginfo.join_tab->ref.key+1;
 
7097
        uint32_t ref_key=(uint) sel->head->reginfo.join_tab->ref.key+1;
7098
7098
        if (i == join->const_tables && ref_key)
7099
7099
        {
7100
7100
          if (!tab->const_keys.is_clear_all() &&
7304
7304
    false  No
7305
7305
*/
7306
7306
 
7307
 
bool uses_index_fields_only(Item *item, Table *tbl, uint keyno, 
 
7307
bool uses_index_fields_only(Item *item, Table *tbl, uint32_t keyno, 
7308
7308
                            bool other_tbls_ok)
7309
7309
{
7310
7310
  if (item->const_item())
7399
7399
    Index condition, or NULL if no condition could be inferred.
7400
7400
*/
7401
7401
 
7402
 
Item *make_cond_for_index(Item *cond, Table *table, uint keyno,
 
7402
Item *make_cond_for_index(Item *cond, Table *table, uint32_t keyno,
7403
7403
                          bool other_tbls_ok)
7404
7404
{
7405
7405
  if (!cond)
7406
7406
    return NULL;
7407
7407
  if (cond->type() == Item::COND_ITEM)
7408
7408
  {
7409
 
    uint n_marked= 0;
 
7409
    uint32_t n_marked= 0;
7410
7410
    if (((Item_cond*) cond)->functype() == Item_func::COND_AND_FUNC)
7411
7411
    {
7412
7412
      Item_cond_and *new_cond=new Item_cond_and;
7538
7538
    Try to extract and push the index condition down to table handler
7539
7539
*/
7540
7540
 
7541
 
static void push_index_cond(JOIN_TAB *tab, uint keyno, bool other_tbls_ok)
 
7541
static void push_index_cond(JOIN_TAB *tab, uint32_t keyno, bool other_tbls_ok)
7542
7542
{
7543
7543
  Item *idx_cond;
7544
7544
  if (tab->table->file->index_flags(keyno, 0, 1) & HA_DO_INDEX_COND_PUSHDOWN &&
7600
7600
      ordered. If there is a temp table the ordering is done as a last
7601
7601
      operation and doesn't prevent join cache usage.
7602
7602
    */
7603
 
uint make_join_orderinfo(JOIN *join)
 
7603
uint32_t make_join_orderinfo(JOIN *join)
7604
7604
{
7605
 
  uint i;
 
7605
  uint32_t i;
7606
7606
  if (join->need_tmp)
7607
7607
    return join->tables;
7608
7608
 
7644
7644
*/
7645
7645
 
7646
7646
static bool
7647
 
make_join_readinfo(JOIN *join, uint64_t options, uint no_jbuf_after)
 
7647
make_join_readinfo(JOIN *join, uint64_t options, uint32_t no_jbuf_after)
7648
7648
{
7649
 
  uint i;
 
7649
  uint32_t i;
7650
7650
  bool statistics= test(!(join->select_options & SELECT_DESCRIBE));
7651
7651
  bool sorted= 1;
7652
7652
 
8113
8113
    return (tab->eq_ref_table=0);               // We must use this
8114
8114
  Item **ref_item=tab->ref.items;
8115
8115
  Item **end=ref_item+tab->ref.key_parts;
8116
 
  uint found=0;
 
8116
  uint32_t found=0;
8117
8117
  table_map map=tab->table->map;
8118
8118
 
8119
8119
  for (; ref_item != end ; ref_item++)
8175
8175
    TABLE_REF *ref= &join_tab->ref;
8176
8176
    table_map depend_map=0;
8177
8177
    Item **item=ref->items;
8178
 
    uint i;
 
8178
    uint32_t i;
8179
8179
    for (i=0 ; i < ref->key_parts ; i++,item++)
8180
8180
      depend_map|=(*item)->used_tables();
8181
8181
    ref->depend_map=depend_map & ~OUTER_REF_TABLE_BIT;
8345
8345
    must clear only the non-const tables, as const tables
8346
8346
    are not re-calculated.
8347
8347
  */
8348
 
  for (uint i=join->const_tables ; i < join->tables ; i++)
 
8348
  for (uint32_t i=join->const_tables ; i < join->tables ; i++)
8349
8349
    mark_as_null_row(join->table[i]);           // All fields are NULL
8350
8350
}
8351
8351
 
8709
8709
static bool check_row_equality(THD *thd, Item *left_row, Item_row *right_row,
8710
8710
                               COND_EQUAL *cond_equal, List<Item>* eq_list)
8711
8711
8712
 
  uint n= left_row->cols();
8713
 
  for (uint i= 0 ; i < n; i++)
 
8712
  uint32_t n= left_row->cols();
 
8713
  for (uint32_t i= 0 ; i < n; i++)
8714
8714
  {
8715
8715
    bool is_converted;
8716
8716
    Item *left_item= left_row->element_index(i);
9937
9937
    First unused bit in nested_join_map after the call.
9938
9938
*/
9939
9939
 
9940
 
static uint build_bitmap_for_nested_joins(List<TableList> *join_list, 
9941
 
                                          uint first_unused)
 
9940
static uint32_t build_bitmap_for_nested_joins(List<TableList> *join_list, 
 
9941
                                          uint32_t first_unused)
9942
9942
{
9943
9943
  List_iterator<TableList> li(*join_list);
9944
9944
  TableList *table;
10947
10947
  }
10948
10948
 
10949
10949
  // 3. Put the rowids
10950
 
  for (uint i=0; tab != tab_end; tab++, i++)
 
10950
  for (uint32_t i=0; tab != tab_end; tab++, i++)
10951
10951
  {
10952
10952
    handler *h= tab->join_tab->table->file;
10953
10953
    if (tab->join_tab->table->maybe_null && tab->join_tab->table->null_row)
11248
11248
    if (rc == NESTED_LOOP_OK &&
11249
11249
        (!join_tab->cache.select || !join_tab->cache.select->skip_record()))
11250
11250
    {
11251
 
      uint i;
 
11251
      uint32_t i;
11252
11252
      reset_cache_read(&join_tab->cache);
11253
11253
      for (i=(join_tab->cache.records- (skip_last ? 1 : 0)) ; i-- > 0 ;)
11254
11254
      {
11530
11530
    table->file->ha_index_init(tab->ref.key, tab->sorted);
11531
11531
 
11532
11532
  /* Perform "Late NULLs Filtering" (see internals manual for explanations) */
11533
 
  for (uint i= 0 ; i < tab->ref.key_parts ; i++)
 
11533
  for (uint32_t i= 0 ; i < tab->ref.key_parts ; i++)
11534
11534
  {
11535
11535
    if ((tab->ref.null_rejecting & 1 << i) && tab->ref.items[i]->is_null())
11536
11536
        return -1;
12532
12532
  if (!table->reginfo.join_tab)
12533
12533
    return (Item*) 0;             // field from outer non-select (UPDATE,...)
12534
12534
 
12535
 
  uint ref_parts=table->reginfo.join_tab->ref.key_parts;
 
12535
  uint32_t ref_parts=table->reginfo.join_tab->ref.key_parts;
12536
12536
  if (ref_parts)
12537
12537
  {
12538
12538
    KEY_PART_INFO *key_part=
12539
12539
      table->key_info[table->reginfo.join_tab->ref.key].key_part;
12540
 
    uint part;
 
12540
    uint32_t part;
12541
12541
 
12542
12542
    for (part=0 ; part < ref_parts ; part++)
12543
12543
    {
12685
12685
*/
12686
12686
 
12687
12687
static uint
12688
 
test_if_subkey(order_st *order, Table *table, uint ref, uint ref_key_parts,
 
12688
test_if_subkey(order_st *order, Table *table, uint32_t ref, uint32_t ref_key_parts,
12689
12689
               const key_map *usable_keys)
12690
12690
{
12691
12691
  uint32_t nr;
12748
12748
list_contains_unique_index(Table *table,
12749
12749
                          bool (*find_func) (Field *, void *), void *data)
12750
12750
{
12751
 
  for (uint keynr= 0; keynr < table->s->keys; keynr++)
 
12751
  for (uint32_t keynr= 0; keynr < table->s->keys; keynr++)
12752
12752
  {
12753
12753
    if (keynr == table->s->primary_key ||
12754
12754
         (table->key_info[keynr].flags & HA_NOSAME))
12872
12872
                        bool no_changes, const key_map *map)
12873
12873
{
12874
12874
  int32_t ref_key;
12875
 
  uint ref_key_parts;
 
12875
  uint32_t ref_key_parts;
12876
12876
  int order_direction;
12877
12877
  uint32_t used_key_parts;
12878
12878
  Table *table=tab->table;
12936
12936
      /*
12937
12937
        We come here when ref_key is not among usable_keys
12938
12938
      */
12939
 
      uint new_ref_key;
 
12939
      uint32_t new_ref_key;
12940
12940
      /*
12941
12941
        If using index only read, only consider other possible index only
12942
12942
        keys
13006
13006
      or a table scan.
13007
13007
      It may be the case if order_st/GROUP BY is used with LIMIT.
13008
13008
    */
13009
 
    uint nr;
 
13009
    uint32_t nr;
13010
13010
    key_map keys;
13011
 
    uint best_key_parts= 0;
 
13011
    uint32_t best_key_parts= 0;
13012
13012
    int best_key_direction= 0;
13013
13013
    ha_rows best_records= 0;
13014
13014
    double read_time;
13016
13016
    bool is_best_covering= false;
13017
13017
    double fanout= 1;
13018
13018
    JOIN *join= tab->join;
13019
 
    uint tablenr= tab - join->join_tab;
 
13019
    uint32_t tablenr= tab - join->join_tab;
13020
13020
    ha_rows table_records= table->file->stats.records;
13021
13021
    bool group= join->group && order == join->group_list;
13022
13022
 
13050
13050
      keys= usable_keys;
13051
13051
 
13052
13052
    read_time= join->best_positions[tablenr].read_time;
13053
 
    for (uint i= tablenr+1; i < join->tables; i++)
 
13053
    for (uint32_t i= tablenr+1; i < join->tables; i++)
13054
13054
      fanout*= join->best_positions[i].records_read; // fanout is always >= 1
13055
13055
 
13056
13056
    for (nr=0; nr < table->s->keys ; nr++)
13316
13316
                  ha_rows filesort_limit, ha_rows select_limit,
13317
13317
                  bool is_order_by)
13318
13318
{
13319
 
  uint length= 0;
 
13319
  uint32_t length= 0;
13320
13320
  ha_rows examined_rows;
13321
13321
  Table *table;
13322
13322
  SQL_SELECT *select;
13440
13440
{
13441
13441
  int error;
13442
13442
  ulong reclength,offset;
13443
 
  uint field_count;
 
13443
  uint32_t field_count;
13444
13444
  THD *thd= join->thd;
13445
13445
 
13446
13446
  entry->reginfo.lock_type=TL_WRITE;
13576
13576
*/
13577
13577
 
13578
13578
static int remove_dup_with_hash_index(THD *thd, Table *table,
13579
 
                                      uint field_count,
 
13579
                                      uint32_t field_count,
13580
13580
                                      Field **first_field,
13581
13581
                                      ulong key_length,
13582
13582
                                      Item *having)
13585
13585
  int error;
13586
13586
  handler *file= table->file;
13587
13587
  ulong extra_length= ALIGN_SIZE(key_length)-key_length;
13588
 
  uint *field_lengths,*field_length;
 
13588
  uint32_t *field_lengths,*field_length;
13589
13589
  HASH hash;
13590
13590
 
13591
13591
  if (!my_multi_malloc(MYF(MY_WME),
13602
13602
    ulong total_length= 0;
13603
13603
    for (ptr= first_field, field_length=field_lengths ; *ptr ; ptr++)
13604
13604
    {
13605
 
      uint length= (*ptr)->sort_length();
 
13605
      uint32_t length= (*ptr)->sort_length();
13606
13606
      (*field_length++)= length;
13607
13607
      total_length+= length;
13608
13608
    }
13680
13680
}
13681
13681
 
13682
13682
 
13683
 
SORT_FIELD *make_unireg_sortorder(order_st *order, uint *length,
 
13683
SORT_FIELD *make_unireg_sortorder(order_st *order, uint32_t *length,
13684
13684
                                  SORT_FIELD *sortorder)
13685
13685
{
13686
 
  uint count;
 
13686
  uint32_t count;
13687
13687
  SORT_FIELD *sort,*pos;
13688
13688
 
13689
13689
  count=0;
13726
13726
******************************************************************************/
13727
13727
 
13728
13728
static int
13729
 
join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count)
 
13729
join_init_cache(THD *thd,JOIN_TAB *tables,uint32_t table_count)
13730
13730
{
13731
13731
  register unsigned int i;
13732
13732
  unsigned int length, blobs;
13769
13769
  length=0;
13770
13770
  for (i=0 ; i < table_count ; i++)
13771
13771
  {
13772
 
    uint null_fields=0, used_fields;
 
13772
    uint32_t null_fields=0, used_fields;
13773
13773
    Field **f_ptr,*field;
13774
13774
    MY_BITMAP *read_set= tables[i].table->read_set;
13775
13775
    for (f_ptr=tables[i].table->field,used_fields=tables[i].used_fields ;
13847
13847
static ulong
13848
13848
used_blob_length(CACHE_FIELD **ptr)
13849
13849
{
13850
 
  uint length,blob_length;
 
13850
  uint32_t length,blob_length;
13851
13851
  for (length=0 ; *ptr ; ptr++)
13852
13852
  {
13853
13853
    (*ptr)->blob_length=blob_length=(*ptr)->blob_field->get_length();
13861
13861
static bool
13862
13862
store_record_in_cache(JOIN_CACHE *cache)
13863
13863
{
13864
 
  uint length;
 
13864
  uint32_t length;
13865
13865
  unsigned char *pos;
13866
13866
  CACHE_FIELD *copy,*end_field;
13867
13867
  bool last_record;
13945
13945
read_cached_record(JOIN_TAB *tab)
13946
13946
{
13947
13947
  unsigned char *pos;
13948
 
  uint length;
 
13948
  uint32_t length;
13949
13949
  bool last_record;
13950
13950
  CACHE_FIELD *copy,*end_field;
13951
13951
 
14097
14097
  Item::Type order_item_type;
14098
14098
  Item **select_item; /* The corresponding item from the SELECT clause. */
14099
14099
  Field *from_field;  /* The corresponding field from the FROM clause. */
14100
 
  uint counter;
 
14100
  uint32_t counter;
14101
14101
  enum_resolution_type resolution;
14102
14102
 
14103
14103
  /*
14106
14106
  */
14107
14107
  if (order_item->type() == Item::INT_ITEM && order_item->basic_const_item())
14108
14108
  {                                             /* Order by position */
14109
 
    uint count= (uint) order_item->val_int();
 
14109
    uint32_t count= (uint) order_item->val_int();
14110
14110
    if (!count || count > fields.elements)
14111
14111
    {
14112
14112
      my_error(ER_BAD_FIELD_ERROR, MYF(0),
14210
14210
       thd->is_fatal_error))
14211
14211
    return true; /* Wrong field. */
14212
14212
 
14213
 
  uint el= all_fields.elements;
 
14213
  uint32_t el= all_fields.elements;
14214
14214
  all_fields.push_front(order_item); /* Add new field to field list. */
14215
14215
  ref_pointer_array[el]= order_item;
14216
14216
  order->item= ref_pointer_array + el;
14276
14276
  if (!order)
14277
14277
    return 0;                           /* Everything is ok */
14278
14278
 
14279
 
  uint org_fields=all_fields.elements;
 
14279
  uint32_t org_fields=all_fields.elements;
14280
14280
 
14281
14281
  thd->where="group statement";
14282
14282
  for (ord= order; ord; ord= ord->next)
14459
14459
            param->quick_group=0;                       // UDF SUM function
14460
14460
          param->sum_func_count++;
14461
14461
 
14462
 
          for (uint i=0 ; i < sum_item->arg_count ; i++)
 
14462
          for (uint32_t i=0 ; i < sum_item->arg_count ; i++)
14463
14463
          {
14464
14464
            if (sum_item->args[0]->real_item()->type() == Item::FIELD_ITEM)
14465
14465
              param->field_count++;
14538
14538
static void
14539
14539
calc_group_buffer(JOIN *join,order_st *group)
14540
14540
{
14541
 
  uint key_length=0, parts=0, null_parts=0;
 
14541
  uint32_t key_length=0, parts=0, null_parts=0;
14542
14542
 
14543
14543
  if (group)
14544
14544
    join->group= 1;
14727
14727
setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
14728
14728
                  Item **ref_pointer_array,
14729
14729
                  List<Item> &res_selected_fields, List<Item> &res_all_fields,
14730
 
                  uint elements, List<Item> &all_fields)
 
14730
                  uint32_t elements, List<Item> &all_fields)
14731
14731
{
14732
14732
  Item *pos;
14733
14733
  List_iterator_fast<Item> li(all_fields);
14736
14736
  res_all_fields.empty();
14737
14737
  List_iterator_fast<Item> itr(res_all_fields);
14738
14738
  List<Item> extra_funcs;
14739
 
  uint i, border= all_fields.elements - elements;
 
14739
  uint32_t i, border= all_fields.elements - elements;
14740
14740
 
14741
14741
  if (param->field_count && 
14742
14742
      !(copy=param->copy_field= new Copy_field[param->field_count]))
14888
14888
 
14889
14889
bool JOIN::alloc_func_list()
14890
14890
{
14891
 
  uint func_count, group_parts;
 
14891
  uint32_t func_count, group_parts;
14892
14892
 
14893
14893
  func_count= tmp_table_param.sum_func_count;
14894
14894
  /*
14966
14966
  }
14967
14967
  else if (rollup.state == ROLLUP::STATE_NONE)
14968
14968
  {
14969
 
    for (uint i=0 ; i <= send_group_parts ;i++)
 
14969
    for (uint32_t i=0 ; i <= send_group_parts ;i++)
14970
14970
      sum_funcs_end[i]= func;
14971
14971
  }
14972
14972
  else if (rollup.state == ROLLUP::STATE_READY)
14997
14997
change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array,
14998
14998
                         List<Item> &res_selected_fields,
14999
14999
                         List<Item> &res_all_fields,
15000
 
                         uint elements, List<Item> &all_fields)
 
15000
                         uint32_t elements, List<Item> &all_fields)
15001
15001
{
15002
15002
  List_iterator_fast<Item> it(all_fields);
15003
15003
  Item *item_field,*item;
15005
15005
  res_selected_fields.empty();
15006
15006
  res_all_fields.empty();
15007
15007
 
15008
 
  uint i, border= all_fields.elements - elements;
 
15008
  uint32_t i, border= all_fields.elements - elements;
15009
15009
  for (i= 0; (item= it++); i++)
15010
15010
  {
15011
15011
    Field *field;
15076
15076
static bool
15077
15077
change_refs_to_tmp_fields(THD *thd, Item **ref_pointer_array,
15078
15078
                          List<Item> &res_selected_fields,
15079
 
                          List<Item> &res_all_fields, uint elements,
 
15079
                          List<Item> &res_all_fields, uint32_t elements,
15080
15080
                          List<Item> &all_fields)
15081
15081
{
15082
15082
  List_iterator_fast<Item> it(all_fields);
15084
15084
  res_selected_fields.empty();
15085
15085
  res_all_fields.empty();
15086
15086
 
15087
 
  uint i, border= all_fields.elements - elements;
 
15087
  uint32_t i, border= all_fields.elements - elements;
15088
15088
  for (i= 0; (item= it++); i++)
15089
15089
  {
15090
15090
    res_all_fields.push_back(new_item= item->get_tmp_table_item(thd));
15218
15218
  if (!cond)
15219
15219
    return(true);
15220
15220
 
15221
 
  for (uint i=0 ; i < join_tab->ref.key_parts ; i++)
 
15221
  for (uint32_t i=0 ; i < join_tab->ref.key_parts ; i++)
15222
15222
  {
15223
15223
    Field *field=table->field[table->key_info[join_tab->ref.key].key_part[i].
15224
15224
                              fieldnr-1];
15352
15352
 
15353
15353
bool JOIN::rollup_init()
15354
15354
{
15355
 
  uint i,j;
 
15355
  uint32_t i,j;
15356
15356
  Item **ref_array;
15357
15357
 
15358
15358
  tmp_table_param.quick_group= 0;       // Can't create groups in tmp table
15472
15472
{
15473
15473
  List_iterator_fast<Item> it(fields_arg);
15474
15474
  Item *first_field= sel_fields.head();
15475
 
  uint level;
 
15475
  uint32_t level;
15476
15476
 
15477
15477
  /*
15478
15478
    Create field lists for the different levels
15497
15497
 
15498
15498
  for (level=0 ; level < send_group_parts ; level++)
15499
15499
  {
15500
 
    uint i;
15501
 
    uint pos= send_group_parts - level -1;
 
15500
    uint32_t i;
 
15501
    uint32_t pos= send_group_parts - level -1;
15502
15502
    bool real_fields= 0;
15503
15503
    Item *item;
15504
15504
    List_iterator<Item> new_it(rollup.fields[pos]);
15601
15601
    1   If send_data_failed()
15602
15602
*/
15603
15603
 
15604
 
int JOIN::rollup_send_data(uint idx)
 
15604
int JOIN::rollup_send_data(uint32_t idx)
15605
15605
{
15606
 
  uint i;
 
15606
  uint32_t i;
15607
15607
  for (i= send_group_parts ; i-- > idx ; )
15608
15608
  {
15609
15609
    /* Get reference pointers to sum functions in place */
15642
15642
    1   if write_data_failed()
15643
15643
*/
15644
15644
 
15645
 
int JOIN::rollup_write_data(uint idx, Table *table_arg)
 
15645
int JOIN::rollup_write_data(uint32_t idx, Table *table_arg)
15646
15646
{
15647
 
  uint i;
 
15647
  uint32_t i;
15648
15648
  for (i= send_group_parts ; i-- > idx ; )
15649
15649
  {
15650
15650
    /* Get reference pointers to sum functions in place */
15724
15724
                                     join->select_lex->select_number));
15725
15725
    item_list.push_back(new Item_string(join->select_lex->type,
15726
15726
                                        strlen(join->select_lex->type), cs));
15727
 
    for (uint i=0 ; i < 7; i++)
 
15727
    for (uint32_t i=0 ; i < 7; i++)
15728
15728
      item_list.push_back(item_null);
15729
15729
    if (join->thd->lex->describe & DESCRIBE_EXTENDED)
15730
15730
      item_list.push_back(item_null);
15753
15753
    /* table */
15754
15754
    {
15755
15755
      SELECT_LEX *sl= join->unit->first_select();
15756
 
      uint len= 6, lastop= 0;
 
15756
      uint32_t len= 6, lastop= 0;
15757
15757
      memcpy(table_name_buffer, STRING_WITH_LEN("<union"));
15758
15758
      for (; sl && len + lastop + 5 < NAME_LEN; sl= sl->next_select())
15759
15759
      {
15803
15803
  else
15804
15804
  {
15805
15805
    table_map used_tables=0;
15806
 
    for (uint i=0 ; i < join->tables ; i++)
 
15806
    for (uint32_t i=0 ; i < join->tables ; i++)
15807
15807
    {
15808
15808
      JOIN_TAB *tab=join->join_tab+i;
15809
15809
      Table *table=tab->table;
15863
15863
      /* Build "possible_keys" value and add it to item_list */
15864
15864
      if (!tab->keys.is_clear_all())
15865
15865
      {
15866
 
        uint j;
 
15866
        uint32_t j;
15867
15867
        for (j=0 ; j < table->s->keys ; j++)
15868
15868
        {
15869
15869
          if (tab->keys.is_set(j))
15885
15885
      if (tab->ref.key_parts)
15886
15886
      {
15887
15887
        KEY *key_info=table->key_info+ tab->ref.key;
15888
 
        register uint length;
 
15888
        register uint32_t length;
15889
15889
        item_list.push_back(new Item_string(key_info->name,
15890
15890
                                            strlen(key_info->name),
15891
15891
                                            system_charset_info));
15905
15905
      else if (tab->type == JT_NEXT)
15906
15906
      {
15907
15907
        KEY *key_info=table->key_info+ tab->index;
15908
 
        register uint length;
 
15908
        register uint32_t length;
15909
15909
        item_list.push_back(new Item_string(key_info->name,
15910
15910
                                            strlen(key_info->name),cs));
15911
15911
        length= int64_t2str(key_info->key_length, keylen_str_buf, 10) - 
16018
16018
      }
16019
16019
      else
16020
16020
      {
16021
 
        uint keyno= MAX_KEY;
 
16021
        uint32_t keyno= MAX_KEY;
16022
16022
        if (tab->ref.key_parts)
16023
16023
          keyno= tab->ref.key;
16024
16024
        else if (tab->select && tab->select->quick)
16139
16139
          extra.append(STRING_WITH_LEN(")"));
16140
16140
        }
16141
16141
 
16142
 
        for (uint part= 0; part < tab->ref.key_parts; part++)
 
16142
        for (uint32_t part= 0; part < tab->ref.key_parts; part++)
16143
16143
        {
16144
16144
          if (tab->ref.cond_guards[part])
16145
16145
          {