1273.13.1
by Brian Aker
First pass through data dictionary. |
1 |
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1999.6.1
by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file |
4 |
* Copyright (C) 2009 Sun Microsystems, Inc.
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
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; either version 2 of the License, or
|
|
9 |
* (at your option) any later version.
|
|
10 |
*
|
|
11 |
* This program is distributed in the hope that it will be useful,
|
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 |
* GNU General Public License for more details.
|
|
15 |
*
|
|
16 |
* You should have received a copy of the GNU General Public License
|
|
17 |
* along with this program; if not, write to the Free Software
|
|
18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
19 |
*/
|
|
20 |
||
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
21 |
#include <config.h> |
1273.13.1
by Brian Aker
First pass through data dictionary. |
22 |
|
1273.13.55
by Brian Aker
Naming fixes. |
23 |
#include <plugin/function_engine/cursor.h> |
1273.13.1
by Brian Aker
First pass through data dictionary. |
24 |
#include <drizzled/session.h> |
2173.2.1
by Monty Taylor
Fixes incorrect usage of include |
25 |
#include <drizzled/internal/my_sys.h> |
2188.1.1
by Stewart Smith
Replace FunctionCursor row_cache of full rows with one that is the |
26 |
#include <drizzled/field/blob.h> |
2234.1.1
by Olaf van der Spek
Refactor includes |
27 |
#include <drizzled/table.h> |
2241.3.1
by Olaf van der Spek
Refactor Session::status_var |
28 |
#include <drizzled/statistics_variables.h> |
1273.13.1
by Brian Aker
First pass through data dictionary. |
29 |
|
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
30 |
#include <unistd.h> |
31 |
#include <fcntl.h> |
|
32 |
||
1273.13.1
by Brian Aker
First pass through data dictionary. |
33 |
#include <string> |
34 |
||
35 |
using namespace std; |
|
36 |
using namespace drizzled; |
|
37 |
||
38 |
/*****************************************************************************
|
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
39 |
** Data Function tables
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
40 |
*****************************************************************************/
|
41 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
42 |
FunctionCursor::FunctionCursor(plugin::StorageEngine &engine_arg, |
1869.1.4
by Brian Aker
TableShare is no longer in the house (i.e. we no longer directly have a copy |
43 |
Table &table_arg) : |
1273.13.60
by Brian Aker
Merge with trunk. |
44 |
Cursor(engine_arg, table_arg), |
45 |
estimate_of_rows(100), // Completely fabricated, I used to use the value 2. |
|
46 |
rows_returned(0) |
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
47 |
{}
|
48 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
49 |
int FunctionCursor::open(const char *name, int, uint32_t) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
50 |
{
|
1869.1.3
by Brian Aker
Engine now as a referene. |
51 |
tool= static_cast<Function *>(getEngine())->getFunction(name); |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
52 |
// assert(tool);
|
53 |
||
2188.1.1
by Stewart Smith
Replace FunctionCursor row_cache of full rows with one that is the |
54 |
row_cache_position= 0; |
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
55 |
|
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
56 |
if (not tool) |
57 |
return HA_ERR_NO_SUCH_TABLE; |
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
58 |
|
59 |
return 0; |
|
60 |
}
|
|
61 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
62 |
int FunctionCursor::close(void) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
63 |
{
|
64 |
tool= NULL; |
|
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
65 |
wipeCache(); |
66 |
||
1273.13.1
by Brian Aker
First pass through data dictionary. |
67 |
return 0; |
68 |
}
|
|
69 |
||
1491.1.10
by Jay Pipes
ha_rnd_init -> startTableScan, rnd_init -> doStartTableScan, ha_rnd_end -> endTableScan, rnd_end -> doEndTableScan |
70 |
int FunctionCursor::doStartTableScan(bool) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
71 |
{
|
1273.13.60
by Brian Aker
Merge with trunk. |
72 |
rows_returned= 0; |
1869.1.5
by Brian Aker
getTable() |
73 |
generator= tool->generator(getTable()->getFields()); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
74 |
|
75 |
return 0; |
|
76 |
}
|
|
77 |
||
78 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
79 |
int FunctionCursor::rnd_next(unsigned char *) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
80 |
{
|
81 |
bool more_rows; |
|
1273.16.8
by Brian Aker
Remove typedef. |
82 |
ha_statistic_increment(&system_status_var::ha_read_rnd_next_count); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
83 |
|
1273.13.48
by Brian Aker
Fix debug assert. |
84 |
/* Fix bug in the debug logic for field */
|
1869.1.5
by Brian Aker
getTable() |
85 |
for (Field **field= getTable()->getFields() ; *field ; field++) |
1273.13.48
by Brian Aker
Fix debug assert. |
86 |
{
|
87 |
(*field)->setWriteSet(); |
|
88 |
}
|
|
89 |
||
1869.1.5
by Brian Aker
getTable() |
90 |
more_rows= generator->sub_populate(getTable()->getShare()->sizeFields()); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
91 |
|
92 |
if (more_rows) |
|
93 |
{
|
|
94 |
return 0; |
|
95 |
}
|
|
96 |
else
|
|
97 |
{
|
|
98 |
delete generator; |
|
99 |
generator= NULL; |
|
100 |
}
|
|
1273.13.60
by Brian Aker
Merge with trunk. |
101 |
rows_returned++; |
1273.13.1
by Brian Aker
First pass through data dictionary. |
102 |
|
103 |
return more_rows ? 0 : HA_ERR_END_OF_FILE; |
|
104 |
}
|
|
105 |
||
2188.1.1
by Stewart Smith
Replace FunctionCursor row_cache of full rows with one that is the |
106 |
uint32_t FunctionCursor::max_row_length() |
107 |
{
|
|
108 |
uint32_t length= (uint32_t)(getTable()->getRecordLength() + getTable()->sizeFields()*2); |
|
109 |
||
110 |
uint32_t *ptr, *end; |
|
111 |
for (ptr= getTable()->getBlobField(), end=ptr + getTable()->sizeBlobFields(); |
|
112 |
ptr != end ; |
|
113 |
ptr++) |
|
114 |
{
|
|
115 |
length += 2 + ((Field_blob*)getTable()->getField(*ptr))->get_length(); |
|
116 |
}
|
|
117 |
||
118 |
return length; |
|
119 |
}
|
|
120 |
||
121 |
unsigned int FunctionCursor::pack_row(const unsigned char *record) |
|
122 |
{
|
|
123 |
unsigned char *ptr; |
|
124 |
||
125 |
record_buffer.resize(max_row_length()); |
|
126 |
||
127 |
/* Copy null bits */
|
|
128 |
memcpy(&record_buffer[0], record, getTable()->getShare()->null_bytes); |
|
129 |
ptr= &record_buffer[0] + getTable()->getShare()->null_bytes; |
|
130 |
||
131 |
for (Field **field=getTable()->getFields() ; *field ; field++) |
|
132 |
{
|
|
133 |
if (!((*field)->is_null())) |
|
134 |
ptr= (*field)->pack(ptr, record + (*field)->offset(record)); |
|
135 |
}
|
|
136 |
||
137 |
return((unsigned int) (ptr - &record_buffer[0])); |
|
138 |
}
|
|
139 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
140 |
void FunctionCursor::position(const unsigned char *record) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
141 |
{
|
2188.1.1
by Stewart Smith
Replace FunctionCursor row_cache of full rows with one that is the |
142 |
uint32_t max_length= max_row_length(); |
143 |
||
144 |
if (row_cache.size() <= row_cache_position + max_length) |
|
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
145 |
{
|
2188.1.1
by Stewart Smith
Replace FunctionCursor row_cache of full rows with one that is the |
146 |
row_cache.resize(row_cache.size() + max_length); |
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
147 |
}
|
2188.1.1
by Stewart Smith
Replace FunctionCursor row_cache of full rows with one that is the |
148 |
|
149 |
unsigned int r_pack_length; |
|
150 |
r_pack_length= pack_row(record); |
|
151 |
internal::my_store_ptr(ref, ref_length, row_cache_position); |
|
152 |
||
153 |
memcpy(&row_cache[row_cache_position], &record_buffer[0], r_pack_length); |
|
154 |
row_cache_position+= r_pack_length; |
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
155 |
}
|
156 |
||
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
157 |
|
158 |
void FunctionCursor::wipeCache() |
|
159 |
{
|
|
160 |
if (rows_returned > estimate_of_rows) |
|
161 |
estimate_of_rows= rows_returned; |
|
162 |
||
163 |
row_cache.clear(); |
|
2188.1.1
by Stewart Smith
Replace FunctionCursor row_cache of full rows with one that is the |
164 |
row_cache_position= 0; |
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
165 |
}
|
166 |
||
1551
by Brian Aker
This fixes the issue with filesort() possibly crashing on a Function based |
167 |
int FunctionCursor::extra(enum ha_extra_function operation) |
168 |
{
|
|
169 |
switch (operation) |
|
170 |
{
|
|
171 |
case drizzled::HA_EXTRA_CACHE: |
|
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
172 |
break; |
1551
by Brian Aker
This fixes the issue with filesort() possibly crashing on a Function based |
173 |
case drizzled::HA_EXTRA_NO_CACHE: |
174 |
break; |
|
175 |
case drizzled::HA_EXTRA_RESET_STATE: |
|
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
176 |
wipeCache(); |
177 |
break; |
|
1551
by Brian Aker
This fixes the issue with filesort() possibly crashing on a Function based |
178 |
default: |
179 |
break; |
|
180 |
}
|
|
181 |
||
182 |
return 0; |
|
183 |
}
|
|
184 |
||
1491.1.10
by Jay Pipes
ha_rnd_init -> startTableScan, rnd_init -> doStartTableScan, ha_rnd_end -> endTableScan, rnd_end -> doEndTableScan |
185 |
int FunctionCursor::doEndTableScan() |
1273.13.1
by Brian Aker
First pass through data dictionary. |
186 |
{
|
187 |
delete generator; // Do this in case of an early exit from rnd_next() |
|
188 |
||
189 |
return 0; |
|
190 |
}
|
|
191 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
192 |
int FunctionCursor::rnd_pos(unsigned char *buf, unsigned char *pos) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
193 |
{
|
1273.16.8
by Brian Aker
Remove typedef. |
194 |
ha_statistic_increment(&system_status_var::ha_read_rnd_count); |
1273.14.5
by Monty Taylor
Merged trunk. |
195 |
size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
196 |
|
2188.1.1
by Stewart Smith
Replace FunctionCursor row_cache of full rows with one that is the |
197 |
const unsigned char *ptr; |
198 |
ptr= &row_cache[position_id]; |
|
199 |
||
200 |
/* Copy null bits */
|
|
201 |
memcpy(buf, ptr, getTable()->getNullBytes()); |
|
202 |
ptr+= getTable()->getNullBytes(); |
|
203 |
// and copy fields
|
|
204 |
for (Field **field= getTable()->getFields() ; *field ; field++) |
|
205 |
{
|
|
206 |
if (!((*field)->is_null())) |
|
207 |
{
|
|
208 |
ptr= (*field)->unpack(buf + (*field)->offset(getTable()->getInsertRecord()), ptr); |
|
209 |
}
|
|
210 |
}
|
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
211 |
|
212 |
return 0; |
|
213 |
}
|
|
214 |
||
215 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
216 |
int FunctionCursor::info(uint32_t flag) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
217 |
{
|
218 |
memset(&stats, 0, sizeof(stats)); |
|
1273.13.60
by Brian Aker
Merge with trunk. |
219 |
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
220 |
if (flag & HA_STATUS_AUTO) |
221 |
stats.auto_increment_value= 1; |
|
1273.13.60
by Brian Aker
Merge with trunk. |
222 |
|
223 |
stats.records= estimate_of_rows; |
|
224 |
||
1273.13.1
by Brian Aker
First pass through data dictionary. |
225 |
return 0; |
226 |
}
|