34
int rr_sequential(READ_RECORD *info);
35
static int rr_quick(READ_RECORD *info);
36
static int rr_from_tempfile(READ_RECORD *info);
37
static int rr_unpack_from_tempfile(READ_RECORD *info);
38
static int rr_unpack_from_buffer(READ_RECORD *info);
39
static int rr_from_pointers(READ_RECORD *info);
40
static int rr_from_cache(READ_RECORD *info);
41
static int init_rr_cache(Session *session, READ_RECORD *info);
34
int rr_sequential(ReadRecord *info);
35
static int rr_quick(ReadRecord *info);
36
static int rr_from_tempfile(ReadRecord *info);
37
static int rr_unpack_from_tempfile(ReadRecord *info);
38
static int rr_unpack_from_buffer(ReadRecord *info);
39
static int rr_from_pointers(ReadRecord *info);
40
static int rr_from_cache(ReadRecord *info);
41
static int init_rr_cache(Session *session, ReadRecord *info);
42
42
static int rr_cmp(unsigned char *a,unsigned char *b);
43
static int rr_index_first(READ_RECORD *info);
44
static int rr_index(READ_RECORD *info);
43
static int rr_index_first(ReadRecord *info);
44
static int rr_index(ReadRecord *info);
46
void init_read_record_idx(READ_RECORD *info,
46
void init_read_record_idx(ReadRecord *info,
67
void init_read_record(READ_RECORD *info,
70
optimizer::SqlSelect *select,
67
void ReadRecord::init_read_record(Session *session_arg,
69
optimizer::SqlSelect *select_arg,
74
73
internal::IO_CACHE *tempfile;
76
memset(info, 0, sizeof(*info));
77
info->session=session;
79
info->cursor= table->cursor;
80
info->forms= &info->table; /* Only one table */
75
memset(this, 0, sizeof(*this));
78
cursor= table->cursor;
79
forms= &table; /* Only one table */
82
81
if (table->sort.addon_field)
84
info->rec_buf= table->sort.addon_buf;
85
info->ref_length= table->sort.addon_length;
83
rec_buf= table->sort.addon_buf;
84
ref_length= table->sort.addon_length;
89
88
table->emptyRecord();
90
info->record= table->record[0];
91
info->ref_length= table->cursor->ref_length;
89
record= table->record[0];
90
ref_length= table->cursor->ref_length;
94
info->print_error= print_error;
95
info->ignore_not_found_rows= 0;
93
print_error= print_error_arg;
94
ignore_not_found_rows= 0;
96
95
table->status=0; /* And it's always found */
98
97
if (select && my_b_inited(select->file))
99
99
tempfile= select->file;
101
103
tempfile= table->sort.io_cache;
102
106
if (tempfile && my_b_inited(tempfile)) // Test if ref-records was used
104
info->read_record= (table->sort.addon_field ?
108
read_record= (table->sort.addon_field ?
105
109
rr_unpack_from_tempfile : rr_from_tempfile);
106
info->io_cache=tempfile;
107
reinit_io_cache(info->io_cache,internal::READ_CACHE,0L,0,0);
108
info->ref_pos=table->cursor->ref;
111
reinit_io_cache(io_cache,internal::READ_CACHE,0L,0,0);
112
ref_pos=table->cursor->ref;
109
113
if (!table->cursor->inited)
110
114
table->cursor->startTableScan(0);
122
126
(uint64_t) table->s->reclength* (table->cursor->stats.records+
123
127
table->cursor->stats.deleted) >
124
128
(uint64_t) MIN_FILE_LENGTH_TO_USE_ROW_CACHE &&
125
info->io_cache->end_of_file/info->ref_length * table->s->reclength >
129
io_cache->end_of_file/ref_length * table->s->reclength >
126
130
(internal::my_off_t) MIN_ROWS_TO_USE_TABLE_CACHE &&
127
131
!table->s->blob_fields &&
128
info->ref_length <= MAX_REFLENGTH)
132
ref_length <= MAX_REFLENGTH)
130
if (! init_rr_cache(session, info))
134
if (! init_rr_cache(session, this))
132
info->read_record=rr_from_cache;
136
read_record=rr_from_cache;
136
140
else if (select && select->quick)
138
info->read_record=rr_quick;
142
read_record=rr_quick;
140
144
else if (table->sort.record_pointers)
142
146
table->cursor->startTableScan(0);
143
info->cache_pos=table->sort.record_pointers;
144
info->cache_end=info->cache_pos+
145
table->sort.found_records*info->ref_length;
146
info->read_record= (table->sort.addon_field ?
147
rr_unpack_from_buffer : rr_from_pointers);
147
cache_pos=table->sort.record_pointers;
148
cache_end= cache_pos+ table->sort.found_records * ref_length;
149
read_record= (table->sort.addon_field ? rr_unpack_from_buffer : rr_from_pointers);
151
info->read_record= rr_sequential;
153
read_record= rr_sequential;
152
154
table->cursor->startTableScan(1);
153
155
/* We can use record cache if we don't update dynamic length tables */
154
156
if (!table->no_cache &&
162
164
} /* init_read_record */
165
void end_read_record(READ_RECORD *info)
167
void ReadRecord::end_read_record()
166
168
{ /* free cache if used */
169
free((char*) info->cache);
174
info->table->filesort_free_buffers();
175
(void) info->cursor->extra(HA_EXTRA_NO_CACHE);
176
if (info->read_record != rr_quick) // otherwise quick_range does it
177
(void) info->cursor->ha_index_or_rnd_end();
176
table->filesort_free_buffers();
177
(void) cursor->extra(HA_EXTRA_NO_CACHE);
178
if (read_record != rr_quick) // otherwise quick_range does it
179
(void) cursor->ha_index_or_rnd_end();
182
static int rr_handle_error(READ_RECORD *info, int error)
185
static int rr_handle_error(ReadRecord *info, int error)
184
187
if (error == HA_ERR_END_OF_FILE)