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> |
1273.13.1
by Brian Aker
First pass through data dictionary. |
26 |
|
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
27 |
#include <unistd.h> |
28 |
#include <fcntl.h> |
|
29 |
||
1273.13.1
by Brian Aker
First pass through data dictionary. |
30 |
#include <string> |
31 |
||
32 |
using namespace std; |
|
33 |
using namespace drizzled; |
|
34 |
||
35 |
/*****************************************************************************
|
|
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
36 |
** Data Function tables
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
37 |
*****************************************************************************/
|
38 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
39 |
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 |
40 |
Table &table_arg) : |
1273.13.60
by Brian Aker
Merge with trunk. |
41 |
Cursor(engine_arg, table_arg), |
42 |
estimate_of_rows(100), // Completely fabricated, I used to use the value 2. |
|
43 |
rows_returned(0) |
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
44 |
{}
|
45 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
46 |
int FunctionCursor::open(const char *name, int, uint32_t) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
47 |
{
|
1869.1.3
by Brian Aker
Engine now as a referene. |
48 |
tool= static_cast<Function *>(getEngine())->getFunction(name); |
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
49 |
// assert(tool);
|
50 |
||
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
51 |
record_id= 0; |
52 |
||
1415
by Brian Aker
Mass overhaul to use schema_identifier. |
53 |
if (not tool) |
54 |
return HA_ERR_NO_SUCH_TABLE; |
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
55 |
|
56 |
return 0; |
|
57 |
}
|
|
58 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
59 |
int FunctionCursor::close(void) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
60 |
{
|
61 |
tool= NULL; |
|
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
62 |
wipeCache(); |
63 |
||
1273.13.1
by Brian Aker
First pass through data dictionary. |
64 |
return 0; |
65 |
}
|
|
66 |
||
1491.1.10
by Jay Pipes
ha_rnd_init -> startTableScan, rnd_init -> doStartTableScan, ha_rnd_end -> endTableScan, rnd_end -> doEndTableScan |
67 |
int FunctionCursor::doStartTableScan(bool) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
68 |
{
|
1273.13.60
by Brian Aker
Merge with trunk. |
69 |
rows_returned= 0; |
1869.1.5
by Brian Aker
getTable() |
70 |
generator= tool->generator(getTable()->getFields()); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
71 |
|
72 |
return 0; |
|
73 |
}
|
|
74 |
||
75 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
76 |
int FunctionCursor::rnd_next(unsigned char *) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
77 |
{
|
78 |
bool more_rows; |
|
1273.16.8
by Brian Aker
Remove typedef. |
79 |
ha_statistic_increment(&system_status_var::ha_read_rnd_next_count); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
80 |
|
1273.13.48
by Brian Aker
Fix debug assert. |
81 |
/* Fix bug in the debug logic for field */
|
1869.1.5
by Brian Aker
getTable() |
82 |
for (Field **field= getTable()->getFields() ; *field ; field++) |
1273.13.48
by Brian Aker
Fix debug assert. |
83 |
{
|
84 |
(*field)->setWriteSet(); |
|
85 |
}
|
|
86 |
||
1869.1.5
by Brian Aker
getTable() |
87 |
more_rows= generator->sub_populate(getTable()->getShare()->sizeFields()); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
88 |
|
89 |
if (more_rows) |
|
90 |
{
|
|
91 |
return 0; |
|
92 |
}
|
|
93 |
else
|
|
94 |
{
|
|
95 |
delete generator; |
|
96 |
generator= NULL; |
|
97 |
}
|
|
1273.13.60
by Brian Aker
Merge with trunk. |
98 |
rows_returned++; |
1273.13.1
by Brian Aker
First pass through data dictionary. |
99 |
|
100 |
return more_rows ? 0 : HA_ERR_END_OF_FILE; |
|
101 |
}
|
|
102 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
103 |
void FunctionCursor::position(const unsigned char *record) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
104 |
{
|
1869.1.5
by Brian Aker
getTable() |
105 |
if (row_cache.size() <= record_id * getTable()->getShare()->getRecordLength()) |
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
106 |
{
|
1869.1.5
by Brian Aker
getTable() |
107 |
row_cache.resize(row_cache.size() + getTable()->getShare()->getRecordLength() * 100); // Hardwired at adding an additional 100 rows of storage |
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
108 |
}
|
1869.1.5
by Brian Aker
getTable() |
109 |
memcpy(&row_cache[record_id * getTable()->getShare()->getRecordLength()], record, getTable()->getShare()->getRecordLength()); |
1273.14.5
by Monty Taylor
Merged trunk. |
110 |
internal::my_store_ptr(ref, ref_length, record_id); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
111 |
record_id++; |
112 |
}
|
|
113 |
||
1552.1.2
by Brian Aker
This 1) fixes issue of reset() 2) uses a better cache design to decrease |
114 |
|
115 |
void FunctionCursor::wipeCache() |
|
116 |
{
|
|
117 |
if (rows_returned > estimate_of_rows) |
|
118 |
estimate_of_rows= rows_returned; |
|
119 |
||
120 |
row_cache.clear(); |
|
121 |
record_id= 0; |
|
122 |
}
|
|
123 |
||
1551
by Brian Aker
This fixes the issue with filesort() possibly crashing on a Function based |
124 |
int FunctionCursor::extra(enum ha_extra_function operation) |
125 |
{
|
|
126 |
switch (operation) |
|
127 |
{
|
|
128 |
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 |
129 |
break; |
1551
by Brian Aker
This fixes the issue with filesort() possibly crashing on a Function based |
130 |
case drizzled::HA_EXTRA_NO_CACHE: |
131 |
break; |
|
132 |
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 |
133 |
wipeCache(); |
134 |
break; |
|
1551
by Brian Aker
This fixes the issue with filesort() possibly crashing on a Function based |
135 |
default: |
136 |
break; |
|
137 |
}
|
|
138 |
||
139 |
return 0; |
|
140 |
}
|
|
141 |
||
1491.1.10
by Jay Pipes
ha_rnd_init -> startTableScan, rnd_init -> doStartTableScan, ha_rnd_end -> endTableScan, rnd_end -> doEndTableScan |
142 |
int FunctionCursor::doEndTableScan() |
1273.13.1
by Brian Aker
First pass through data dictionary. |
143 |
{
|
144 |
delete generator; // Do this in case of an early exit from rnd_next() |
|
145 |
||
146 |
return 0; |
|
147 |
}
|
|
148 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
149 |
int FunctionCursor::rnd_pos(unsigned char *buf, unsigned char *pos) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
150 |
{
|
1273.16.8
by Brian Aker
Remove typedef. |
151 |
ha_statistic_increment(&system_status_var::ha_read_rnd_count); |
1273.14.5
by Monty Taylor
Merged trunk. |
152 |
size_t position_id= (size_t)internal::my_get_ptr(pos, ref_length); |
1273.13.1
by Brian Aker
First pass through data dictionary. |
153 |
|
1869.1.5
by Brian Aker
getTable() |
154 |
assert(position_id * getTable()->getShare()->getRecordLength() < row_cache.size()); |
155 |
memcpy(buf, &row_cache[position_id * getTable()->getShare()->getRecordLength()], getTable()->getShare()->getRecordLength()); |
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
156 |
|
157 |
return 0; |
|
158 |
}
|
|
159 |
||
160 |
||
1273.13.18
by Brian Aker
Update code, first pass through cleaner method for recursing through |
161 |
int FunctionCursor::info(uint32_t flag) |
1273.13.1
by Brian Aker
First pass through data dictionary. |
162 |
{
|
163 |
memset(&stats, 0, sizeof(stats)); |
|
1273.13.60
by Brian Aker
Merge with trunk. |
164 |
|
1273.13.1
by Brian Aker
First pass through data dictionary. |
165 |
if (flag & HA_STATUS_AUTO) |
166 |
stats.auto_increment_value= 1; |
|
1273.13.60
by Brian Aker
Merge with trunk. |
167 |
|
168 |
stats.records= estimate_of_rows; |
|
169 |
||
1273.13.1
by Brian Aker
First pass through data dictionary. |
170 |
return 0; |
171 |
}
|