~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/quick_range_select.cc

  • Committer: Monty Taylor
  • Date: 2010-04-22 02:46:23 UTC
  • mto: (1497.3.4 enable-dtrace)
  • mto: This revision was merged to the branch mainline in revision 1527.
  • Revision ID: mordred@inaugust.com-20100422024623-4urw8fi8eraci08p
Don't overwrite the pandora_vc_revinfo file if we don't have new
authoratative information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include "drizzled/session.h"
22
22
#include "drizzled/optimizer/quick_range.h"
23
23
#include "drizzled/optimizer/quick_range_select.h"
 
24
#include "drizzled/sql_bitmap.h"
24
25
#include "drizzled/internal/m_string.h"
25
26
#include <fcntl.h>
26
27
 
34
35
                                              Table *table,
35
36
                                              uint32_t key_nr,
36
37
                                              bool no_alloc,
37
 
                                              memory::Root *parent_alloc)
 
38
                                              memory::Root *parent_alloc,
 
39
                                              bool *create_error)
38
40
  :
 
41
    mrr_flags(0),
 
42
    alloc(),
39
43
    cursor(NULL),
40
44
    ranges(),
41
45
    in_ror_merged_scan(false),
42
 
    column_bitmap(NULL),
 
46
    column_bitmap(),
43
47
    save_read_set(NULL),
44
48
    save_write_set(NULL),
45
49
    free_file(false),
47
51
    last_range(NULL),
48
52
    qr_traversal_ctx(),
49
53
    mrr_buf_size(0),
 
54
    mrr_buf_desc(NULL),
50
55
    key_parts(NULL),
51
 
    dont_free(false),
52
 
    mrr_flags(0),
53
 
    alloc()
 
56
    dont_free(false)
54
57
{
 
58
  my_bitmap_map *bitmap= NULL;
 
59
 
55
60
  sorted= 0;
56
61
  index= key_nr;
57
62
  head= table;
60
65
 
61
66
  /* 'session' is not accessible in QuickRangeSelect::reset(). */
62
67
  mrr_buf_size= session->variables.read_rnd_buff_size;
 
68
  mrr_buf_desc= NULL;
63
69
 
64
70
  if (! no_alloc && ! parent_alloc)
65
71
  {
76
82
  record= head->record[0];
77
83
  save_read_set= head->read_set;
78
84
  save_write_set= head->write_set;
79
 
  column_bitmap= new boost::dynamic_bitset<>(table->getShare()->sizeFields());
 
85
 
 
86
  /* Allocate a bitmap for used columns. Using memory::sql_alloc instead of malloc
 
87
     simply as a "fix" to the MySQL 6.0 code that also free()s it at the
 
88
     same time we destroy the mem_root.
 
89
   */
 
90
 
 
91
  bitmap= reinterpret_cast<my_bitmap_map*>(memory::sql_alloc(head->s->column_bitmap_size));
 
92
  if (! bitmap)
 
93
  {
 
94
    column_bitmap.setBitmap(NULL);
 
95
    *create_error= 1;
 
96
  }
 
97
  else
 
98
  {
 
99
    column_bitmap.init(bitmap, head->s->fields);
 
100
  }
80
101
}
81
102
 
82
103
 
84
105
{
85
106
  if (cursor->inited != Cursor::NONE)
86
107
    cursor->ha_index_or_rnd_end();
87
 
  return (cursor->startIndexScan(index, 1));
 
108
  return (cursor->ha_index_init(index, 1));
88
109
}
89
110
 
90
111
 
116
137
      }
117
138
    }
118
139
    delete_dynamic(&ranges); /* ranges are allocated in alloc */
119
 
    delete column_bitmap;
120
140
    alloc.free_root(MYF(0));
121
141
  }
122
 
  head->column_bitmaps_set(*save_read_set, *save_write_set);
 
142
  head->column_bitmaps_set(save_read_set, save_write_set);
 
143
  assert(mrr_buf_desc == NULL);
 
144
  if (mrr_buf_desc)
 
145
  {
 
146
    free(mrr_buf_desc);
 
147
  }
123
148
}
124
149
 
125
150
 
135
160
    {
136
161
      return 0;
137
162
    }
138
 
    head->column_bitmaps_set(*column_bitmap, *column_bitmap);
 
163
    head->column_bitmaps_set(&column_bitmap, &column_bitmap);
139
164
    goto end;
140
165
  }
141
166
 
161
186
    goto failure;
162
187
  }
163
188
 
164
 
  head->column_bitmaps_set(*column_bitmap, *column_bitmap);
 
189
  head->column_bitmaps_set(&column_bitmap, &column_bitmap);
165
190
 
166
191
  if (cursor->ha_external_lock(session, F_RDLCK))
167
192
    goto failure;
192
217
  }
193
218
  head->prepare_for_position();
194
219
  head->cursor= org_file;
195
 
  *column_bitmap|= *head->read_set;
196
 
  head->column_bitmaps_set(*column_bitmap, *column_bitmap);
 
220
  column_bitmap= *head->read_set;
 
221
  head->column_bitmaps_set(&column_bitmap, &column_bitmap);
197
222
 
198
223
  return 0;
199
224
 
200
225
failure:
201
 
  head->column_bitmaps_set(*save_read_set, *save_write_set);
 
226
  head->column_bitmaps_set(save_read_set, save_write_set);
202
227
  delete cursor;
203
228
  cursor= save_file;
204
229
  return 0;
218
243
    optimizer::QuickRange *tmp= *((optimizer::QuickRange**)ranges.buffer);
219
244
    if ((tmp->flag & (EQ_RANGE | NULL_RANGE)) == EQ_RANGE)
220
245
    {
221
 
      KeyInfo *key=head->key_info+index;
 
246
      KEY *key=head->key_info+index;
222
247
      return ((key->flags & (HA_NOSAME)) == HA_NOSAME &&
223
248
              key->key_length == tmp->min_length);
224
249
    }
233
258
  last_range= NULL;
234
259
  cur_range= (optimizer::QuickRange**) ranges.buffer;
235
260
 
236
 
  if (cursor->inited == Cursor::NONE && (error= cursor->startIndexScan(index, 1)))
 
261
  if (cursor->inited == Cursor::NONE && (error= cursor->ha_index_init(index, 1)))
237
262
  {
238
263
    return error;
239
264
  }
243
268
    There is a later assert in th code that hoped to catch random free() that might
244
269
    have done this.
245
270
  */
246
 
  assert(not (mrr_buf_size));
 
271
  assert(not (mrr_buf_size && ! mrr_buf_desc));
247
272
 
248
273
  if (sorted)
249
274
  {
270
295
      We don't need to signal the bitmap change as the bitmap is always the
271
296
      same for this head->cursor
272
297
    */
273
 
    head->column_bitmaps_set(*column_bitmap, *column_bitmap);
 
298
    head->column_bitmaps_set(&column_bitmap, &column_bitmap);
274
299
  }
275
300
 
276
301
  int result= cursor->multi_range_read_next(&dummy);
278
303
  if (in_ror_merged_scan)
279
304
  {
280
305
    /* Restore bitmaps set on entry */
281
 
    head->column_bitmaps_set(*save_read_set, *save_write_set);
 
306
    head->column_bitmaps_set(save_read_set, save_write_set);
282
307
  }
283
308
  return result;
284
309
}
418
443
 
419
444
void optimizer::QuickRangeSelect::add_info_string(String *str)
420
445
{
421
 
  KeyInfo *key_info= head->key_info + index;
 
446
  KEY *key_info= head->key_info + index;
422
447
  str->append(key_info->name);
423
448
}
424
449
 
428
453
{
429
454
  char buf[64];
430
455
  uint32_t length;
431
 
  KeyInfo *key_info= head->key_info + index;
 
456
  KEY *key_info= head->key_info + index;
432
457
  key_names->append(key_info->name);
433
458
  length= internal::int64_t2str(max_used_key_length, buf, 10) - buf;
434
459
  used_lengths->append(buf, length);