~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/opt_range.cc

Merged build changes from Antony.

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
#endif
109
109
 
110
110
#include "mysql_priv.h"
111
 
#include <m_ctype.h>
112
111
#include "sql_select.h"
113
112
 
114
113
#ifndef EXTRA_DEBUG
122
121
*/
123
122
#define double2rows(x) ((ha_rows)(x))
124
123
 
125
 
static int sel_cmp(Field *f,uchar *a,uchar *b,uint8 a_flag,uint8 b_flag);
 
124
static int sel_cmp(Field *f,uchar *a,uchar *b,uint8_t a_flag,uint8_t b_flag);
126
125
 
127
126
static uchar is_null_string[2]= {1,0};
128
127
 
300
299
class SEL_ARG :public Sql_alloc
301
300
{
302
301
public:
303
 
  uint8 min_flag,max_flag,maybe_flag;
304
 
  uint8 part;                                   // Which key part
305
 
  uint8 maybe_null;
 
302
  uint8_t min_flag,max_flag,maybe_flag;
 
303
  uint8_t part;                                 // Which key part
 
304
  uint8_t maybe_null;
306
305
  /* 
307
306
    Number of children of this element in the RB-tree, plus 1 for this
308
307
    element itself.
309
308
  */
310
 
  uint16 elements;
 
309
  uint16_t elements;
311
310
  /*
312
311
    Valid only for elements which are RB-tree roots: Number of times this
313
312
    RB-tree is referred to (it is referred by SEL_ARG::next_key_part or by
333
332
  SEL_ARG() {}
334
333
  SEL_ARG(SEL_ARG &);
335
334
  SEL_ARG(Field *,const uchar *, const uchar *);
336
 
  SEL_ARG(Field *field, uint8 part, uchar *min_value, uchar *max_value,
337
 
          uint8 min_flag, uint8 max_flag, uint8 maybe_flag);
 
335
  SEL_ARG(Field *field, uint8_t part, uchar *min_value, uchar *max_value,
 
336
          uint8_t min_flag, uint8_t max_flag, uint8_t maybe_flag);
338
337
  SEL_ARG(enum Type type_arg)
339
338
    :min_flag(0),elements(1),use_count(1),left(0),right(0),next_key_part(0),
340
339
    color(BLACK), type(type_arg)
370
369
  SEL_ARG *clone_and(SEL_ARG* arg)
371
370
  {                                             // Get overlapping range
372
371
    uchar *new_min,*new_max;
373
 
    uint8 flag_min,flag_max;
 
372
    uint8_t flag_min,flag_max;
374
373
    if (cmp_min_to_min(arg) >= 0)
375
374
    {
376
375
      new_min=min_value; flag_min=min_flag;
452
451
      if (maybe_null && *min_value)
453
452
      {
454
453
        **min_key=1;
455
 
        bzero(*min_key+1,length-1);
 
454
        memset(*min_key+1, 0, length-1);
456
455
      }
457
456
      else
458
457
        memcpy(*min_key,min_value,length);
470
469
      if (maybe_null && *max_value)
471
470
      {
472
471
        **max_key=1;
473
 
        bzero(*max_key+1,length-1);
 
472
        memset(*max_key+1, 0, length-1);
474
473
      }
475
474
      else
476
475
        memcpy(*max_key,max_value,length);
615
614
  SEL_TREE() :type(KEY)
616
615
  {
617
616
    keys_map.clear_all();
618
 
    bzero((char*) keys,sizeof(keys));
 
617
    memset((char*) keys, 0, sizeof(keys));
619
618
  }
620
619
  /*
621
620
    Note: there may exist SEL_TREE objects with sel_tree->type=KEY and
725
724
                            Item_func::Functype type,Item *value);
726
725
static SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param,COND *cond);
727
726
 
728
 
static bool is_key_scan_ror(PARAM *param, uint keynr, uint8 nparts);
 
727
static bool is_key_scan_ror(PARAM *param, uint keynr, uint8_t nparts);
729
728
static ha_rows check_quick_select(PARAM *param, uint idx, bool index_only,
730
729
                                  SEL_ARG *tree, bool update_tbl_stats, 
731
730
                                  uint *mrr_flags, uint *bufsize,
1093
1092
    thd->mem_root= &alloc;
1094
1093
  }
1095
1094
  else
1096
 
    bzero((char*) &alloc,sizeof(alloc));
 
1095
    memset((char*) &alloc, 0, sizeof(alloc));
1097
1096
  file= head->file;
1098
1097
  record= head->record[0];
1099
1098
  save_read_set= head->read_set;
1163
1162
{
1164
1163
  index= MAX_KEY;
1165
1164
  head= table;
1166
 
  bzero(&read_record, sizeof(read_record));
 
1165
  memset(&read_record, 0, sizeof(read_record));
1167
1166
  init_sql_alloc(&alloc, thd->variables.range_alloc_block_size, 0);
1168
1167
  return;
1169
1168
}
1220
1219
  if (!parent_alloc)
1221
1220
    init_sql_alloc(&alloc, thd->variables.range_alloc_block_size, 0);
1222
1221
  else
1223
 
    bzero(&alloc, sizeof(MEM_ROOT));
 
1222
    memset(&alloc, 0, sizeof(MEM_ROOT));
1224
1223
  last_rowid= (uchar*) alloc_root(parent_alloc? parent_alloc : &alloc,
1225
1224
                                  head->file->ref_length);
1226
1225
}
1475
1474
                 false , QUICK_ROR_UNION_SELECT::queue_cmp,
1476
1475
                 (void*) this))
1477
1476
  {
1478
 
    bzero(&queue, sizeof(QUEUE));
 
1477
    memset(&queue, 0, sizeof(QUEUE));
1479
1478
    return(1);
1480
1479
  }
1481
1480
 
1616
1615
  left=right= &null_element;
1617
1616
}
1618
1617
 
1619
 
SEL_ARG::SEL_ARG(Field *field_,uint8 part_,
 
1618
SEL_ARG::SEL_ARG(Field *field_,uint8_t part_,
1620
1619
                 uchar *min_value_, uchar *max_value_,
1621
 
                 uint8 min_flag_,uint8 max_flag_,uint8 maybe_flag_)
 
1620
                 uint8_t min_flag_,uint8_t max_flag_,uint8_t maybe_flag_)
1622
1621
  :min_flag(min_flag_),max_flag(max_flag_),maybe_flag(maybe_flag_),
1623
1622
   part(part_),maybe_null(field_->real_maybe_null()), elements(1),use_count(1),
1624
1623
   field(field_), min_value(min_value_), max_value(max_value_),
1695
1694
  Returns -2 or 2 if the ranges where 'joined' like  < 2 and >= 2
1696
1695
*/
1697
1696
 
1698
 
static int sel_cmp(Field *field, uchar *a, uchar *b, uint8 a_flag,
1699
 
                   uint8 b_flag)
 
1697
static int sel_cmp(Field *field, uchar *a, uchar *b, uint8_t a_flag,
 
1698
                   uint8_t b_flag)
1700
1699
{
1701
1700
  int cmp;
1702
1701
  /* First check if there was a compare to a min or max element */
1886
1885
  /* Table read plans are allocated on MEM_ROOT and are never deleted */
1887
1886
  static void *operator new(size_t size, MEM_ROOT *mem_root)
1888
1887
  { return (void*) alloc_root(mem_root, (uint) size); }
1889
 
  static void operator delete(void *ptr __attribute__((__unused__)),
1890
 
                              size_t size __attribute__((__unused__)))
 
1888
  static void operator delete(void *ptr __attribute__((unused)),
 
1889
                              size_t size __attribute__((unused)))
1891
1890
    { TRASH(ptr, size); }
1892
 
  static void operator delete(void *ptr __attribute__((__unused__)),
1893
 
                              MEM_ROOT *mem_root __attribute__((__unused__)))
 
1891
  static void operator delete(void *ptr __attribute__((unused)),
 
1892
                              MEM_ROOT *mem_root __attribute__((unused)))
1894
1893
    { /* Never called */ }
1895
1894
  virtual ~TABLE_READ_PLAN() {}               /* Remove gcc warning */
1896
1895
 
1922
1921
  virtual ~TRP_RANGE() {}                     /* Remove gcc warning */
1923
1922
 
1924
1923
  QUICK_SELECT_I *make_quick(PARAM *param,
1925
 
                             bool retrieve_full_rows __attribute__((__unused__)),
 
1924
                             bool retrieve_full_rows __attribute__((unused)),
1926
1925
                             MEM_ROOT *parent_alloc)
1927
1926
  {
1928
1927
    QUICK_RANGE_SELECT *quick;
2241
2240
        key_parts->null_bit=     key_part_info->null_bit;
2242
2241
        key_parts->image_type =  Field::itRAW;
2243
2242
        /* Only HA_PART_KEY_SEG is used */
2244
 
        key_parts->flag=         (uint8) key_part_info->key_part_flag;
 
2243
        key_parts->flag=         (uint8_t) key_part_info->key_part_flag;
2245
2244
      }
2246
2245
      param.real_keynr[param.keys++]=idx;
2247
2246
    }
3601
3600
 
3602
3601
 
3603
3602
QUICK_SELECT_I *TRP_INDEX_MERGE::make_quick(PARAM *param,
3604
 
                                            bool retrieve_full_rows __attribute__((__unused__)),
3605
 
                                            MEM_ROOT *parent_alloc __attribute__((__unused__)))
 
3603
                                            bool retrieve_full_rows __attribute__((unused)),
 
3604
                                            MEM_ROOT *parent_alloc __attribute__((unused)))
3606
3605
{
3607
3606
  QUICK_INDEX_MERGE_SELECT *quick_imerge;
3608
3607
  QUICK_RANGE_SELECT *quick;
3678
3677
 
3679
3678
 
3680
3679
QUICK_SELECT_I *TRP_ROR_UNION::make_quick(PARAM *param,
3681
 
                                          bool retrieve_full_rows __attribute__((__unused__)),
3682
 
                                          MEM_ROOT *parent_alloc __attribute__((__unused__)))
 
3680
                                          bool retrieve_full_rows __attribute__((unused)),
 
3681
                                          MEM_ROOT *parent_alloc __attribute__((unused)))
3683
3682
{
3684
3683
  QUICK_ROR_UNION_SELECT *quick_roru;
3685
3684
  TABLE_READ_PLAN **scan;
4264
4263
get_mm_parts(RANGE_OPT_PARAM *param, COND *cond_func, Field *field,
4265
4264
             Item_func::Functype type,
4266
4265
             Item *value,
4267
 
             Item_result cmp_type __attribute__((__unused__)))
 
4266
             Item_result cmp_type __attribute__((unused)))
4268
4267
{
4269
4268
  if (field->table != param->table)
4270
4269
    return(0);
4472
4471
  /* For comparison purposes allow invalid dates like 2000-01-32 */
4473
4472
  orig_sql_mode= field->table->in_use->variables.sql_mode;
4474
4473
  if (value->real_item()->type() == Item::STRING_ITEM &&
4475
 
      (field->type() == MYSQL_TYPE_NEWDATE ||
4476
 
       field->type() == MYSQL_TYPE_DATETIME))
 
4474
      (field->type() == DRIZZLE_TYPE_NEWDATE ||
 
4475
       field->type() == DRIZZLE_TYPE_DATETIME))
4477
4476
    field->table->in_use->variables.sql_mode|= MODE_INVALID_DATES;
4478
4477
  err= value->save_in_field_no_warnings(field, 1);
4479
4478
  if (err > 0)
4495
4494
          for the cases like int_field > 999999999999999999999999 as well.
4496
4495
        */
4497
4496
        tree= 0;
4498
 
        if (err == 3 && field->type() == FIELD_TYPE_NEWDATE &&
 
4497
        if (err == 3 && field->type() == DRIZZLE_TYPE_NEWDATE &&
4499
4498
            (type == Item_func::GT_FUNC || type == Item_func::GE_FUNC ||
4500
4499
             type == Item_func::LT_FUNC || type == Item_func::LE_FUNC) )
4501
4500
        {
5925
5924
*/
5926
5925
 
5927
5926
range_seq_t sel_arg_range_seq_init(void *init_param,
5928
 
                                   uint n_ranges __attribute__((__unused__)),
5929
 
                                   uint flags __attribute__((__unused__)))
 
5927
                                   uint n_ranges __attribute__((unused)),
 
5928
                                   uint flags __attribute__((unused)))
5930
5929
{
5931
5930
  SEL_ARG_RANGE_SEQ *seq= (SEL_ARG_RANGE_SEQ*)init_param;
5932
5931
  seq->at_start= true;
5954
5953
  cur->min_key_parts= prev->min_key_parts;
5955
5954
  cur->max_key_parts= prev->max_key_parts;
5956
5955
 
5957
 
  uint16 stor_length= arg->param->key[arg->keyno][key_tree->part].store_length;
 
5956
  uint16_t stor_length= arg->param->key[arg->keyno][key_tree->part].store_length;
5958
5957
  cur->min_key_parts += key_tree->store_min(stor_length, &cur->min_key,
5959
5958
                                            prev->min_key_flag);
5960
5959
  cur->max_key_parts += key_tree->store_max(stor_length, &cur->max_key,
6281
6280
    false  Otherwise
6282
6281
*/
6283
6282
 
6284
 
static bool is_key_scan_ror(PARAM *param, uint keynr, uint8 nparts)
 
6283
static bool is_key_scan_ror(PARAM *param, uint keynr, uint8_t nparts)
6285
6284
{
6286
6285
  KEY *table_key= param->table->key_info + keynr;
6287
6286
  KEY_PART_INFO *key_part= table_key->key_part + nparts;
6291
6290
  
6292
6291
  for (KEY_PART_INFO *kp= table_key->key_part; kp < key_part; kp++)
6293
6292
  {
6294
 
    uint16 fieldnr= param->table->key_info[keynr].
 
6293
    uint16_t fieldnr= param->table->key_info[keynr].
6295
6294
                    key_part[kp - table_key->key_part].fieldnr - 1;
6296
6295
    if (param->table->field[fieldnr]->key_length() != kp->length)
6297
6296
      return false;
6652
6651
    key_part->length=       key_info->key_part[part].length;
6653
6652
    key_part->store_length= key_info->key_part[part].store_length;
6654
6653
    key_part->null_bit=     key_info->key_part[part].null_bit;
6655
 
    key_part->flag=         (uint8) key_info->key_part[part].key_part_flag;
 
6654
    key_part->flag=         (uint8_t) key_info->key_part[part].key_part_flag;
6656
6655
  }
6657
6656
  if (insert_dynamic(&quick->ranges,(uchar*)&range))
6658
6657
    goto err;
7043
7042
*/
7044
7043
 
7045
7044
range_seq_t quick_range_seq_init(void *init_param,
7046
 
                                 uint n_ranges __attribute__((__unused__)),
7047
 
                                 uint flags __attribute__((__unused__)))
 
7045
                                 uint n_ranges __attribute__((unused)),
 
7046
                                 uint flags __attribute__((unused)))
7048
7047
{
7049
7048
  QUICK_RANGE_SELECT *quick= (QUICK_RANGE_SELECT*)init_param;
7050
7049
  quick->qr_traversal_ctx.first=  (QUICK_RANGE**)quick->ranges.buffer;
7120
7119
    Reference to range_flag associated with range number #idx
7121
7120
*/
7122
7121
 
7123
 
uint16 &mrr_persistent_flag_storage(range_seq_t seq, uint idx)
 
7122
uint16_t &mrr_persistent_flag_storage(range_seq_t seq, uint idx)
7124
7123
{
7125
7124
  QUICK_RANGE_SEQ_CTX *ctx= (QUICK_RANGE_SEQ_CTX*)seq;
7126
7125
  return ctx->first[idx]->flag;
7152
7151
    Reference to range-associated data
7153
7152
*/
7154
7153
 
7155
 
char* &mrr_get_ptr_by_idx(range_seq_t seq __attribute__((__unused__)),
7156
 
                          uint idx __attribute__((__unused__)))
 
7154
char* &mrr_get_ptr_by_idx(range_seq_t seq __attribute__((unused)),
 
7155
                          uint idx __attribute__((unused)))
7157
7156
{
7158
7157
  static char *dummy;
7159
7158
  return dummy;
7334
7333
 */
7335
7334
 
7336
7335
QUICK_SELECT_DESC::QUICK_SELECT_DESC(QUICK_RANGE_SELECT *q,
7337
 
                                     uint used_key_parts_arg __attribute__((__unused__)),
7338
 
                                     bool *create_err __attribute__((__unused__)))
 
7336
                                     uint used_key_parts_arg __attribute__((unused)),
 
7337
                                     bool *create_err __attribute__((unused)))
7339
7338
 :QUICK_RANGE_SELECT(*q), rev_it(rev_ranges)
7340
7339
{
7341
7340
  QUICK_RANGE *r;
8319
8318
 
8320
8319
        /* Check that pred compares min_max_arg_item with a constant. */
8321
8320
        Item *args[3];
8322
 
        bzero(args, 3 * sizeof(Item*));
 
8321
        memset(args, 0, 3 * sizeof(Item*));
8323
8322
        bool inv;
8324
8323
        /* Test if this is a comparison of a field and a constant. */
8325
8324
        if (!simple_pred(pred, args, &inv))
8395
8394
*/
8396
8395
 
8397
8396
static bool
8398
 
get_constant_key_infix(KEY *index_info __attribute__((__unused__)),
 
8397
get_constant_key_infix(KEY *index_info __attribute__((unused)),
8399
8398
                       SEL_ARG *index_range_tree,
8400
8399
                       KEY_PART_INFO *first_non_group_part,
8401
8400
                       KEY_PART_INFO *min_max_arg_part,
8402
8401
                       KEY_PART_INFO *last_part,
8403
 
                       THD *thd __attribute__((__unused__)),
 
8402
                       THD *thd __attribute__((unused)),
8404
8403
                       uchar *key_infix, uint *key_infix_len,
8405
8404
                       KEY_PART_INFO **first_non_infix_part)
8406
8405
{
8594
8593
 
8595
8594
void cost_group_min_max(TABLE* table, KEY *index_info, uint used_key_parts,
8596
8595
                        uint group_key_parts, SEL_TREE *range_tree,
8597
 
                        SEL_ARG *index_tree __attribute__((__unused__)),
 
8596
                        SEL_ARG *index_tree __attribute__((unused)),
8598
8597
                        ha_rows quick_prefix_records,
8599
8598
                        bool have_min, bool have_max,
8600
8599
                        double *read_cost, ha_rows *records)
8691
8690
 
8692
8691
QUICK_SELECT_I *
8693
8692
TRP_GROUP_MIN_MAX::make_quick(PARAM *param,
8694
 
                              bool retrieve_full_rows __attribute__((__unused__)),
 
8693
                              bool retrieve_full_rows __attribute__((unused)),
8695
8694
                              MEM_ROOT *parent_alloc)
8696
8695
{
8697
8696
  QUICK_GROUP_MIN_MAX_SELECT *quick;
8829
8828
    join->thd->mem_root= &alloc;
8830
8829
  }
8831
8830
  else
8832
 
    bzero(&alloc, sizeof(MEM_ROOT));            // ensure that it's not used
 
8831
    memset(&alloc, 0, sizeof(MEM_ROOT));  // ensure that it's not used
8833
8832
}
8834
8833
 
8835
8834
 
9742
9741
}
9743
9742
 
9744
9743
static void print_sel_tree(PARAM *param, SEL_TREE *tree, key_map *tree_map,
9745
 
                           const char *msg __attribute__((__unused__)))
 
9744
                           const char *msg __attribute__((unused)))
9746
9745
{
9747
9746
  SEL_ARG **key,**end;
9748
9747
  int idx;
9770
9769
 
9771
9770
 
9772
9771
static void print_ror_scans_arr(TABLE *table,
9773
 
                                const char *msg __attribute__((__unused__)),
 
9772
                                const char *msg __attribute__((unused)),
9774
9773
                                struct st_ror_scan_info **start,
9775
9774
                                struct st_ror_scan_info **end)
9776
9775
{