~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/records.cc

  • Committer: Jay Pipes
  • Date: 2009-05-31 21:21:44 UTC
  • mto: This revision was merged to the branch mainline in revision 1046.
  • Revision ID: jpipes@serialcoder-20090531212144-dn18058mx55azhms
Yet more indentation and style cleanup

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
 
 
17
16
/**
18
17
  @file
19
18
 
25
24
#include <drizzled/table.h>
26
25
#include <drizzled/session.h>
27
26
 
 
27
int rr_sequential(READ_RECORD *info);
28
28
static int rr_quick(READ_RECORD *info);
29
 
int rr_sequential(READ_RECORD *info);
30
29
static int rr_from_tempfile(READ_RECORD *info);
31
30
static int rr_unpack_from_tempfile(READ_RECORD *info);
32
31
static int rr_unpack_from_buffer(READ_RECORD *info);
37
36
static int rr_index_first(READ_RECORD *info);
38
37
static int rr_index(READ_RECORD *info);
39
38
 
40
 
 
41
39
/**
42
40
  Initialize READ_RECORD structure to perform full index scan (in forward
43
41
  direction) using read_record.read_record() interface.
53
51
                      occurs (except for end-of-records error)
54
52
  @param idx          index to scan
55
53
*/
56
 
 
57
 
void init_read_record_idx(READ_RECORD *info, Session *, Table *table,
58
 
                          bool print_error, uint32_t idx)
 
54
void init_read_record_idx(READ_RECORD *info, 
 
55
                          Session *, 
 
56
                          Table *table,
 
57
                          bool print_error, 
 
58
                          uint32_t idx)
59
59
{
60
60
  table->emptyRecord();
61
61
  memset(info, 0, sizeof(*info));
71
71
  info->read_record= rr_index_first;
72
72
}
73
73
 
74
 
 
75
74
/*
76
75
  init_read_record is used to scan by using a number of different methods.
77
76
  Which method to use is set-up in this call so that later calls to
140
139
    This is the most basic access method of a table using rnd_init,
141
140
    rnd_next and rnd_end. No indexes are used.
142
141
*/
143
 
void init_read_record(READ_RECORD *info,Session *session, Table *table,
144
 
                      SQL_SELECT *select,
145
 
                      int use_record_cache, bool print_error)
 
142
void init_read_record(READ_RECORD *info,
 
143
                      Session *session, 
 
144
                      Table *table,
 
145
                                  SQL_SELECT *select,
 
146
                                  int use_record_cache, 
 
147
                      bool print_error)
146
148
{
147
149
  IO_CACHE *tempfile;
148
150
 
192
194
      and table->sort.io_cache is read sequentially
193
195
    */
194
196
    if (!table->sort.addon_field &&
195
 
        session->variables.read_rnd_buff_size &&
196
 
        !(table->file->ha_table_flags() & HA_FAST_KEY_READ) &&
197
 
        (table->db_stat & HA_READ_ONLY ||
198
 
         table->reginfo.lock_type <= TL_READ_NO_INSERT) &&
199
 
        (uint64_t) table->s->reclength* (table->file->stats.records+
200
 
                                          table->file->stats.deleted) >
201
 
        (uint64_t) MIN_FILE_LENGTH_TO_USE_ROW_CACHE &&
202
 
        info->io_cache->end_of_file/info->ref_length * table->s->reclength >
203
 
        (my_off_t) MIN_ROWS_TO_USE_TABLE_CACHE &&
204
 
        !table->s->blob_fields &&
 
197
        session->variables.read_rnd_buff_size &&
 
198
        !(table->file->ha_table_flags() & HA_FAST_KEY_READ) &&
 
199
        (table->db_stat & HA_READ_ONLY ||
 
200
        table->reginfo.lock_type <= TL_READ_NO_INSERT) &&
 
201
        (uint64_t) table->s->reclength* (table->file->stats.records+
 
202
                                                table->file->stats.deleted) >
 
203
        (uint64_t) MIN_FILE_LENGTH_TO_USE_ROW_CACHE &&
 
204
        info->io_cache->end_of_file/info->ref_length * table->s->reclength >
 
205
        (my_off_t) MIN_ROWS_TO_USE_TABLE_CACHE &&
 
206
        !table->s->blob_fields &&
205
207
        info->ref_length <= MAX_REFLENGTH)
206
208
    {
207
209
      if (! init_rr_cache(session, info))
208
210
      {
209
 
        info->read_record=rr_from_cache;
 
211
        info->read_record=rr_from_cache;
210
212
      }
211
213
    }
212
214
  }
229
231
    table->file->ha_rnd_init(1);
230
232
    /* We can use record cache if we don't update dynamic length tables */
231
233
    if (!table->no_cache &&
232
 
        (use_record_cache > 0 ||
233
 
         (int) table->reginfo.lock_type <= (int) TL_READ_WITH_SHARED_LOCKS ||
234
 
         !(table->s->db_options_in_use & HA_OPTION_PACK_RECORD) ||
235
 
         (use_record_cache < 0 &&
236
 
          !(table->file->ha_table_flags() & HA_NOT_DELETE_WITH_CACHE))))
 
234
        (use_record_cache > 0 ||
 
235
        (int) table->reginfo.lock_type <= (int) TL_READ_WITH_SHARED_LOCKS ||
 
236
        !(table->s->db_options_in_use & HA_OPTION_PACK_RECORD) ||
 
237
        (use_record_cache < 0 &&
 
238
          !(table->file->ha_table_flags() & HA_NOT_DELETE_WITH_CACHE))))
237
239
      table->file->extra_opt(HA_EXTRA_CACHE, session->variables.read_buff_size);
238
240
  }
239
241
  /*
250
252
  return;
251
253
} /* init_read_record */
252
254
 
253
 
 
254
 
 
255
255
void end_read_record(READ_RECORD *info)
256
256
{                   /* free cache if used */
257
257
  if (info->cache)
283
283
  return error;
284
284
}
285
285
 
286
 
 
287
286
/** Read a record from head-database. */
288
 
 
289
287
static int rr_quick(READ_RECORD *info)
290
288
{
291
289
  int tmp;
306
304
  return tmp;
307
305
}
308
306
 
309
 
 
310
307
/**
311
308
  Reads first row in an index scan.
312
309
 
319
316
  @retval
320
317
    1   Error
321
318
*/
322
 
 
323
319
static int rr_index_first(READ_RECORD *info)
324
320
{
325
321
  int tmp= info->file->index_first(info->record);
329
325
  return tmp;
330
326
}
331
327
 
332
 
 
333
328
/**
334
329
  Reads index sequentially after first row.
335
330
 
345
340
  @retval
346
341
    1   Error
347
342
*/
348
 
 
349
343
static int rr_index(READ_RECORD *info)
350
344
{
351
345
  int tmp= info->file->index_next(info->record);
354
348
  return tmp;
355
349
}
356
350
 
357
 
 
358
351
int rr_sequential(READ_RECORD *info)
359
352
{
360
353
  int tmp;
380
373
  return tmp;
381
374
}
382
375
 
383
 
 
384
376
static int rr_from_tempfile(READ_RECORD *info)
385
377
{
386
378
  int tmp;
400
392
  return tmp;
401
393
} /* rr_from_tempfile */
402
394
 
403
 
 
404
395
/**
405
396
  Read a result set record from a temporary file after sorting.
406
397
 
416
407
  @retval
417
408
    -1   There is no record to be read anymore.
418
409
*/
419
 
 
420
410
static int rr_unpack_from_tempfile(READ_RECORD *info)
421
411
{
422
412
  if (my_b_read(info->io_cache, info->rec_buf, info->ref_length))
467
457
  @retval
468
458
    -1   There is no record to be read anymore.
469
459
*/
470
 
 
471
460
static int rr_unpack_from_buffer(READ_RECORD *info)
472
461
{
473
462
  if (info->cache_pos == info->cache_end)
478
467
 
479
468
  return 0;
480
469
}
481
 
        /* cacheing of records from a database */
482
470
 
 
471
/* cacheing of records from a database */
483
472
static int init_rr_cache(Session *session, READ_RECORD *info)
484
473
{
485
474
  uint32_t rec_cache_size;
510
499
  return(0);
511
500
} /* init_rr_cache */
512
501
 
513
 
 
514
502
static int rr_from_cache(READ_RECORD *info)
515
503
{
516
504
  register uint32_t i;
526
514
    {
527
515
      if (info->cache_pos[info->error_offset])
528
516
      {
529
 
        shortget(error,info->cache_pos);
530
 
        if (info->print_error)
531
 
          info->table->file->print_error(error,MYF(0));
 
517
        shortget(error,info->cache_pos);
 
518
        if (info->print_error)
 
519
          info->table->file->print_error(error,MYF(0));
532
520
      }
533
521
      else
534
522
      {
535
 
        error=0;
536
 
        memcpy(info->record,info->cache_pos,
537
 
               (size_t) info->table->s->reclength);
 
523
        error=0;
 
524
        memcpy(info->record,info->cache_pos, (size_t) info->table->s->reclength);
538
525
      }
539
526
      info->cache_pos+=info->reclength;
540
527
      return ((int) error);
571
558
      record_pos=info->cache+record*info->reclength;
572
559
      if ((error=(int16_t) info->file->rnd_pos(record_pos,info->ref_pos)))
573
560
      {
574
 
        record_pos[info->error_offset]=1;
575
 
        shortstore(record_pos,error);
 
561
        record_pos[info->error_offset]=1;
 
562
        shortstore(record_pos,error);
576
563
      }
577
564
      else
578
 
        record_pos[info->error_offset]=0;
 
565
        record_pos[info->error_offset]=0;
579
566
    }
580
567
    info->cache_end=(info->cache_pos=info->cache)+length*info->reclength;
581
568
  }
582
569
} /* rr_from_cache */
583
570
 
584
 
 
585
571
static int rr_cmp(unsigned char *a,unsigned char *b)
586
572
{
587
573
  if (a[0] != b[0])