~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/records.cc

  • Committer: brian
  • Date: 2009-11-11 19:42:27 UTC
  • mfrom: (1211 staging)
  • mto: (1211.1.4 staging)
  • mto: This revision was merged to the branch mainline in revision 1212.
  • Revision ID: brian@orisndriz04-20091111194227-mky4am3ym0dlosaa
Update for Cursor renaming.

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
  @param info         READ_RECORD structure to initialize.
48
48
  @param session          Thread handle
49
49
  @param table        Table to be accessed
50
 
  @param print_error  If true, call table->file->print_error() if an error
 
50
  @param print_error  If true, call table->cursor->print_error() if an error
51
51
                      occurs (except for end-of-records error)
52
52
  @param idx          index to scan
53
53
*/
60
60
  table->emptyRecord();
61
61
  memset(info, 0, sizeof(*info));
62
62
  info->table= table;
63
 
  info->file=  table->file;
 
63
  info->cursor=  table->cursor;
64
64
  info->record= table->record[0];
65
65
  info->print_error= print_error;
66
66
 
67
67
  table->status=0;                      /* And it's always found */
68
 
  if (!table->file->inited)
69
 
    table->file->ha_index_init(idx, 1);
 
68
  if (!table->cursor->inited)
 
69
    table->cursor->ha_index_init(idx, 1);
70
70
  /* read_record will be changed to rr_index in rr_index_first */
71
71
  info->read_record= rr_index_first;
72
72
}
82
82
  calls. The other two methods are used for normal table access.
83
83
 
84
84
  The filesort will produce references to the records sorted, these
85
 
  references can be stored in memory or in a temporary file.
 
85
  references can be stored in memory or in a temporary cursor.
86
86
 
87
 
  The temporary file is normally used when the references doesn't fit into
 
87
  The temporary cursor is normally used when the references doesn't fit into
88
88
  a properly sized memory buffer. For most small queries the references
89
89
  are stored in the memory buffer.
90
90
 
91
 
  The temporary file is also used when performing an update where a key is
 
91
  The temporary cursor is also used when performing an update where a key is
92
92
  modified.
93
93
 
94
94
  Methods used when ref's are in memory (using rr_from_pointers):
106
106
      In this case the record data is fetched from the handler using the
107
107
      saved reference using the rnd_pos handler call.
108
108
 
109
 
  Methods used when ref's are in a temporary file (using rr_from_tempfile)
 
109
  Methods used when ref's are in a temporary cursor (using rr_from_tempfile)
110
110
    rr_unpack_from_tempfile:
111
111
    ------------------------
112
112
      Same as rr_unpack_from_buffer except that references are fetched from
113
 
      temporary file. Should obviously not really happen other than in
 
113
      temporary cursor. Should obviously not really happen other than in
114
114
      strange configurations.
115
115
 
116
116
    rr_from_tempfile:
117
117
    -----------------
118
118
      Same as rr_from_pointers except that references are fetched from
119
 
      temporary file instead of from
 
119
      temporary cursor instead of from
120
120
    rr_from_cache:
121
121
    --------------
122
122
      This is a special variant of rr_from_tempfile that can be used for
123
123
      handlers that is not using the HA_FAST_KEY_READ table flag. Instead
124
 
      of reading the references one by one from the temporary file it reads
 
124
      of reading the references one by one from the temporary cursor it reads
125
125
      a set of them, sorts them and reads all of them into a buffer which
126
126
      is then used for a number of subsequent calls to rr_from_cache.
127
127
      It is only used for SELECT queries and a number of other conditions
151
151
  memset(info, 0, sizeof(*info));
152
152
  info->session=session;
153
153
  info->table=table;
154
 
  info->file= table->file;
 
154
  info->cursor= table->cursor;
155
155
  info->forms= &info->table;            /* Only one table */
156
156
 
157
157
  if (table->sort.addon_field)
163
163
  {
164
164
    table->emptyRecord();
165
165
    info->record= table->record[0];
166
 
    info->ref_length= table->file->ref_length;
 
166
    info->ref_length= table->cursor->ref_length;
167
167
  }
168
168
  info->select=select;
169
169
  info->print_error=print_error;
180
180
                        rr_unpack_from_tempfile : rr_from_tempfile);
181
181
    info->io_cache=tempfile;
182
182
    reinit_io_cache(info->io_cache,READ_CACHE,0L,0,0);
183
 
    info->ref_pos=table->file->ref;
184
 
    if (!table->file->inited)
185
 
      table->file->ha_rnd_init(0);
 
183
    info->ref_pos=table->cursor->ref;
 
184
    if (!table->cursor->inited)
 
185
      table->cursor->ha_rnd_init(0);
186
186
 
187
187
    /*
188
188
      table->sort.addon_field is checked because if we use addon fields,
191
191
    */
192
192
    if (!table->sort.addon_field &&
193
193
        session->variables.read_rnd_buff_size &&
194
 
        !(table->file->ha_table_flags() & HA_FAST_KEY_READ) &&
 
194
        !(table->cursor->ha_table_flags() & HA_FAST_KEY_READ) &&
195
195
        (table->db_stat & HA_READ_ONLY ||
196
196
        table->reginfo.lock_type <= TL_READ_NO_INSERT) &&
197
 
        (uint64_t) table->s->reclength* (table->file->stats.records+
198
 
                                                table->file->stats.deleted) >
 
197
        (uint64_t) table->s->reclength* (table->cursor->stats.records+
 
198
                                                table->cursor->stats.deleted) >
199
199
        (uint64_t) MIN_FILE_LENGTH_TO_USE_ROW_CACHE &&
200
200
        info->io_cache->end_of_file/info->ref_length * table->s->reclength >
201
201
        (my_off_t) MIN_ROWS_TO_USE_TABLE_CACHE &&
214
214
  }
215
215
  else if (table->sort.record_pointers)
216
216
  {
217
 
    table->file->ha_rnd_init(0);
 
217
    table->cursor->ha_rnd_init(0);
218
218
    info->cache_pos=table->sort.record_pointers;
219
219
    info->cache_end=info->cache_pos+
220
220
                    table->sort.found_records*info->ref_length;
224
224
  else
225
225
  {
226
226
    info->read_record=rr_sequential;
227
 
    table->file->ha_rnd_init(1);
 
227
    table->cursor->ha_rnd_init(1);
228
228
    /* We can use record cache if we don't update dynamic length tables */
229
229
    if (!table->no_cache &&
230
230
        (use_record_cache > 0 ||
231
231
        (int) table->reginfo.lock_type <= (int) TL_READ_WITH_SHARED_LOCKS ||
232
232
        !(table->s->db_options_in_use & HA_OPTION_PACK_RECORD) ||
233
233
        (use_record_cache < 0 &&
234
 
          !(table->file->ha_table_flags() & HA_NOT_DELETE_WITH_CACHE))))
235
 
      table->file->extra_opt(HA_EXTRA_CACHE, session->variables.read_buff_size);
 
234
          !(table->cursor->ha_table_flags() & HA_NOT_DELETE_WITH_CACHE))))
 
235
      table->cursor->extra_opt(HA_EXTRA_CACHE, session->variables.read_buff_size);
236
236
  }
237
237
 
238
238
  return;
248
248
  if (info->table)
249
249
  {
250
250
    info->table->filesort_free_buffers();
251
 
    (void) info->file->extra(HA_EXTRA_NO_CACHE);
 
251
    (void) info->cursor->extra(HA_EXTRA_NO_CACHE);
252
252
    if (info->read_record != rr_quick) // otherwise quick_range does it
253
 
      (void) info->file->ha_index_or_rnd_end();
 
253
      (void) info->cursor->ha_index_or_rnd_end();
254
254
    info->table=0;
255
255
  }
256
256
}
262
262
  else
263
263
  {
264
264
    if (info->print_error)
265
 
      info->table->file->print_error(error, MYF(0));
 
265
      info->table->cursor->print_error(error, MYF(0));
266
266
    if (error < 0)                            // Fix negative BDB errno
267
267
      error= 1;
268
268
  }
304
304
*/
305
305
static int rr_index_first(READ_RECORD *info)
306
306
{
307
 
  int tmp= info->file->index_first(info->record);
 
307
  int tmp= info->cursor->index_first(info->record);
308
308
  info->read_record= rr_index;
309
309
  if (tmp)
310
310
    tmp= rr_handle_error(info, tmp);
328
328
*/
329
329
static int rr_index(READ_RECORD *info)
330
330
{
331
 
  int tmp= info->file->index_next(info->record);
 
331
  int tmp= info->cursor->index_next(info->record);
332
332
  if (tmp)
333
333
    tmp= rr_handle_error(info, tmp);
334
334
  return tmp;
337
337
int rr_sequential(READ_RECORD *info)
338
338
{
339
339
  int tmp;
340
 
  while ((tmp= info->file->rnd_next(info->record)))
 
340
  while ((tmp= info->cursor->rnd_next(info->record)))
341
341
  {
342
342
    if (info->session->killed)
343
343
    {
365
365
  for (;;)
366
366
  {
367
367
    if (my_b_read(info->io_cache,info->ref_pos,info->ref_length))
368
 
      return -1;                                        /* End of file */
369
 
    if (!(tmp=info->file->rnd_pos(info->record,info->ref_pos)))
 
368
      return -1;                                        /* End of cursor */
 
369
    if (!(tmp=info->cursor->rnd_pos(info->record,info->ref_pos)))
370
370
      break;
371
371
    /* The following is extremely unlikely to happen */
372
372
    if (tmp == HA_ERR_RECORD_DELETED ||
379
379
} /* rr_from_tempfile */
380
380
 
381
381
/**
382
 
  Read a result set record from a temporary file after sorting.
 
382
  Read a result set record from a temporary cursor after sorting.
383
383
 
384
 
  The function first reads the next sorted record from the temporary file.
 
384
  The function first reads the next sorted record from the temporary cursor.
385
385
  into a buffer. If a success it calls a callback function that unpacks
386
386
  the fields values use in the result set from this buffer into their
387
387
  positions in the regular record buffer.
411
411
  for (;;)
412
412
  {
413
413
    if (info->cache_pos == info->cache_end)
414
 
      return -1;                                        /* End of file */
 
414
      return -1;                                        /* End of cursor */
415
415
    cache_pos= info->cache_pos;
416
416
    info->cache_pos+= info->ref_length;
417
417
 
418
 
    if (!(tmp=info->file->rnd_pos(info->record,cache_pos)))
 
418
    if (!(tmp=info->cursor->rnd_pos(info->record,cache_pos)))
419
419
      break;
420
420
 
421
421
    /* The following is extremely unlikely to happen */
502
502
      {
503
503
        shortget(error,info->cache_pos);
504
504
        if (info->print_error)
505
 
          info->table->file->print_error(error,MYF(0));
 
505
          info->table->cursor->print_error(error,MYF(0));
506
506
      }
507
507
      else
508
508
      {
518
518
      length= (uint32_t) rest_of_file;
519
519
    if (!length || my_b_read(info->io_cache,info->cache,length))
520
520
    {
521
 
      return -1;                        /* End of file */
 
521
      return -1;                        /* End of cursor */
522
522
    }
523
523
 
524
524
    length/=info->ref_length;
542
542
      record=uint3korr(position);
543
543
      position+=3;
544
544
      record_pos=info->cache+record*info->reclength;
545
 
      if ((error=(int16_t) info->file->rnd_pos(record_pos,info->ref_pos)))
 
545
      if ((error=(int16_t) info->cursor->rnd_pos(record_pos,info->ref_pos)))
546
546
      {
547
547
        record_pos[info->error_offset]=1;
548
548
        shortstore(record_pos,error);