140
138
HA_KEYSEG *keyseg;
141
139
TABLE_SHARE *share= table_arg->s;
142
140
uint options= share->db_options_in_use;
143
DBUG_ENTER("table2myisam");
144
141
if (!(my_multi_malloc(MYF(MY_WME),
145
142
recinfo_out, (share->fields * 2 + 2) * sizeof(MI_COLUMNDEF),
146
143
keydef_out, share->keys * sizeof(MI_KEYDEF),
148
145
(share->key_parts + share->keys) * sizeof(HA_KEYSEG),
150
DBUG_RETURN(HA_ERR_OUT_OF_MEM); /* purecov: inspected */
147
return(HA_ERR_OUT_OF_MEM); /* purecov: inspected */
151
148
keydef= *keydef_out;
152
149
recinfo= *recinfo_out;
153
150
pos= table_arg->key_info;
336
329
uint t2_keys, uint t2_recs, bool strict)
339
DBUG_ENTER("check_definition");
340
332
if ((strict ? t1_keys != t2_keys : t1_keys > t2_keys))
342
DBUG_PRINT("error", ("Number of keys differs: t1_keys=%u, t2_keys=%u",
346
336
if (t1_recs != t2_recs)
348
DBUG_PRINT("error", ("Number of recs differs: t1_recs=%u, t2_recs=%u",
352
340
for (i= 0; i < t1_keys; i++)
358
346
else if (t1_keyinfo[i].flag & HA_FULLTEXT ||
359
347
t2_keyinfo[i].flag & HA_FULLTEXT)
361
DBUG_PRINT("error", ("Key %d has different definition", i));
362
DBUG_PRINT("error", ("t1_fulltext= %d, t2_fulltext=%d",
363
test(t1_keyinfo[i].flag & HA_FULLTEXT),
364
test(t2_keyinfo[i].flag & HA_FULLTEXT)));
367
351
if (t1_keyinfo[i].flag & HA_SPATIAL && t2_keyinfo[i].flag & HA_SPATIAL)
369
353
else if (t1_keyinfo[i].flag & HA_SPATIAL ||
370
354
t2_keyinfo[i].flag & HA_SPATIAL)
372
DBUG_PRINT("error", ("Key %d has different definition", i));
373
DBUG_PRINT("error", ("t1_spatial= %d, t2_spatial=%d",
374
test(t1_keyinfo[i].flag & HA_SPATIAL),
375
test(t2_keyinfo[i].flag & HA_SPATIAL)));
378
358
if (t1_keyinfo[i].keysegs != t2_keyinfo[i].keysegs ||
379
359
t1_keyinfo[i].key_alg != t2_keyinfo[i].key_alg)
381
DBUG_PRINT("error", ("Key %d has different definition", i));
382
DBUG_PRINT("error", ("t1_keysegs=%d, t1_key_alg=%d",
383
t1_keyinfo[i].keysegs, t1_keyinfo[i].key_alg));
384
DBUG_PRINT("error", ("t2_keysegs=%d, t2_key_alg=%d",
385
t2_keyinfo[i].keysegs, t2_keyinfo[i].key_alg));
388
363
for (j= t1_keyinfo[i].keysegs; j--;)
411
386
t1_keysegs[j].null_bit != t2_keysegs[j].null_bit ||
412
387
t1_keysegs[j].length != t2_keysegs[j].length)
414
DBUG_PRINT("error", ("Key segment %d (key %d) has different "
415
"definition", j, i));
416
DBUG_PRINT("error", ("t1_type=%d, t1_language=%d, t1_null_bit=%d, "
418
t1_keysegs[j].type, t1_keysegs[j].language,
419
t1_keysegs[j].null_bit, t1_keysegs[j].length));
420
DBUG_PRINT("error", ("t2_type=%d, t2_language=%d, t2_null_bit=%d, "
422
t2_keysegs[j].type, t2_keysegs[j].language,
423
t2_keysegs[j].null_bit, t2_keysegs[j].length));
441
405
t1_rec->length != t2_rec->length ||
442
406
t1_rec->null_bit != t2_rec->null_bit)
444
DBUG_PRINT("error", ("Field %d has different definition", i));
445
DBUG_PRINT("error", ("t1_type=%d, t1_length=%d, t1_null_bit=%d",
446
t1_rec->type, t1_rec->length, t1_rec->null_bit));
447
DBUG_PRINT("error", ("t2_type=%d, t2_length=%d, t2_null_bit=%d",
448
t2_rec->type, t2_rec->length, t2_rec->null_bit));
1045
1001
int error= HA_ADMIN_OK;
1047
1003
TABLE_LIST *table_list= table->pos_in_table_list;
1048
DBUG_ENTER("ha_myisam::assign_to_keycache");
1050
1005
table->keys_in_use_for_query.clear_all();
1052
1007
if (table_list->process_index_hints(table))
1053
DBUG_RETURN(HA_ADMIN_FAILED);
1008
return(HA_ADMIN_FAILED);
1054
1009
map= ~(uint64_t) 0;
1055
1010
if (!table->keys_in_use_for_query.is_clear_all())
1056
1011
/* use all keys if there's no list specified by the user through hints */
1252
1207
void ha_myisam::start_bulk_insert(ha_rows rows)
1254
DBUG_ENTER("ha_myisam::start_bulk_insert");
1255
1209
THD *thd= current_thd;
1256
1210
ulong size= min(thd->variables.read_buff_size,
1257
1211
(ulong) (table->s->avg_row_length*rows));
1258
DBUG_PRINT("info",("start_bulk_insert: rows %lu size %lu",
1259
(ulong) rows, size));
1261
1213
/* don't enable row cache if too few rows */
1262
1214
if (! rows || (rows > MI_MIN_ROWS_TO_USE_WRITE_CACHE))
1411
1362
key_part_map keypart_map,
1412
1363
enum ha_rkey_function find_flag)
1414
DBUG_ASSERT(inited==INDEX);
1365
assert(inited==INDEX);
1415
1366
ha_statistic_increment(&SSV::ha_read_key_count);
1416
1367
int error=mi_rkey(file, buf, active_index, key, keypart_map, find_flag);
1417
1368
table->status=error ? STATUS_NOT_FOUND: 0;
1431
1382
int ha_myisam::index_read_last_map(uchar *buf, const uchar *key,
1432
1383
key_part_map keypart_map)
1434
DBUG_ENTER("ha_myisam::index_read_last");
1435
DBUG_ASSERT(inited==INDEX);
1385
assert(inited==INDEX);
1436
1386
ha_statistic_increment(&SSV::ha_read_key_count);
1437
1387
int error=mi_rkey(file, buf, active_index, key, keypart_map,
1438
1388
HA_READ_PREFIX_LAST);
1439
1389
table->status=error ? STATUS_NOT_FOUND: 0;
1443
1393
int ha_myisam::index_next(uchar *buf)
1445
DBUG_ASSERT(inited==INDEX);
1395
assert(inited==INDEX);
1446
1396
ha_statistic_increment(&SSV::ha_read_next_count);
1447
1397
int error=mi_rnext(file,buf,active_index);
1448
1398
table->status=error ? STATUS_NOT_FOUND: 0;
1709
1658
if ((error= table2myisam(table_arg, &keydef, &recinfo, &records)))
1710
DBUG_RETURN(error); /* purecov: inspected */
1659
return(error); /* purecov: inspected */
1711
1660
bzero((char*) &create_info, sizeof(create_info));
1712
1661
create_info.max_rows= share->max_rows;
1713
1662
create_info.reloc_rows= share->min_rows;
1952
1901
NULL /* config options */
1954
1903
mysql_declare_plugin_end;
1957
#ifdef HAVE_QUERY_CACHE
1959
@brief Register a named table with a call back function to the query cache.
1961
@param thd The thread handle
1962
@param table_key A pointer to the table name in the table cache
1963
@param key_length The length of the table name
1964
@param[out] engine_callback The pointer to the storage engine call back
1965
function, currently 0
1966
@param[out] engine_data Engine data will be set to 0.
1968
@note Despite the name of this function, it is used to check each statement
1969
before it is cached and not to register a table or callback function.
1971
@see handler::register_query_cache_table
1973
@return The error code. The engine_data and engine_callback will be set to 0.
1974
@retval true Success
1975
@retval false An error occured
1978
my_bool ha_myisam::register_query_cache_table(THD *thd, char *table_name,
1979
uint table_name_len,
1982
uint64_t *engine_data)
1984
DBUG_ENTER("ha_myisam::register_query_cache_table");
1986
No call back function is needed to determine if a cached statement
1989
*engine_callback= 0;
1992
No engine data is needed.
1996
if (file->s->concurrent_insert)
1999
If a concurrent INSERT has happened just before the currently
2000
processed SELECT statement, the total size of the table is
2003
To determine if the table size is known, the current thread's snap
2004
shot of the table size with the actual table size are compared.
2006
If the table size is unknown the SELECT statement can't be cached.
2008
When concurrent inserts are disabled at table open, mi_open()
2009
does not assign a get_status() function. In this case the local
2010
("current") status is never updated. We would wrongly think that
2011
we cannot cache the statement.
2013
uint64_t actual_data_file_length;
2014
uint64_t current_data_file_length;
2017
POSIX visibility rules specify that "2. Whatever memory values a
2018
thread can see when it unlocks a mutex <...> can also be seen by any
2019
thread that later locks the same mutex". In this particular case,
2020
concurrent insert thread had modified the data_file_length in
2021
MYISAM_SHARE before it has unlocked (or even locked)
2022
structure_guard_mutex. So, here we're guaranteed to see at least that
2023
value after we've locked the same mutex. We can see a later value
2024
(modified by some other thread) though, but it's ok, as we only want
2025
to know if the variable was changed, the actual new value doesn't matter
2027
actual_data_file_length= file->s->state.state.data_file_length;
2028
current_data_file_length= file->save_state.data_file_length;
2030
if (current_data_file_length != actual_data_file_length)
2032
/* Don't cache current statement. */
2037
/* It is ok to try to cache current statement. */