1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
1237.9.4
by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file. |
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
3 |
*
|
|
4 |
* Copyright (C) 2009 Sun Microsystems
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
19 |
||
20 |
#ifndef DRIZZLED_RECORDS_H
|
|
21 |
#define DRIZZLED_RECORDS_H
|
|
22 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
23 |
namespace drizzled |
24 |
{
|
|
25 |
||
1539.1.3
by Brian Aker
Additional function -> method for readrecord |
26 |
struct ReadRecord { /* Parameter to read_record */ |
27 |
Table *table; /* Head-form */ |
|
28 |
Cursor *cursor; |
|
29 |
Table **forms; /* head and ref forms */ |
|
30 |
int (*read_record)(ReadRecord *); |
|
31 |
Session *session; |
|
32 |
optimizer::SqlSelect *select; |
|
33 |
uint32_t cache_records; |
|
34 |
uint32_t ref_length; |
|
35 |
uint32_t struct_length; |
|
36 |
uint32_t reclength; |
|
37 |
uint32_t rec_cache_size; |
|
38 |
uint32_t error_offset; |
|
39 |
uint32_t index; |
|
40 |
unsigned char *ref_pos; /* pointer to form->refpos */ |
|
41 |
unsigned char *record; |
|
42 |
unsigned char *rec_buf; /* to read field values after filesort */ |
|
1578.4.6
by Brian Aker
Modify cache to be a vector. |
43 |
private: |
1578.4.13
by Brian Aker
Revert records |
44 |
unsigned char *cache; |
1578.4.6
by Brian Aker
Modify cache to be a vector. |
45 |
public: |
46 |
unsigned char *getCache() |
|
47 |
{
|
|
1578.4.13
by Brian Aker
Revert records |
48 |
return cache; |
1578.4.6
by Brian Aker
Modify cache to be a vector. |
49 |
}
|
1539.1.3
by Brian Aker
Additional function -> method for readrecord |
50 |
unsigned char *cache_pos; |
51 |
unsigned char *cache_end; |
|
52 |
unsigned char *read_positions; |
|
53 |
internal::IO_CACHE *io_cache; |
|
54 |
bool print_error; |
|
55 |
bool ignore_not_found_rows; |
|
56 |
JoinTable *do_insideout_scan; |
|
57 |
ReadRecord() : |
|
58 |
table(NULL), |
|
59 |
cursor(NULL), |
|
60 |
forms(0), |
|
61 |
read_record(0), |
|
62 |
session(0), |
|
63 |
select(0), |
|
64 |
cache_records(0), |
|
65 |
ref_length(0), |
|
66 |
struct_length(0), |
|
67 |
reclength(0), |
|
68 |
rec_cache_size(0), |
|
69 |
error_offset(0), |
|
70 |
index(0), |
|
71 |
ref_pos(0), |
|
72 |
record(0), |
|
73 |
rec_buf(0), |
|
74 |
cache(0), |
|
75 |
cache_pos(0), |
|
76 |
cache_end(0), |
|
77 |
read_positions(0), |
|
78 |
io_cache(0), |
|
79 |
print_error(0), |
|
80 |
ignore_not_found_rows(0), |
|
81 |
do_insideout_scan(0) |
|
82 |
{
|
|
83 |
}
|
|
84 |
||
1711.6.5
by Brian Aker
Updating so that structures have constructor (removed memset calls). |
85 |
void init() |
86 |
{
|
|
87 |
table= NULL; |
|
88 |
cursor= NULL; |
|
89 |
forms= 0; |
|
90 |
read_record= 0; |
|
91 |
session= 0; |
|
92 |
select= 0; |
|
93 |
cache_records= 0; |
|
94 |
ref_length= 0; |
|
95 |
struct_length= 0; |
|
96 |
reclength= 0; |
|
97 |
rec_cache_size= 0; |
|
98 |
error_offset= 0; |
|
99 |
index= 0; |
|
100 |
ref_pos= 0; |
|
101 |
record= 0; |
|
102 |
rec_buf= 0; |
|
103 |
cache= 0; |
|
104 |
cache_pos= 0; |
|
105 |
cache_end= 0; |
|
106 |
read_positions= 0; |
|
107 |
io_cache= 0; |
|
108 |
print_error= 0; |
|
109 |
ignore_not_found_rows= 0; |
|
110 |
do_insideout_scan= 0; |
|
111 |
}
|
|
112 |
||
1539.1.3
by Brian Aker
Additional function -> method for readrecord |
113 |
virtual ~ReadRecord() |
114 |
{ } |
|
1237.9.4
by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file. |
115 |
|
116 |
/*
|
|
117 |
init_read_record is used to scan by using a number of different methods.
|
|
118 |
Which method to use is set-up in this call so that later calls to
|
|
119 |
the info->read_record will call the appropriate method using a function
|
|
120 |
pointer.
|
|
121 |
||
122 |
There are five methods that relate completely to the sort function
|
|
123 |
filesort. The result of a filesort is retrieved using read_record
|
|
124 |
calls. The other two methods are used for normal table access.
|
|
125 |
||
126 |
The filesort will produce references to the records sorted, these
|
|
127 |
references can be stored in memory or in a temporary cursor.
|
|
128 |
||
129 |
The temporary cursor is normally used when the references doesn't fit into
|
|
130 |
a properly sized memory buffer. For most small queries the references
|
|
131 |
are stored in the memory buffer.
|
|
132 |
||
133 |
The temporary cursor is also used when performing an update where a key is
|
|
134 |
modified.
|
|
135 |
||
136 |
Methods used when ref's are in memory (using rr_from_pointers):
|
|
137 |
rr_unpack_from_buffer:
|
|
138 |
----------------------
|
|
139 |
This method is used when table->sort.addon_field is allocated.
|
|
140 |
This is allocated for most SELECT queries not involving any BLOB's.
|
|
141 |
In this case the records are fetched from a memory buffer.
|
|
142 |
rr_from_pointers:
|
|
143 |
-----------------
|
|
144 |
Used when the above is not true, UPDATE, DELETE and so forth and
|
|
145 |
SELECT's involving BLOB's. It is also used when the addon_field
|
|
146 |
buffer is not allocated due to that its size was bigger than the
|
|
147 |
session variable max_length_for_sort_data.
|
|
148 |
In this case the record data is fetched from the handler using the
|
|
149 |
saved reference using the rnd_pos handler call.
|
|
150 |
||
151 |
Methods used when ref's are in a temporary cursor (using rr_from_tempfile)
|
|
152 |
rr_unpack_from_tempfile:
|
|
153 |
------------------------
|
|
154 |
Same as rr_unpack_from_buffer except that references are fetched from
|
|
155 |
temporary cursor. Should obviously not really happen other than in
|
|
156 |
strange configurations.
|
|
157 |
||
158 |
rr_from_tempfile:
|
|
159 |
-----------------
|
|
160 |
Same as rr_from_pointers except that references are fetched from
|
|
161 |
temporary cursor instead of from
|
|
162 |
rr_from_cache:
|
|
163 |
--------------
|
|
164 |
This is a special variant of rr_from_tempfile that can be used for
|
|
165 |
handlers that is not using the HA_FAST_KEY_READ table flag. Instead
|
|
166 |
of reading the references one by one from the temporary cursor it reads
|
|
167 |
a set of them, sorts them and reads all of them into a buffer which
|
|
168 |
is then used for a number of subsequent calls to rr_from_cache.
|
|
169 |
It is only used for SELECT queries and a number of other conditions
|
|
170 |
on table size.
|
|
171 |
||
172 |
All other accesses use either index access methods (rr_quick) or a full
|
|
173 |
table scan (rr_sequential).
|
|
174 |
rr_quick:
|
|
175 |
---------
|
|
176 |
rr_quick uses one of the QUICK_SELECT classes in optimizer/range.cc to
|
|
177 |
perform an index scan. There are loads of functionality hidden
|
|
178 |
in these quick classes. It handles all index scans of various kinds.
|
|
179 |
rr_sequential:
|
|
180 |
--------------
|
|
181 |
This is the most basic access method of a table using rnd_init,
|
|
182 |
rnd_next and rnd_end. No indexes are used.
|
|
183 |
*/
|
|
1538
by Brian Aker
Code shuffle on ReadRecord |
184 |
void init_read_record(Session *session, |
185 |
Table *reg_form, |
|
186 |
optimizer::SqlSelect *select, |
|
187 |
int use_record_cache, |
|
188 |
bool print_errors); |
|
189 |
||
190 |
void end_read_record(); |
|
1539.1.3
by Brian Aker
Additional function -> method for readrecord |
191 |
|
192 |
||
193 |
/**
|
|
194 |
Initialize ReadRecord structure to perform full index scan (in forward
|
|
195 |
direction) using read_record.read_record() interface.
|
|
196 |
||
197 |
This function has been added at late stage and is used only by
|
|
198 |
UPDATE/DELETE. Other statements perform index scans using
|
|
199 |
join_read_first/next functions.
|
|
200 |
||
201 |
@param info ReadRecord structure to initialize.
|
|
202 |
@param session Thread handle
|
|
203 |
@param table Table to be accessed
|
|
204 |
@param print_error If true, call table->print_error() if an error
|
|
205 |
occurs (except for end-of-records error)
|
|
206 |
@param idx index to scan
|
|
207 |
*/
|
|
208 |
void init_read_record_idx(Session *session, |
|
209 |
Table *table, |
|
210 |
bool print_error, |
|
211 |
uint32_t idx); |
|
1578.4.1
by Brian Aker
Static/contain the only function that was seen outside of records.cc |
212 |
|
213 |
void init_reard_record_sequential(); |
|
214 |
||
1539.1.4
by Brian Aker
More RR encapsulation. |
215 |
bool init_rr_cache(); |
1538
by Brian Aker
Code shuffle on ReadRecord |
216 |
};
|
1237.9.4
by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file. |
217 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
218 |
} /* namespace drizzled */ |
219 |
||
1237.9.4
by Padraig O'Sullivan
Removed the inclusion of drizzled/field.h in the server_includes header file. |
220 |
#endif /* DRIZZLED_RECORDS_H */ |