~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/optimizer/quick_range_select.cc

  • Committer: Mark Atwood
  • Date: 2010-06-24 03:15:21 UTC
  • mto: (1637.2.4 build)
  • mto: This revision was merged to the branch mainline in revision 1639.
  • Revision ID: me@mark.atwood.name-20100624031521-gafmppfbf5afm68w
new syslog module, with plugins for query log, error message, and SYSLOG() function

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#include <config.h>
21
 
 
22
 
#include <drizzled/session.h>
23
 
#include <drizzled/optimizer/quick_range.h>
24
 
#include <drizzled/optimizer/quick_range_select.h>
25
 
#include <drizzled/internal/m_string.h>
26
 
#include <drizzled/current_session.h>
27
 
 
 
20
#include "config.h"
 
21
#include "drizzled/session.h"
 
22
#include "drizzled/optimizer/quick_range.h"
 
23
#include "drizzled/optimizer/quick_range_select.h"
 
24
#include "drizzled/sql_bitmap.h"
 
25
#include "drizzled/internal/m_string.h"
28
26
#include <fcntl.h>
29
27
 
30
28
using namespace std;
37
35
                                              Table *table,
38
36
                                              uint32_t key_nr,
39
37
                                              bool no_alloc,
40
 
                                              memory::Root *parent_alloc)
 
38
                                              memory::Root *parent_alloc,
 
39
                                              bool *create_error)
41
40
  :
42
41
    cursor(NULL),
43
42
    ranges(),
44
43
    in_ror_merged_scan(false),
45
 
    column_bitmap(NULL),
 
44
    column_bitmap(),
46
45
    save_read_set(NULL),
47
46
    save_write_set(NULL),
48
47
    free_file(false),
50
49
    last_range(NULL),
51
50
    qr_traversal_ctx(),
52
51
    mrr_buf_size(0),
 
52
    mrr_buf_desc(NULL),
53
53
    key_parts(NULL),
54
54
    dont_free(false),
55
55
    mrr_flags(0),
56
56
    alloc()
57
57
{
 
58
  my_bitmap_map *bitmap= NULL;
 
59
 
58
60
  sorted= 0;
59
61
  index= key_nr;
60
62
  head= table;
63
65
 
64
66
  /* 'session' is not accessible in QuickRangeSelect::reset(). */
65
67
  mrr_buf_size= session->variables.read_rnd_buff_size;
 
68
  mrr_buf_desc= NULL;
66
69
 
67
70
  if (! no_alloc && ! parent_alloc)
68
71
  {
79
82
  record= head->record[0];
80
83
  save_read_set= head->read_set;
81
84
  save_write_set= head->write_set;
82
 
  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->getShare()->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->getShare()->sizeFields());
 
100
  }
83
101
}
84
102
 
85
103
 
119
137
      }
120
138
    }
121
139
    delete_dynamic(&ranges); /* ranges are allocated in alloc */
122
 
    delete column_bitmap;
123
140
    alloc.free_root(MYF(0));
124
141
  }
125
 
  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
  }
126
148
}
127
149
 
128
150
 
138
160
    {
139
161
      return 0;
140
162
    }
141
 
    head->column_bitmaps_set(*column_bitmap, *column_bitmap);
 
163
    head->column_bitmaps_set(&column_bitmap, &column_bitmap);
142
164
    goto end;
143
165
  }
144
166
 
164
186
    goto failure;
165
187
  }
166
188
 
167
 
  head->column_bitmaps_set(*column_bitmap, *column_bitmap);
 
189
  head->column_bitmaps_set(&column_bitmap, &column_bitmap);
168
190
 
169
191
  if (cursor->ha_external_lock(session, F_RDLCK))
170
192
    goto failure;
195
217
  }
196
218
  head->prepare_for_position();
197
219
  head->cursor= org_file;
198
 
  *column_bitmap|= *head->read_set;
199
 
  head->column_bitmaps_set(*column_bitmap, *column_bitmap);
 
220
  column_bitmap= *head->read_set;
 
221
  head->column_bitmaps_set(&column_bitmap, &column_bitmap);
200
222
 
201
223
  return 0;
202
224
 
203
225
failure:
204
 
  head->column_bitmaps_set(*save_read_set, *save_write_set);
 
226
  head->column_bitmaps_set(save_read_set, save_write_set);
205
227
  delete cursor;
206
228
  cursor= save_file;
207
229
  return 0;
246
268
    There is a later assert in th code that hoped to catch random free() that might
247
269
    have done this.
248
270
  */
249
 
  assert(not (mrr_buf_size));
 
271
  assert(not (mrr_buf_size && ! mrr_buf_desc));
250
272
 
251
273
  if (sorted)
252
274
  {
273
295
      We don't need to signal the bitmap change as the bitmap is always the
274
296
      same for this head->cursor
275
297
    */
276
 
    head->column_bitmaps_set(*column_bitmap, *column_bitmap);
 
298
    head->column_bitmaps_set(&column_bitmap, &column_bitmap);
277
299
  }
278
300
 
279
301
  int result= cursor->multi_range_read_next(&dummy);
281
303
  if (in_ror_merged_scan)
282
304
  {
283
305
    /* Restore bitmaps set on entry */
284
 
    head->column_bitmaps_set(*save_read_set, *save_write_set);
 
306
    head->column_bitmaps_set(save_read_set, save_write_set);
285
307
  }
286
308
  return result;
287
309
}
419
441
}
420
442
 
421
443
 
422
 
void optimizer::QuickRangeSelect::add_info_string(string *str)
 
444
void optimizer::QuickRangeSelect::add_info_string(String *str)
423
445
{
424
446
  KeyInfo *key_info= head->key_info + index;
425
447
  str->append(key_info->name);
426
448
}
427
449
 
428
450
 
429
 
void optimizer::QuickRangeSelect::add_keys_and_lengths(string *key_names,
430
 
                                                       string *used_lengths)
 
451
void optimizer::QuickRangeSelect::add_keys_and_lengths(String *key_names,
 
452
                                                       String *used_lengths)
431
453
{
432
454
  char buf[64];
433
455
  uint32_t length;