12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
20
20
Functions for easy reading of records, possible through a cache
22
22
#include "config.h"
24
#include "drizzled/drizzled.h"
25
23
#include "drizzled/error.h"
24
#include "drizzled/table.h"
25
#include "drizzled/session.h"
26
#include "drizzled/records.h"
27
#include "drizzled/optimizer/range.h"
28
#include "drizzled/internal/my_sys.h"
26
29
#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"
50
47
read_record= rr_sequential;
53
int ReadRecord::init_read_record_idx(Session *,
50
void ReadRecord::init_read_record_idx(Session *,
58
55
table_arg->emptyRecord();
56
memset(this, 0, sizeof(*this));
60
58
cursor= table->cursor;
61
record= table->getInsertRecord();
59
record= table->record[0];
62
60
print_error= print_error_arg;
64
62
table->status=0; /* And it's always found */
65
63
if (not table->cursor->inited)
67
int error= table->cursor->startIndexScan(idx, 1);
64
table->cursor->startIndexScan(idx, 1);
71
65
/* read_record will be changed to rr_index in rr_index_first */
72
66
read_record= rr_index_first;
78
int ReadRecord::init_read_record(Session *session_arg,
80
optimizer::SqlSelect *select_arg,
70
void ReadRecord::init_read_record(Session *session_arg,
72
optimizer::SqlSelect *select_arg,
84
76
internal::IO_CACHE *tempfile;
78
memset(this, 0, sizeof(*this));
87
79
session= session_arg;
89
81
cursor= table->cursor;
120
112
rr_unpack_from_tempfile : rr_from_tempfile);
122
114
io_cache=tempfile;
123
io_cache->reinit_io_cache(internal::READ_CACHE,0L,0,0);
115
reinit_io_cache(io_cache,internal::READ_CACHE,0L,0,0);
124
116
ref_pos=table->cursor->ref;
125
117
if (!table->cursor->inited)
127
error= table->cursor->startTableScan(0);
118
table->cursor->startTableScan(0);
133
121
table->sort.addon_field is checked because if we use addon fields,
160
148
else if (table->sort.record_pointers)
162
error= table->cursor->startTableScan(0);
150
table->cursor->startTableScan(0);
166
151
cache_pos=table->sort.record_pointers;
167
152
cache_end= cache_pos+ table->sort.found_records * ref_length;
168
153
read_record= (table->sort.addon_field ? rr_unpack_from_buffer : rr_from_pointers);
228
209
while ((tmp= info->select->quick->get_next()))
230
if (info->session->getKilled())
211
if (info->session->killed)
232
213
my_error(ER_SERVER_SHUTDOWN, MYF(0));
423
404
local_rec_cache_size= cache_records * reclength;
424
405
rec_cache_size= cache_records * ref_length;
426
if (not global_read_rnd_buffer.add(session->variables.read_rnd_buff_size))
428
my_error(ER_OUT_OF_GLOBAL_READRNDMEMORY, MYF(ME_ERROR+ME_WAITTANG));
432
407
// We have to allocate one more byte to use uint3korr (see comments for it)
433
408
if (cache_records <= 2 ||
434
409
!(cache=(unsigned char*) malloc(local_rec_cache_size + cache_records * struct_length + 1)))
439
414
// Avoid warnings in qsort
440
415
memset(cache, 0, local_rec_cache_size + cache_records * struct_length + 1);
486
462
length/=info->ref_length;
487
463
position=info->getCache();
488
464
ref_position=info->read_positions;
489
for (uint32_t i= 0 ; i < length ; i++,position+=info->ref_length)
465
for (i=0 ; i < length ; i++,position+=info->ref_length)
491
467
memcpy(ref_position,position,(size_t) info->ref_length);
492
468
ref_position+=MAX_REFLENGTH;
497
473
(qsort_cmp) rr_cmp);
499
475
position=info->read_positions;
500
for (uint32_t i= 0 ; i < length ; i++)
476
for (i=0 ; i < length ; i++)
502
478
memcpy(info->ref_pos, position, (size_t)info->ref_length);
503
479
position+=MAX_REFLENGTH;