~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
/* Copyright (C) 2000-2006 MySQL AB
2
3
   This program is free software; you can redistribute it and/or modify
4
   it under the terms of the GNU General Public License as published by
5
   the Free Software Foundation; version 2 of the License.
6
7
   This program is distributed in the hope that it will be useful,
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
   GNU General Public License for more details.
11
12
   You should have received a copy of the GNU General Public License
13
   along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
1 by brian
clean slate
15
16
/**
17
  @file
18
19
  @brief
20
  Functions for easy reading of records, possible through a cache
21
*/
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
22
#include <config.h>
2148.7.12 by Brian Aker
Merge in header fixes.
23
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
24
#include <drizzled/drizzled.h>
25
#include <drizzled/error.h>
26
#include <drizzled/internal/iocache.h>
27
#include <drizzled/internal/my_sys.h>
28
#include <drizzled/optimizer/range.h>
29
#include <drizzled/plugin/storage_engine.h>
30
#include <drizzled/records.h>
31
#include <drizzled/session.h>
32
#include <drizzled/table.h>
2241.3.2 by Olaf van der Spek
Refactor Session::variables
33
#include <drizzled/system_variables.h>
1237.9.2 by Padraig O'Sullivan
Moved opt_range.[cc,h] into the optimizer directory and namespace and renamed the files to
34
2241.3.2 by Olaf van der Spek
Refactor Session::variables
35
namespace drizzled {
1 by brian
clean slate
36
1578.4.1 by Brian Aker
Static/contain the only function that was seen outside of records.cc
37
static int rr_sequential(ReadRecord *info);
1538 by Brian Aker
Code shuffle on ReadRecord
38
static int rr_quick(ReadRecord *info);
39
static int rr_from_tempfile(ReadRecord *info);
40
static int rr_unpack_from_tempfile(ReadRecord *info);
41
static int rr_unpack_from_buffer(ReadRecord *info);
42
static int rr_from_pointers(ReadRecord *info);
43
static int rr_from_cache(ReadRecord *info);
481 by Brian Aker
Remove all of uchar.
44
static int rr_cmp(unsigned char *a,unsigned char *b);
1538 by Brian Aker
Code shuffle on ReadRecord
45
static int rr_index_first(ReadRecord *info);
46
static int rr_index(ReadRecord *info);
1 by brian
clean slate
47
1578.4.1 by Brian Aker
Static/contain the only function that was seen outside of records.cc
48
void ReadRecord::init_reard_record_sequential()
49
{
50
  read_record= rr_sequential;
51
}
52
2049.2.7 by Stewart Smith
init_read_record_idx return result should be checked now that it checks startIndexScan result.
53
int ReadRecord::init_read_record_idx(Session *,
54
                                     Table *table_arg,
55
                                     bool print_error_arg,
56
                                     uint32_t idx)
1 by brian
clean slate
57
{
1539.1.3 by Brian Aker
Additional function -> method for readrecord
58
  table_arg->emptyRecord();
59
  table= table_arg;
60
  cursor=  table->cursor;
1672.3.6 by Brian Aker
First pass in encapsulating row
61
  record= table->getInsertRecord();
1539.1.3 by Brian Aker
Additional function -> method for readrecord
62
  print_error= print_error_arg;
1 by brian
clean slate
63
64
  table->status=0;			/* And it's always found */
1539.1.3 by Brian Aker
Additional function -> method for readrecord
65
  if (not table->cursor->inited)
2049.2.7 by Stewart Smith
init_read_record_idx return result should be checked now that it checks startIndexScan result.
66
  {
67
    int error= table->cursor->startIndexScan(idx, 1);
68
    if (error != 0)
69
      return error;
70
  }
1 by brian
clean slate
71
  /* read_record will be changed to rr_index in rr_index_first */
1539.1.3 by Brian Aker
Additional function -> method for readrecord
72
  read_record= rr_index_first;
2049.2.7 by Stewart Smith
init_read_record_idx return result should be checked now that it checks startIndexScan result.
73
74
  return 0;
1 by brian
clean slate
75
}
76
1237.9.4 by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file.
77
2049.2.1 by Stewart Smith
doStartTableScan() result not checked.
78
int ReadRecord::init_read_record(Session *session_arg,
79
                                 Table *table_arg,
80
                                 optimizer::SqlSelect *select_arg,
81
                                 int use_record_cache,
82
                                 bool print_error_arg)
1 by brian
clean slate
83
{
2296.1.1 by Mark Atwood
Merge in Fixes of Brian's IOCACHE.
84
  internal::io_cache_st *tempfile;
2049.2.1 by Stewart Smith
doStartTableScan() result not checked.
85
  int error= 0;
1 by brian
clean slate
86
1538 by Brian Aker
Code shuffle on ReadRecord
87
  session= session_arg;
88
  table= table_arg;
89
  cursor= table->cursor;
90
  forms= &table;		/* Only one table */
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
91
1 by brian
clean slate
92
  if (table->sort.addon_field)
93
  {
1538 by Brian Aker
Code shuffle on ReadRecord
94
    rec_buf= table->sort.addon_buf;
95
    ref_length= table->sort.addon_length;
1 by brian
clean slate
96
  }
97
  else
98
  {
997.5.1 by chris
Replace macros around unireg.h, store_record,restore_record,cmp_record,empty_record
99
    table->emptyRecord();
1672.3.6 by Brian Aker
First pass in encapsulating row
100
    record= table->getInsertRecord();
1538 by Brian Aker
Code shuffle on ReadRecord
101
    ref_length= table->cursor->ref_length;
1 by brian
clean slate
102
  }
1538 by Brian Aker
Code shuffle on ReadRecord
103
  select= select_arg;
104
  print_error= print_error_arg;
105
  ignore_not_found_rows= 0;
1 by brian
clean slate
106
  table->status=0;			/* And it's always found */
107
2385.3.10 by Olaf van der Spek
Refactor iocache
108
  if (select && select->file->inited())
1538 by Brian Aker
Code shuffle on ReadRecord
109
  {
1241.9.48 by Monty Taylor
Made one of the drizzled instances of IO_CACHE a pointer.
110
    tempfile= select->file;
1538 by Brian Aker
Code shuffle on ReadRecord
111
  }
1 by brian
clean slate
112
  else
1538 by Brian Aker
Code shuffle on ReadRecord
113
  {
1 by brian
clean slate
114
    tempfile= table->sort.io_cache;
1538 by Brian Aker
Code shuffle on ReadRecord
115
  }
116
2385.3.10 by Olaf van der Spek
Refactor iocache
117
  if (tempfile && tempfile->inited()) // Test if ref-records was used
1 by brian
clean slate
118
  {
2385.3.10 by Olaf van der Spek
Refactor iocache
119
    read_record= table->sort.addon_field ? rr_unpack_from_tempfile : rr_from_tempfile;
1578.4.7 by Brian Aker
Small syntax update.
120
1538 by Brian Aker
Code shuffle on ReadRecord
121
    io_cache=tempfile;
1909.1.1 by Brian Aker
Encapsulation of IO_CACHE.
122
    io_cache->reinit_io_cache(internal::READ_CACHE,0L,0,0);
1538 by Brian Aker
Code shuffle on ReadRecord
123
    ref_pos=table->cursor->ref;
1208.3.2 by brian
Update for Cursor renaming.
124
    if (!table->cursor->inited)
2049.2.1 by Stewart Smith
doStartTableScan() result not checked.
125
    {
126
      error= table->cursor->startTableScan(0);
127
      if (error != 0)
128
        return error;
129
    }
1 by brian
clean slate
130
131
    /*
132
      table->sort.addon_field is checked because if we use addon fields,
133
      it doesn't make sense to use cache - we don't read from the table
134
      and table->sort.io_cache is read sequentially
135
    */
136
    if (!table->sort.addon_field &&
1039.2.8 by Jay Pipes
Yet more indentation and style cleanup
137
        session->variables.read_rnd_buff_size &&
1233.1.5 by Brian Aker
More table_flags converted.
138
        !(table->cursor->getEngine()->check_flag(HTON_BIT_FAST_KEY_READ)) &&
1039.2.8 by Jay Pipes
Yet more indentation and style cleanup
139
        (table->db_stat & HA_READ_ONLY ||
140
        table->reginfo.lock_type <= TL_READ_NO_INSERT) &&
1578.2.8 by Brian Aker
Encapsulate record length.
141
        (uint64_t) table->getShare()->getRecordLength() * (table->cursor->stats.records+
1208.3.2 by brian
Update for Cursor renaming.
142
                                                table->cursor->stats.deleted) >
1039.2.8 by Jay Pipes
Yet more indentation and style cleanup
143
        (uint64_t) MIN_FILE_LENGTH_TO_USE_ROW_CACHE &&
1578.2.8 by Brian Aker
Encapsulate record length.
144
        io_cache->end_of_file/ref_length * table->getShare()->getRecordLength() >
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
145
        (internal::my_off_t) MIN_ROWS_TO_USE_TABLE_CACHE &&
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
146
        !table->getShare()->blob_fields &&
1538 by Brian Aker
Code shuffle on ReadRecord
147
        ref_length <= MAX_REFLENGTH)
1 by brian
clean slate
148
    {
1539.1.4 by Brian Aker
More RR encapsulation.
149
      if (init_rr_cache())
1 by brian
clean slate
150
      {
1578.4.7 by Brian Aker
Small syntax update.
151
        read_record= rr_from_cache;
1 by brian
clean slate
152
      }
153
    }
154
  }
155
  else if (select && select->quick)
156
  {
1578.4.7 by Brian Aker
Small syntax update.
157
    read_record= rr_quick;
1 by brian
clean slate
158
  }
159
  else if (table->sort.record_pointers)
160
  {
2049.2.1 by Stewart Smith
doStartTableScan() result not checked.
161
    error= table->cursor->startTableScan(0);
162
    if (error != 0)
163
      return error;
164
1538 by Brian Aker
Code shuffle on ReadRecord
165
    cache_pos=table->sort.record_pointers;
166
    cache_end= cache_pos+ table->sort.found_records * ref_length;
167
    read_record= (table->sort.addon_field ?  rr_unpack_from_buffer : rr_from_pointers);
1 by brian
clean slate
168
  }
169
  else
170
  {
1538 by Brian Aker
Code shuffle on ReadRecord
171
    read_record= rr_sequential;
2049.2.1 by Stewart Smith
doStartTableScan() result not checked.
172
    error= table->cursor->startTableScan(1);
173
    if (error != 0)
174
      return error;
175
1 by brian
clean slate
176
    /* We can use record cache if we don't update dynamic length tables */
177
    if (!table->no_cache &&
1039.2.8 by Jay Pipes
Yet more indentation and style cleanup
178
        (use_record_cache > 0 ||
179
        (int) table->reginfo.lock_type <= (int) TL_READ_WITH_SHARED_LOCKS ||
1532.1.15 by Brian Aker
Partial encapsulation of TableShare from Table.
180
        !(table->getShare()->db_options_in_use & HA_OPTION_PACK_RECORD)))
1578.4.7 by Brian Aker
Small syntax update.
181
    {
1208.3.2 by brian
Update for Cursor renaming.
182
      table->cursor->extra_opt(HA_EXTRA_CACHE, session->variables.read_buff_size);
1578.4.7 by Brian Aker
Small syntax update.
183
    }
1 by brian
clean slate
184
  }
185
2049.2.1 by Stewart Smith
doStartTableScan() result not checked.
186
  return 0;
1 by brian
clean slate
187
} /* init_read_record */
188
1237.9.4 by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file.
189
1538 by Brian Aker
Code shuffle on ReadRecord
190
void ReadRecord::end_read_record()
1 by brian
clean slate
191
{                   /* free cache if used */
1578.4.13 by Brian Aker
Revert records
192
  if (cache)
193
  {
1796.4.10 by Andrew Hutchings
Add global constraint for --read-rnd-buffer-size
194
    global_read_rnd_buffer.sub(session->variables.read_rnd_buff_size);
1578.4.13 by Brian Aker
Revert records
195
    free((char*) cache);
196
    cache= NULL;
197
  }
1538 by Brian Aker
Code shuffle on ReadRecord
198
  if (table)
1 by brian
clean slate
199
  {
1538 by Brian Aker
Code shuffle on ReadRecord
200
    table->filesort_free_buffers();
201
    (void) cursor->extra(HA_EXTRA_NO_CACHE);
202
    if (read_record != rr_quick) // otherwise quick_range does it
203
      (void) cursor->ha_index_or_rnd_end();
204
205
    table= NULL;
1 by brian
clean slate
206
  }
207
}
208
1538 by Brian Aker
Code shuffle on ReadRecord
209
static int rr_handle_error(ReadRecord *info, int error)
1 by brian
clean slate
210
{
211
  if (error == HA_ERR_END_OF_FILE)
212
    error= -1;
213
  else
214
  {
215
    if (info->print_error)
1216.1.1 by Brian Aker
Move print_error up to Engine.
216
      info->table->print_error(error, MYF(0));
1 by brian
clean slate
217
    if (error < 0)                            // Fix negative BDB errno
218
      error= 1;
219
  }
220
  return error;
221
}
222
223
/** Read a record from head-database. */
1538 by Brian Aker
Code shuffle on ReadRecord
224
static int rr_quick(ReadRecord *info)
1 by brian
clean slate
225
{
226
  int tmp;
227
  while ((tmp= info->select->quick->get_next()))
228
  {
1910.2.8 by Brian Aker
Enapsulate Kill.
229
    if (info->session->getKilled())
1 by brian
clean slate
230
    {
231
      my_error(ER_SERVER_SHUTDOWN, MYF(0));
232
      return 1;
233
    }
234
    if (tmp != HA_ERR_RECORD_DELETED)
235
    {
236
      tmp= rr_handle_error(info, tmp);
237
      break;
238
    }
239
  }
998.1.2 by Brian Aker
First pass on removing virt columns
240
1 by brian
clean slate
241
  return tmp;
242
}
243
244
/**
245
  Reads first row in an index scan.
246
247
  @param info  	Scan info
248
249
  @retval
250
    0   Ok
251
  @retval
252
    -1   End of records
253
  @retval
254
    1   Error
255
*/
1538 by Brian Aker
Code shuffle on ReadRecord
256
static int rr_index_first(ReadRecord *info)
1 by brian
clean slate
257
{
1208.3.2 by brian
Update for Cursor renaming.
258
  int tmp= info->cursor->index_first(info->record);
1 by brian
clean slate
259
  info->read_record= rr_index;
260
  if (tmp)
261
    tmp= rr_handle_error(info, tmp);
262
  return tmp;
263
}
264
265
/**
266
  Reads index sequentially after first row.
267
268
  Read the next index record (in forward direction) and translate return
269
  value.
270
271
  @param info  Scan info
272
273
  @retval
274
    0   Ok
275
  @retval
276
    -1   End of records
277
  @retval
278
    1   Error
279
*/
1538 by Brian Aker
Code shuffle on ReadRecord
280
static int rr_index(ReadRecord *info)
1 by brian
clean slate
281
{
1208.3.2 by brian
Update for Cursor renaming.
282
  int tmp= info->cursor->index_next(info->record);
1 by brian
clean slate
283
  if (tmp)
284
    tmp= rr_handle_error(info, tmp);
285
  return tmp;
286
}
287
1538 by Brian Aker
Code shuffle on ReadRecord
288
int rr_sequential(ReadRecord *info)
1 by brian
clean slate
289
{
290
  int tmp;
1208.3.2 by brian
Update for Cursor renaming.
291
  while ((tmp= info->cursor->rnd_next(info->record)))
1 by brian
clean slate
292
  {
1910.2.8 by Brian Aker
Enapsulate Kill.
293
    if (info->session->getKilled())
1 by brian
clean slate
294
    {
520.1.22 by Brian Aker
Second pass of thd cleanup
295
      info->session->send_kill_message();
1 by brian
clean slate
296
      return 1;
297
    }
298
    /*
822 by Brian Aker
Merge from Stewart.
299
      TODO> Fix this so that engine knows how to behave on its own.
1 by brian
clean slate
300
      rnd_next can return RECORD_DELETED for MyISAM when one thread is
301
      reading and another deleting without locks.
302
    */
303
    if (tmp != HA_ERR_RECORD_DELETED)
304
    {
305
      tmp= rr_handle_error(info, tmp);
306
      break;
307
    }
308
  }
998.1.2 by Brian Aker
First pass on removing virt columns
309
1 by brian
clean slate
310
  return tmp;
311
}
312
1538 by Brian Aker
Code shuffle on ReadRecord
313
static int rr_from_tempfile(ReadRecord *info)
1 by brian
clean slate
314
{
315
  int tmp;
316
  for (;;)
317
  {
2385.3.13 by Olaf van der Spek
Refactor iocache
318
    if (info->io_cache->read(info->ref_pos, info->ref_length))
1208.3.2 by brian
Update for Cursor renaming.
319
      return -1;					/* End of cursor */
320
    if (!(tmp=info->cursor->rnd_pos(info->record,info->ref_pos)))
1 by brian
clean slate
321
      break;
322
    /* The following is extremely unlikely to happen */
323
    if (tmp == HA_ERR_RECORD_DELETED ||
324
        (tmp == HA_ERR_KEY_NOT_FOUND && info->ignore_not_found_rows))
325
      continue;
326
    tmp= rr_handle_error(info, tmp);
327
    break;
328
  }
329
  return tmp;
330
} /* rr_from_tempfile */
331
332
/**
1208.3.2 by brian
Update for Cursor renaming.
333
  Read a result set record from a temporary cursor after sorting.
1 by brian
clean slate
334
1208.3.2 by brian
Update for Cursor renaming.
335
  The function first reads the next sorted record from the temporary cursor.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
336
  into a buffer. If a success it calls a callback function that unpacks
1 by brian
clean slate
337
  the fields values use in the result set from this buffer into their
338
  positions in the regular record buffer.
339
340
  @param info          Reference to the context including record descriptors
341
342
  @retval
343
    0   Record successfully read.
344
  @retval
345
    -1   There is no record to be read anymore.
346
*/
1538 by Brian Aker
Code shuffle on ReadRecord
347
static int rr_unpack_from_tempfile(ReadRecord *info)
1 by brian
clean slate
348
{
2385.3.13 by Olaf van der Spek
Refactor iocache
349
  if (info->io_cache->read(info->rec_buf, info->ref_length))
1 by brian
clean slate
350
    return -1;
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
351
  Table *table= info->table;
1 by brian
clean slate
352
  (*table->sort.unpack)(table->sort.addon_field, info->rec_buf);
353
354
  return 0;
355
}
356
1538 by Brian Aker
Code shuffle on ReadRecord
357
static int rr_from_pointers(ReadRecord *info)
1 by brian
clean slate
358
{
359
  int tmp;
481 by Brian Aker
Remove all of uchar.
360
  unsigned char *cache_pos;
1 by brian
clean slate
361
1578.4.7 by Brian Aker
Small syntax update.
362
1 by brian
clean slate
363
  for (;;)
364
  {
365
    if (info->cache_pos == info->cache_end)
1208.3.2 by brian
Update for Cursor renaming.
366
      return -1;					/* End of cursor */
1 by brian
clean slate
367
    cache_pos= info->cache_pos;
368
    info->cache_pos+= info->ref_length;
369
1208.3.2 by brian
Update for Cursor renaming.
370
    if (!(tmp=info->cursor->rnd_pos(info->record,cache_pos)))
1 by brian
clean slate
371
      break;
372
373
    /* The following is extremely unlikely to happen */
374
    if (tmp == HA_ERR_RECORD_DELETED ||
375
        (tmp == HA_ERR_KEY_NOT_FOUND && info->ignore_not_found_rows))
376
      continue;
377
    tmp= rr_handle_error(info, tmp);
378
    break;
379
  }
380
  return tmp;
381
}
382
383
/**
384
  Read a result set record from a buffer after sorting.
385
386
  The function first reads the next sorted record from the sort buffer.
660.1.3 by Eric Herman
removed trailing whitespace with simple script:
387
  If a success it calls a callback function that unpacks
1 by brian
clean slate
388
  the fields values use in the result set from this buffer into their
389
  positions in the regular record buffer.
390
391
  @param info          Reference to the context including record descriptors
392
393
  @retval
394
    0   Record successfully read.
395
  @retval
396
    -1   There is no record to be read anymore.
397
*/
1538 by Brian Aker
Code shuffle on ReadRecord
398
static int rr_unpack_from_buffer(ReadRecord *info)
1 by brian
clean slate
399
{
400
  if (info->cache_pos == info->cache_end)
401
    return -1;                      /* End of buffer */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
402
  Table *table= info->table;
1 by brian
clean slate
403
  (*table->sort.unpack)(table->sort.addon_field, info->cache_pos);
404
  info->cache_pos+= info->ref_length;
405
406
  return 0;
407
}
408
1039.2.8 by Jay Pipes
Yet more indentation and style cleanup
409
/* cacheing of records from a database */
1539.1.4 by Brian Aker
More RR encapsulation.
410
bool ReadRecord::init_rr_cache()
1 by brian
clean slate
411
{
1539.1.4 by Brian Aker
More RR encapsulation.
412
  uint32_t local_rec_cache_size;
413
414
  struct_length= 3 + MAX_REFLENGTH;
1578.2.8 by Brian Aker
Encapsulate record length.
415
  reclength= ALIGN_SIZE(table->getShare()->getRecordLength() + 1);
1539.1.4 by Brian Aker
More RR encapsulation.
416
  if (reclength < struct_length)
417
    reclength= ALIGN_SIZE(struct_length);
418
1578.2.8 by Brian Aker
Encapsulate record length.
419
  error_offset= table->getShare()->getRecordLength();
1539.1.4 by Brian Aker
More RR encapsulation.
420
  cache_records= (session->variables.read_rnd_buff_size /
1578.2.8 by Brian Aker
Encapsulate record length.
421
                        (reclength + struct_length));
1539.1.4 by Brian Aker
More RR encapsulation.
422
  local_rec_cache_size= cache_records * reclength;
423
  rec_cache_size= cache_records * ref_length;
1 by brian
clean slate
424
1796.4.10 by Andrew Hutchings
Add global constraint for --read-rnd-buffer-size
425
  if (not global_read_rnd_buffer.add(session->variables.read_rnd_buff_size))
426
  {
427
    my_error(ER_OUT_OF_GLOBAL_READRNDMEMORY, MYF(ME_ERROR+ME_WAITTANG));
428
    return false;
429
  }
430
1 by brian
clean slate
431
  // We have to allocate one more byte to use uint3korr (see comments for it)
2318.4.8 by Olaf van der Spek
Remove malloc NULL check. Just die.
432
  if (cache_records <= 2)
1539.1.4 by Brian Aker
More RR encapsulation.
433
    return false;
2318.4.8 by Olaf van der Spek
Remove malloc NULL check. Just die.
434
  cache= (unsigned char*) malloc(local_rec_cache_size + cache_records * struct_length + 1);
1859.2.14 by Brian Aker
Add support for --with-valgrind
435
#ifdef HAVE_VALGRIND
1578.4.13 by Brian Aker
Revert records
436
  // Avoid warnings in qsort
437
  memset(cache, 0, local_rec_cache_size + cache_records * struct_length + 1);
438
#endif
439
  read_positions= cache + local_rec_cache_size;
440
  cache_pos= cache_end= cache;
1539.1.4 by Brian Aker
More RR encapsulation.
441
442
  return true;
1 by brian
clean slate
443
} /* init_rr_cache */
444
1538 by Brian Aker
Code shuffle on ReadRecord
445
static int rr_from_cache(ReadRecord *info)
1 by brian
clean slate
446
{
308 by Brian Aker
ulong conversion
447
  uint32_t length;
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
448
  internal::my_off_t rest_of_file;
206 by Brian Aker
Removed final uint dead types.
449
  int16_t error;
481 by Brian Aker
Remove all of uchar.
450
  unsigned char *position,*ref_position,*record_pos;
308 by Brian Aker
ulong conversion
451
  uint32_t record;
1 by brian
clean slate
452
453
  for (;;)
454
  {
455
    if (info->cache_pos != info->cache_end)
456
    {
457
      if (info->cache_pos[info->error_offset])
458
      {
1039.2.8 by Jay Pipes
Yet more indentation and style cleanup
459
        shortget(error,info->cache_pos);
460
        if (info->print_error)
1216.1.1 by Brian Aker
Move print_error up to Engine.
461
          info->table->print_error(error,MYF(0));
1 by brian
clean slate
462
      }
463
      else
464
      {
1039.2.8 by Jay Pipes
Yet more indentation and style cleanup
465
        error=0;
1578.2.8 by Brian Aker
Encapsulate record length.
466
        memcpy(info->record,info->cache_pos, (size_t) info->table->getShare()->getRecordLength());
1 by brian
clean slate
467
      }
1578.2.8 by Brian Aker
Encapsulate record length.
468
      info->cache_pos+= info->reclength;
1 by brian
clean slate
469
      return ((int) error);
470
    }
471
    length=info->rec_cache_size;
2385.3.12 by Olaf van der Spek
Refactor iocache
472
    rest_of_file= info->io_cache->end_of_file - info->io_cache->tell();
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
473
    if ((internal::my_off_t) length > rest_of_file)
1578.4.7 by Brian Aker
Small syntax update.
474
    {
308 by Brian Aker
ulong conversion
475
      length= (uint32_t) rest_of_file;
1578.4.7 by Brian Aker
Small syntax update.
476
    }
477
2385.3.13 by Olaf van der Spek
Refactor iocache
478
    if (!length || info->io_cache->read(info->getCache(), length))
1 by brian
clean slate
479
    {
1208.3.2 by brian
Update for Cursor renaming.
480
      return -1;			/* End of cursor */
1 by brian
clean slate
481
    }
482
483
    length/=info->ref_length;
1578.4.6 by Brian Aker
Modify cache to be a vector.
484
    position=info->getCache();
1 by brian
clean slate
485
    ref_position=info->read_positions;
1749.3.12 by Brian Aker
Localize increment
486
    for (uint32_t i= 0 ; i < length ; i++,position+=info->ref_length)
1 by brian
clean slate
487
    {
488
      memcpy(ref_position,position,(size_t) info->ref_length);
489
      ref_position+=MAX_REFLENGTH;
490
      int3store(ref_position,(long) i);
491
      ref_position+=3;
492
    }
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
493
    internal::my_qsort(info->read_positions, length, info->struct_length,
494
                       (qsort_cmp) rr_cmp);
1 by brian
clean slate
495
496
    position=info->read_positions;
1749.3.12 by Brian Aker
Localize increment
497
    for (uint32_t i= 0 ; i < length ; i++)
1 by brian
clean slate
498
    {
1578.4.13 by Brian Aker
Revert records
499
      memcpy(info->ref_pos, position, (size_t)info->ref_length);
1 by brian
clean slate
500
      position+=MAX_REFLENGTH;
501
      record=uint3korr(position);
502
      position+=3;
1578.4.13 by Brian Aker
Revert records
503
      record_pos= info->getCache() + record * info->reclength;
1208.3.2 by brian
Update for Cursor renaming.
504
      if ((error=(int16_t) info->cursor->rnd_pos(record_pos,info->ref_pos)))
1 by brian
clean slate
505
      {
1039.2.8 by Jay Pipes
Yet more indentation and style cleanup
506
        record_pos[info->error_offset]=1;
507
        shortstore(record_pos,error);
1 by brian
clean slate
508
      }
509
      else
1039.2.8 by Jay Pipes
Yet more indentation and style cleanup
510
        record_pos[info->error_offset]=0;
1 by brian
clean slate
511
    }
1578.4.7 by Brian Aker
Small syntax update.
512
    info->cache_end= (info->cache_pos= info->getCache())+length*info->reclength;
1 by brian
clean slate
513
  }
514
} /* rr_from_cache */
515
481 by Brian Aker
Remove all of uchar.
516
static int rr_cmp(unsigned char *a,unsigned char *b)
1 by brian
clean slate
517
{
518
  if (a[0] != b[0])
519
    return (int) a[0] - (int) b[0];
520
  if (a[1] != b[1])
521
    return (int) a[1] - (int) b[1];
522
  if (a[2] != b[2])
523
    return (int) a[2] - (int) b[2];
524
#if MAX_REFLENGTH == 4
525
  return (int) a[3] - (int) b[3];
526
#else
527
  if (a[3] != b[3])
528
    return (int) a[3] - (int) b[3];
529
  if (a[4] != b[4])
530
    return (int) a[4] - (int) b[4];
531
  if (a[5] != b[5])
532
    return (int) a[1] - (int) b[5];
533
  if (a[6] != b[6])
534
    return (int) a[6] - (int) b[6];
535
  return (int) a[7] - (int) b[7];
536
#endif
537
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
538
539
} /* namespace drizzled */