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