Commit a8ca3e2a authored by Rich Prohaska's avatar Rich Prohaska

#184 fix mismatch between table_share->key_parts and the number really there. ...

#184 fix mismatch between table_share->key_parts and the number really there.  mysql increments key_parts for the extended keys.
parent 4d04076c
...@@ -5944,14 +5944,15 @@ int ha_tokudb::info(uint flag) { ...@@ -5944,14 +5944,15 @@ int ha_tokudb::info(uint flag) {
} }
if ((flag & HA_STATUS_CONST)) { if ((flag & HA_STATUS_CONST)) {
stats.max_data_file_length= 9223372036854775807ULL; stats.max_data_file_length= 9223372036854775807ULL;
uint64_t rec_per_key[table_share->key_parts]; uint total_key_parts = tokudb::compute_total_key_parts(table_share);
error = tokudb::get_card_from_status(share->status_block, txn, table_share->key_parts, rec_per_key); uint64_t rec_per_key[total_key_parts];
error = tokudb::get_card_from_status(share->status_block, txn, total_key_parts, rec_per_key);
if (error == 0) { if (error == 0) {
tokudb::set_card_in_key_info(table, table_share->key_parts, rec_per_key); tokudb::set_card_in_key_info(table, total_key_parts, rec_per_key);
} else { } else {
for (uint i = 0; i < table_share->key_parts; i++) for (uint i = 0; i < total_key_parts; i++)
rec_per_key[i] = 0; rec_per_key[i] = 0;
tokudb::set_card_in_key_info(table, table_share->key_parts, rec_per_key); tokudb::set_card_in_key_info(table, total_key_parts, rec_per_key);
} }
} }
/* Don't return key if we got an error for the internal primary key */ /* Don't return key if we got an error for the internal primary key */
...@@ -6155,10 +6156,12 @@ static const char *lock_type_str(int lock_type) { ...@@ -6155,10 +6156,12 @@ static const char *lock_type_str(int lock_type) {
// //
int ha_tokudb::external_lock(THD * thd, int lock_type) { int ha_tokudb::external_lock(THD * thd, int lock_type) {
TOKUDB_HANDLER_DBUG_ENTER("cmd %d lock %d %s %s", thd_sql_command(thd), lock_type, lock_type_str(lock_type), share->table_name); TOKUDB_HANDLER_DBUG_ENTER("cmd %d lock %d %s %s", thd_sql_command(thd), lock_type, lock_type_str(lock_type), share->table_name);
if (tokudb_debug & TOKUDB_DEBUG_LOCK) if (!(tokudb_debug & TOKUDB_DEBUG_ENTER) && (tokudb_debug & TOKUDB_DEBUG_LOCK)) {
TOKUDB_HANDLER_TRACE("cmd %d lock %d %s %s", thd_sql_command(thd), lock_type, lock_type_str(lock_type), share->table_name); TOKUDB_HANDLER_TRACE("cmd %d lock %d %s %s", thd_sql_command(thd), lock_type, lock_type_str(lock_type), share->table_name);
if (0) }
if (tokudb_debug & TOKUDB_DEBUG_LOCK) {
TOKUDB_HANDLER_TRACE("q %s", thd->query()); TOKUDB_HANDLER_TRACE("q %s", thd->query());
}
int error = 0; int error = 0;
tokudb_trx_data *trx = NULL; tokudb_trx_data *trx = NULL;
......
...@@ -131,10 +131,11 @@ int ha_tokudb::analyze(THD *thd, HA_CHECK_OPT *check_opt) { ...@@ -131,10 +131,11 @@ int ha_tokudb::analyze(THD *thd, HA_CHECK_OPT *check_opt) {
uint64_t rec_per_key[table_share->key_parts]; uint64_t rec_per_key[table_share->key_parts];
int result = HA_ADMIN_OK; int result = HA_ADMIN_OK;
DB_TXN *txn = transaction; DB_TXN *txn = transaction;
if (!txn) if (!txn) {
result = HA_ADMIN_FAILED; result = HA_ADMIN_FAILED;
}
uint total_key_parts = 0;
if (result == HA_ADMIN_OK) { if (result == HA_ADMIN_OK) {
uint next_key_part = 0;
// compute cardinality for each key // compute cardinality for each key
for (uint i = 0; result == HA_ADMIN_OK && i < table_share->keys; i++) { for (uint i = 0; result == HA_ADMIN_OK && i < table_share->keys; i++) {
KEY *key_info = &table_share->key_info[i]; KEY *key_info = &table_share->key_info[i];
...@@ -146,7 +147,7 @@ int ha_tokudb::analyze(THD *thd, HA_CHECK_OPT *check_opt) { ...@@ -146,7 +147,7 @@ int ha_tokudb::analyze(THD *thd, HA_CHECK_OPT *check_opt) {
bool is_unique = false; bool is_unique = false;
if (i == primary_key || (key_info->flags & HA_NOSAME)) if (i == primary_key || (key_info->flags & HA_NOSAME))
is_unique = true; is_unique = true;
int error = tokudb::analyze_card(share->key_file[i], txn, is_unique, num_key_parts, &rec_per_key[next_key_part], int error = tokudb::analyze_card(share->key_file[i], txn, is_unique, num_key_parts, &rec_per_key[total_key_parts],
tokudb_cmp_dbt_key_parts, analyze_progress, &analyze_progress_extra); tokudb_cmp_dbt_key_parts, analyze_progress, &analyze_progress_extra);
if (error != 0 && error != ETIME) { if (error != 0 && error != ETIME) {
result = HA_ADMIN_FAILED; result = HA_ADMIN_FAILED;
...@@ -156,14 +157,15 @@ int ha_tokudb::analyze(THD *thd, HA_CHECK_OPT *check_opt) { ...@@ -156,14 +157,15 @@ int ha_tokudb::analyze(THD *thd, HA_CHECK_OPT *check_opt) {
TOKUDB_HANDLER_TRACE("%s.%s.%s", TOKUDB_HANDLER_TRACE("%s.%s.%s",
table_share->db.str, table_share->table_name.str, i == primary_key ? "primary" : table_share->key_info[i].name); table_share->db.str, table_share->table_name.str, i == primary_key ? "primary" : table_share->key_info[i].name);
for (uint j = 0; j < num_key_parts; j++) for (uint j = 0; j < num_key_parts; j++)
TOKUDB_HANDLER_TRACE("%lu", rec_per_key[next_key_part+j]); TOKUDB_HANDLER_TRACE("%lu", rec_per_key[total_key_parts+j]);
}
} }
total_key_parts += num_key_parts;
} }
next_key_part += num_key_parts;
} }
if (result == HA_ADMIN_OK) {
tokudb::set_card_in_status(share->status_block, txn, total_key_parts, rec_per_key);
} }
if (result == HA_ADMIN_OK)
tokudb::set_card_in_status(share->status_block, txn, table_share->key_parts, rec_per_key);
TOKUDB_HANDLER_DBUG_RETURN(result); TOKUDB_HANDLER_DBUG_RETURN(result);
} }
......
...@@ -89,6 +89,13 @@ PATENT RIGHTS GRANT: ...@@ -89,6 +89,13 @@ PATENT RIGHTS GRANT:
#ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved." #ident "Copyright (c) 2007-2013 Tokutek Inc. All rights reserved."
#ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it." #ident "The technology is licensed by the Massachusetts Institute of Technology, Rutgers State University of New Jersey, and the Research Foundation of State University of New York at Stony Brook under United States of America Serial No. 11/760379 and to the patents and/or patent applications resulting from it."
namespace tokudb { namespace tokudb {
uint compute_total_key_parts(TABLE_SHARE *table_share) {
uint total_key_parts = 0;
for (uint i = 0; i < table_share->keys; i++) {
total_key_parts += get_key_parts(&table_share->key_info[i]);
}
return total_key_parts;
}
// Set the key_info cardinality counters for the table. // Set the key_info cardinality counters for the table.
void set_card_in_key_info(TABLE *table, uint rec_per_keys, uint64_t rec_per_key[]) { void set_card_in_key_info(TABLE *table, uint rec_per_keys, uint64_t rec_per_key[]) {
...@@ -171,11 +178,13 @@ namespace tokudb { ...@@ -171,11 +178,13 @@ namespace tokudb {
void set_card_from_status(DB *status_db, DB_TXN *txn, TABLE_SHARE *table_share, TABLE_SHARE *altered_table_share) { void set_card_from_status(DB *status_db, DB_TXN *txn, TABLE_SHARE *table_share, TABLE_SHARE *altered_table_share) {
int error; int error;
// read existing cardinality data from status // read existing cardinality data from status
uint64_t rec_per_key[table_share->key_parts]; uint table_total_key_parts = tokudb::compute_total_key_parts(table_share);
error = get_card_from_status(status_db, txn, table_share->key_parts, rec_per_key); uint64_t rec_per_key[table_total_key_parts];
error = get_card_from_status(status_db, txn, table_total_key_parts, rec_per_key);
// set altered records per key to unknown // set altered records per key to unknown
uint64_t altered_rec_per_key[altered_table_share->key_parts]; uint altered_table_total_key_parts = tokudb::compute_total_key_parts(altered_table_share);
for (uint i = 0; i < altered_table_share->key_parts; i++) uint64_t altered_rec_per_key[altered_table_total_key_parts];
for (uint i = 0; i < altered_table_total_key_parts; i++)
altered_rec_per_key[i] = 0; altered_rec_per_key[i] = 0;
// compute the beginning of the key offsets in the original table // compute the beginning of the key offsets in the original table
uint orig_key_offset[table_share->keys]; uint orig_key_offset[table_share->keys];
...@@ -197,7 +206,7 @@ namespace tokudb { ...@@ -197,7 +206,7 @@ namespace tokudb {
} }
} }
if (error == 0) if (error == 0)
set_card_in_status(status_db, txn, altered_table_share->key_parts, altered_rec_per_key); set_card_in_status(status_db, txn, altered_table_total_key_parts, altered_rec_per_key);
else else
delete_card_from_status(status_db, txn); delete_card_from_status(status_db, txn);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment