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
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
||
17 |
||
243.1.17
by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.) |
18 |
#include <drizzled/server_includes.h> |
212.5.28
by Monty Taylor
Moved my_bit and my_list |
19 |
#include <mysys/my_bit.h> |
685.1.3
by Monty Taylor
Turned off stdinc - and then fixed the carnage. |
20 |
#include "myisampack.h" |
1
by brian
clean slate |
21 |
#include "ha_myisam.h" |
22 |
#include "myisamdef.h" |
|
492.1.7
by Monty Taylor
Moved test() to its own file. |
23 |
#include <drizzled/util/test.h> |
549
by Monty Taylor
Took gettext.h out of header files. |
24 |
#include <drizzled/error.h> |
722.4.1
by Mark Atwood
integrate errmsg plugin into sql_print_* functions |
25 |
#include <drizzled/errmsg_print.h> |
549
by Monty Taylor
Took gettext.h out of header files. |
26 |
#include <drizzled/gettext.h> |
916.1.31
by Padraig O'Sullivan
Reverting some refactoring changes I made to MyISAM that didn't really work |
27 |
#include <drizzled/session.h> |
971.3.48
by Eric Day
New Listen interface about done, not quite compiling yet, but need a backup. |
28 |
#include <drizzled/plugin/protocol.h> |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
29 |
#include <drizzled/table.h> |
584.5.1
by Monty Taylor
Removed field includes from field.h. |
30 |
#include <drizzled/field/timestamp.h> |
1
by brian
clean slate |
31 |
|
960.2.41
by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method. |
32 |
#include <string> |
1067.4.8
by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max. |
33 |
#include <algorithm> |
960.2.41
by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method. |
34 |
|
35 |
using namespace std; |
|
36 |
||
37 |
static const string engine_name("MyISAM"); |
|
38 |
||
1
by brian
clean slate |
39 |
ulong myisam_recover_options= HA_RECOVER_NONE; |
598
by Brian Aker
Removed mutex which are myisam from global to just engine. |
40 |
pthread_mutex_t THR_LOCK_myisam= PTHREAD_MUTEX_INITIALIZER; |
1
by brian
clean slate |
41 |
|
753
by Brian Aker
Converted myisam_repair_threads to being in module for MyISAM |
42 |
static uint32_t repair_threads; |
754
by Brian Aker
Make block_size for myisam fit into plugin. |
43 |
static uint32_t block_size; |
788
by Brian Aker
Move MyISAM bits to myisam plugin |
44 |
static uint64_t max_sort_file_size; |
789
by Brian Aker
MyISAM fix. |
45 |
static uint64_t sort_buffer_size; |
753
by Brian Aker
Converted myisam_repair_threads to being in module for MyISAM |
46 |
|
1
by brian
clean slate |
47 |
/* bits in myisam_recover_options */
|
48 |
const char *myisam_recover_names[] = |
|
461
by Monty Taylor
Removed NullS. bu-bye. |
49 |
{ "DEFAULT", "BACKUP", "FORCE", "QUICK", NULL}; |
1
by brian
clean slate |
50 |
TYPELIB myisam_recover_typelib= {array_elements(myisam_recover_names)-1,"", |
584.5.1
by Monty Taylor
Removed field includes from field.h. |
51 |
myisam_recover_names, NULL}; |
1
by brian
clean slate |
52 |
|
53 |
||
54 |
||
55 |
/*****************************************************************************
|
|
56 |
** MyISAM tables
|
|
57 |
*****************************************************************************/
|
|
58 |
||
1039.3.1
by Stewart Smith
move bas_ext to StorageEngine instead of handler |
59 |
static const char *ha_myisam_exts[] = { |
60 |
".MYI", |
|
61 |
".MYD", |
|
62 |
NULL
|
|
63 |
};
|
|
64 |
||
960.2.33
by Monty Taylor
Converted MyISAM. |
65 |
class MyisamEngine : public StorageEngine |
1
by brian
clean slate |
66 |
{
|
960.2.41
by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method. |
67 |
public: |
964.1.4
by Monty Taylor
Moved flags into private area. |
68 |
MyisamEngine(string name_arg) |
1095.3.14
by Brian Aker
Moved file based flag up to engine (from handler). checkLowercaseNames() is now a ember of StorageEngine. |
69 |
: StorageEngine(name_arg, HTON_CAN_RECREATE | HTON_TEMPORARY_ONLY | HTON_FILE_BASED) {} |
960.2.41
by Monty Taylor
Made StorageEngine name private. Added constructor param and accessor method. |
70 |
|
1000.1.3
by Brian Aker
Renamed TABLE_SHARE to TableShare |
71 |
virtual handler *create(TableShare *table, |
960.2.33
by Monty Taylor
Converted MyISAM. |
72 |
MEM_ROOT *mem_root) |
73 |
{
|
|
960.2.38
by Monty Taylor
Removed extraneous send myself to myself argument. |
74 |
return new (mem_root) ha_myisam(this, table); |
960.2.33
by Monty Taylor
Converted MyISAM. |
75 |
}
|
1039.3.1
by Stewart Smith
move bas_ext to StorageEngine instead of handler |
76 |
|
77 |
const char **bas_ext() const { |
|
78 |
return ha_myisam_exts; |
|
79 |
}
|
|
1039.3.3
by Stewart Smith
Move handler::create to StorageEngine::create_table |
80 |
|
1095.3.29
by Stewart Smith
s/Impl/Implementation/ |
81 |
int createTableImplementation(Session *, const char *table_name, |
82 |
Table *table_arg, |
|
83 |
HA_CREATE_INFO *ha_create_info, |
|
84 |
drizzled::message::Table*); |
|
85 |
||
86 |
int renameTableImplementation(Session*, const char *from, const char *to); |
|
87 |
||
88 |
int deleteTableImplementation(Session*, const string table_name); |
|
960.2.33
by Monty Taylor
Converted MyISAM. |
89 |
};
|
1
by brian
clean slate |
90 |
|
91 |
// collect errors printed by mi_check routines
|
|
92 |
||
93 |
static void mi_check_print_msg(MI_CHECK *param, const char* msg_type, |
|
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
94 |
const char *fmt, va_list args) |
1
by brian
clean slate |
95 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
96 |
Session* session = (Session*)param->session; |
971.3.65
by Eric Day
Namespace cleanup for Protocol and Listen. |
97 |
drizzled::plugin::Protocol *protocol= session->protocol; |
482
by Brian Aker
Remove uint. |
98 |
uint32_t length, msg_length; |
1
by brian
clean slate |
99 |
char msgbuf[MI_MAX_MSG_BUF]; |
100 |
char name[NAME_LEN*2+2]; |
|
101 |
||
77.1.18
by Monty Taylor
Removed my_vsnprintf and my_snprintf. |
102 |
msg_length= vsnprintf(msgbuf, sizeof(msgbuf), fmt, args); |
1
by brian
clean slate |
103 |
msgbuf[sizeof(msgbuf) - 1] = 0; // healthy paranoia |
104 |
||
971.3.12
by Eric Day
Started abstracting Protocol, removed init_connect, init_file. |
105 |
if (!session->protocol->isConnected()) |
1
by brian
clean slate |
106 |
{
|
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
107 |
errmsg_printf(ERRMSG_LVL_ERROR, "%s",msgbuf); |
1
by brian
clean slate |
108 |
return; |
109 |
}
|
|
110 |
||
111 |
if (param->testflag & (T_CREATE_MISSING_KEYS | T_SAFE_REPAIR | |
|
112 |
T_AUTO_REPAIR)) |
|
113 |
{
|
|
114 |
my_message(ER_NOT_KEYFILE,msgbuf,MYF(MY_WME)); |
|
115 |
return; |
|
116 |
}
|
|
673.2.2
by Toru Maesaka
Final pass of replacing MySQL's strxmov with libc's alternatives |
117 |
length= sprintf(name,"%s.%s",param->db_name,param->table_name); |
118 |
||
1
by brian
clean slate |
119 |
/*
|
120 |
TODO: switch from protocol to push_warning here. The main reason we didn't
|
|
121 |
it yet is parallel repair. Due to following trace:
|
|
122 |
mi_check_print_msg/push_warning/sql_alloc/my_pthread_getspecific_ptr.
|
|
123 |
||
124 |
Also we likely need to lock mutex here (in both cases with protocol and
|
|
125 |
push_warning).
|
|
126 |
*/
|
|
971.3.19
by Eric Day
Finished first pass at Protocol cleanup, still some things to remove but they are a bit more involved. |
127 |
protocol->prepareForResend(); |
1054.2.9
by Monty Taylor
Removed CHARSET_INFO stuff from protocol plugin interface - it makes no sense. |
128 |
protocol->store(name, length); |
129 |
protocol->store(param->op_name); |
|
130 |
protocol->store(msg_type); |
|
131 |
protocol->store(msgbuf, msg_length); |
|
1
by brian
clean slate |
132 |
if (protocol->write()) |
840.1.17
by Monty Taylor
Renamed my_net_* to drizzleclient_net_* to help with namespace issues. |
133 |
errmsg_printf(ERRMSG_LVL_ERROR, "Failed on drizzleclient_net_write, writing to stderr instead: %s\n", |
1
by brian
clean slate |
134 |
msgbuf); |
135 |
return; |
|
136 |
}
|
|
137 |
||
138 |
||
139 |
/*
|
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
140 |
Convert Table object to MyISAM key and column definition
|
1
by brian
clean slate |
141 |
|
142 |
SYNOPSIS
|
|
143 |
table2myisam()
|
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
144 |
table_arg in Table object.
|
1
by brian
clean slate |
145 |
keydef_out out MyISAM key definition.
|
146 |
recinfo_out out MyISAM column definition.
|
|
147 |
records_out out Number of fields.
|
|
148 |
||
149 |
DESCRIPTION
|
|
150 |
This function will allocate and initialize MyISAM key and column
|
|
151 |
definition for further use in mi_create or for a check for underlying
|
|
152 |
table conformance in merge engine.
|
|
153 |
||
154 |
The caller needs to free *recinfo_out after use. Since *recinfo_out
|
|
155 |
and *keydef_out are allocated with a my_multi_malloc, *keydef_out
|
|
156 |
is freed automatically when *recinfo_out is freed.
|
|
157 |
||
158 |
RETURN VALUE
|
|
159 |
0 OK
|
|
160 |
!0 error code
|
|
161 |
*/
|
|
162 |
||
1085.1.2
by Monty Taylor
Fixed -Wmissing-declarations |
163 |
static int table2myisam(Table *table_arg, MI_KEYDEF **keydef_out, |
164 |
MI_COLUMNDEF **recinfo_out, uint32_t *records_out) |
|
1
by brian
clean slate |
165 |
{
|
482
by Brian Aker
Remove uint. |
166 |
uint32_t i, j, recpos, minpos, fieldpos, temp_length, length; |
1
by brian
clean slate |
167 |
enum ha_base_keytype type= HA_KEYTYPE_BINARY; |
481
by Brian Aker
Remove all of uchar. |
168 |
unsigned char *record; |
1
by brian
clean slate |
169 |
KEY *pos; |
170 |
MI_KEYDEF *keydef; |
|
171 |
MI_COLUMNDEF *recinfo, *recinfo_pos; |
|
172 |
HA_KEYSEG *keyseg; |
|
1000.1.3
by Brian Aker
Renamed TABLE_SHARE to TableShare |
173 |
TableShare *share= table_arg->s; |
482
by Brian Aker
Remove uint. |
174 |
uint32_t options= share->db_options_in_use; |
1
by brian
clean slate |
175 |
if (!(my_multi_malloc(MYF(MY_WME), |
176 |
recinfo_out, (share->fields * 2 + 2) * sizeof(MI_COLUMNDEF), |
|
177 |
keydef_out, share->keys * sizeof(MI_KEYDEF), |
|
178 |
&keyseg, |
|
179 |
(share->key_parts + share->keys) * sizeof(HA_KEYSEG), |
|
461
by Monty Taylor
Removed NullS. bu-bye. |
180 |
NULL))) |
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
181 |
return(HA_ERR_OUT_OF_MEM); /* purecov: inspected */ |
1
by brian
clean slate |
182 |
keydef= *keydef_out; |
183 |
recinfo= *recinfo_out; |
|
184 |
pos= table_arg->key_info; |
|
185 |
for (i= 0; i < share->keys; i++, pos++) |
|
186 |
{
|
|
249
by Brian Aker
Random key cleanup (it is a friday...) |
187 |
keydef[i].flag= ((uint16_t) pos->flags & (HA_NOSAME)); |
188 |
keydef[i].key_alg= HA_KEY_ALG_BTREE; |
|
1
by brian
clean slate |
189 |
keydef[i].block_length= pos->block_size; |
190 |
keydef[i].seg= keyseg; |
|
191 |
keydef[i].keysegs= pos->key_parts; |
|
192 |
for (j= 0; j < pos->key_parts; j++) |
|
193 |
{
|
|
194 |
Field *field= pos->key_part[j].field; |
|
195 |
type= field->key_type(); |
|
196 |
keydef[i].seg[j].flag= pos->key_part[j].key_part_flag; |
|
197 |
||
198 |
if (options & HA_OPTION_PACK_KEYS || |
|
199 |
(pos->flags & (HA_PACK_KEY | HA_BINARY_PACK_KEY | |
|
200 |
HA_SPACE_PACK_USED))) |
|
201 |
{
|
|
202 |
if (pos->key_part[j].length > 8 && |
|
203 |
(type == HA_KEYTYPE_TEXT || |
|
204 |
type == HA_KEYTYPE_NUM || |
|
205 |
(type == HA_KEYTYPE_BINARY && !field->zero_pack()))) |
|
206 |
{
|
|
207 |
/* No blobs here */
|
|
208 |
if (j == 0) |
|
209 |
keydef[i].flag|= HA_PACK_KEY; |
|
241
by Brian Aker
First pass of CHAR removal. |
210 |
if ((((int) (pos->key_part[j].length - field->decimals())) >= 4)) |
1
by brian
clean slate |
211 |
keydef[i].seg[j].flag|= HA_SPACE_PACK; |
212 |
}
|
|
213 |
else if (j == 0 && (!(pos->flags & HA_NOSAME) || pos->key_length > 16)) |
|
214 |
keydef[i].flag|= HA_BINARY_PACK_KEY; |
|
215 |
}
|
|
216 |
keydef[i].seg[j].type= (int) type; |
|
217 |
keydef[i].seg[j].start= pos->key_part[j].offset; |
|
218 |
keydef[i].seg[j].length= pos->key_part[j].length; |
|
219 |
keydef[i].seg[j].bit_start= keydef[i].seg[j].bit_end= |
|
220 |
keydef[i].seg[j].bit_length= 0; |
|
221 |
keydef[i].seg[j].bit_pos= 0; |
|
222 |
keydef[i].seg[j].language= field->charset()->number; |
|
223 |
||
224 |
if (field->null_ptr) |
|
225 |
{
|
|
226 |
keydef[i].seg[j].null_bit= field->null_bit; |
|
227 |
keydef[i].seg[j].null_pos= (uint) (field->null_ptr- |
|
481
by Brian Aker
Remove all of uchar. |
228 |
(unsigned char*) table_arg->record[0]); |
1
by brian
clean slate |
229 |
}
|
230 |
else
|
|
231 |
{
|
|
232 |
keydef[i].seg[j].null_bit= 0; |
|
233 |
keydef[i].seg[j].null_pos= 0; |
|
234 |
}
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
235 |
if (field->type() == DRIZZLE_TYPE_BLOB) |
1
by brian
clean slate |
236 |
{
|
237 |
keydef[i].seg[j].flag|= HA_BLOB_PART; |
|
238 |
/* save number of bytes used to pack length */
|
|
239 |
keydef[i].seg[j].bit_start= (uint) (field->pack_length() - |
|
240 |
share->blob_ptr_size); |
|
241 |
}
|
|
242 |
}
|
|
243 |
keyseg+= pos->key_parts; |
|
244 |
}
|
|
245 |
if (table_arg->found_next_number_field) |
|
246 |
keydef[share->next_number_index].flag|= HA_AUTO_KEY; |
|
247 |
record= table_arg->record[0]; |
|
248 |
recpos= 0; |
|
249 |
recinfo_pos= recinfo; |
|
383.7.1
by Andrey Zhakov
Initial submit of code and tests |
250 |
while (recpos < (uint) share->stored_rec_length) |
1
by brian
clean slate |
251 |
{
|
252 |
Field **field, *found= 0; |
|
253 |
minpos= share->reclength; |
|
254 |
length= 0; |
|
255 |
||
256 |
for (field= table_arg->field; *field; field++) |
|
257 |
{
|
|
258 |
if ((fieldpos= (*field)->offset(record)) >= recpos && |
|
259 |
fieldpos <= minpos) |
|
260 |
{
|
|
261 |
/* skip null fields */
|
|
262 |
if (!(temp_length= (*field)->pack_length_in_rec())) |
|
263 |
continue; /* Skip null-fields */ |
|
264 |
if (! found || fieldpos < minpos || |
|
265 |
(fieldpos == minpos && temp_length < length)) |
|
266 |
{
|
|
267 |
minpos= fieldpos; |
|
268 |
found= *field; |
|
269 |
length= temp_length; |
|
270 |
}
|
|
271 |
}
|
|
272 |
}
|
|
273 |
if (recpos != minpos) |
|
274 |
{ // Reserved space (Null bits?) |
|
212.6.12
by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove(). |
275 |
memset(recinfo_pos, 0, sizeof(*recinfo_pos)); |
1
by brian
clean slate |
276 |
recinfo_pos->type= (int) FIELD_NORMAL; |
206
by Brian Aker
Removed final uint dead types. |
277 |
recinfo_pos++->length= (uint16_t) (minpos - recpos); |
1
by brian
clean slate |
278 |
}
|
279 |
if (!found) |
|
280 |
break; |
|
281 |
||
282 |
if (found->flags & BLOB_FLAG) |
|
283 |
recinfo_pos->type= (int) FIELD_BLOB; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
284 |
else if (found->type() == DRIZZLE_TYPE_VARCHAR) |
1
by brian
clean slate |
285 |
recinfo_pos->type= FIELD_VARCHAR; |
286 |
else if (!(options & HA_OPTION_PACK_RECORD)) |
|
287 |
recinfo_pos->type= (int) FIELD_NORMAL; |
|
288 |
else if (found->zero_pack()) |
|
289 |
recinfo_pos->type= (int) FIELD_SKIP_ZERO; |
|
290 |
else
|
|
241
by Brian Aker
First pass of CHAR removal. |
291 |
recinfo_pos->type= (int) ((length <= 3) ? FIELD_NORMAL : FIELD_SKIP_PRESPACE); |
1
by brian
clean slate |
292 |
if (found->null_ptr) |
293 |
{
|
|
294 |
recinfo_pos->null_bit= found->null_bit; |
|
295 |
recinfo_pos->null_pos= (uint) (found->null_ptr - |
|
481
by Brian Aker
Remove all of uchar. |
296 |
(unsigned char*) table_arg->record[0]); |
1
by brian
clean slate |
297 |
}
|
298 |
else
|
|
299 |
{
|
|
300 |
recinfo_pos->null_bit= 0; |
|
301 |
recinfo_pos->null_pos= 0; |
|
302 |
}
|
|
206
by Brian Aker
Removed final uint dead types. |
303 |
(recinfo_pos++)->length= (uint16_t) length; |
1
by brian
clean slate |
304 |
recpos= minpos + length; |
305 |
}
|
|
306 |
*records_out= (uint) (recinfo_pos - recinfo); |
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
307 |
return(0); |
1
by brian
clean slate |
308 |
}
|
309 |
||
310 |
||
311 |
/*
|
|
312 |
Check for underlying table conformance
|
|
313 |
||
314 |
SYNOPSIS
|
|
315 |
check_definition()
|
|
316 |
t1_keyinfo in First table key definition
|
|
317 |
t1_recinfo in First table record definition
|
|
318 |
t1_keys in Number of keys in first table
|
|
319 |
t1_recs in Number of records in first table
|
|
320 |
t2_keyinfo in Second table key definition
|
|
321 |
t2_recinfo in Second table record definition
|
|
322 |
t2_keys in Number of keys in second table
|
|
323 |
t2_recs in Number of records in second table
|
|
324 |
strict in Strict check switch
|
|
325 |
||
326 |
DESCRIPTION
|
|
327 |
This function compares two MyISAM definitions. By intention it was done
|
|
328 |
to compare merge table definition against underlying table definition.
|
|
329 |
It may also be used to compare dot-frm and MYI definitions of MyISAM
|
|
330 |
table as well to compare different MyISAM table definitions.
|
|
331 |
||
332 |
For merge table it is not required that number of keys in merge table
|
|
333 |
must exactly match number of keys in underlying table. When calling this
|
|
334 |
function for underlying table conformance check, 'strict' flag must be
|
|
335 |
set to false, and converted merge definition must be passed as t1_*.
|
|
336 |
||
337 |
Otherwise 'strict' flag must be set to 1 and it is not required to pass
|
|
338 |
converted dot-frm definition as t1_*.
|
|
339 |
||
340 |
RETURN VALUE
|
|
341 |
0 - Equal definitions.
|
|
342 |
1 - Different definitions.
|
|
343 |
||
344 |
TODO
|
|
345 |
- compare FULLTEXT keys;
|
|
346 |
- compare SPATIAL keys;
|
|
347 |
- compare FIELD_SKIP_ZERO which is converted to FIELD_NORMAL correctly
|
|
348 |
(should be corretly detected in table2myisam).
|
|
349 |
*/
|
|
350 |
||
1085.1.2
by Monty Taylor
Fixed -Wmissing-declarations |
351 |
static int check_definition(MI_KEYDEF *t1_keyinfo, MI_COLUMNDEF *t1_recinfo, |
352 |
uint32_t t1_keys, uint32_t t1_recs, |
|
353 |
MI_KEYDEF *t2_keyinfo, MI_COLUMNDEF *t2_recinfo, |
|
354 |
uint32_t t2_keys, uint32_t t2_recs, bool strict) |
|
1
by brian
clean slate |
355 |
{
|
482
by Brian Aker
Remove uint. |
356 |
uint32_t i, j; |
1
by brian
clean slate |
357 |
if ((strict ? t1_keys != t2_keys : t1_keys > t2_keys)) |
358 |
{
|
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
359 |
return(1); |
1
by brian
clean slate |
360 |
}
|
361 |
if (t1_recs != t2_recs) |
|
362 |
{
|
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
363 |
return(1); |
1
by brian
clean slate |
364 |
}
|
365 |
for (i= 0; i < t1_keys; i++) |
|
366 |
{
|
|
367 |
HA_KEYSEG *t1_keysegs= t1_keyinfo[i].seg; |
|
368 |
HA_KEYSEG *t2_keysegs= t2_keyinfo[i].seg; |
|
369 |
if (t1_keyinfo[i].keysegs != t2_keyinfo[i].keysegs || |
|
370 |
t1_keyinfo[i].key_alg != t2_keyinfo[i].key_alg) |
|
371 |
{
|
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
372 |
return(1); |
1
by brian
clean slate |
373 |
}
|
374 |
for (j= t1_keyinfo[i].keysegs; j--;) |
|
375 |
{
|
|
206
by Brian Aker
Removed final uint dead types. |
376 |
uint8_t t1_keysegs_j__type= t1_keysegs[j].type; |
1
by brian
clean slate |
377 |
|
378 |
/*
|
|
379 |
Table migration from 4.1 to 5.1. In 5.1 a *TEXT key part is
|
|
380 |
always HA_KEYTYPE_VARTEXT2. In 4.1 we had only the equivalent of
|
|
381 |
HA_KEYTYPE_VARTEXT1. Since we treat both the same on MyISAM
|
|
382 |
level, we can ignore a mismatch between these types.
|
|
383 |
*/
|
|
384 |
if ((t1_keysegs[j].flag & HA_BLOB_PART) && |
|
385 |
(t2_keysegs[j].flag & HA_BLOB_PART)) |
|
386 |
{
|
|
387 |
if ((t1_keysegs_j__type == HA_KEYTYPE_VARTEXT2) && |
|
388 |
(t2_keysegs[j].type == HA_KEYTYPE_VARTEXT1)) |
|
389 |
t1_keysegs_j__type= HA_KEYTYPE_VARTEXT1; /* purecov: tested */ |
|
390 |
else if ((t1_keysegs_j__type == HA_KEYTYPE_VARBINARY2) && |
|
391 |
(t2_keysegs[j].type == HA_KEYTYPE_VARBINARY1)) |
|
392 |
t1_keysegs_j__type= HA_KEYTYPE_VARBINARY1; /* purecov: inspected */ |
|
393 |
}
|
|
394 |
||
395 |
if (t1_keysegs_j__type != t2_keysegs[j].type || |
|
396 |
t1_keysegs[j].language != t2_keysegs[j].language || |
|
397 |
t1_keysegs[j].null_bit != t2_keysegs[j].null_bit || |
|
398 |
t1_keysegs[j].length != t2_keysegs[j].length) |
|
399 |
{
|
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
400 |
return(1); |
1
by brian
clean slate |
401 |
}
|
402 |
}
|
|
403 |
}
|
|
404 |
for (i= 0; i < t1_recs; i++) |
|
405 |
{
|
|
406 |
MI_COLUMNDEF *t1_rec= &t1_recinfo[i]; |
|
407 |
MI_COLUMNDEF *t2_rec= &t2_recinfo[i]; |
|
408 |
/*
|
|
409 |
FIELD_SKIP_ZERO can be changed to FIELD_NORMAL in mi_create,
|
|
410 |
see NOTE1 in mi_create.c
|
|
411 |
*/
|
|
412 |
if ((t1_rec->type != t2_rec->type && |
|
413 |
!(t1_rec->type == (int) FIELD_SKIP_ZERO && |
|
414 |
t1_rec->length == 1 && |
|
415 |
t2_rec->type == (int) FIELD_NORMAL)) || |
|
416 |
t1_rec->length != t2_rec->length || |
|
417 |
t1_rec->null_bit != t2_rec->null_bit) |
|
418 |
{
|
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
419 |
return(1); |
1
by brian
clean slate |
420 |
}
|
421 |
}
|
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
422 |
return(0); |
1
by brian
clean slate |
423 |
}
|
424 |
||
425 |
||
426 |
extern "C" { |
|
427 |
||
428 |
volatile int *killed_ptr(MI_CHECK *param) |
|
429 |
{
|
|
430 |
/* In theory Unsafe conversion, but should be ok for now */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
431 |
return (int*) &(((Session *)(param->session))->killed); |
1
by brian
clean slate |
432 |
}
|
433 |
||
434 |
void mi_check_print_error(MI_CHECK *param, const char *fmt,...) |
|
435 |
{
|
|
436 |
param->error_printed|=1; |
|
437 |
param->out_flag|= O_DATA_LOST; |
|
438 |
va_list args; |
|
439 |
va_start(args, fmt); |
|
440 |
mi_check_print_msg(param, "error", fmt, args); |
|
441 |
va_end(args); |
|
442 |
}
|
|
443 |
||
444 |
void mi_check_print_info(MI_CHECK *param, const char *fmt,...) |
|
445 |
{
|
|
446 |
va_list args; |
|
447 |
va_start(args, fmt); |
|
448 |
mi_check_print_msg(param, "info", fmt, args); |
|
449 |
va_end(args); |
|
450 |
}
|
|
451 |
||
452 |
void mi_check_print_warning(MI_CHECK *param, const char *fmt,...) |
|
453 |
{
|
|
454 |
param->warning_printed=1; |
|
455 |
param->out_flag|= O_DATA_LOST; |
|
456 |
va_list args; |
|
457 |
va_start(args, fmt); |
|
458 |
mi_check_print_msg(param, "warning", fmt, args); |
|
459 |
va_end(args); |
|
460 |
}
|
|
461 |
||
462 |
/**
|
|
463 |
Report list of threads (and queries) accessing a table, thread_id of a
|
|
464 |
thread that detected corruption, ource file name and line number where
|
|
465 |
this corruption was detected, optional extra information (string).
|
|
466 |
||
467 |
This function is intended to be used when table corruption is detected.
|
|
468 |
||
469 |
@param[in] file MI_INFO object.
|
|
470 |
@param[in] message Optional error message.
|
|
471 |
@param[in] sfile Name of source file.
|
|
472 |
@param[in] sline Line number in source file.
|
|
473 |
||
474 |
@return void
|
|
475 |
*/
|
|
476 |
||
477 |
void _mi_report_crashed(MI_INFO *file, const char *message, |
|
482
by Brian Aker
Remove uint. |
478 |
const char *sfile, uint32_t sline) |
1
by brian
clean slate |
479 |
{
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
480 |
Session *cur_session; |
1
by brian
clean slate |
481 |
pthread_mutex_lock(&file->s->intern_lock); |
916.1.35
by Padraig O'Sullivan
Removing the last of LIST from the MyISAM storage engine. |
482 |
if ((cur_session= file->in_use)) |
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
483 |
errmsg_printf(ERRMSG_LVL_ERROR, _("Got an error from thread_id=%"PRIu64", %s:%d"), |
553
by Monty Taylor
Changed my_thread_id type. |
484 |
cur_session->thread_id, |
1
by brian
clean slate |
485 |
sfile, sline); |
486 |
else
|
|
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
487 |
errmsg_printf(ERRMSG_LVL_ERROR, _("Got an error from unknown thread, %s:%d"), sfile, sline); |
1
by brian
clean slate |
488 |
if (message) |
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
489 |
errmsg_printf(ERRMSG_LVL_ERROR, "%s", message); |
916.1.35
by Padraig O'Sullivan
Removing the last of LIST from the MyISAM storage engine. |
490 |
list<Session *>::iterator it= file->s->in_use->begin(); |
491 |
while (it != file->s->in_use->end()) |
|
1
by brian
clean slate |
492 |
{
|
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
493 |
errmsg_printf(ERRMSG_LVL_ERROR, "%s", _("Unknown thread accessing table")); |
916.1.35
by Padraig O'Sullivan
Removing the last of LIST from the MyISAM storage engine. |
494 |
++it; |
1
by brian
clean slate |
495 |
}
|
496 |
pthread_mutex_unlock(&file->s->intern_lock); |
|
497 |
}
|
|
498 |
||
77.1.13
by Monty Taylor
Fixed wonky linkage thing. |
499 |
}
|
1
by brian
clean slate |
500 |
|
1000.1.3
by Brian Aker
Renamed TABLE_SHARE to TableShare |
501 |
ha_myisam::ha_myisam(StorageEngine *engine_arg, TableShare *table_arg) |
960.2.37
by Monty Taylor
More naming fixes. |
502 |
:handler(engine_arg, table_arg), file(0), |
413.2.2
by Brian Aker
Removed UNSIGNED from parser. |
503 |
int_table_flags(HA_NULL_IN_KEY | |
504 |
HA_DUPLICATE_POS | |
|
505 |
HA_CAN_INDEX_BLOBS | |
|
506 |
HA_AUTO_PART_KEY | |
|
507 |
HA_NO_TRANSACTIONS | |
|
508 |
HA_HAS_RECORDS | |
|
509 |
HA_STATS_RECORDS_IS_EXACT | |
|
510 |
HA_NEED_READ_RANGE_BUFFER | |
|
511 |
HA_MRR_CANT_SORT), |
|
1
by brian
clean slate |
512 |
can_enable_indexes(1) |
513 |
{}
|
|
514 |
||
515 |
handler *ha_myisam::clone(MEM_ROOT *mem_root) |
|
516 |
{
|
|
517 |
ha_myisam *new_handler= static_cast <ha_myisam *>(handler::clone(mem_root)); |
|
518 |
if (new_handler) |
|
519 |
new_handler->file->state= file->state; |
|
520 |
return new_handler; |
|
521 |
}
|
|
522 |
||
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
523 |
const char *ha_myisam::index_type(uint32_t ) |
1
by brian
clean slate |
524 |
{
|
74
by Brian Aker
More removal of FT from MyISAM |
525 |
return "BTREE"; |
1
by brian
clean slate |
526 |
}
|
527 |
||
528 |
/* Name is here without an extension */
|
|
482
by Brian Aker
Remove uint. |
529 |
int ha_myisam::open(const char *name, int mode, uint32_t test_if_locked) |
1
by brian
clean slate |
530 |
{
|
531 |
MI_KEYDEF *keyinfo; |
|
532 |
MI_COLUMNDEF *recinfo= 0; |
|
482
by Brian Aker
Remove uint. |
533 |
uint32_t recs; |
534 |
uint32_t i; |
|
1
by brian
clean slate |
535 |
|
536 |
/*
|
|
537 |
If the user wants to have memory mapped data files, add an
|
|
538 |
open_flag. Do not memory map temporary tables because they are
|
|
539 |
expected to be inserted and thus extended a lot. Memory mapping is
|
|
540 |
efficient for files that keep their size, but very inefficient for
|
|
541 |
growing files. Using an open_flag instead of calling mi_extra(...
|
|
542 |
HA_EXTRA_MMAP ...) after mi_open() has the advantage that the
|
|
543 |
mapping is not repeated for every open, but just done on the initial
|
|
544 |
open, when the MyISAM share is created. Everytime the server
|
|
545 |
requires to open a new instance of a table it calls this method. We
|
|
546 |
will always supply HA_OPEN_MMAP for a permanent table. However, the
|
|
547 |
MyISAM storage engine will ignore this flag if this is a secondary
|
|
548 |
open of a table that is in use by other threads already (if the
|
|
549 |
MyISAM share exists already).
|
|
550 |
*/
|
|
1115.1.7
by Brian Aker
Remove dead myisam program |
551 |
if (!(file=mi_open(name, mode, test_if_locked))) |
1
by brian
clean slate |
552 |
return (my_errno ? my_errno : -1); |
1115.1.7
by Brian Aker
Remove dead myisam program |
553 |
|
1
by brian
clean slate |
554 |
if (!table->s->tmp_table) /* No need to perform a check for tmp table */ |
555 |
{
|
|
556 |
if ((my_errno= table2myisam(table, &keyinfo, &recinfo, &recs))) |
|
557 |
{
|
|
558 |
/* purecov: begin inspected */
|
|
559 |
goto err; |
|
560 |
/* purecov: end */
|
|
561 |
}
|
|
562 |
if (check_definition(keyinfo, recinfo, table->s->keys, recs, |
|
563 |
file->s->keyinfo, file->s->rec, |
|
564 |
file->s->base.keys, file->s->base.fields, true)) |
|
565 |
{
|
|
566 |
/* purecov: begin inspected */
|
|
567 |
my_errno= HA_ERR_CRASHED; |
|
568 |
goto err; |
|
569 |
/* purecov: end */
|
|
570 |
}
|
|
571 |
}
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
572 |
|
1
by brian
clean slate |
573 |
if (test_if_locked & (HA_OPEN_IGNORE_IF_LOCKED | HA_OPEN_TMP_TABLE)) |
398.1.10
by Monty Taylor
Actually removed VOID() this time. |
574 |
mi_extra(file, HA_EXTRA_NO_WAIT_LOCK, 0); |
1
by brian
clean slate |
575 |
|
576 |
info(HA_STATUS_NO_LOCK | HA_STATUS_VARIABLE | HA_STATUS_CONST); |
|
577 |
if (!(test_if_locked & HA_OPEN_WAIT_IF_LOCKED)) |
|
398.1.10
by Monty Taylor
Actually removed VOID() this time. |
578 |
mi_extra(file, HA_EXTRA_WAIT_LOCK, 0); |
1
by brian
clean slate |
579 |
if (!table->s->db_record_offset) |
580 |
int_table_flags|=HA_REC_NOT_IN_SEQ; |
|
581 |
if (file->s->options & (HA_OPTION_CHECKSUM | HA_OPTION_COMPRESS_RECORD)) |
|
582 |
int_table_flags|=HA_HAS_CHECKSUM; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
583 |
|
1005.2.6
by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<> |
584 |
keys_with_parts.reset(); |
1
by brian
clean slate |
585 |
for (i= 0; i < table->s->keys; i++) |
586 |
{
|
|
587 |
table->key_info[i].block_size= file->s->keyinfo[i].block_length; |
|
588 |
||
589 |
KEY_PART_INFO *kp= table->key_info[i].key_part; |
|
590 |
KEY_PART_INFO *kp_end= kp + table->key_info[i].key_parts; |
|
591 |
for (; kp != kp_end; kp++) |
|
592 |
{
|
|
1005.2.6
by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<> |
593 |
if (!kp->field->part_of_key.test(i)) |
1
by brian
clean slate |
594 |
{
|
1005.2.6
by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<> |
595 |
keys_with_parts.set(i); |
1
by brian
clean slate |
596 |
break; |
597 |
}
|
|
598 |
}
|
|
599 |
}
|
|
600 |
my_errno= 0; |
|
601 |
goto end; |
|
602 |
err: |
|
603 |
this->close(); |
|
604 |
end: |
|
605 |
/*
|
|
606 |
Both recinfo and keydef are allocated by my_multi_malloc(), thus only
|
|
607 |
recinfo must be freed.
|
|
608 |
*/
|
|
609 |
if (recinfo) |
|
481
by Brian Aker
Remove all of uchar. |
610 |
free((unsigned char*) recinfo); |
1
by brian
clean slate |
611 |
return my_errno; |
612 |
}
|
|
613 |
||
614 |
int ha_myisam::close(void) |
|
615 |
{
|
|
616 |
MI_INFO *tmp=file; |
|
617 |
file=0; |
|
618 |
return mi_close(tmp); |
|
619 |
}
|
|
620 |
||
481
by Brian Aker
Remove all of uchar. |
621 |
int ha_myisam::write_row(unsigned char *buf) |
1
by brian
clean slate |
622 |
{
|
623 |
ha_statistic_increment(&SSV::ha_write_count); |
|
624 |
||
625 |
/*
|
|
626 |
If we have an auto_increment column and we are writing a changed row
|
|
627 |
or a new row, then update the auto_increment value in the record.
|
|
628 |
*/
|
|
629 |
if (table->next_number_field && buf == table->record[0]) |
|
630 |
{
|
|
631 |
int error; |
|
632 |
if ((error= update_auto_increment())) |
|
633 |
return error; |
|
634 |
}
|
|
635 |
return mi_write(file,buf); |
|
636 |
}
|
|
637 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
638 |
int ha_myisam::check(Session* session, HA_CHECK_OPT* check_opt) |
1
by brian
clean slate |
639 |
{
|
640 |
if (!file) return HA_ADMIN_INTERNAL_ERROR; |
|
641 |
int error; |
|
642 |
MI_CHECK param; |
|
643 |
MYISAM_SHARE* share = file->s; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
644 |
const char *old_proc_info= session->get_proc_info(); |
1
by brian
clean slate |
645 |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
646 |
session->set_proc_info("Checking table"); |
1
by brian
clean slate |
647 |
myisamchk_init(¶m); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
648 |
param.session = session; |
1
by brian
clean slate |
649 |
param.op_name = "check"; |
650 |
param.db_name= table->s->db.str; |
|
651 |
param.table_name= table->alias; |
|
652 |
param.testflag = check_opt->flags | T_CHECK | T_SILENT; |
|
1115.1.3
by Brian Aker
Remove final bits of "myisam" specific from drizzled.cc |
653 |
param.stats_method= MI_STATS_METHOD_NULLS_NOT_EQUAL; |
1
by brian
clean slate |
654 |
|
655 |
if (!(table->db_stat & HA_READ_ONLY)) |
|
656 |
param.testflag|= T_STATISTICS; |
|
657 |
param.using_global_keycache = 1; |
|
658 |
||
659 |
if (!mi_is_crashed(file) && |
|
660 |
(((param.testflag & T_CHECK_ONLY_CHANGED) && |
|
661 |
!(share->state.changed & (STATE_CHANGED | STATE_CRASHED | |
|
662 |
STATE_CRASHED_ON_REPAIR)) && |
|
663 |
share->state.open_count == 0) || |
|
664 |
((param.testflag & T_FAST) && (share->state.open_count == |
|
665 |
(uint) (share->global_changed ? 1 : 0))))) |
|
666 |
return HA_ADMIN_ALREADY_DONE; |
|
667 |
||
668 |
error = chk_status(¶m, file); // Not fatal |
|
669 |
error = chk_size(¶m, file); |
|
670 |
if (!error) |
|
671 |
error |= chk_del(¶m, file, param.testflag); |
|
672 |
if (!error) |
|
673 |
error = chk_key(¶m, file); |
|
674 |
if (!error) |
|
675 |
{
|
|
676 |
if ((!(param.testflag & T_QUICK) && |
|
677 |
((share->options & |
|
678 |
(HA_OPTION_PACK_RECORD | HA_OPTION_COMPRESS_RECORD)) || |
|
679 |
(param.testflag & (T_EXTEND | T_MEDIUM)))) || |
|
680 |
mi_is_crashed(file)) |
|
681 |
{
|
|
482
by Brian Aker
Remove uint. |
682 |
uint32_t old_testflag=param.testflag; |
1
by brian
clean slate |
683 |
param.testflag|=T_MEDIUM; |
684 |
if (!(error= init_io_cache(¶m.read_cache, file->dfile, |
|
685 |
my_default_record_cache_size, READ_CACHE, |
|
686 |
share->pack.header_length, 1, MYF(MY_WME)))) |
|
687 |
{
|
|
688 |
error= chk_data_link(¶m, file, param.testflag & T_EXTEND); |
|
689 |
end_io_cache(&(param.read_cache)); |
|
690 |
}
|
|
691 |
param.testflag= old_testflag; |
|
692 |
}
|
|
693 |
}
|
|
694 |
if (!error) |
|
695 |
{
|
|
696 |
if ((share->state.changed & (STATE_CHANGED | |
|
697 |
STATE_CRASHED_ON_REPAIR | |
|
698 |
STATE_CRASHED | STATE_NOT_ANALYZED)) || |
|
699 |
(param.testflag & T_STATISTICS) || |
|
700 |
mi_is_crashed(file)) |
|
701 |
{
|
|
702 |
file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; |
|
703 |
pthread_mutex_lock(&share->intern_lock); |
|
704 |
share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED | |
|
705 |
STATE_CRASHED_ON_REPAIR); |
|
706 |
if (!(table->db_stat & HA_READ_ONLY)) |
|
707 |
error=update_state_info(¶m,file,UPDATE_TIME | UPDATE_OPEN_COUNT | |
|
708 |
UPDATE_STAT); |
|
709 |
pthread_mutex_unlock(&share->intern_lock); |
|
710 |
info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE | |
|
711 |
HA_STATUS_CONST); |
|
712 |
}
|
|
713 |
}
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
714 |
else if (!mi_is_crashed(file) && !session->killed) |
1
by brian
clean slate |
715 |
{
|
716 |
mi_mark_crashed(file); |
|
717 |
file->update |= HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; |
|
718 |
}
|
|
719 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
720 |
session->set_proc_info(old_proc_info); |
1
by brian
clean slate |
721 |
return error ? HA_ADMIN_CORRUPT : HA_ADMIN_OK; |
722 |
}
|
|
723 |
||
724 |
||
725 |
/*
|
|
726 |
analyze the key distribution in the table
|
|
727 |
As the table may be only locked for read, we have to take into account that
|
|
728 |
two threads may do an analyze at the same time!
|
|
729 |
*/
|
|
730 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
731 |
int ha_myisam::analyze(Session *session, |
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
732 |
HA_CHECK_OPT* ) |
1
by brian
clean slate |
733 |
{
|
734 |
int error=0; |
|
735 |
MI_CHECK param; |
|
736 |
MYISAM_SHARE* share = file->s; |
|
737 |
||
738 |
myisamchk_init(¶m); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
739 |
param.session = session; |
1
by brian
clean slate |
740 |
param.op_name= "analyze"; |
741 |
param.db_name= table->s->db.str; |
|
742 |
param.table_name= table->alias; |
|
743 |
param.testflag= (T_FAST | T_CHECK | T_SILENT | T_STATISTICS | |
|
744 |
T_DONT_CHECK_CHECKSUM); |
|
745 |
param.using_global_keycache = 1; |
|
1115.1.3
by Brian Aker
Remove final bits of "myisam" specific from drizzled.cc |
746 |
param.stats_method= MI_STATS_METHOD_NULLS_NOT_EQUAL; |
1
by brian
clean slate |
747 |
|
748 |
if (!(share->state.changed & STATE_NOT_ANALYZED)) |
|
749 |
return HA_ADMIN_ALREADY_DONE; |
|
750 |
||
751 |
error = chk_key(¶m, file); |
|
752 |
if (!error) |
|
753 |
{
|
|
754 |
pthread_mutex_lock(&share->intern_lock); |
|
755 |
error=update_state_info(¶m,file,UPDATE_STAT); |
|
756 |
pthread_mutex_unlock(&share->intern_lock); |
|
757 |
}
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
758 |
else if (!mi_is_crashed(file) && !session->killed) |
1
by brian
clean slate |
759 |
mi_mark_crashed(file); |
760 |
return error ? HA_ADMIN_CORRUPT : HA_ADMIN_OK; |
|
761 |
}
|
|
762 |
||
763 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
764 |
int ha_myisam::repair(Session* session, HA_CHECK_OPT *check_opt) |
1
by brian
clean slate |
765 |
{
|
766 |
int error; |
|
767 |
MI_CHECK param; |
|
768 |
ha_rows start_records; |
|
769 |
||
770 |
if (!file) return HA_ADMIN_INTERNAL_ERROR; |
|
771 |
||
772 |
myisamchk_init(¶m); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
773 |
param.session = session; |
1
by brian
clean slate |
774 |
param.op_name= "repair"; |
775 |
param.testflag= ((check_opt->flags & ~(T_EXTEND)) | |
|
776 |
T_SILENT | T_FORCE_CREATE | T_CALC_CHECKSUM | |
|
777 |
(check_opt->flags & T_EXTEND ? T_REP : T_REP_BY_SORT)); |
|
779.3.20
by Monty Taylor
Fixed Solaris warnings for MyISAM. |
778 |
param.sort_buffer_length= (size_t)sort_buffer_size; |
873.2.11
by Monty Taylor
call ha_release_temporary_latches |
779 |
|
780 |
// Release latches since this can take a long time
|
|
781 |
ha_release_temporary_latches(session); |
|
782 |
||
1
by brian
clean slate |
783 |
start_records=file->state->records; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
784 |
while ((error=repair(session,param,0)) && param.retry_repair) |
1
by brian
clean slate |
785 |
{
|
786 |
param.retry_repair=0; |
|
787 |
if (test_all_bits(param.testflag, |
|
788 |
(uint) (T_RETRY_WITHOUT_QUICK | T_QUICK))) |
|
789 |
{
|
|
790 |
param.testflag&= ~T_RETRY_WITHOUT_QUICK; |
|
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
791 |
errmsg_printf(ERRMSG_LVL_INFO, "Retrying repair of: '%s' without quick", |
1
by brian
clean slate |
792 |
table->s->path.str); |
793 |
continue; |
|
794 |
}
|
|
795 |
param.testflag&= ~T_QUICK; |
|
796 |
if ((param.testflag & T_REP_BY_SORT)) |
|
797 |
{
|
|
798 |
param.testflag= (param.testflag & ~T_REP_BY_SORT) | T_REP; |
|
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
799 |
errmsg_printf(ERRMSG_LVL_INFO, "Retrying repair of: '%s' with keycache", |
1
by brian
clean slate |
800 |
table->s->path.str); |
801 |
continue; |
|
802 |
}
|
|
803 |
break; |
|
804 |
}
|
|
805 |
if (!error && start_records != file->state->records && |
|
806 |
!(check_opt->flags & T_VERY_SILENT)) |
|
807 |
{
|
|
808 |
char llbuff[22],llbuff2[22]; |
|
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
809 |
errmsg_printf(ERRMSG_LVL_INFO, "Found %s of %s rows when repairing '%s'", |
1
by brian
clean slate |
810 |
llstr(file->state->records, llbuff), |
811 |
llstr(start_records, llbuff2), |
|
812 |
table->s->path.str); |
|
813 |
}
|
|
814 |
return error; |
|
815 |
}
|
|
816 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
817 |
int ha_myisam::optimize(Session* session, HA_CHECK_OPT *check_opt) |
1
by brian
clean slate |
818 |
{
|
819 |
int error; |
|
820 |
if (!file) return HA_ADMIN_INTERNAL_ERROR; |
|
821 |
MI_CHECK param; |
|
822 |
||
823 |
myisamchk_init(¶m); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
824 |
param.session = session; |
1
by brian
clean slate |
825 |
param.op_name= "optimize"; |
826 |
param.testflag= (check_opt->flags | T_SILENT | T_FORCE_CREATE | |
|
827 |
T_REP_BY_SORT | T_STATISTICS | T_SORT_INDEX); |
|
779.3.20
by Monty Taylor
Fixed Solaris warnings for MyISAM. |
828 |
param.sort_buffer_length= (size_t)sort_buffer_size; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
829 |
if ((error= repair(session,param,1)) && param.retry_repair) |
1
by brian
clean slate |
830 |
{
|
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
831 |
errmsg_printf(ERRMSG_LVL_WARN, "Warning: Optimize table got errno %d on %s.%s, retrying", |
1
by brian
clean slate |
832 |
my_errno, param.db_name, param.table_name); |
833 |
param.testflag&= ~T_REP_BY_SORT; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
834 |
error= repair(session,param,1); |
1
by brian
clean slate |
835 |
}
|
836 |
return error; |
|
837 |
}
|
|
838 |
||
839 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
840 |
int ha_myisam::repair(Session *session, MI_CHECK ¶m, bool do_optimize) |
1
by brian
clean slate |
841 |
{
|
842 |
int error=0; |
|
789
by Brian Aker
MyISAM fix. |
843 |
uint32_t local_testflag= param.testflag; |
1
by brian
clean slate |
844 |
bool optimize_done= !do_optimize, statistics_done=0; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
845 |
const char *old_proc_info= session->get_proc_info(); |
1
by brian
clean slate |
846 |
char fixed_name[FN_REFLEN]; |
847 |
MYISAM_SHARE* share = file->s; |
|
848 |
ha_rows rows= file->state->records; |
|
849 |
||
850 |
/*
|
|
851 |
Normally this method is entered with a properly opened table. If the
|
|
852 |
repair fails, it can be repeated with more elaborate options. Under
|
|
853 |
special circumstances it can happen that a repair fails so that it
|
|
854 |
closed the data file and cannot re-open it. In this case file->dfile
|
|
855 |
is set to -1. We must not try another repair without an open data
|
|
856 |
file. (Bug #25289)
|
|
857 |
*/
|
|
858 |
if (file->dfile == -1) |
|
859 |
{
|
|
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
860 |
errmsg_printf(ERRMSG_LVL_INFO, "Retrying repair of: '%s' failed. " |
1
by brian
clean slate |
861 |
"Please try REPAIR EXTENDED or myisamchk", |
862 |
table->s->path.str); |
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
863 |
return(HA_ADMIN_FAILED); |
1
by brian
clean slate |
864 |
}
|
865 |
||
866 |
param.db_name= table->s->db.str; |
|
867 |
param.table_name= table->alias; |
|
868 |
param.tmpfile_createflag = O_RDWR | O_TRUNC; |
|
869 |
param.using_global_keycache = 1; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
870 |
param.session= session; |
1
by brian
clean slate |
871 |
param.out_flag= 0; |
779.3.20
by Monty Taylor
Fixed Solaris warnings for MyISAM. |
872 |
param.sort_buffer_length= (size_t)sort_buffer_size; |
641.4.3
by Toru Maesaka
Final pass of replacing MySQL's my_stpcpy() with appropriate libc calls |
873 |
strcpy(fixed_name,file->filename); |
1
by brian
clean slate |
874 |
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
875 |
// Don't lock tables if we have used LOCK Table
|
1054.1.8
by Brian Aker
Remove lock_tables list from session. |
876 |
if (mi_lock_database(file, table->s->tmp_table ? F_EXTRA_LCK : F_WRLCK)) |
1
by brian
clean slate |
877 |
{
|
878 |
mi_check_print_error(¶m,ER(ER_CANT_LOCK),my_errno); |
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
879 |
return(HA_ADMIN_FAILED); |
1
by brian
clean slate |
880 |
}
|
881 |
||
882 |
if (!do_optimize || |
|
883 |
((file->state->del || share->state.split != file->state->records) && |
|
884 |
(!(param.testflag & T_QUICK) || |
|
885 |
!(share->state.changed & STATE_NOT_OPTIMIZED_KEYS)))) |
|
886 |
{
|
|
887 |
uint64_t key_map= ((local_testflag & T_CREATE_MISSING_KEYS) ? |
|
888 |
mi_get_mask_all_keys_active(share->base.keys) : |
|
889 |
share->state.key_map); |
|
482
by Brian Aker
Remove uint. |
890 |
uint32_t testflag=param.testflag; |
1
by brian
clean slate |
891 |
if (mi_test_if_sort_rep(file,file->state->records,key_map,0) && |
892 |
(local_testflag & T_REP_BY_SORT)) |
|
893 |
{
|
|
894 |
local_testflag|= T_STATISTICS; |
|
895 |
param.testflag|= T_STATISTICS; // We get this for free |
|
896 |
statistics_done=1; |
|
753
by Brian Aker
Converted myisam_repair_threads to being in module for MyISAM |
897 |
if (repair_threads > 1) |
1
by brian
clean slate |
898 |
{
|
899 |
char buf[40]; |
|
900 |
/* TODO: respect myisam_repair_threads variable */
|
|
77.1.18
by Monty Taylor
Removed my_vsnprintf and my_snprintf. |
901 |
snprintf(buf, 40, "Repair with %d threads", my_count_bits(key_map)); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
902 |
session->set_proc_info(buf); |
1
by brian
clean slate |
903 |
error = mi_repair_parallel(¶m, file, fixed_name, |
904 |
param.testflag & T_QUICK); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
905 |
session->set_proc_info("Repair done"); // to reset proc_info, as |
1
by brian
clean slate |
906 |
// it was pointing to local buffer
|
907 |
}
|
|
908 |
else
|
|
909 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
910 |
session->set_proc_info("Repair by sorting"); |
1
by brian
clean slate |
911 |
error = mi_repair_by_sort(¶m, file, fixed_name, |
912 |
param.testflag & T_QUICK); |
|
913 |
}
|
|
914 |
}
|
|
915 |
else
|
|
916 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
917 |
session->set_proc_info("Repair with keycache"); |
1
by brian
clean slate |
918 |
param.testflag &= ~T_REP_BY_SORT; |
919 |
error= mi_repair(¶m, file, fixed_name, |
|
920 |
param.testflag & T_QUICK); |
|
921 |
}
|
|
922 |
param.testflag=testflag; |
|
923 |
optimize_done=1; |
|
924 |
}
|
|
925 |
if (!error) |
|
926 |
{
|
|
927 |
if ((local_testflag & T_SORT_INDEX) && |
|
928 |
(share->state.changed & STATE_NOT_SORTED_PAGES)) |
|
929 |
{
|
|
930 |
optimize_done=1; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
931 |
session->set_proc_info("Sorting index"); |
1
by brian
clean slate |
932 |
error=mi_sort_index(¶m,file,fixed_name); |
933 |
}
|
|
934 |
if (!statistics_done && (local_testflag & T_STATISTICS)) |
|
935 |
{
|
|
936 |
if (share->state.changed & STATE_NOT_ANALYZED) |
|
937 |
{
|
|
938 |
optimize_done=1; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
939 |
session->set_proc_info("Analyzing"); |
1
by brian
clean slate |
940 |
error = chk_key(¶m, file); |
941 |
}
|
|
942 |
else
|
|
943 |
local_testflag&= ~T_STATISTICS; // Don't update statistics |
|
944 |
}
|
|
945 |
}
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
946 |
session->set_proc_info("Saving state"); |
1
by brian
clean slate |
947 |
if (!error) |
948 |
{
|
|
949 |
if ((share->state.changed & STATE_CHANGED) || mi_is_crashed(file)) |
|
950 |
{
|
|
951 |
share->state.changed&= ~(STATE_CHANGED | STATE_CRASHED | |
|
952 |
STATE_CRASHED_ON_REPAIR); |
|
953 |
file->update|=HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; |
|
954 |
}
|
|
955 |
/*
|
|
956 |
the following 'if', thought conceptually wrong,
|
|
957 |
is a useful optimization nevertheless.
|
|
958 |
*/
|
|
959 |
if (file->state != &file->s->state.state) |
|
960 |
file->s->state.state = *file->state; |
|
961 |
if (file->s->base.auto_key) |
|
962 |
update_auto_increment_key(¶m, file, 1); |
|
963 |
if (optimize_done) |
|
964 |
error = update_state_info(¶m, file, |
|
965 |
UPDATE_TIME | UPDATE_OPEN_COUNT | |
|
966 |
(local_testflag & |
|
967 |
T_STATISTICS ? UPDATE_STAT : 0)); |
|
968 |
info(HA_STATUS_NO_LOCK | HA_STATUS_TIME | HA_STATUS_VARIABLE | |
|
969 |
HA_STATUS_CONST); |
|
970 |
if (rows != file->state->records && ! (param.testflag & T_VERY_SILENT)) |
|
971 |
{
|
|
972 |
char llbuff[22],llbuff2[22]; |
|
973 |
mi_check_print_warning(¶m,"Number of rows changed from %s to %s", |
|
974 |
llstr(rows,llbuff), |
|
975 |
llstr(file->state->records,llbuff2)); |
|
976 |
}
|
|
977 |
}
|
|
978 |
else
|
|
979 |
{
|
|
980 |
mi_mark_crashed_on_repair(file); |
|
981 |
file->update |= HA_STATE_CHANGED | HA_STATE_ROW_CHANGED; |
|
982 |
update_state_info(¶m, file, 0); |
|
983 |
}
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
984 |
session->set_proc_info(old_proc_info); |
1054.1.8
by Brian Aker
Remove lock_tables list from session. |
985 |
mi_lock_database(file,F_UNLCK); |
986 |
||
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
987 |
return(error ? HA_ADMIN_FAILED : |
1
by brian
clean slate |
988 |
!optimize_done ? HA_ADMIN_ALREADY_DONE : HA_ADMIN_OK); |
989 |
}
|
|
990 |
||
991 |
||
992 |
/*
|
|
993 |
Assign table indexes to a specific key cache.
|
|
994 |
*/
|
|
995 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
996 |
int ha_myisam::assign_to_keycache(Session* session, HA_CHECK_OPT *check_opt) |
1
by brian
clean slate |
997 |
{
|
998 |
KEY_CACHE *new_key_cache= check_opt->key_cache; |
|
999 |
const char *errmsg= 0; |
|
1000 |
int error= HA_ADMIN_OK; |
|
327.2.4
by Brian Aker
Refactoring table.h |
1001 |
TableList *table_list= table->pos_in_table_list; |
1
by brian
clean slate |
1002 |
|
1005.2.6
by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<> |
1003 |
table->keys_in_use_for_query.reset(); |
1
by brian
clean slate |
1004 |
|
1005 |
if (table_list->process_index_hints(table)) |
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1006 |
return(HA_ADMIN_FAILED); |
1
by brian
clean slate |
1007 |
|
1005.2.6
by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<> |
1008 |
if ((error= mi_assign_to_key_cache(file, new_key_cache))) |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1009 |
{
|
1
by brian
clean slate |
1010 |
char buf[STRING_BUFFER_USUAL_SIZE]; |
77.1.18
by Monty Taylor
Removed my_vsnprintf and my_snprintf. |
1011 |
snprintf(buf, sizeof(buf), |
1
by brian
clean slate |
1012 |
"Failed to flush to index file (errno: %d)", error); |
1013 |
errmsg= buf; |
|
1014 |
error= HA_ADMIN_CORRUPT; |
|
1015 |
}
|
|
1016 |
||
1017 |
if (error != HA_ADMIN_OK) |
|
1018 |
{
|
|
1019 |
/* Send error to user */
|
|
1020 |
MI_CHECK param; |
|
1021 |
myisamchk_init(¶m); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1022 |
param.session= session; |
1
by brian
clean slate |
1023 |
param.op_name= "assign_to_keycache"; |
1024 |
param.db_name= table->s->db.str; |
|
1025 |
param.table_name= table->s->table_name.str; |
|
1026 |
param.testflag= 0; |
|
1027 |
mi_check_print_error(¶m, errmsg); |
|
1028 |
}
|
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1029 |
return(error); |
1
by brian
clean slate |
1030 |
}
|
1031 |
||
1032 |
||
1033 |
/*
|
|
1034 |
Disable indexes, making it persistent if requested.
|
|
1035 |
||
1036 |
SYNOPSIS
|
|
1037 |
disable_indexes()
|
|
1038 |
mode mode of operation:
|
|
1039 |
HA_KEY_SWITCH_NONUNIQ disable all non-unique keys
|
|
1040 |
HA_KEY_SWITCH_ALL disable all keys
|
|
1041 |
HA_KEY_SWITCH_NONUNIQ_SAVE dis. non-uni. and make persistent
|
|
1042 |
HA_KEY_SWITCH_ALL_SAVE dis. all keys and make persistent
|
|
1043 |
||
1044 |
IMPLEMENTATION
|
|
1045 |
HA_KEY_SWITCH_NONUNIQ is not implemented.
|
|
1046 |
HA_KEY_SWITCH_ALL_SAVE is not implemented.
|
|
1047 |
||
1048 |
RETURN
|
|
1049 |
0 ok
|
|
1050 |
HA_ERR_WRONG_COMMAND mode not implemented.
|
|
1051 |
*/
|
|
1052 |
||
482
by Brian Aker
Remove uint. |
1053 |
int ha_myisam::disable_indexes(uint32_t mode) |
1
by brian
clean slate |
1054 |
{
|
1055 |
int error; |
|
1056 |
||
1057 |
if (mode == HA_KEY_SWITCH_ALL) |
|
1058 |
{
|
|
1059 |
/* call a storage engine function to switch the key map */
|
|
1060 |
error= mi_disable_indexes(file); |
|
1061 |
}
|
|
1062 |
else if (mode == HA_KEY_SWITCH_NONUNIQ_SAVE) |
|
1063 |
{
|
|
1064 |
mi_extra(file, HA_EXTRA_NO_KEYS, 0); |
|
1065 |
info(HA_STATUS_CONST); // Read new key info |
|
1066 |
error= 0; |
|
1067 |
}
|
|
1068 |
else
|
|
1069 |
{
|
|
1070 |
/* mode not implemented */
|
|
1071 |
error= HA_ERR_WRONG_COMMAND; |
|
1072 |
}
|
|
1073 |
return error; |
|
1074 |
}
|
|
1075 |
||
1076 |
||
1077 |
/*
|
|
1078 |
Enable indexes, making it persistent if requested.
|
|
1079 |
||
1080 |
SYNOPSIS
|
|
1081 |
enable_indexes()
|
|
1082 |
mode mode of operation:
|
|
1083 |
HA_KEY_SWITCH_NONUNIQ enable all non-unique keys
|
|
1084 |
HA_KEY_SWITCH_ALL enable all keys
|
|
1085 |
HA_KEY_SWITCH_NONUNIQ_SAVE en. non-uni. and make persistent
|
|
1086 |
HA_KEY_SWITCH_ALL_SAVE en. all keys and make persistent
|
|
1087 |
||
1088 |
DESCRIPTION
|
|
1089 |
Enable indexes, which might have been disabled by disable_index() before.
|
|
1090 |
The modes without _SAVE work only if both data and indexes are empty,
|
|
1091 |
since the MyISAM repair would enable them persistently.
|
|
1092 |
To be sure in these cases, call handler::delete_all_rows() before.
|
|
1093 |
||
1094 |
IMPLEMENTATION
|
|
1095 |
HA_KEY_SWITCH_NONUNIQ is not implemented.
|
|
1096 |
HA_KEY_SWITCH_ALL_SAVE is not implemented.
|
|
1097 |
||
1098 |
RETURN
|
|
1099 |
0 ok
|
|
1100 |
!=0 Error, among others:
|
|
1101 |
HA_ERR_CRASHED data or index is non-empty. Delete all rows and retry.
|
|
1102 |
HA_ERR_WRONG_COMMAND mode not implemented.
|
|
1103 |
*/
|
|
1104 |
||
482
by Brian Aker
Remove uint. |
1105 |
int ha_myisam::enable_indexes(uint32_t mode) |
1
by brian
clean slate |
1106 |
{
|
1107 |
int error; |
|
1108 |
||
1109 |
if (mi_is_all_keys_active(file->s->state.key_map, file->s->base.keys)) |
|
1110 |
{
|
|
1111 |
/* All indexes are enabled already. */
|
|
1112 |
return 0; |
|
1113 |
}
|
|
1114 |
||
1115 |
if (mode == HA_KEY_SWITCH_ALL) |
|
1116 |
{
|
|
1117 |
error= mi_enable_indexes(file); |
|
1118 |
/*
|
|
1119 |
Do not try to repair on error,
|
|
1120 |
as this could make the enabled state persistent,
|
|
1121 |
but mode==HA_KEY_SWITCH_ALL forbids it.
|
|
1122 |
*/
|
|
1123 |
}
|
|
1124 |
else if (mode == HA_KEY_SWITCH_NONUNIQ_SAVE) |
|
1125 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1126 |
Session *session=current_session; |
1
by brian
clean slate |
1127 |
MI_CHECK param; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
1128 |
const char *save_proc_info= session->get_proc_info(); |
1129 |
session->set_proc_info("Creating index"); |
|
1
by brian
clean slate |
1130 |
myisamchk_init(¶m); |
1131 |
param.op_name= "recreating_index"; |
|
1132 |
param.testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK | |
|
1133 |
T_CREATE_MISSING_KEYS); |
|
1134 |
param.myf_rw&= ~MY_WAIT_IF_FULL; |
|
779.3.20
by Monty Taylor
Fixed Solaris warnings for MyISAM. |
1135 |
param.sort_buffer_length= (size_t)sort_buffer_size; |
1115.1.3
by Brian Aker
Remove final bits of "myisam" specific from drizzled.cc |
1136 |
param.stats_method= MI_STATS_METHOD_NULLS_NOT_EQUAL; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
1137 |
if ((error= (repair(session,param,0) != HA_ADMIN_OK)) && param.retry_repair) |
1
by brian
clean slate |
1138 |
{
|
755.2.1
by Mark Atwood
replace sql_print_error etc with errmsg_print |
1139 |
errmsg_printf(ERRMSG_LVL_WARN, "Warning: Enabling keys got errno %d on %s.%s, retrying", |
1
by brian
clean slate |
1140 |
my_errno, param.db_name, param.table_name); |
1141 |
/* Repairing by sort failed. Now try standard repair method. */
|
|
1142 |
param.testflag&= ~(T_REP_BY_SORT | T_QUICK); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1143 |
error= (repair(session,param,0) != HA_ADMIN_OK); |
1
by brian
clean slate |
1144 |
/*
|
1145 |
If the standard repair succeeded, clear all error messages which
|
|
1146 |
might have been set by the first repair. They can still be seen
|
|
1147 |
with SHOW WARNINGS then.
|
|
1148 |
*/
|
|
1149 |
if (! error) |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1150 |
session->clear_error(); |
1
by brian
clean slate |
1151 |
}
|
1152 |
info(HA_STATUS_CONST); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1153 |
session->set_proc_info(save_proc_info); |
1
by brian
clean slate |
1154 |
}
|
1155 |
else
|
|
1156 |
{
|
|
1157 |
/* mode not implemented */
|
|
1158 |
error= HA_ERR_WRONG_COMMAND; |
|
1159 |
}
|
|
1160 |
return error; |
|
1161 |
}
|
|
1162 |
||
1163 |
||
1164 |
/*
|
|
1165 |
Test if indexes are disabled.
|
|
1166 |
||
1167 |
||
1168 |
SYNOPSIS
|
|
1169 |
indexes_are_disabled()
|
|
1170 |
no parameters
|
|
1171 |
||
1172 |
||
1173 |
RETURN
|
|
1174 |
0 indexes are not disabled
|
|
1175 |
1 all indexes are disabled
|
|
1176 |
[2 non-unique indexes are disabled - NOT YET IMPLEMENTED]
|
|
1177 |
*/
|
|
1178 |
||
1179 |
int ha_myisam::indexes_are_disabled(void) |
|
1180 |
{
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1181 |
|
1
by brian
clean slate |
1182 |
return mi_indexes_are_disabled(file); |
1183 |
}
|
|
1184 |
||
1185 |
||
1186 |
/*
|
|
1187 |
prepare for a many-rows insert operation
|
|
1188 |
e.g. - disable indexes (if they can be recreated fast) or
|
|
1189 |
activate special bulk-insert optimizations
|
|
1190 |
||
1191 |
SYNOPSIS
|
|
1192 |
start_bulk_insert(rows)
|
|
1193 |
rows Rows to be inserted
|
|
1194 |
0 if we don't know
|
|
1195 |
||
1196 |
NOTICE
|
|
1197 |
Do not forget to call end_bulk_insert() later!
|
|
1198 |
*/
|
|
1199 |
||
1200 |
void ha_myisam::start_bulk_insert(ha_rows rows) |
|
1201 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1202 |
Session *session= current_session; |
1067.4.8
by Nathan Williams
Converted all usages of cmin/cmax in plugin directory to std::min/max. |
1203 |
ulong size= min(session->variables.read_buff_size, |
1204 |
(uint32_t)(table->s->avg_row_length*rows)); |
|
1
by brian
clean slate |
1205 |
|
1206 |
/* don't enable row cache if too few rows */
|
|
1207 |
if (! rows || (rows > MI_MIN_ROWS_TO_USE_WRITE_CACHE)) |
|
1208 |
mi_extra(file, HA_EXTRA_WRITE_CACHE, (void*) &size); |
|
1209 |
||
1210 |
can_enable_indexes= mi_is_all_keys_active(file->s->state.key_map, |
|
1211 |
file->s->base.keys); |
|
1212 |
||
362
by Brian Aker
No more dead special flags... |
1213 |
/*
|
1214 |
Only disable old index if the table was empty and we are inserting
|
|
1215 |
a lot of rows.
|
|
1216 |
We should not do this for only a few rows as this is slower and
|
|
1217 |
we don't want to update the key statistics based of only a few rows.
|
|
1218 |
*/
|
|
1219 |
if (file->state->records == 0 && can_enable_indexes && |
|
1220 |
(!rows || rows >= MI_MIN_ROWS_TO_DISABLE_INDEXES)) |
|
1221 |
mi_disable_non_unique_index(file,rows); |
|
1222 |
else
|
|
1
by brian
clean slate |
1223 |
if (!file->bulk_insert && |
1224 |
(!rows || rows >= MI_MIN_ROWS_TO_USE_BULK_INSERT)) |
|
1225 |
{
|
|
779.3.20
by Monty Taylor
Fixed Solaris warnings for MyISAM. |
1226 |
mi_init_bulk_insert(file, |
1227 |
(size_t)session->variables.bulk_insert_buff_size, |
|
1228 |
rows); |
|
1
by brian
clean slate |
1229 |
}
|
362
by Brian Aker
No more dead special flags... |
1230 |
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1231 |
return; |
1
by brian
clean slate |
1232 |
}
|
1233 |
||
1234 |
/*
|
|
1235 |
end special bulk-insert optimizations,
|
|
1236 |
which have been activated by start_bulk_insert().
|
|
1237 |
||
1238 |
SYNOPSIS
|
|
1239 |
end_bulk_insert()
|
|
1240 |
no arguments
|
|
1241 |
||
1242 |
RETURN
|
|
1243 |
0 OK
|
|
1244 |
!= 0 Error
|
|
1245 |
*/
|
|
1246 |
||
1247 |
int ha_myisam::end_bulk_insert() |
|
1248 |
{
|
|
1249 |
mi_end_bulk_insert(file); |
|
1250 |
int err=mi_extra(file, HA_EXTRA_NO_CACHE, 0); |
|
1251 |
return err ? err : can_enable_indexes ? |
|
1252 |
enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE) : 0; |
|
1253 |
}
|
|
1254 |
||
1255 |
||
1256 |
||
1257 |
bool ha_myisam::is_crashed() const |
|
1258 |
{
|
|
1259 |
return (file->s->state.changed & STATE_CRASHED || |
|
77.1.96
by Monty Taylor
Removed skip-external-locking. |
1260 |
(file->s->state.open_count)); |
1
by brian
clean slate |
1261 |
}
|
1262 |
||
481
by Brian Aker
Remove all of uchar. |
1263 |
int ha_myisam::update_row(const unsigned char *old_data, unsigned char *new_data) |
1
by brian
clean slate |
1264 |
{
|
1265 |
ha_statistic_increment(&SSV::ha_update_count); |
|
1266 |
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE) |
|
1267 |
table->timestamp_field->set_time(); |
|
1268 |
return mi_update(file,old_data,new_data); |
|
1269 |
}
|
|
1270 |
||
481
by Brian Aker
Remove all of uchar. |
1271 |
int ha_myisam::delete_row(const unsigned char *buf) |
1
by brian
clean slate |
1272 |
{
|
1273 |
ha_statistic_increment(&SSV::ha_delete_count); |
|
1274 |
return mi_delete(file,buf); |
|
1275 |
}
|
|
1276 |
||
1277 |
||
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
1278 |
int ha_myisam::index_init(uint32_t idx, bool ) |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1279 |
{
|
1
by brian
clean slate |
1280 |
active_index=idx; |
163
by Brian Aker
Merge Monty's code. |
1281 |
//in_range_read= false;
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1282 |
return 0; |
1
by brian
clean slate |
1283 |
}
|
1284 |
||
1285 |
||
1286 |
int ha_myisam::index_end() |
|
1287 |
{
|
|
1288 |
active_index=MAX_KEY; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1289 |
return 0; |
1
by brian
clean slate |
1290 |
}
|
1291 |
||
1292 |
||
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
1293 |
uint32_t ha_myisam::index_flags(uint32_t inx, uint32_t, bool) const |
1294 |
{
|
|
1295 |
return ((table_share->key_info[inx].algorithm == HA_KEY_ALG_FULLTEXT) ? |
|
1296 |
0 : HA_READ_NEXT | HA_READ_PREV | HA_READ_RANGE | |
|
1297 |
HA_READ_ORDER | HA_KEYREAD_ONLY | |
|
1005.2.6
by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<> |
1298 |
(keys_with_parts.test(inx)?0:HA_DO_INDEX_COND_PUSHDOWN)); |
584.1.15
by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes. |
1299 |
}
|
1300 |
||
1301 |
||
481
by Brian Aker
Remove all of uchar. |
1302 |
int ha_myisam::index_read_map(unsigned char *buf, const unsigned char *key, |
1
by brian
clean slate |
1303 |
key_part_map keypart_map, |
1304 |
enum ha_rkey_function find_flag) |
|
1305 |
{
|
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1306 |
assert(inited==INDEX); |
1
by brian
clean slate |
1307 |
ha_statistic_increment(&SSV::ha_read_key_count); |
1308 |
int error=mi_rkey(file, buf, active_index, key, keypart_map, find_flag); |
|
1309 |
table->status=error ? STATUS_NOT_FOUND: 0; |
|
1310 |
return error; |
|
1311 |
}
|
|
1312 |
||
482
by Brian Aker
Remove uint. |
1313 |
int ha_myisam::index_read_idx_map(unsigned char *buf, uint32_t index, const unsigned char *key, |
1
by brian
clean slate |
1314 |
key_part_map keypart_map, |
1315 |
enum ha_rkey_function find_flag) |
|
1316 |
{
|
|
1317 |
ha_statistic_increment(&SSV::ha_read_key_count); |
|
1318 |
int error=mi_rkey(file, buf, index, key, keypart_map, find_flag); |
|
1319 |
table->status=error ? STATUS_NOT_FOUND: 0; |
|
1320 |
return error; |
|
1321 |
}
|
|
1322 |
||
481
by Brian Aker
Remove all of uchar. |
1323 |
int ha_myisam::index_read_last_map(unsigned char *buf, const unsigned char *key, |
1
by brian
clean slate |
1324 |
key_part_map keypart_map) |
1325 |
{
|
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1326 |
assert(inited==INDEX); |
1
by brian
clean slate |
1327 |
ha_statistic_increment(&SSV::ha_read_key_count); |
1328 |
int error=mi_rkey(file, buf, active_index, key, keypart_map, |
|
1329 |
HA_READ_PREFIX_LAST); |
|
1330 |
table->status=error ? STATUS_NOT_FOUND: 0; |
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1331 |
return(error); |
1
by brian
clean slate |
1332 |
}
|
1333 |
||
481
by Brian Aker
Remove all of uchar. |
1334 |
int ha_myisam::index_next(unsigned char *buf) |
1
by brian
clean slate |
1335 |
{
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1336 |
assert(inited==INDEX); |
1
by brian
clean slate |
1337 |
ha_statistic_increment(&SSV::ha_read_next_count); |
1338 |
int error=mi_rnext(file,buf,active_index); |
|
1339 |
table->status=error ? STATUS_NOT_FOUND: 0; |
|
1340 |
return error; |
|
1341 |
}
|
|
1342 |
||
481
by Brian Aker
Remove all of uchar. |
1343 |
int ha_myisam::index_prev(unsigned char *buf) |
1
by brian
clean slate |
1344 |
{
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1345 |
assert(inited==INDEX); |
1
by brian
clean slate |
1346 |
ha_statistic_increment(&SSV::ha_read_prev_count); |
1347 |
int error=mi_rprev(file,buf, active_index); |
|
1348 |
table->status=error ? STATUS_NOT_FOUND: 0; |
|
1349 |
return error; |
|
1350 |
}
|
|
1351 |
||
481
by Brian Aker
Remove all of uchar. |
1352 |
int ha_myisam::index_first(unsigned char *buf) |
1
by brian
clean slate |
1353 |
{
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1354 |
assert(inited==INDEX); |
1
by brian
clean slate |
1355 |
ha_statistic_increment(&SSV::ha_read_first_count); |
1356 |
int error=mi_rfirst(file, buf, active_index); |
|
1357 |
table->status=error ? STATUS_NOT_FOUND: 0; |
|
1358 |
return error; |
|
1359 |
}
|
|
1360 |
||
481
by Brian Aker
Remove all of uchar. |
1361 |
int ha_myisam::index_last(unsigned char *buf) |
1
by brian
clean slate |
1362 |
{
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1363 |
assert(inited==INDEX); |
1
by brian
clean slate |
1364 |
ha_statistic_increment(&SSV::ha_read_last_count); |
1365 |
int error=mi_rlast(file, buf, active_index); |
|
1366 |
table->status=error ? STATUS_NOT_FOUND: 0; |
|
1367 |
return error; |
|
1368 |
}
|
|
1369 |
||
481
by Brian Aker
Remove all of uchar. |
1370 |
int ha_myisam::index_next_same(unsigned char *buf, |
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
1371 |
const unsigned char *, |
1372 |
uint32_t ) |
|
1
by brian
clean slate |
1373 |
{
|
1374 |
int error; |
|
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1375 |
assert(inited==INDEX); |
1
by brian
clean slate |
1376 |
ha_statistic_increment(&SSV::ha_read_next_count); |
1377 |
do
|
|
1378 |
{
|
|
1379 |
error= mi_rnext_same(file,buf); |
|
1380 |
} while (error == HA_ERR_RECORD_DELETED); |
|
1381 |
table->status=error ? STATUS_NOT_FOUND: 0; |
|
1382 |
return error; |
|
1383 |
}
|
|
1384 |
||
1385 |
int ha_myisam::read_range_first(const key_range *start_key, |
|
1386 |
const key_range *end_key, |
|
1387 |
bool eq_range_arg, |
|
1388 |
bool sorted /* ignored */) |
|
1389 |
{
|
|
1390 |
int res; |
|
1391 |
//if (!eq_range_arg)
|
|
163
by Brian Aker
Merge Monty's code. |
1392 |
// in_range_read= true;
|
1
by brian
clean slate |
1393 |
|
1394 |
res= handler::read_range_first(start_key, end_key, eq_range_arg, sorted); |
|
1395 |
||
1396 |
//if (res)
|
|
163
by Brian Aker
Merge Monty's code. |
1397 |
// in_range_read= false;
|
1
by brian
clean slate |
1398 |
return res; |
1399 |
}
|
|
1400 |
||
1401 |
||
1402 |
int ha_myisam::read_range_next() |
|
1403 |
{
|
|
1404 |
int res= handler::read_range_next(); |
|
1405 |
//if (res)
|
|
163
by Brian Aker
Merge Monty's code. |
1406 |
// in_range_read= false;
|
1
by brian
clean slate |
1407 |
return res; |
1408 |
}
|
|
1409 |
||
1410 |
||
1411 |
int ha_myisam::rnd_init(bool scan) |
|
1412 |
{
|
|
1413 |
if (scan) |
|
1414 |
return mi_scan_init(file); |
|
1415 |
return mi_reset(file); // Free buffers |
|
1416 |
}
|
|
1417 |
||
481
by Brian Aker
Remove all of uchar. |
1418 |
int ha_myisam::rnd_next(unsigned char *buf) |
1
by brian
clean slate |
1419 |
{
|
1420 |
ha_statistic_increment(&SSV::ha_read_rnd_next_count); |
|
1421 |
int error=mi_scan(file, buf); |
|
1422 |
table->status=error ? STATUS_NOT_FOUND: 0; |
|
1423 |
return error; |
|
1424 |
}
|
|
1425 |
||
481
by Brian Aker
Remove all of uchar. |
1426 |
int ha_myisam::restart_rnd_next(unsigned char *buf, unsigned char *pos) |
1
by brian
clean slate |
1427 |
{
|
1428 |
return rnd_pos(buf,pos); |
|
1429 |
}
|
|
1430 |
||
481
by Brian Aker
Remove all of uchar. |
1431 |
int ha_myisam::rnd_pos(unsigned char *buf, unsigned char *pos) |
1
by brian
clean slate |
1432 |
{
|
1433 |
ha_statistic_increment(&SSV::ha_read_rnd_count); |
|
1434 |
int error=mi_rrnd(file, buf, my_get_ptr(pos,ref_length)); |
|
1435 |
table->status=error ? STATUS_NOT_FOUND: 0; |
|
1436 |
return error; |
|
1437 |
}
|
|
1438 |
||
1439 |
||
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
1440 |
void ha_myisam::position(const unsigned char *) |
1
by brian
clean slate |
1441 |
{
|
1442 |
my_off_t row_position= mi_position(file); |
|
1443 |
my_store_ptr(ref, ref_length, row_position); |
|
1444 |
}
|
|
1445 |
||
482
by Brian Aker
Remove uint. |
1446 |
int ha_myisam::info(uint32_t flag) |
1
by brian
clean slate |
1447 |
{
|
1448 |
MI_ISAMINFO misam_info; |
|
1449 |
char name_buff[FN_REFLEN]; |
|
1450 |
||
1451 |
(void) mi_status(file,&misam_info,flag); |
|
1452 |
if (flag & HA_STATUS_VARIABLE) |
|
1453 |
{
|
|
1454 |
stats.records= misam_info.records; |
|
1455 |
stats.deleted= misam_info.deleted; |
|
1456 |
stats.data_file_length= misam_info.data_file_length; |
|
1457 |
stats.index_file_length= misam_info.index_file_length; |
|
1458 |
stats.delete_length= misam_info.delete_length; |
|
1459 |
stats.check_time= misam_info.check_time; |
|
1460 |
stats.mean_rec_length= misam_info.mean_reclength; |
|
1461 |
}
|
|
1462 |
if (flag & HA_STATUS_CONST) |
|
1463 |
{
|
|
1000.1.3
by Brian Aker
Renamed TABLE_SHARE to TableShare |
1464 |
TableShare *share= table->s; |
1
by brian
clean slate |
1465 |
stats.max_data_file_length= misam_info.max_data_file_length; |
1466 |
stats.max_index_file_length= misam_info.max_index_file_length; |
|
1467 |
stats.create_time= misam_info.create_time; |
|
1468 |
ref_length= misam_info.reflength; |
|
1469 |
share->db_options_in_use= misam_info.options; |
|
754
by Brian Aker
Make block_size for myisam fit into plugin. |
1470 |
stats.block_size= block_size; /* record block size */ |
1
by brian
clean slate |
1471 |
|
1472 |
/* Update share */
|
|
1473 |
if (share->tmp_table == NO_TMP_TABLE) |
|
1474 |
pthread_mutex_lock(&share->mutex); |
|
1005.2.6
by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<> |
1475 |
set_prefix(share->keys_in_use, share->keys); |
1095.6.1
by Padraig O'Sullivan
Fix for 32 bit Solaris builds. Issue was with conversion of 64-bit unsigned |
1476 |
/*
|
1477 |
* Due to bug 394932 (32-bit solaris build failure), we need
|
|
1478 |
* to convert the uint64_t key_map member of the misam_info
|
|
1479 |
* structure in to a std::bitset so that we can logically and
|
|
1480 |
* it with the share->key_in_use key_map.
|
|
1481 |
*/
|
|
1482 |
ostringstream ostr; |
|
1483 |
string binary_key_map; |
|
1484 |
uint64_t num= misam_info.key_map; |
|
1485 |
/*
|
|
1486 |
* Convert the uint64_t to a binary
|
|
1487 |
* string representation of it.
|
|
1488 |
*/
|
|
1489 |
while (num > 0) |
|
1490 |
{
|
|
1491 |
uint64_t bin_digit= num % 2; |
|
1492 |
ostr << bin_digit; |
|
1493 |
num/= 2; |
|
1494 |
}
|
|
1495 |
binary_key_map.append(ostr.str()); |
|
1496 |
/*
|
|
1497 |
* Now we have the binary string representation of the
|
|
1498 |
* flags, we need to fill that string representation out
|
|
1499 |
* with the appropriate number of bits. This is needed
|
|
1500 |
* since key_map is declared as a std::bitset of a certain bit
|
|
1501 |
* width that depends on the MAX_INDEXES variable.
|
|
1502 |
*/
|
|
1503 |
if (MAX_INDEXES <= 64) |
|
1504 |
{
|
|
1505 |
size_t len= 72 - binary_key_map.length(); |
|
1506 |
string all_zeros(len, '0'); |
|
1507 |
binary_key_map.insert(binary_key_map.begin(), |
|
1508 |
all_zeros.begin(), |
|
1509 |
all_zeros.end()); |
|
1510 |
}
|
|
1511 |
else
|
|
1512 |
{
|
|
1513 |
size_t len= (MAX_INDEXES + 7) / 8 * 8; |
|
1514 |
string all_zeros(len, '0'); |
|
1515 |
binary_key_map.insert(binary_key_map.begin(), |
|
1516 |
all_zeros.begin(), |
|
1517 |
all_zeros.end()); |
|
1518 |
}
|
|
1519 |
key_map tmp_map(binary_key_map); |
|
1520 |
share->keys_in_use&= tmp_map; |
|
1005.2.6
by Monty Taylor
Re-added bitset<> as a replacement for Bitmap<> |
1521 |
share->keys_for_keyread&= share->keys_in_use; |
1
by brian
clean slate |
1522 |
share->db_record_offset= misam_info.record_offset; |
1523 |
if (share->key_parts) |
|
212.6.12
by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove(). |
1524 |
memcpy(table->key_info[0].rec_per_key, |
1525 |
misam_info.rec_per_key, |
|
1
by brian
clean slate |
1526 |
sizeof(table->key_info[0].rec_per_key)*share->key_parts); |
1527 |
if (share->tmp_table == NO_TMP_TABLE) |
|
1528 |
pthread_mutex_unlock(&share->mutex); |
|
1529 |
||
1530 |
/*
|
|
1531 |
Set data_file_name and index_file_name to point at the symlink value
|
|
1532 |
if table is symlinked (Ie; Real name is not same as generated name)
|
|
1533 |
*/
|
|
1534 |
data_file_name= index_file_name= 0; |
|
1535 |
fn_format(name_buff, file->filename, "", MI_NAME_DEXT, |
|
1536 |
MY_APPEND_EXT | MY_UNPACK_FILENAME); |
|
1537 |
if (strcmp(name_buff, misam_info.data_file_name)) |
|
1538 |
data_file_name=misam_info.data_file_name; |
|
1539 |
fn_format(name_buff, file->filename, "", MI_NAME_IEXT, |
|
1540 |
MY_APPEND_EXT | MY_UNPACK_FILENAME); |
|
1541 |
if (strcmp(name_buff, misam_info.index_file_name)) |
|
1542 |
index_file_name=misam_info.index_file_name; |
|
1543 |
}
|
|
1544 |
if (flag & HA_STATUS_ERRKEY) |
|
1545 |
{
|
|
1546 |
errkey = misam_info.errkey; |
|
1547 |
my_store_ptr(dup_ref, ref_length, misam_info.dupp_key_pos); |
|
1548 |
}
|
|
1549 |
if (flag & HA_STATUS_TIME) |
|
1550 |
stats.update_time = misam_info.update_time; |
|
1551 |
if (flag & HA_STATUS_AUTO) |
|
1552 |
stats.auto_increment_value= misam_info.auto_increment; |
|
1553 |
||
1554 |
return 0; |
|
1555 |
}
|
|
1556 |
||
1557 |
||
1558 |
int ha_myisam::extra(enum ha_extra_function operation) |
|
1559 |
{
|
|
1560 |
return mi_extra(file, operation, 0); |
|
1561 |
}
|
|
1562 |
||
1563 |
int ha_myisam::reset(void) |
|
1564 |
{
|
|
1565 |
return mi_reset(file); |
|
1566 |
}
|
|
1567 |
||
1568 |
/* To be used with WRITE_CACHE and EXTRA_CACHE */
|
|
1569 |
||
61
by Brian Aker
Conversion of handler type. |
1570 |
int ha_myisam::extra_opt(enum ha_extra_function operation, uint32_t cache_size) |
1
by brian
clean slate |
1571 |
{
|
1572 |
return mi_extra(file, operation, (void*) &cache_size); |
|
1573 |
}
|
|
1574 |
||
1575 |
int ha_myisam::delete_all_rows() |
|
1576 |
{
|
|
1577 |
return mi_delete_all_rows(file); |
|
1578 |
}
|
|
1579 |
||
1095.3.29
by Stewart Smith
s/Impl/Implementation/ |
1580 |
int MyisamEngine::deleteTableImplementation(Session*, const string table_name) |
1
by brian
clean slate |
1581 |
{
|
1039.3.6
by Stewart Smith
fix myisam delete_table path: should be in StorageEngine. |
1582 |
return mi_delete_table(table_name.c_str()); |
1
by brian
clean slate |
1583 |
}
|
1584 |
||
1585 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1586 |
int ha_myisam::external_lock(Session *session, int lock_type) |
1
by brian
clean slate |
1587 |
{
|
916.1.35
by Padraig O'Sullivan
Removing the last of LIST from the MyISAM storage engine. |
1588 |
file->in_use= session; |
1
by brian
clean slate |
1589 |
return mi_lock_database(file, !table->s->tmp_table ? |
1590 |
lock_type : ((lock_type == F_UNLCK) ? |
|
1591 |
F_UNLCK : F_EXTRA_LCK)); |
|
1592 |
}
|
|
1593 |
||
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
1594 |
THR_LOCK_DATA **ha_myisam::store_lock(Session *, |
1
by brian
clean slate |
1595 |
THR_LOCK_DATA **to, |
1596 |
enum thr_lock_type lock_type) |
|
1597 |
{
|
|
1598 |
if (lock_type != TL_IGNORE && file->lock.type == TL_UNLOCK) |
|
1599 |
file->lock.type=lock_type; |
|
1600 |
*to++= &file->lock; |
|
1046.1.7
by Brian Aker
Style cleanup. |
1601 |
|
1
by brian
clean slate |
1602 |
return to; |
1603 |
}
|
|
1604 |
||
1605 |
void ha_myisam::update_create_info(HA_CREATE_INFO *create_info) |
|
1606 |
{
|
|
1607 |
ha_myisam::info(HA_STATUS_AUTO | HA_STATUS_CONST); |
|
1608 |
if (!(create_info->used_fields & HA_CREATE_USED_AUTO)) |
|
1609 |
{
|
|
1610 |
create_info->auto_increment_value= stats.auto_increment_value; |
|
1611 |
}
|
|
1612 |
create_info->data_file_name=data_file_name; |
|
1613 |
create_info->index_file_name=index_file_name; |
|
1614 |
}
|
|
1615 |
||
1616 |
||
1095.3.29
by Stewart Smith
s/Impl/Implementation/ |
1617 |
int MyisamEngine::createTableImplementation(Session *, const char *table_name, |
1618 |
Table *table_arg, |
|
1619 |
HA_CREATE_INFO *ha_create_info, |
|
1620 |
drizzled::message::Table*) |
|
1
by brian
clean slate |
1621 |
{
|
1622 |
int error; |
|
779.3.10
by Monty Taylor
Turned on -Wshadow. |
1623 |
uint32_t create_flags= 0, create_records; |
1
by brian
clean slate |
1624 |
char buff[FN_REFLEN]; |
1625 |
MI_KEYDEF *keydef; |
|
1626 |
MI_COLUMNDEF *recinfo; |
|
1627 |
MI_CREATE_INFO create_info; |
|
1000.1.3
by Brian Aker
Renamed TABLE_SHARE to TableShare |
1628 |
TableShare *share= table_arg->s; |
482
by Brian Aker
Remove uint. |
1629 |
uint32_t options= share->db_options_in_use; |
779.3.10
by Monty Taylor
Turned on -Wshadow. |
1630 |
if ((error= table2myisam(table_arg, &keydef, &recinfo, &create_records))) |
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1631 |
return(error); /* purecov: inspected */ |
212.6.12
by Mats Kindahl
Removing redundant use of casts in MyISAM storage for memcmp(), memcpy(), memset(), and memmove(). |
1632 |
memset(&create_info, 0, sizeof(create_info)); |
1
by brian
clean slate |
1633 |
create_info.max_rows= share->max_rows; |
1634 |
create_info.reloc_rows= share->min_rows; |
|
1635 |
create_info.with_auto_increment= share->next_number_key_offset == 0; |
|
1636 |
create_info.auto_increment= (ha_create_info->auto_increment_value ? |
|
1637 |
ha_create_info->auto_increment_value -1 : |
|
1638 |
(uint64_t) 0); |
|
1639 |
create_info.data_file_length= ((uint64_t) share->max_rows * |
|
1640 |
share->avg_row_length); |
|
1641 |
create_info.data_file_name= ha_create_info->data_file_name; |
|
1642 |
create_info.index_file_name= ha_create_info->index_file_name; |
|
1643 |
create_info.language= share->table_charset->number; |
|
1644 |
||
1645 |
if (ha_create_info->options & HA_LEX_CREATE_TMP_TABLE) |
|
1646 |
create_flags|= HA_CREATE_TMP_TABLE; |
|
1647 |
if (ha_create_info->options & HA_CREATE_KEEP_FILES) |
|
1648 |
create_flags|= HA_CREATE_KEEP_FILES; |
|
1649 |
if (options & HA_OPTION_PACK_RECORD) |
|
1650 |
create_flags|= HA_PACK_RECORD; |
|
1651 |
if (options & HA_OPTION_CHECKSUM) |
|
1652 |
create_flags|= HA_CREATE_CHECKSUM; |
|
1653 |
if (options & HA_OPTION_DELAY_KEY_WRITE) |
|
1654 |
create_flags|= HA_CREATE_DELAY_KEY_WRITE; |
|
1655 |
||
1656 |
/* TODO: Check that the following fn_format is really needed */
|
|
1039.3.3
by Stewart Smith
Move handler::create to StorageEngine::create_table |
1657 |
error= mi_create(fn_format(buff, table_name, "", "", |
1
by brian
clean slate |
1658 |
MY_UNPACK_FILENAME|MY_APPEND_EXT), |
1659 |
share->keys, keydef, |
|
779.3.10
by Monty Taylor
Turned on -Wshadow. |
1660 |
create_records, recinfo, |
1
by brian
clean slate |
1661 |
0, (MI_UNIQUEDEF*) 0, |
1662 |
&create_info, create_flags); |
|
481
by Brian Aker
Remove all of uchar. |
1663 |
free((unsigned char*) recinfo); |
51.1.89
by Jay Pipes
Removed/replaced DBUG symbols and TRUE/FALSE |
1664 |
return(error); |
1
by brian
clean slate |
1665 |
}
|
1666 |
||
1667 |
||
1095.3.29
by Stewart Smith
s/Impl/Implementation/ |
1668 |
int MyisamEngine::renameTableImplementation(Session*, |
1669 |
const char *from, const char *to) |
|
1
by brian
clean slate |
1670 |
{
|
1671 |
return mi_rename(from,to); |
|
1672 |
}
|
|
1673 |
||
1674 |
||
779.1.27
by Monty Taylor
Got rid of __attribute__((unused)) and the like from the .cc files. |
1675 |
void ha_myisam::get_auto_increment(uint64_t , |
1676 |
uint64_t , |
|
1677 |
uint64_t , |
|
1
by brian
clean slate |
1678 |
uint64_t *first_value, |
1679 |
uint64_t *nb_reserved_values) |
|
1680 |
{
|
|
1681 |
uint64_t nr; |
|
1682 |
int error; |
|
481
by Brian Aker
Remove all of uchar. |
1683 |
unsigned char key[MI_MAX_KEY_LENGTH]; |
1
by brian
clean slate |
1684 |
|
1685 |
if (!table->s->next_number_key_offset) |
|
1686 |
{ // Autoincrement at key-start |
|
1687 |
ha_myisam::info(HA_STATUS_AUTO); |
|
1688 |
*first_value= stats.auto_increment_value; |
|
1689 |
/* MyISAM has only table-level lock, so reserves to +inf */
|
|
163
by Brian Aker
Merge Monty's code. |
1690 |
*nb_reserved_values= UINT64_MAX; |
1
by brian
clean slate |
1691 |
return; |
1692 |
}
|
|
1693 |
||
1694 |
/* it's safe to call the following if bulk_insert isn't on */
|
|
1695 |
mi_flush_bulk_insert(file, table->s->next_number_index); |
|
1696 |
||
1697 |
(void) extra(HA_EXTRA_KEYREAD); |
|
1698 |
key_copy(key, table->record[0], |
|
1699 |
table->key_info + table->s->next_number_index, |
|
1700 |
table->s->next_number_key_offset); |
|
1701 |
error= mi_rkey(file, table->record[1], (int) table->s->next_number_index, |
|
1702 |
key, make_prev_keypart_map(table->s->next_number_keypart), |
|
1703 |
HA_READ_PREFIX_LAST); |
|
1704 |
if (error) |
|
1705 |
nr= 1; |
|
1706 |
else
|
|
1707 |
{
|
|
1708 |
/* Get data from record[1] */
|
|
1709 |
nr= ((uint64_t) table->next_number_field-> |
|
1710 |
val_int_offset(table->s->rec_buff_length)+1); |
|
1711 |
}
|
|
1712 |
extra(HA_EXTRA_NO_KEYREAD); |
|
1713 |
*first_value= nr; |
|
1714 |
/*
|
|
1715 |
MySQL needs to call us for next row: assume we are inserting ("a",null)
|
|
1716 |
here, we return 3, and next this statement will want to insert ("b",null):
|
|
1717 |
there is no reason why ("b",3+1) would be the good row to insert: maybe it
|
|
1718 |
already exists, maybe 3+1 is too large...
|
|
1719 |
*/
|
|
1720 |
*nb_reserved_values= 1; |
|
1721 |
}
|
|
1722 |
||
1723 |
||
1724 |
/*
|
|
1725 |
Find out how many rows there is in the given range
|
|
1726 |
||
1727 |
SYNOPSIS
|
|
1728 |
records_in_range()
|
|
1729 |
inx Index to use
|
|
1730 |
min_key Start of range. Null pointer if from first key
|
|
1731 |
max_key End of range. Null pointer if to last key
|
|
1732 |
||
1733 |
NOTES
|
|
1734 |
min_key.flag can have one of the following values:
|
|
1735 |
HA_READ_KEY_EXACT Include the key in the range
|
|
1736 |
HA_READ_AFTER_KEY Don't include key in range
|
|
1737 |
||
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1738 |
max_key.flag can have one of the following values:
|
1
by brian
clean slate |
1739 |
HA_READ_BEFORE_KEY Don't include key in range
|
1740 |
HA_READ_AFTER_KEY Include all 'end_key' values in the range
|
|
1741 |
||
1742 |
RETURN
|
|
1743 |
HA_POS_ERROR Something is wrong with the index tree.
|
|
1744 |
0 There is no matching keys in the given range
|
|
1745 |
number > 0 There is approximately 'number' matching rows in
|
|
1746 |
the range.
|
|
1747 |
*/
|
|
1748 |
||
482
by Brian Aker
Remove uint. |
1749 |
ha_rows ha_myisam::records_in_range(uint32_t inx, key_range *min_key, |
1
by brian
clean slate |
1750 |
key_range *max_key) |
1751 |
{
|
|
1752 |
return (ha_rows) mi_records_in_range(file, (int) inx, min_key, max_key); |
|
1753 |
}
|
|
1754 |
||
1755 |
||
482
by Brian Aker
Remove uint. |
1756 |
uint32_t ha_myisam::checksum() const |
1
by brian
clean slate |
1757 |
{
|
1758 |
return (uint)file->state->checksum; |
|
1759 |
}
|
|
1760 |
||
971.1.51
by Monty Taylor
New-style plugin registration now works. |
1761 |
static MyisamEngine *engine= NULL; |
1762 |
||
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
1763 |
static int myisam_init(drizzled::plugin::Registry ®istry) |
971.1.51
by Monty Taylor
New-style plugin registration now works. |
1764 |
{
|
1106.4.2
by Brian Aker
Remove multi key cache |
1765 |
int error; |
971.1.51
by Monty Taylor
New-style plugin registration now works. |
1766 |
engine= new MyisamEngine(engine_name); |
971.1.52
by Monty Taylor
Did the finalizers. Renamed plugin_registry. |
1767 |
registry.add(engine); |
971.1.51
by Monty Taylor
New-style plugin registration now works. |
1768 |
|
1769 |
pthread_mutex_init(&THR_LOCK_myisam,MY_MUTEX_INIT_FAST); |
|
1770 |
||
1106.4.2
by Brian Aker
Remove multi key cache |
1771 |
/* call ha_init_key_cache() on all key caches to init them */
|
1772 |
error= init_key_cache(dflt_key_cache, |
|
1773 |
(uint32_t) dflt_key_cache->param_block_size, |
|
1774 |
(uint32_t) dflt_key_cache->param_buff_size, |
|
1775 |
dflt_key_cache->param_division_limit, |
|
1776 |
dflt_key_cache->param_age_threshold); |
|
1777 |
||
1778 |
if (error == 0) |
|
1779 |
exit(1); /* Memory Allocation Failure */ |
|
1780 |
||
971.1.51
by Monty Taylor
New-style plugin registration now works. |
1781 |
return 0; |
1782 |
}
|
|
1783 |
||
1110.1.5
by Monty Taylor
Renamed PluginRegistry to plugin::Registry. |
1784 |
static int myisam_deinit(drizzled::plugin::Registry ®istry) |
971.1.51
by Monty Taylor
New-style plugin registration now works. |
1785 |
{
|
971.1.52
by Monty Taylor
Did the finalizers. Renamed plugin_registry. |
1786 |
registry.remove(engine); |
960.2.33
by Monty Taylor
Converted MyISAM. |
1787 |
delete engine; |
1788 |
||
598
by Brian Aker
Removed mutex which are myisam from global to just engine. |
1789 |
pthread_mutex_destroy(&THR_LOCK_myisam); |
1106.4.2
by Brian Aker
Remove multi key cache |
1790 |
end_key_cache(dflt_key_cache, 1); // Can never fail |
598
by Brian Aker
Removed mutex which are myisam from global to just engine. |
1791 |
|
224.2.3
by Brian Aker
Fix for memory leak in shutdown/restart of an engine (not fixed in 5.1) |
1792 |
return mi_panic(HA_PANIC_CLOSE); |
1
by brian
clean slate |
1793 |
}
|
1794 |
||
754
by Brian Aker
Make block_size for myisam fit into plugin. |
1795 |
static DRIZZLE_SYSVAR_UINT(block_size, block_size, |
1796 |
PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, |
|
1797 |
N_("Block size to be used for MyISAM index pages."), |
|
1798 |
NULL, NULL, MI_KEY_BLOCK_LENGTH, MI_MIN_KEY_BLOCK_LENGTH, |
|
1799 |
MI_MAX_KEY_BLOCK_LENGTH, 0); |
|
1800 |
||
753
by Brian Aker
Converted myisam_repair_threads to being in module for MyISAM |
1801 |
static DRIZZLE_SYSVAR_UINT(repair_threads, repair_threads, |
754
by Brian Aker
Make block_size for myisam fit into plugin. |
1802 |
PLUGIN_VAR_RQCMDARG, |
1803 |
N_("Number of threads to use when repairing MyISAM tables. The value of " |
|
1804 |
"1 disables parallel repair."), |
|
1805 |
NULL, NULL, 1, 1, UINT32_MAX, 0); |
|
753
by Brian Aker
Converted myisam_repair_threads to being in module for MyISAM |
1806 |
|
788
by Brian Aker
Move MyISAM bits to myisam plugin |
1807 |
static DRIZZLE_SYSVAR_ULONGLONG(max_sort_file_size, max_sort_file_size, |
789
by Brian Aker
MyISAM fix. |
1808 |
PLUGIN_VAR_RQCMDARG, |
1809 |
N_("Don't use the fast sort index method to created index if the temporary file would get bigger than this."), |
|
1810 |
NULL, NULL, INT32_MAX, 0, UINT64_MAX, 0); |
|
1811 |
||
1812 |
static DRIZZLE_SYSVAR_ULONGLONG(sort_buffer_size, sort_buffer_size, |
|
1813 |
PLUGIN_VAR_RQCMDARG, |
|
1814 |
N_("The buffer that is allocated when sorting the index when doing a REPAIR or when creating indexes with CREATE INDEX or ALTER TABLE."), |
|
779.3.20
by Monty Taylor
Fixed Solaris warnings for MyISAM. |
1815 |
NULL, NULL, 8192*1024, 1024, SIZE_MAX, 0); |
788
by Brian Aker
Move MyISAM bits to myisam plugin |
1816 |
|
790
by Brian Aker
More myisam plugin conversion. |
1817 |
extern uint32_t data_pointer_size; |
1818 |
static DRIZZLE_SYSVAR_UINT(data_pointer_size, data_pointer_size, |
|
1819 |
PLUGIN_VAR_RQCMDARG, |
|
1820 |
N_("Default pointer size to be used for MyISAM tables."), |
|
1821 |
NULL, NULL, 6, 2, 7, 0); |
|
1822 |
||
753
by Brian Aker
Converted myisam_repair_threads to being in module for MyISAM |
1823 |
static struct st_mysql_sys_var* system_variables[]= { |
754
by Brian Aker
Make block_size for myisam fit into plugin. |
1824 |
DRIZZLE_SYSVAR(block_size), |
753
by Brian Aker
Converted myisam_repair_threads to being in module for MyISAM |
1825 |
DRIZZLE_SYSVAR(repair_threads), |
788
by Brian Aker
Move MyISAM bits to myisam plugin |
1826 |
DRIZZLE_SYSVAR(max_sort_file_size), |
789
by Brian Aker
MyISAM fix. |
1827 |
DRIZZLE_SYSVAR(sort_buffer_size), |
790
by Brian Aker
More myisam plugin conversion. |
1828 |
DRIZZLE_SYSVAR(data_pointer_size), |
753
by Brian Aker
Converted myisam_repair_threads to being in module for MyISAM |
1829 |
NULL
|
1830 |
};
|
|
1831 |
||
1
by brian
clean slate |
1832 |
|
813.2.1
by Toru Maesaka
Renamed mysql_declare_plugin to drizzle_declare_plugin |
1833 |
drizzle_declare_plugin(myisam) |
1
by brian
clean slate |
1834 |
{
|
1835 |
"MyISAM", |
|
177.4.3
by mark
ripped out more plugin ABI and API version checking, and plugin versions are now strings |
1836 |
"1.0", |
1
by brian
clean slate |
1837 |
"MySQL AB", |
1838 |
"Default engine as of MySQL 3.23 with great performance", |
|
1839 |
PLUGIN_LICENSE_GPL, |
|
1840 |
myisam_init, /* Plugin Init */ |
|
224.2.3
by Brian Aker
Fix for memory leak in shutdown/restart of an engine (not fixed in 5.1) |
1841 |
myisam_deinit, /* Plugin Deinit */ |
1
by brian
clean slate |
1842 |
NULL, /* status variables */ |
753
by Brian Aker
Converted myisam_repair_threads to being in module for MyISAM |
1843 |
system_variables, /* system variables */ |
1
by brian
clean slate |
1844 |
NULL /* config options */ |
1845 |
}
|
|
813.2.2
by Toru Maesaka
Renamed mysql_declare_plugin_end to drizzle_declare_plugin_end |
1846 |
drizzle_declare_plugin_end; |