19
19
Handler-calling-functions
22
#ifdef USE_PRAGMA_IMPLEMENTATION
23
#pragma implementation // gcc: Class implementation
26
#include "mysql_priv.h"
22
#include <drizzled/server_includes.h>
27
23
#include "rpl_filter.h"
28
#include <myisampack.h>
24
#include <drizzled/drizzled_error_messages.h>
32
27
While we have legacy_db_type, we have this array to
40
35
#define BITMAP_STACKBUF_SIZE (128/8)
42
KEY_CREATE_INFO default_key_create_info= { HA_KEY_ALG_UNDEF, 0, {NullS,0}, {NullS,0} };
37
KEY_CREATE_INFO default_key_create_info= { HA_KEY_ALG_UNDEF, 0, {NULL,0}, {NULL,0} };
44
39
/* number of entries in handlertons[] */
45
40
uint32_t total_ha= 0;
53
48
{ C_STRING_WITH_LEN("INNOBASE") }, { C_STRING_WITH_LEN("INNODB") },
54
49
{ C_STRING_WITH_LEN("HEAP") }, { C_STRING_WITH_LEN("MEMORY") },
58
53
const char *ha_row_type[] = {
62
57
const char *tx_isolation_names[] =
63
58
{ "READ-UNCOMMITTED", "READ-COMMITTED", "REPEATABLE-READ", "SERIALIZABLE",
65
60
TYPELIB tx_isolation_typelib= {array_elements(tx_isolation_names)-1,"",
66
61
tx_isolation_names, NULL};
68
63
static TYPELIB known_extensions= {0,"known_exts", NULL, NULL};
69
uint known_extensions_id= 0;
64
uint32_t known_extensions_id= 0;
115
110
/* my_strnncoll is a macro and gcc doesn't do early expansion of macro */
116
if (thd && !my_charset_latin1.coll->strnncoll(&my_charset_latin1,
117
(const uchar *)name->str, name->length,
118
(const uchar *)STRING_WITH_LEN("DEFAULT"), 0))
111
if (thd && !my_charset_utf8_general_ci.coll->strnncoll(&my_charset_utf8_general_ci,
112
(const unsigned char *)name->str, name->length,
113
(const unsigned char *)STRING_WITH_LEN("DEFAULT"), 0))
119
114
return ha_default_plugin(thd);
121
if ((plugin= my_plugin_lock_by_name(thd, name, MYSQL_STORAGE_ENGINE_PLUGIN)))
116
if ((plugin= my_plugin_lock_by_name(thd, name, DRIZZLE_STORAGE_ENGINE_PLUGIN)))
123
118
handlerton *hton= plugin_data(plugin, handlerton *);
124
119
if (!(hton->flags & HTON_NOT_USER_SELECTABLE))
136
131
for (table_alias= sys_table_aliases; table_alias->str; table_alias+= 2)
138
if (!my_strnncoll(&my_charset_latin1,
139
(const uchar *)name->str, name->length,
140
(const uchar *)table_alias->str, table_alias->length))
133
if (!my_strnncoll(&my_charset_utf8_general_ci,
134
(const unsigned char *)name->str, name->length,
135
(const unsigned char *)table_alias->str, table_alias->length))
142
137
name= table_alias + 1;
311
299
/* Allocate a pointer array for the error message strings. */
312
300
if (! (errmsgs= my_error_unregister(HA_ERR_FIRST, HA_ERR_LAST)))
314
my_free((uchar*) errmsgs, MYF(0));
302
free((unsigned char*) errmsgs);
335
hton->panic(hton, HA_PANIC_CLOSE);
322
if (hton && plugin->plugin->deinit)
323
(void)plugin->plugin->deinit(hton);
337
my_free((uchar*)hton, MYF(0));
325
free((unsigned char*)hton);
353
341
structure. Apparently get_backup_engine was not NULL even though it was
356
bzero(hton, sizeof(hton));
344
memset(hton, 0, sizeof(hton));
357
345
/* Historical Requirement */
358
346
plugin->data= hton; // shortcut for the future
359
347
if (plugin->plugin->init)
361
349
if (plugin->plugin->init(hton))
363
sql_print_error("Plugin '%s' init function returned error.",
351
sql_print_error(_("Plugin '%s' init function returned error."),
364
352
plugin->name.str);
389
377
if (idx == (int) DB_TYPE_DEFAULT)
391
sql_print_warning("Too many storage engines!");
379
sql_print_warning(_("Too many storage engines!"));
394
382
if (hton->db_type != DB_TYPE_UNKNOWN)
395
sql_print_warning("Storage engine '%s' has conflicting typecode. "
396
"Assigning value %d.", plugin->plugin->name, idx);
383
sql_print_warning(_("Storage engine '%s' has conflicting typecode. "
384
"Assigning value %d."), plugin->plugin->name, idx);
397
385
hton->db_type= (enum legacy_db_type) idx;
399
387
installed_htons[hton->db_type]= hton;
417
405
"memory" hton which will be configurable longterm. We should be able to
418
406
remove partition and myisammrg.
420
switch (hton->db_type) {
408
if (strcmp(plugin->plugin->name, "MEMORY") == 0)
411
if (strcmp(plugin->plugin->name, "MyISAM") == 0)
425
412
myisam_hton= hton;
477
460
void ha_drop_database(char* path)
479
plugin_foreach(NULL, dropdb_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, path);
462
plugin_foreach(NULL, dropdb_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, path);
483
466
static bool closecon_handlerton(THD *thd, plugin_ref plugin,
484
void *unused __attribute__((__unused__)))
467
void *unused __attribute__((unused)))
486
469
handlerton *hton= plugin_data(plugin, handlerton *);
502
485
void ha_close_connection(THD* thd)
504
plugin_foreach(thd, closecon_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, 0);
487
plugin_foreach(thd, closecon_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, 0);
507
490
/* ========================================================================
777
760
to maintain atomicity: if CREATE TABLE .. SELECT failed,
778
761
the newly created table is deleted.
779
762
In addition, some DDL statements issue interim transaction
780
commits: e.g. ALTER TABLE issues a commit after data is copied
763
commits: e.g. ALTER Table issues a commit after data is copied
781
764
from the original table to the internal temporary table. Other
782
765
statements, e.g. CREATE TABLE ... SELECT do not always commit
784
767
And finally there is a group of DDL statements such as
785
RENAME/DROP TABLE that doesn't start a new transaction
768
RENAME/DROP Table that doesn't start a new transaction
786
769
and doesn't commit.
788
771
This diversity makes it hard to say what will happen if
870
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
853
push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
871
854
ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
872
855
ha_resolve_storage_engine_name(ht));
967
950
assert(thd->transaction.stmt.ha_list == NULL ||
968
951
trans == &thd->transaction.stmt);
970
if (thd->in_sub_stmt)
973
Since we don't support nested statement transactions in 5.0,
974
we can't commit or rollback stmt transactions while we are inside
975
stored functions or triggers. So we simply do nothing now.
976
TODO: This should be fixed in later ( >= 5.1) releases.
981
We assume that all statements which commit or rollback main transaction
982
are prohibited inside of stored functions or triggers. So they should
983
bail out with error even before ha_commit_trans() call. To be 100% safe
984
let us throw error in non-debug builds.
987
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
1105
1068
assert(thd->transaction.stmt.ha_list == NULL ||
1106
1069
trans == &thd->transaction.stmt);
1108
if (thd->in_sub_stmt)
1111
If we are inside stored function or trigger we should not commit or
1112
rollback current statement transaction. See comment in ha_commit_trans()
1113
call for more information.
1118
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
1123
1073
for (; ha_info; ha_info= ha_info_next)
1158
1108
if (is_real_trans && thd->transaction.all.modified_non_trans_table &&
1159
1109
!thd->slave_thread && thd->killed != THD::KILL_CONNECTION)
1160
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1110
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
1161
1111
ER_WARNING_NOT_COMPLETE_ROLLBACK,
1162
1112
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
1235
1185
xaop.result= 1;
1237
1187
plugin_foreach(NULL, commit ? xacommit_handlerton : xarollback_handlerton,
1238
MYSQL_STORAGE_ENGINE_PLUGIN, &xaop);
1188
DRIZZLE_STORAGE_ENGINE_PLUGIN, &xaop);
1240
1190
return xaop.result;
1277
1227
while ((got= hton->recover(hton, info->list, info->len)) > 0 )
1279
sql_print_information("Found %d prepared transaction(s) in %s",
1229
sql_print_information(_("Found %d prepared transaction(s) in %s"),
1280
1230
got, ha_resolve_storage_engine_name(hton));
1281
1231
for (int i=0; i < got; i ++)
1295
1245
// recovery mode
1296
1246
if (info->commit_list ?
1297
hash_search(info->commit_list, (uchar *)&x, sizeof(x)) != 0 :
1247
hash_search(info->commit_list, (unsigned char *)&x, sizeof(x)) != 0 :
1298
1248
tc_heuristic_recover == TC_HEURISTIC_RECOVER_COMMIT)
1300
1250
hton->commit_by_xid(hton, info->list+i);
1358
1308
plugin_foreach(NULL, xarecover_handlerton,
1359
MYSQL_STORAGE_ENGINE_PLUGIN, &info);
1309
DRIZZLE_STORAGE_ENGINE_PLUGIN, &info);
1361
my_free((uchar*)info.list, MYF(0));
1311
free((unsigned char*)info.list);
1362
1312
if (info.found_foreign_xids)
1363
sql_print_warning("Found %d prepared XA transactions",
1313
sql_print_warning(_("Found %d prepared XA transactions"),
1364
1314
info.found_foreign_xids);
1365
1315
if (info.dry_run && info.found_my_xids)
1367
sql_print_error("Found %d prepared transactions! It means that mysqld was "
1368
"not shut down properly last time and critical recovery "
1369
"information (last binlog or %s file) was manually deleted "
1370
"after a crash. You have to start mysqld with "
1371
"--tc-heuristic-recover switch to commit or rollback "
1372
"pending transactions.",
1317
sql_print_error(_("Found %d prepared transactions! It means that drizzled "
1318
"was not shut down properly last time and critical "
1319
"recovery information (last binlog or %s file) was "
1320
"manually deleted after a crash. You have to start "
1321
"drizzled with the --tc-heuristic-recover switch to "
1322
"commit or rollback pending transactions."),
1373
1323
info.found_my_xids, opt_tc_log_file);
1376
1326
if (info.commit_list)
1377
sql_print_information("Crash recovery finished.");
1327
sql_print_information(_("Crash recovery finished."));
1447
1397
static bool release_temporary_latches(THD *thd, plugin_ref plugin,
1448
void *unused __attribute__((__unused__)))
1398
void *unused __attribute__((unused)))
1450
1400
handlerton *hton= plugin_data(plugin, handlerton *);
1459
1409
int ha_release_temporary_latches(THD *thd)
1461
plugin_foreach(thd, release_temporary_latches, MYSQL_STORAGE_ENGINE_PLUGIN,
1411
plugin_foreach(thd, release_temporary_latches, DRIZZLE_STORAGE_ENGINE_PLUGIN,
1467
1417
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv)
1470
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
1471
&thd->transaction.all);
1420
THD_TRANS *trans= &thd->transaction.all;
1472
1421
Ha_trx_info *ha_info, *ha_info_next;
1474
1423
trans->no_2pc=0;
1484
1433
assert(ht->savepoint_set != 0);
1485
1434
if ((err= ht->savepoint_rollback(ht, thd,
1486
(uchar *)(sv+1)+ht->savepoint_offset)))
1435
(unsigned char *)(sv+1)+ht->savepoint_offset)))
1487
1436
{ // cannot happen
1488
1437
my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
1502
1451
handlerton *ht= ha_info->ht();
1503
if ((err= ht->rollback(ht, thd, !thd->in_sub_stmt)))
1452
if ((err= ht->rollback(ht, thd, !(0))))
1504
1453
{ // cannot happen
1505
1454
my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
1522
1471
int ha_savepoint(THD *thd, SAVEPOINT *sv)
1525
THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
1526
&thd->transaction.all);
1474
THD_TRANS *trans= &thd->transaction.all;
1527
1475
Ha_trx_info *ha_info= trans->ha_list;
1528
1476
for (; ha_info; ha_info= ha_info->next())
1539
if ((err= ht->savepoint_set(ht, thd, (uchar *)(sv+1)+ht->savepoint_offset)))
1487
if ((err= ht->savepoint_set(ht, thd, (unsigned char *)(sv+1)+ht->savepoint_offset)))
1540
1488
{ // cannot happen
1541
1489
my_error(ER_GET_ERRNO, MYF(0), err);
1565
1513
if (!ht->savepoint_release)
1567
1515
if ((err= ht->savepoint_release(ht, thd,
1568
(uchar *)(sv+1) + ht->savepoint_offset)))
1516
(unsigned char *)(sv+1) + ht->savepoint_offset)))
1569
1517
{ // cannot happen
1570
1518
my_error(ER_GET_ERRNO, MYF(0), err);
1592
1540
bool warn= true;
1594
plugin_foreach(thd, snapshot_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, &warn);
1542
plugin_foreach(thd, snapshot_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, &warn);
1597
1545
Same idea as when one wants to CREATE TABLE in one engine which does not
1601
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
1549
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
1602
1550
"This MySQL server does not support any "
1603
1551
"consistent-read capable storage engine");
1608
static bool flush_handlerton(THD *thd __attribute__((__unused__)),
1556
static bool flush_handlerton(THD *thd __attribute__((unused)),
1609
1557
plugin_ref plugin,
1610
void *arg __attribute__((__unused__)))
1558
void *arg __attribute__((unused)))
1612
1560
handlerton *hton= plugin_data(plugin, handlerton *);
1613
1561
if (hton->state == SHOW_OPTION_YES && hton->flush_logs &&
1622
1570
if (db_type == NULL)
1624
1572
if (plugin_foreach(NULL, flush_handlerton,
1625
MYSQL_STORAGE_ENGINE_PLUGIN, 0))
1573
DRIZZLE_STORAGE_ENGINE_PLUGIN, 0))
1662
1610
struct Ha_delete_table_error_handler: public Internal_error_handler
1665
virtual bool handle_error(uint sql_errno,
1613
virtual bool handle_error(uint32_t sql_errno,
1666
1614
const char *message,
1667
MYSQL_ERROR::enum_warning_level level,
1615
DRIZZLE_ERROR::enum_warning_level level,
1669
char buff[MYSQL_ERRMSG_SIZE];
1617
char buff[DRIZZLE_ERRMSG_SIZE];
1674
1622
Ha_delete_table_error_handler::
1675
handle_error(uint sql_errno __attribute__((__unused__)),
1623
handle_error(uint32_t sql_errno __attribute__((unused)),
1676
1624
const char *message,
1677
MYSQL_ERROR::enum_warning_level level __attribute__((__unused__)),
1678
THD *thd __attribute__((__unused__)))
1625
DRIZZLE_ERROR::enum_warning_level level __attribute__((unused)),
1626
THD *thd __attribute__((unused)))
1680
1628
/* Grab the error message */
1681
1629
strmake(buff, message, sizeof(buff)-1);
1694
1642
char tmp_path[FN_REFLEN];
1697
1645
TABLE_SHARE dummy_share;
1699
bzero((char*) &dummy_table, sizeof(dummy_table));
1700
bzero((char*) &dummy_share, sizeof(dummy_share));
1647
memset(&dummy_table, 0, sizeof(dummy_table));
1648
memset(&dummy_share, 0, sizeof(dummy_share));
1701
1649
dummy_table.s= &dummy_share;
1703
/* DB_TYPE_UNKNOWN is used in ALTER TABLE when renaming only .frm files */
1651
/* DB_TYPE_UNKNOWN is used in ALTER Table when renaming only .frm files */
1704
1652
if (table_type == NULL ||
1705
1653
! (file=get_new_handler((TABLE_SHARE*)0, thd->mem_root, table_type)))
1706
1654
return(ENOENT);
1736
1684
XXX: should we convert *all* errors to warnings here?
1737
1685
What if the error is fatal?
1739
push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, error,
1687
push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error,
1740
1688
ha_delete_table_error_handler.buff);
1754
1702
on this->table->mem_root and we will not be able to reclaim that memory
1755
1703
when the clone handler object is destroyed.
1757
if (!(new_handler->ref= (uchar*) alloc_root(mem_root, ALIGN_SIZE(ref_length)*2)))
1705
if (!(new_handler->ref= (unsigned char*) alloc_root(mem_root, ALIGN_SIZE(ref_length)*2)))
1759
1707
if (new_handler && !new_handler->ha_open(table,
1760
1708
table->s->normalized_path.str,
1762
1710
HA_OPEN_IGNORE_IF_LOCKED))
1763
1711
return new_handler;
1788
1736
Try O_RDONLY if cannot open as O_RDWR
1789
1737
Don't wait for locks if not HA_OPEN_WAIT_IF_LOCKED is set
1791
int handler::ha_open(TABLE *table_arg, const char *name, int mode,
1739
int handler::ha_open(Table *table_arg, const char *name, int mode,
1792
1740
int test_if_locked)
1817
1765
(void) extra(HA_EXTRA_NO_READCHECK); // Not needed in SQL
1819
1767
/* ref is already allocated for us if we're called from handler::clone() */
1820
if (!ref && !(ref= (uchar*) alloc_root(&table->mem_root,
1768
if (!ref && !(ref= (unsigned char*) alloc_root(&table->mem_root,
1821
1769
ALIGN_SIZE(ref_length)*2)))
1856
1804
This is never called for InnoDB tables, as these table types
1857
1805
has the HA_STATS_RECORDS_IS_EXACT set.
1859
int handler::read_first_row(uchar * buf, uint primary_key)
1807
int handler::read_first_row(unsigned char * buf, uint32_t primary_key)
1861
1809
register int error;
2044
1992
assert(next_insert_id >= auto_inc_interval_for_cur_row.minimum());
2046
if (((nr= table->next_number_field->val_int()) != 0) ||
2047
(table->auto_increment_field_not_null && (thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO)))
1994
if ((nr= table->next_number_field->val_int()) != 0)
2050
1997
Update next_insert_id if we had already generated a value in this
2073
2020
handler::estimation_rows_to_insert was set by
2074
2021
handler::ha_start_bulk_insert(); if 0 it means "unknown".
2076
uint nb_already_reserved_intervals=
2023
uint32_t nb_already_reserved_intervals=
2077
2024
thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements();
2078
2025
uint64_t nb_desired_values;
2210
2157
@param first_value (OUT) the first value reserved by the handler
2211
2158
@param nb_reserved_values (OUT) how many values the handler reserved
2213
void handler::get_auto_increment(uint64_t offset __attribute__((__unused__)),
2214
uint64_t increment __attribute__((__unused__)),
2215
uint64_t nb_desired_values __attribute__((__unused__)),
2160
void handler::get_auto_increment(uint64_t offset __attribute__((unused)),
2161
uint64_t increment __attribute__((unused)),
2162
uint64_t nb_desired_values __attribute__((unused)),
2216
2163
uint64_t *first_value,
2217
2164
uint64_t *nb_reserved_values)
2239
uchar key[MAX_KEY_LENGTH];
2186
unsigned char key[MAX_KEY_LENGTH];
2240
2187
key_copy(key, table->record[0],
2241
2188
table->key_info + table->s->next_number_index,
2242
2189
table->s->next_number_key_offset);
2283
void handler::print_keydup_error(uint key_nr, const char *msg)
2230
void handler::print_keydup_error(uint32_t key_nr, const char *msg)
2285
2232
/* Write the duplicated key in the error message */
2286
2233
char key[MAX_KEY_LENGTH];
2297
2244
/* Table is opened and defined at this point */
2298
2245
key_unpack(&str,table,(uint) key_nr);
2299
uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(msg);
2246
uint32_t max_length=DRIZZLE_ERRMSG_SIZE-(uint) strlen(msg);
2300
2247
if (str.length() >= max_length)
2302
2249
str.length(max_length-4);
2341
2288
case HA_ERR_FOUND_DUPP_KEY:
2343
uint key_nr=get_dup_key(error);
2290
uint32_t key_nr=get_dup_key(error);
2344
2291
if ((int) key_nr >= 0)
2346
2293
print_keydup_error(key_nr, ER(ER_DUP_ENTRY_WITH_KEY_NAME));
2352
2299
case HA_ERR_FOREIGN_DUPLICATE_KEY:
2354
uint key_nr= get_dup_key(error);
2301
uint32_t key_nr= get_dup_key(error);
2355
2302
if ((int) key_nr >= 0)
2304
uint32_t max_length;
2358
2305
/* Write the key in the error message */
2359
2306
char key[MAX_KEY_LENGTH];
2360
2307
String str(key,sizeof(key),system_charset_info);
2361
2308
/* Table is opened and defined at this point */
2362
2309
key_unpack(&str,table,(uint) key_nr);
2363
max_length= (MYSQL_ERRMSG_SIZE-
2310
max_length= (DRIZZLE_ERRMSG_SIZE-
2364
2311
(uint) strlen(ER(ER_FOREIGN_DUPLICATE_KEY)));
2365
2312
if (str.length() >= max_length)
2453
2400
case HA_ERR_DROP_INDEX_FK:
2455
2402
const char *ptr= "???";
2456
uint key_nr= get_dup_key(error);
2403
uint32_t key_nr= get_dup_key(error);
2457
2404
if ((int) key_nr >= 0)
2458
2405
ptr= table->key_info[key_nr].name;
2459
2406
my_error(ER_DROP_INDEX_FK, MYF(0), ptr);
2511
2458
Returns true if this is a temporary error
2513
bool handler::get_error_message(int error __attribute__((__unused__)),
2514
String* buf __attribute__((__unused__)))
2460
bool handler::get_error_message(int error __attribute__((unused)),
2461
String* buf __attribute__((unused)))
2536
2483
if (!keypart->fieldnr)
2538
2485
Field *field= table->field[keypart->fieldnr-1];
2539
if (field->type() == MYSQL_TYPE_BLOB)
2486
if (field->type() == DRIZZLE_TYPE_BLOB)
2541
2488
if (check_opt->sql_flags & TT_FOR_UPGRADE)
2542
2489
check_opt->flags= T_MEDIUM;
2568
2515
update frm version for temporary tables as this code doesn't support
2569
2516
temporary tables.
2571
if (table->s->mysql_version == MYSQL_VERSION_ID)
2518
if (table->s->mysql_version == DRIZZLE_VERSION_ID)
2574
strxmov(path, table->s->normalized_path.str, reg_ext, NullS);
2521
strxmov(path, table->s->normalized_path.str, reg_ext, NULL);
2576
if ((file= my_open(path, O_RDWR|O_BINARY, MYF(MY_WME))) >= 0)
2523
if ((file= my_open(path, O_RDWR, MYF(MY_WME))) >= 0)
2525
unsigned char version[4];
2579
2526
char *key= table->s->table_cache_key.str;
2580
uint key_length= table->s->table_cache_key.length;
2527
uint32_t key_length= table->s->table_cache_key.length;
2582
2529
HASH_SEARCH_STATE state;
2584
int4store(version, MYSQL_VERSION_ID);
2531
int4store(version, DRIZZLE_VERSION_ID);
2586
if (pwrite(file, (uchar*)version, 4, 51L) == 0)
2533
if (pwrite(file, (unsigned char*)version, 4, 51L) == 0)
2592
for (entry=(TABLE*) hash_first(&open_cache,(uchar*) key,key_length, &state);
2539
for (entry=(Table*) hash_first(&open_cache,(unsigned char*) key,key_length, &state);
2594
entry= (TABLE*) hash_next(&open_cache,(uchar*) key,key_length, &state))
2595
entry->s->mysql_version= MYSQL_VERSION_ID;
2541
entry= (Table*) hash_next(&open_cache,(unsigned char*) key,key_length, &state))
2542
entry->s->mysql_version= DRIZZLE_VERSION_ID;
2599
VOID(my_close(file,MYF(MY_WME)));
2546
my_close(file,MYF(MY_WME));
2600
2547
return(result);
2607
2554
key if error because of duplicated keys
2609
uint handler::get_dup_key(int error)
2556
uint32_t handler::get_dup_key(int error)
2611
2558
table->file->errkey = (uint) -1;
2612
2559
if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
2699
if ((table->s->mysql_version >= MYSQL_VERSION_ID) &&
2646
if ((table->s->mysql_version >= DRIZZLE_VERSION_ID) &&
2700
2647
(check_opt->sql_flags & TT_FOR_UPGRADE))
2703
if (table->s->mysql_version < MYSQL_VERSION_ID)
2650
if (table->s->mysql_version < DRIZZLE_VERSION_ID)
2705
2652
if ((error= check_old_types()))
2997
2944
Tell the storage engine that it is allowed to "disable transaction" in the
2998
2945
handler. It is a hint that ACID is not required - it is used in NDB for
2999
ALTER TABLE, for example, when data are copied to temporary table.
2946
ALTER Table, for example, when data are copied to temporary table.
3000
2947
A storage engine may treat this hint any way it likes. NDB for example
3001
2948
starts to commit every now and then automatically.
3002
2949
This hint can be safely ignored.
3022
int handler::index_next_same(uchar *buf, const uchar *key, uint keylen)
2969
int handler::index_next_same(unsigned char *buf, const unsigned char *key, uint32_t keylen)
3025
2972
if (!(error=index_next(buf)))
3027
2974
my_ptrdiff_t ptrdiff= buf - table->record[0];
3028
uchar *save_record_0= NULL;
2975
unsigned char *save_record_0= NULL;
3029
2976
KEY *key_info= NULL;
3030
2977
KEY_PART_INFO *key_part;
3031
2978
KEY_PART_INFO *key_part_end= NULL;
3102
3049
if (update_create_info)
3103
update_create_info_from_table(create_info, &table);
3050
table.updateCreateInfo(create_info);
3105
3052
name= check_lowercase_names(table.file, share.path.str, name_buff);
3107
3054
error= table.file->ha_create(name, &table, create_info);
3108
VOID(closefrm(&table, 0));
3055
closefrm(&table, 0);
3111
strxmov(name_buff, db, ".", table_name, NullS);
3058
strxmov(name_buff, db, ".", table_name, NULL);
3112
3059
my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), name_buff, error);
3132
3079
int ha_create_table_from_engine(THD* thd, const char *db, const char *name)
3082
unsigned char *frmblob;
3137
3084
char path[FN_REFLEN];
3138
3085
HA_CREATE_INFO create_info;
3140
3087
TABLE_SHARE share;
3142
bzero((uchar*) &create_info,sizeof(create_info));
3089
memset(&create_info, 0, sizeof(create_info));
3143
3090
if ((error= ha_discover(thd, db, name, &frmblob, &frmlen)))
3145
3092
/* Table could not be discovered and thus not created */
3154
3101
build_table_filename(path, FN_REFLEN-1, db, name, "", 0);
3155
3102
// Save the frm file
3156
3103
error= writefrm(path, frmblob, frmlen);
3157
my_free(frmblob, MYF(0));
3172
update_create_info_from_table(&create_info, &table);
3119
table.updateCreateInfo(&create_info);
3173
3120
create_info.table_options|= HA_OPTION_CREATE_FROM_ENGINE;
3175
3122
check_lowercase_names(table.file, path, path);
3176
3123
error=table.file->ha_create(path, &table, &create_info);
3177
VOID(closefrm(&table, 1));
3124
closefrm(&table, 1);
3179
3126
return(error != 0);
3200
3147
Init a key cache if it has not been initied before.
3202
int ha_init_key_cache(const char *name __attribute__((__unused__)),
3149
int ha_init_key_cache(const char *name __attribute__((unused)),
3203
3150
KEY_CACHE *key_cache)
3205
3152
if (!key_cache->key_cache_inited)
3207
3154
pthread_mutex_lock(&LOCK_global_system_variables);
3208
3155
uint32_t tmp_buff_size= (uint32_t) key_cache->param_buff_size;
3209
uint tmp_block_size= (uint) key_cache->param_block_size;
3210
uint division_limit= key_cache->param_division_limit;
3211
uint age_threshold= key_cache->param_age_threshold;
3156
uint32_t tmp_block_size= (uint) key_cache->param_block_size;
3157
uint32_t division_limit= key_cache->param_division_limit;
3158
uint32_t age_threshold= key_cache->param_age_threshold;
3212
3159
pthread_mutex_unlock(&LOCK_global_system_variables);
3213
3160
return(!init_key_cache(key_cache,
3214
3161
tmp_block_size,
3229
3176
pthread_mutex_lock(&LOCK_global_system_variables);
3230
3177
long tmp_buff_size= (long) key_cache->param_buff_size;
3231
3178
long tmp_block_size= (long) key_cache->param_block_size;
3232
uint division_limit= key_cache->param_division_limit;
3233
uint age_threshold= key_cache->param_age_threshold;
3179
uint32_t division_limit= key_cache->param_division_limit;
3180
uint32_t age_threshold= key_cache->param_age_threshold;
3234
3181
pthread_mutex_unlock(&LOCK_global_system_variables);
3235
3182
return(!resize_key_cache(key_cache, tmp_block_size,
3248
3195
if (key_cache->key_cache_inited)
3250
3197
pthread_mutex_lock(&LOCK_global_system_variables);
3251
uint division_limit= key_cache->param_division_limit;
3252
uint age_threshold= key_cache->param_age_threshold;
3198
uint32_t division_limit= key_cache->param_division_limit;
3199
uint32_t age_threshold= key_cache->param_age_threshold;
3253
3200
pthread_mutex_unlock(&LOCK_global_system_variables);
3254
3201
change_key_cache_param(key_cache, division_limit, age_threshold);
3311
3258
int ha_discover(THD *thd, const char *db, const char *name,
3312
uchar **frmblob, size_t *frmlen)
3259
unsigned char **frmblob, size_t *frmlen)
3314
3261
int error= -1; // Table does not exist in any handler
3315
3262
st_discover_args args= {db, name, frmblob, frmlen};
3320
3267
if (plugin_foreach(thd, discover_handlerton,
3321
MYSQL_STORAGE_ENGINE_PLUGIN, &args))
3268
DRIZZLE_STORAGE_ENGINE_PLUGIN, &args))
3380
3327
st_table_exists_in_engine_args args= {db, name, HA_ERR_NO_SUCH_TABLE};
3381
3328
plugin_foreach(thd, table_exists_in_engine_handlerton,
3382
MYSQL_STORAGE_ENGINE_PLUGIN, &args);
3329
DRIZZLE_STORAGE_ENGINE_PLUGIN, &args);
3383
3330
return(args.err);
3404
3351
Estimated cost of 'index only' scan
3407
double handler::index_only_read_time(uint keynr, double records)
3354
double handler::index_only_read_time(uint32_t keynr, double records)
3409
3356
double read_time;
3410
uint keys_per_block= (stats.block_size/2/
3357
uint32_t keys_per_block= (stats.block_size/2/
3411
3358
(table->key_info[keynr].key_length + ref_length) + 1);
3412
3359
read_time=((double) (records + keys_per_block-1) /
3413
3360
(double) keys_per_block);
3454
handler::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
3401
handler::multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
3455
3402
void *seq_init_param,
3456
uint n_ranges_arg __attribute__((__unused__)),
3457
uint *bufsz, uint *flags, COST_VECT *cost)
3403
uint32_t n_ranges_arg __attribute__((unused)),
3404
uint32_t *bufsz, uint32_t *flags, COST_VECT *cost)
3459
3406
KEY_MULTI_RANGE range;
3460
3407
range_seq_t seq_it;
3461
3408
ha_rows rows, total_rows= 0;
3409
uint32_t n_ranges=0;
3463
3410
THD *thd= current_thd;
3465
3412
/* Default MRR implementation doesn't need buffer */
3542
3489
other Error or can't perform the requested scan
3545
int handler::multi_range_read_info(uint keyno, uint n_ranges, uint n_rows,
3546
uint *bufsz, uint *flags, COST_VECT *cost)
3492
int handler::multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t n_rows,
3493
uint32_t *bufsz, uint32_t *flags, COST_VECT *cost)
3548
3495
*bufsz= 0; /* Default implementation doesn't need a buffer */
3606
3553
handler::multi_range_read_init(RANGE_SEQ_IF *seq_funcs, void *seq_init_param,
3607
uint n_ranges, uint mode,
3608
HANDLER_BUFFER *buf __attribute__((__unused__)))
3554
uint32_t n_ranges, uint32_t mode,
3555
HANDLER_BUFFER *buf __attribute__((unused)))
3610
3557
mrr_iter= seq_funcs->init(seq_init_param, n_ranges, mode);
3611
3558
mrr_funcs= *seq_funcs;
3707
3654
int DsMrr_impl::dsmrr_init(handler *h, KEY *key,
3708
3655
RANGE_SEQ_IF *seq_funcs, void *seq_init_param,
3709
uint n_ranges, uint mode, HANDLER_BUFFER *buf)
3656
uint32_t n_ranges, uint32_t mode, HANDLER_BUFFER *buf)
3713
3660
Item *pushed_cond= NULL;
3714
3661
handler *new_h2;
3715
3662
keyno= h->active_index;
3802
static int rowid_cmp(void *h, uchar *a, uchar *b)
3749
static int rowid_cmp(void *h, unsigned char *a, unsigned char *b)
3804
3751
return ((handler*)h)->cmp_ref(a, b);
3822
3769
@retval other Error
3825
int DsMrr_impl::dsmrr_fill_buffer(handler *unused __attribute__((__unused__)))
3772
int DsMrr_impl::dsmrr_fill_buffer(handler *unused __attribute__((unused)))
3827
3774
char *range_info;
3830
3777
rowids_buf_cur= rowids_buf;
3831
3778
while ((rowids_buf_cur < rowids_buf_end) &&
3848
3795
dsmrr_eof= test(res == HA_ERR_END_OF_FILE);
3850
3797
/* Sort the buffer contents by rowid */
3851
uint elem_size= h->ref_length + (int)is_mrr_assoc * sizeof(void*);
3852
uint n_rowids= (rowids_buf_cur - rowids_buf) / elem_size;
3798
uint32_t elem_size= h->ref_length + (int)is_mrr_assoc * sizeof(void*);
3799
uint32_t n_rowids= (rowids_buf_cur - rowids_buf) / elem_size;
3854
3801
my_qsort2(rowids_buf, n_rowids, elem_size, (qsort2_cmp)rowid_cmp,
3908
3855
DS-MRR implementation: multi_range_read_info() function
3910
int DsMrr_impl::dsmrr_info(uint keyno, uint n_ranges, uint rows, uint *bufsz,
3911
uint *flags, COST_VECT *cost)
3857
int DsMrr_impl::dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t rows, uint32_t *bufsz,
3858
uint32_t *flags, COST_VECT *cost)
3914
uint def_flags= *flags;
3915
uint def_bufsz= *bufsz;
3861
uint32_t def_flags= *flags;
3862
uint32_t def_bufsz= *bufsz;
3917
3864
/* Get cost/flags/mem_usage of default MRR implementation */
3918
3865
res= h->handler::multi_range_read_info(keyno, n_ranges, rows, &def_bufsz,
3934
3881
DS-MRR Implementation: multi_range_read_info_const() function
3937
ha_rows DsMrr_impl::dsmrr_info_const(uint keyno, RANGE_SEQ_IF *seq,
3938
void *seq_init_param, uint n_ranges,
3939
uint *bufsz, uint *flags, COST_VECT *cost)
3884
ha_rows DsMrr_impl::dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
3885
void *seq_init_param, uint32_t n_ranges,
3886
uint32_t *bufsz, uint32_t *flags, COST_VECT *cost)
3942
uint def_flags= *flags;
3943
uint def_bufsz= *bufsz;
3889
uint32_t def_flags= *flags;
3890
uint32_t def_bufsz= *bufsz;
3944
3891
/* Get cost/flags/mem_usage of default MRR implementation */
3945
3892
rows= h->handler::multi_range_read_info_const(keyno, seq, seq_init_param,
3946
3893
n_ranges, &def_bufsz,
3988
3935
@retval false No
3991
bool DsMrr_impl::key_uses_partial_cols(uint keyno)
3938
bool DsMrr_impl::key_uses_partial_cols(uint32_t keyno)
3993
3940
KEY_PART_INFO *kp= table->key_info[keyno].key_part;
3994
3941
KEY_PART_INFO *kp_end= kp + table->key_info[keyno].key_parts;
4024
3971
@retval false DS-MRR implementation should be used
4027
bool DsMrr_impl::choose_mrr_impl(uint keyno, ha_rows rows, uint *flags,
4028
uint *bufsz, COST_VECT *cost)
3974
bool DsMrr_impl::choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags,
3975
uint32_t *bufsz, COST_VECT *cost)
4030
3977
COST_VECT dsmrr_cost;
4044
uint add_len= table->key_info[keyno].key_length + h->ref_length;
3991
uint32_t add_len= table->key_info[keyno].key_length + h->ref_length;
4045
3992
*bufsz -= add_len;
4046
3993
if (get_disk_sweep_mrr_cost(keyno, rows, *flags, bufsz, &dsmrr_cost))
4091
4038
for even 1 rowid)
4094
bool DsMrr_impl::get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags,
4095
uint *buffer_size, COST_VECT *cost)
4041
bool DsMrr_impl::get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags,
4042
uint32_t *buffer_size, COST_VECT *cost)
4097
4044
uint32_t max_buff_entries, elem_size;
4098
4045
ha_rows rows_in_full_step, rows_in_last_step;
4046
uint32_t n_full_steps;
4100
4047
double index_read_cost;
4102
4049
elem_size= h->ref_length + sizeof(void*) * (!test(flags & HA_MRR_NO_ASSOCIATION));
4128
*buffer_size= max(*buffer_size,
4075
*buffer_size= cmax((ulong)*buffer_size,
4129
4076
(size_t)(1.2*rows_in_last_step) * elem_size +
4130
4077
h->ref_length + table->key_info[keynr].key_length);
4221
4168
@param cost OUT The cost.
4224
void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted,
4171
void get_sweep_read_cost(Table *table, ha_rows nrows, bool interrupted,
4225
4172
COST_VECT *cost)
4277
4224
int handler::read_range_first(const key_range *start_key,
4278
4225
const key_range *end_key,
4279
4226
bool eq_range_arg,
4280
bool sorted __attribute__((__unused__)))
4227
bool sorted __attribute__((unused)))
4385
int handler::index_read_idx_map(uchar * buf, uint index, const uchar * key,
4332
int handler::index_read_idx_map(unsigned char * buf, uint32_t index, const unsigned char * key,
4386
4333
key_part_map keypart_map,
4387
4334
enum ha_rkey_function find_flag)
4447
4394
known_extensions_id= mysys_usage_id;
4449
4396
plugin_foreach(NULL, exts_handlerton,
4450
MYSQL_STORAGE_ENGINE_PLUGIN, &found_exts);
4397
DRIZZLE_STORAGE_ENGINE_PLUGIN, &found_exts);
4452
4399
ext= (const char **) my_once_alloc(sizeof(char *)*
4453
4400
(found_exts.elements+1),
4469
static bool stat_print(THD *thd, const char *type, uint type_len,
4470
const char *file, uint file_len,
4471
const char *status, uint status_len)
4416
static bool stat_print(THD *thd, const char *type, uint32_t type_len,
4417
const char *file, uint32_t file_len,
4418
const char *status, uint32_t status_len)
4473
4420
Protocol *protocol= thd->protocol;
4474
4421
protocol->prepare_for_resend();
4515
4462
- table is not mysql.event
4518
static bool check_table_binlog_row_based(THD *thd, TABLE *table)
4465
static bool check_table_binlog_row_based(THD *thd, Table *table)
4520
4467
if (table->s->cached_row_logging_check == -1)
4558
4505
if (thd->get_binlog_table_maps() == 0)
4560
MYSQL_LOCK *locks[3];
4507
DRIZZLE_LOCK *locks[3];
4561
4508
locks[0]= thd->extra_lock;
4562
4509
locks[1]= thd->lock;
4563
4510
locks[2]= thd->locked_tables;
4564
for (uint i= 0 ; i < sizeof(locks)/sizeof(*locks) ; ++i )
4511
for (uint32_t i= 0 ; i < sizeof(locks)/sizeof(*locks) ; ++i )
4566
MYSQL_LOCK const *const lock= locks[i];
4513
DRIZZLE_LOCK const *const lock= locks[i];
4567
4514
if (lock == NULL)
4570
TABLE **const end_ptr= lock->table + lock->table_count;
4571
for (TABLE **table_ptr= lock->table ;
4517
Table **const end_ptr= lock->table + lock->table_count;
4518
for (Table **table_ptr= lock->table ;
4572
4519
table_ptr != end_ptr ;
4575
TABLE *const table= *table_ptr;
4522
Table *const table= *table_ptr;
4576
4523
if (table->current_lock == F_WRLCK &&
4577
4524
check_table_binlog_row_based(thd, table))
4595
typedef bool Log_func(THD*, TABLE*, bool, const uchar*, const uchar*);
4542
typedef bool Log_func(THD*, Table*, bool, const unsigned char*, const unsigned char*);
4597
static int binlog_log_row(TABLE* table,
4598
const uchar *before_record,
4599
const uchar *after_record,
4544
static int binlog_log_row(Table* table,
4545
const unsigned char *before_record,
4546
const unsigned char *after_record,
4600
4547
Log_func *log_func)
4602
4549
if (table->no_replicate)
4633
4580
We cache the table flags if the locking succeeded. Otherwise, we
4634
4581
keep them as they were when they were fetched in ha_open().
4636
MYSQL_EXTERNAL_LOCK(lock_type);
4583
DRIZZLE_EXTERNAL_LOCK(lock_type);
4638
4585
int error= external_lock(thd, lock_type);
4639
4586
if (error == 0)
4648
4595
int handler::ha_reset()
4650
4597
/* Check that we have called all proper deallocation functions */
4651
assert((uchar*) table->def_read_set.bitmap +
4598
assert((unsigned char*) table->def_read_set.bitmap +
4652
4599
table->s->column_bitmap_size ==
4653
(uchar*) table->def_write_set.bitmap);
4600
(unsigned char*) table->def_write_set.bitmap);
4654
4601
assert(bitmap_is_set_all(&table->s->all_set));
4655
4602
assert(table->key_read == 0);
4656
4603
/* ensure that ha_index_end / ha_rnd_end has been called */
4666
int handler::ha_write_row(uchar *buf)
4613
int handler::ha_write_row(unsigned char *buf)
4669
4616
Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
4670
MYSQL_INSERT_ROW_START();
4617
DRIZZLE_INSERT_ROW_START();
4672
4619
mark_trx_read_write();
4676
4623
if (unlikely(error= binlog_log_row(table, 0, buf, log_func)))
4677
4624
return(error); /* purecov: inspected */
4678
MYSQL_INSERT_ROW_END();
4625
DRIZZLE_INSERT_ROW_END();
4683
int handler::ha_update_row(const uchar *old_data, uchar *new_data)
4630
int handler::ha_update_row(const unsigned char *old_data, unsigned char *new_data)
4686
4633
Log_func *log_func= Update_rows_log_event::binlog_row_logging_function;