~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/records.cc

  • Committer: Brian Aker
  • Date: 2008-07-15 06:45:16 UTC
  • Revision ID: brian@tangent.org-20080715064516-fnbq7kowh7w57bxj
Merge Monty's code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
  @brief
21
21
  Functions for easy reading of records, possible through a cache
22
22
*/
23
 
#include <drizzled/server_includes.h>
 
23
 
 
24
#include "mysql_priv.h"
24
25
 
25
26
static int rr_quick(READ_RECORD *info);
26
27
int rr_sequential(READ_RECORD *info);
30
31
static int rr_from_pointers(READ_RECORD *info);
31
32
static int rr_from_cache(READ_RECORD *info);
32
33
static int init_rr_cache(THD *thd, READ_RECORD *info);
33
 
static int rr_cmp(unsigned char *a,unsigned char *b);
 
34
static int rr_cmp(uchar *a,uchar *b);
34
35
static int rr_index_first(READ_RECORD *info);
35
36
static int rr_index(READ_RECORD *info);
36
37
 
52
53
*/
53
54
 
54
55
void init_read_record_idx(READ_RECORD *info,
55
 
                          THD *thd __attribute__((unused)),
56
 
                          Table *table,
57
 
                          bool print_error, uint32_t idx)
 
56
                          THD *thd __attribute__((__unused__)),
 
57
                          TABLE *table,
 
58
                          bool print_error, uint idx)
58
59
{
59
60
  empty_record(table);
60
 
  memset(info, 0, sizeof(*info));
 
61
  bzero((char*) info,sizeof(*info));
61
62
  info->table= table;
62
63
  info->file=  table->file;
63
64
  info->record= table->record[0];
139
140
    This is the most basic access method of a table using rnd_init,
140
141
    rnd_next and rnd_end. No indexes are used.
141
142
*/
142
 
void init_read_record(READ_RECORD *info,THD *thd, Table *table,
 
143
void init_read_record(READ_RECORD *info,THD *thd, TABLE *table,
143
144
                      SQL_SELECT *select,
144
145
                      int use_record_cache, bool print_error)
145
146
{
146
147
  IO_CACHE *tempfile;
147
148
 
148
 
  memset(info, 0, sizeof(*info));
 
149
  bzero((char*) info,sizeof(*info));
149
150
  info->thd=thd;
150
151
  info->table=table;
151
152
  info->file= table->file;
153
154
  
154
155
  if (table->s->tmp_table == NON_TRANSACTIONAL_TMP_TABLE &&
155
156
      !table->sort.addon_field)
156
 
    table->file->extra(HA_EXTRA_MMAP);
 
157
    VOID(table->file->extra(HA_EXTRA_MMAP));
157
158
  
158
159
  if (table->sort.addon_field)
159
160
  {
191
192
      and table->sort.io_cache is read sequentially
192
193
    */
193
194
    if (!table->sort.addon_field &&
 
195
        ! (specialflag & SPECIAL_SAFE_MODE) &&
194
196
        thd->variables.read_rnd_buff_size &&
195
197
        !(table->file->ha_table_flags() & HA_FAST_KEY_READ) &&
196
198
        (table->db_stat & HA_READ_ONLY ||
233
235
         !(table->s->db_options_in_use & HA_OPTION_PACK_RECORD) ||
234
236
         (use_record_cache < 0 &&
235
237
          !(table->file->ha_table_flags() & HA_NOT_DELETE_WITH_CACHE))))
236
 
      table->file->extra_opt(HA_EXTRA_CACHE, thd->variables.read_buff_size);
 
238
      VOID(table->file->extra_opt(HA_EXTRA_CACHE,
 
239
                                  thd->variables.read_buff_size));
237
240
  }
238
241
  /* 
239
242
    Do condition pushdown for UPDATE/DELETE.
255
258
{                   /* free cache if used */
256
259
  if (info->cache)
257
260
  {
258
 
    free((char*) info->cache);
 
261
    my_free_lock((char*) info->cache,MYF(0));
259
262
    info->cache=0;
260
263
  }
261
264
  if (info->table)
301
304
      break;
302
305
    }
303
306
  }
304
 
  update_virtual_fields_marked_for_write(info->table);
305
307
  return tmp;
306
308
}
307
309
 
374
376
      break;
375
377
    }
376
378
  }
377
 
  if (!tmp)
378
 
    update_virtual_fields_marked_for_write(info->table);
379
379
  return tmp;
380
380
}
381
381
 
420
420
{
421
421
  if (my_b_read(info->io_cache, info->rec_buf, info->ref_length))
422
422
    return -1;
423
 
  Table *table= info->table;
 
423
  TABLE *table= info->table;
424
424
  (*table->sort.unpack)(table->sort.addon_field, info->rec_buf);
425
425
 
426
426
  return 0;
429
429
static int rr_from_pointers(READ_RECORD *info)
430
430
{
431
431
  int tmp;
432
 
  unsigned char *cache_pos;
 
432
  uchar *cache_pos;
433
433
 
434
434
  for (;;)
435
435
  {
471
471
{
472
472
  if (info->cache_pos == info->cache_end)
473
473
    return -1;                      /* End of buffer */
474
 
  Table *table= info->table;
 
474
  TABLE *table= info->table;
475
475
  (*table->sort.unpack)(table->sort.addon_field, info->cache_pos);
476
476
  info->cache_pos+= info->ref_length;
477
477
 
481
481
 
482
482
static int init_rr_cache(THD *thd, READ_RECORD *info)
483
483
{
484
 
  uint32_t rec_cache_size;
 
484
  uint rec_cache_size;
485
485
 
486
486
  info->struct_length= 3+MAX_REFLENGTH;
487
487
  info->reclength= ALIGN_SIZE(info->table->s->reclength+1);
496
496
 
497
497
  // We have to allocate one more byte to use uint3korr (see comments for it)
498
498
  if (info->cache_records <= 2 ||
499
 
      !(info->cache=(unsigned char*) my_malloc_lock(rec_cache_size+info->cache_records*
 
499
      !(info->cache=(uchar*) my_malloc_lock(rec_cache_size+info->cache_records*
500
500
                                           info->struct_length+1,
501
501
                                           MYF(0))))
502
502
    return(1);
503
503
#ifdef HAVE_purify
504
504
  // Avoid warnings in qsort
505
 
  memset(info->cache, 0,
506
 
         rec_cache_size+info->cache_records* info->struct_length+1);
 
505
  bzero(info->cache,rec_cache_size+info->cache_records* info->struct_length+1);
507
506
#endif
508
507
  info->read_positions=info->cache+rec_cache_size;
509
508
  info->cache_pos=info->cache_end=info->cache;
513
512
 
514
513
static int rr_from_cache(READ_RECORD *info)
515
514
{
516
 
  register uint32_t i;
517
 
  uint32_t length;
 
515
  register uint i;
 
516
  ulong length;
518
517
  my_off_t rest_of_file;
519
 
  int16_t error;
520
 
  unsigned char *position,*ref_position,*record_pos;
521
 
  uint32_t record;
 
518
  int16 error;
 
519
  uchar *position,*ref_position,*record_pos;
 
520
  ulong record;
522
521
 
523
522
  for (;;)
524
523
  {
542
541
    length=info->rec_cache_size;
543
542
    rest_of_file=info->io_cache->end_of_file - my_b_tell(info->io_cache);
544
543
    if ((my_off_t) length > rest_of_file)
545
 
      length= (uint32_t) rest_of_file;
 
544
      length= (ulong) rest_of_file;
546
545
    if (!length || my_b_read(info->io_cache,info->cache,length))
547
546
    {
548
547
      return -1;                        /* End of file */
569
568
      record=uint3korr(position);
570
569
      position+=3;
571
570
      record_pos=info->cache+record*info->reclength;
572
 
      if ((error=(int16_t) info->file->rnd_pos(record_pos,info->ref_pos)))
 
571
      if ((error=(int16) info->file->rnd_pos(record_pos,info->ref_pos)))
573
572
      {
574
573
        record_pos[info->error_offset]=1;
575
574
        shortstore(record_pos,error);
582
581
} /* rr_from_cache */
583
582
 
584
583
 
585
 
static int rr_cmp(unsigned char *a,unsigned char *b)
 
584
static int rr_cmp(uchar *a,uchar *b)
586
585
{
587
586
  if (a[0] != b[0])
588
587
    return (int) a[0] - (int) b[0];