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