~hartmut-php/drizzle/drizzle-udf-levenshtein

« back to all changes in this revision

Viewing changes to drizzled/records.cc

  • Committer: Brian Aker
  • Date: 2010-05-17 23:12:39 UTC
  • Revision ID: brian@gaz-20100517231239-kgcnn613z0gga7ie
Code shuffle on ReadRecord

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
namespace drizzled
32
32
{
33
33
 
34
 
int rr_sequential(READ_RECORD *info);
35
 
static int rr_quick(READ_RECORD *info);
36
 
static int rr_from_tempfile(READ_RECORD *info);
37
 
static int rr_unpack_from_tempfile(READ_RECORD *info);
38
 
static int rr_unpack_from_buffer(READ_RECORD *info);
39
 
static int rr_from_pointers(READ_RECORD *info);
40
 
static int rr_from_cache(READ_RECORD *info);
41
 
static int init_rr_cache(Session *session, READ_RECORD *info);
 
34
int rr_sequential(ReadRecord *info);
 
35
static int rr_quick(ReadRecord *info);
 
36
static int rr_from_tempfile(ReadRecord *info);
 
37
static int rr_unpack_from_tempfile(ReadRecord *info);
 
38
static int rr_unpack_from_buffer(ReadRecord *info);
 
39
static int rr_from_pointers(ReadRecord *info);
 
40
static int rr_from_cache(ReadRecord *info);
 
41
static int init_rr_cache(Session *session, ReadRecord *info);
42
42
static int rr_cmp(unsigned char *a,unsigned char *b);
43
 
static int rr_index_first(READ_RECORD *info);
44
 
static int rr_index(READ_RECORD *info);
 
43
static int rr_index_first(ReadRecord *info);
 
44
static int rr_index(ReadRecord *info);
45
45
 
46
 
void init_read_record_idx(READ_RECORD *info, 
 
46
void init_read_record_idx(ReadRecord *info, 
47
47
                          Session *, 
48
48
                          Table *table,
49
49
                          bool print_error, 
64
64
}
65
65
 
66
66
 
67
 
void init_read_record(READ_RECORD *info,
68
 
                      Session *session, 
69
 
                      Table *table,
70
 
                      optimizer::SqlSelect *select,
71
 
                      int use_record_cache, 
72
 
                      bool print_error)
 
67
void ReadRecord::init_read_record(Session *session_arg, 
 
68
                                  Table *table_arg,
 
69
                                  optimizer::SqlSelect *select_arg,
 
70
                                  int use_record_cache, 
 
71
                                  bool print_error_arg)
73
72
{
74
73
  internal::IO_CACHE *tempfile;
75
74
 
76
 
  memset(info, 0, sizeof(*info));
77
 
  info->session=session;
78
 
  info->table=table;
79
 
  info->cursor= table->cursor;
80
 
  info->forms= &info->table;            /* Only one table */
 
75
  memset(this, 0, sizeof(*this));
 
76
  session= session_arg;
 
77
  table= table_arg;
 
78
  cursor= table->cursor;
 
79
  forms= &table;                /* Only one table */
81
80
 
82
81
  if (table->sort.addon_field)
83
82
  {
84
 
    info->rec_buf= table->sort.addon_buf;
85
 
    info->ref_length= table->sort.addon_length;
 
83
    rec_buf= table->sort.addon_buf;
 
84
    ref_length= table->sort.addon_length;
86
85
  }
87
86
  else
88
87
  {
89
88
    table->emptyRecord();
90
 
    info->record= table->record[0];
91
 
    info->ref_length= table->cursor->ref_length;
 
89
    record= table->record[0];
 
90
    ref_length= table->cursor->ref_length;
92
91
  }
93
 
  info->select=select;
94
 
  info->print_error= print_error;
95
 
  info->ignore_not_found_rows= 0;
 
92
  select= select_arg;
 
93
  print_error= print_error_arg;
 
94
  ignore_not_found_rows= 0;
96
95
  table->status=0;                      /* And it's always found */
97
96
 
98
97
  if (select && my_b_inited(select->file))
 
98
  {
99
99
    tempfile= select->file;
 
100
  }
100
101
  else
 
102
  {
101
103
    tempfile= table->sort.io_cache;
 
104
  }
 
105
 
102
106
  if (tempfile && my_b_inited(tempfile)) // Test if ref-records was used
103
107
  {
104
 
    info->read_record= (table->sort.addon_field ?
 
108
    read_record= (table->sort.addon_field ?
105
109
                        rr_unpack_from_tempfile : rr_from_tempfile);
106
 
    info->io_cache=tempfile;
107
 
    reinit_io_cache(info->io_cache,internal::READ_CACHE,0L,0,0);
108
 
    info->ref_pos=table->cursor->ref;
 
110
    io_cache=tempfile;
 
111
    reinit_io_cache(io_cache,internal::READ_CACHE,0L,0,0);
 
112
    ref_pos=table->cursor->ref;
109
113
    if (!table->cursor->inited)
110
114
      table->cursor->startTableScan(0);
111
115
 
122
126
        (uint64_t) table->s->reclength* (table->cursor->stats.records+
123
127
                                                table->cursor->stats.deleted) >
124
128
        (uint64_t) MIN_FILE_LENGTH_TO_USE_ROW_CACHE &&
125
 
        info->io_cache->end_of_file/info->ref_length * table->s->reclength >
 
129
        io_cache->end_of_file/ref_length * table->s->reclength >
126
130
        (internal::my_off_t) MIN_ROWS_TO_USE_TABLE_CACHE &&
127
131
        !table->s->blob_fields &&
128
 
        info->ref_length <= MAX_REFLENGTH)
 
132
        ref_length <= MAX_REFLENGTH)
129
133
    {
130
 
      if (! init_rr_cache(session, info))
 
134
      if (! init_rr_cache(session, this))
131
135
      {
132
 
        info->read_record=rr_from_cache;
 
136
        read_record=rr_from_cache;
133
137
      }
134
138
    }
135
139
  }
136
140
  else if (select && select->quick)
137
141
  {
138
 
    info->read_record=rr_quick;
 
142
    read_record=rr_quick;
139
143
  }
140
144
  else if (table->sort.record_pointers)
141
145
  {
142
146
    table->cursor->startTableScan(0);
143
 
    info->cache_pos=table->sort.record_pointers;
144
 
    info->cache_end=info->cache_pos+
145
 
                    table->sort.found_records*info->ref_length;
146
 
    info->read_record= (table->sort.addon_field ?
147
 
                        rr_unpack_from_buffer : rr_from_pointers);
 
147
    cache_pos=table->sort.record_pointers;
 
148
    cache_end= cache_pos+ table->sort.found_records * ref_length;
 
149
    read_record= (table->sort.addon_field ?  rr_unpack_from_buffer : rr_from_pointers);
148
150
  }
149
151
  else
150
152
  {
151
 
    info->read_record= rr_sequential;
 
153
    read_record= rr_sequential;
152
154
    table->cursor->startTableScan(1);
153
155
    /* We can use record cache if we don't update dynamic length tables */
154
156
    if (!table->no_cache &&
162
164
} /* init_read_record */
163
165
 
164
166
 
165
 
void end_read_record(READ_RECORD *info)
 
167
void ReadRecord::end_read_record()
166
168
{                   /* free cache if used */
167
 
  if (info->cache)
 
169
  if (cache)
168
170
  {
169
 
    free((char*) info->cache);
170
 
    info->cache=0;
 
171
    free((char*) cache);
 
172
    cache= NULL;
171
173
  }
172
 
  if (info->table)
 
174
  if (table)
173
175
  {
174
 
    info->table->filesort_free_buffers();
175
 
    (void) info->cursor->extra(HA_EXTRA_NO_CACHE);
176
 
    if (info->read_record != rr_quick) // otherwise quick_range does it
177
 
      (void) info->cursor->ha_index_or_rnd_end();
178
 
    info->table=0;
 
176
    table->filesort_free_buffers();
 
177
    (void) cursor->extra(HA_EXTRA_NO_CACHE);
 
178
    if (read_record != rr_quick) // otherwise quick_range does it
 
179
      (void) cursor->ha_index_or_rnd_end();
 
180
 
 
181
    table= NULL;
179
182
  }
180
183
}
181
184
 
182
 
static int rr_handle_error(READ_RECORD *info, int error)
 
185
static int rr_handle_error(ReadRecord *info, int error)
183
186
{
184
187
  if (error == HA_ERR_END_OF_FILE)
185
188
    error= -1;
194
197
}
195
198
 
196
199
/** Read a record from head-database. */
197
 
static int rr_quick(READ_RECORD *info)
 
200
static int rr_quick(ReadRecord *info)
198
201
{
199
202
  int tmp;
200
203
  while ((tmp= info->select->quick->get_next()))
226
229
  @retval
227
230
    1   Error
228
231
*/
229
 
static int rr_index_first(READ_RECORD *info)
 
232
static int rr_index_first(ReadRecord *info)
230
233
{
231
234
  int tmp= info->cursor->index_first(info->record);
232
235
  info->read_record= rr_index;
250
253
  @retval
251
254
    1   Error
252
255
*/
253
 
static int rr_index(READ_RECORD *info)
 
256
static int rr_index(ReadRecord *info)
254
257
{
255
258
  int tmp= info->cursor->index_next(info->record);
256
259
  if (tmp)
258
261
  return tmp;
259
262
}
260
263
 
261
 
int rr_sequential(READ_RECORD *info)
 
264
int rr_sequential(ReadRecord *info)
262
265
{
263
266
  int tmp;
264
267
  while ((tmp= info->cursor->rnd_next(info->record)))
283
286
  return tmp;
284
287
}
285
288
 
286
 
static int rr_from_tempfile(READ_RECORD *info)
 
289
static int rr_from_tempfile(ReadRecord *info)
287
290
{
288
291
  int tmp;
289
292
  for (;;)
317
320
  @retval
318
321
    -1   There is no record to be read anymore.
319
322
*/
320
 
static int rr_unpack_from_tempfile(READ_RECORD *info)
 
323
static int rr_unpack_from_tempfile(ReadRecord *info)
321
324
{
322
325
  if (my_b_read(info->io_cache, info->rec_buf, info->ref_length))
323
326
    return -1;
327
330
  return 0;
328
331
}
329
332
 
330
 
static int rr_from_pointers(READ_RECORD *info)
 
333
static int rr_from_pointers(ReadRecord *info)
331
334
{
332
335
  int tmp;
333
336
  unsigned char *cache_pos;
367
370
  @retval
368
371
    -1   There is no record to be read anymore.
369
372
*/
370
 
static int rr_unpack_from_buffer(READ_RECORD *info)
 
373
static int rr_unpack_from_buffer(ReadRecord *info)
371
374
{
372
375
  if (info->cache_pos == info->cache_end)
373
376
    return -1;                      /* End of buffer */
379
382
}
380
383
 
381
384
/* cacheing of records from a database */
382
 
static int init_rr_cache(Session *session, READ_RECORD *info)
 
385
static int init_rr_cache(Session *session, ReadRecord *info)
383
386
{
384
387
  uint32_t rec_cache_size;
385
388
 
409
412
  return(0);
410
413
} /* init_rr_cache */
411
414
 
412
 
static int rr_from_cache(READ_RECORD *info)
 
415
static int rr_from_cache(ReadRecord *info)
413
416
{
414
417
  register uint32_t i;
415
418
  uint32_t length;