Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tianmu): fix specified key was too long; max key length is 255 bytes(#228) #475

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mysql-test/suite/tianmu/r/issue228.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use test;
create table t1 (a varchar(112) charset utf8 collate utf8_bin not null,primary key (a)) select 'test' as a ;
select a from t1;
a
test
drop table t1;
4 changes: 4 additions & 0 deletions mysql-test/suite/tianmu/t/issue228.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
use test;
create table t1 (a varchar(112) charset utf8 collate utf8_bin not null,primary key (a)) select 'test' as a ;
select a from t1;
drop table t1;
3 changes: 3 additions & 0 deletions storage/tianmu/common/common_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ constexpr int64_t MAX_ROW_NUMBER = 0x00007FFFFFFFFFFFULL; // 2^47 - 1
constexpr int64_t TIANMU_BIGINT_MAX = PLUS_INF_64;
constexpr int64_t TIANMU_BIGINT_MIN = NULL_VALUE_64;

constexpr int32_t TIANMU_MAX_INDEX_COL_LEN_LARGE = 3072;
constexpr int32_t TIANMU_MAX_INDEX_COL_LEN_SMALL = 767;

#define NULL_VALUE_D (*(double *)("\x01\x00\x00\x00\x00\x00\x00\x80"))
#define TIANMU_INT_MIN (-2147483647)
#define TIANMU_MEDIUMINT_MAX ((1 << 23) - 1)
Expand Down
56 changes: 31 additions & 25 deletions storage/tianmu/handler/tianmu_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@ int TianmuHandler::external_lock(THD *thd, int lock_type) {

if (thd->lex->sql_command == SQLCOM_LOCK_TABLES) DBUG_RETURN(HA_ERR_WRONG_COMMAND);

if (is_delay_insert(thd)
&& table_share->tmp_table == NO_TMP_TABLE
&& lock_type == F_WRLCK) {
if (is_delay_insert(thd) && table_share->tmp_table == NO_TMP_TABLE && lock_type == F_WRLCK) {
DBUG_RETURN(0);
}

Expand All @@ -273,8 +271,9 @@ int TianmuHandler::external_lock(THD *thd, int lock_type) {
tx->AddTableRD(share);
} else {
tx->AddTableWR(share);
trans_register_ha(thd, false, rcbase_hton,NULL);
if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) trans_register_ha(thd, true, rcbase_hton,NULL);
trans_register_ha(thd, false, rcbase_hton, NULL);
if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
trans_register_ha(thd, true, rcbase_hton, NULL);
}
}
ret = 0;
Expand Down Expand Up @@ -430,7 +429,7 @@ int TianmuHandler::write_row([[maybe_unused]] uchar *buf) {
my_message(static_cast<int>(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0));
} catch (common::FormatException &e) {
TIANMU_LOG(LogCtl_Level::ERROR, "An exception is caught in Engine::InsertRow: %s Row: %ld, field %u.", e.what(),
e.m_row_no, e.m_field_no);
e.m_row_no, e.m_field_no);
my_message(static_cast<int>(common::ErrorCode::UNKNOWN_ERROR), e.what(), MYF(0));
} catch (common::FileException &e) {
TIANMU_LOG(LogCtl_Level::ERROR, "An exception is caught in Engine::InsertRow: %s.", e.what());
Expand Down Expand Up @@ -797,8 +796,8 @@ int TianmuHandler::index_end() {
index.
*/
int TianmuHandler::index_read([[maybe_unused]] uchar *buf, [[maybe_unused]] const uchar *key,
[[maybe_unused]] uint key_len __attribute__((unused)),
enum ha_rkey_function find_flag __attribute__((unused))) {
[[maybe_unused]] uint key_len __attribute__((unused)),
enum ha_rkey_function find_flag __attribute__((unused))) {
DBUG_ENTER(__PRETTY_FUNCTION__);
int rc = HA_ERR_KEY_NOT_FOUND;
try {
Expand Down Expand Up @@ -982,7 +981,7 @@ int TianmuHandler::rnd_init(bool scan) {
table_new_iter_end = ((core::RCTable *)table_ptr)->End();
} catch (common::Exception const &e) {
rc_control_ << system::lock << "Error in push-down execution, push-down execution aborted: " << e.what()
<< system::unlock;
<< system::unlock;
TIANMU_LOG(LogCtl_Level::ERROR, "An exception is caught in push-down execution: %s", e.what());
}
m_query.reset();
Expand All @@ -993,8 +992,8 @@ int TianmuHandler::rnd_init(bool scan) {
table_new_iter_end = ((core::RCTable *)table_ptr)->End();
} else {
std::shared_ptr<core::RCTable> rctp;
ha_rcengine_->GetTableIterator(m_table_name, table_new_iter, table_new_iter_end, rctp, GetAttrsUseIndicator(table),
table->in_use);
ha_rcengine_->GetTableIterator(m_table_name, table_new_iter, table_new_iter_end, rctp,
GetAttrsUseIndicator(table), table->in_use);
table_ptr = rctp.get();
filter_ptr.reset();
}
Expand Down Expand Up @@ -1134,9 +1133,9 @@ int TianmuHandler::extra(enum ha_extra_function operation) {
int TianmuHandler::start_stmt(THD *thd, thr_lock_type lock_type) {
try {
if (lock_type == TL_WRITE_CONCURRENT_INSERT || lock_type == TL_WRITE_DEFAULT || lock_type == TL_WRITE) {
trans_register_ha(thd, false, rcbase_hton,NULL);
trans_register_ha(thd, false, rcbase_hton, NULL);
if (thd_test_options(thd, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) {
trans_register_ha(thd, true, rcbase_hton,NULL);
trans_register_ha(thd, true, rcbase_hton, NULL);
}
current_txn_ = ha_rcengine_->GetTx(thd);
current_txn_->AddTableWRIfNeeded(share);
Expand All @@ -1157,8 +1156,8 @@ int TianmuHandler::start_stmt(THD *thd, thr_lock_type lock_type) {
caching.
*/
my_bool TianmuHandler::register_query_cache_table(THD *thd, char *table_key, size_t key_length,
qc_engine_callback *call_back,
[[maybe_unused]] ulonglong *engine_data) {
qc_engine_callback *call_back,
[[maybe_unused]] ulonglong *engine_data) {
*call_back = rcbase_query_caching_of_table_permitted;
return rcbase_query_caching_of_table_permitted(thd, table_key, key_length, 0);
}
Expand Down Expand Up @@ -1202,7 +1201,7 @@ int TianmuHandler::delete_table(const char *name) {
Called from opt_range.cc by check_quick_keys().
*/
ha_rows TianmuHandler::records_in_range([[maybe_unused]] uint inx, [[maybe_unused]] key_range *min_key,
[[maybe_unused]] key_range *max_key) {
[[maybe_unused]] key_range *max_key) {
DBUG_ENTER(__PRETTY_FUNCTION__);
DBUG_RETURN(10); // low number to force index usage
}
Expand Down Expand Up @@ -1254,6 +1253,13 @@ int TianmuHandler::truncate() {
DBUG_RETURN(ret);
}

uint TianmuHandler::max_supported_key_part_length(HA_CREATE_INFO *create_info) const {
if (tianmu_sysvar_large_prefix)
return (Tianmu::common::TIANMU_MAX_INDEX_COL_LEN_LARGE);
else
return (Tianmu::common::TIANMU_MAX_INDEX_COL_LEN_SMALL);
}

int TianmuHandler::fill_row(uchar *buf) {
if (table_new_iter == table_new_iter_end) return HA_ERR_END_OF_FILE;

Expand Down Expand Up @@ -1307,7 +1313,7 @@ char *TianmuHandler::update_table_comment(const char *comment) {
int count = std::sprintf(buf, "Overall compression ratio: %.3f, Raw size=%ld MB", ratio, sum_u >> 20);
extra_len += count;

str = (char *)my_malloc(PSI_NOT_INSTRUMENTED,length + extra_len + 3, MYF(0));
str = (char *)my_malloc(PSI_NOT_INSTRUMENTED, length + extra_len + 3, MYF(0));
if (str) {
char *pos = str + length;
if (length) {
Expand Down Expand Up @@ -1367,7 +1373,7 @@ int TianmuHandler::set_cond_iter() {
ret = 0;
} catch (common::Exception const &e) {
rc_control_ << system::lock << "Error in push-down execution, push-down execution aborted: " << e.what()
<< system::unlock;
<< system::unlock;
TIANMU_LOG(LogCtl_Level::ERROR, "Error in push-down execution, push-down execution aborted: %s", e.what());
}
m_query.reset();
Expand All @@ -1383,8 +1389,8 @@ const Item *TianmuHandler::cond_push(const Item *a_cond) {
try {
if (!m_query) {
std::shared_ptr<core::RCTable> rctp;
ha_rcengine_->GetTableIterator(m_table_name, table_new_iter, table_new_iter_end, rctp, GetAttrsUseIndicator(table),
table->in_use);
ha_rcengine_->GetTableIterator(m_table_name, table_new_iter, table_new_iter_end, rctp,
GetAttrsUseIndicator(table), table->in_use);
table_ptr = rctp.get();
m_query.reset(new core::Query(current_txn_));
m_cq.reset(new core::CompiledQuery);
Expand Down Expand Up @@ -1473,7 +1479,7 @@ int TianmuHandler::reset() {
}

enum_alter_inplace_result TianmuHandler::check_if_supported_inplace_alter([[maybe_unused]] TABLE *altered_table,
Alter_inplace_info *ha_alter_info) {
Alter_inplace_info *ha_alter_info) {
if ((ha_alter_info->handler_flags & ~TIANMU_SUPPORTED_ALTER_ADD_DROP_ORDER) &&
(ha_alter_info->handler_flags != TIANMU_SUPPORTED_ALTER_COLUMN_NAME)) {
return HA_ALTER_ERROR;
Expand Down Expand Up @@ -1502,8 +1508,8 @@ bool TianmuHandler::inplace_alter_table(TABLE *altered_table, Alter_inplace_info
return true;
}

bool TianmuHandler::commit_inplace_alter_table([[maybe_unused]] TABLE *altered_table,
Alter_inplace_info *ha_alter_info, bool commit) {
bool TianmuHandler::commit_inplace_alter_table([[maybe_unused]] TABLE *altered_table, Alter_inplace_info *ha_alter_info,
bool commit) {
if (!commit) {
TIANMU_LOG(LogCtl_Level::INFO, "Alter table failed : %s%s", m_table_name.c_str(), " rollback");
return true;
Expand Down Expand Up @@ -1542,7 +1548,7 @@ bool TianmuHandler::commit_inplace_alter_table([[maybe_unused]] TABLE *altered_t
fs::remove_all(bak_dir);
} catch (fs::filesystem_error &e) {
TIANMU_LOG(LogCtl_Level::ERROR, "file system error: %s %s|%s", e.what(), e.path1().string().c_str(),
e.path2().string().c_str());
e.path2().string().c_str());
my_message(static_cast<int>(common::ErrorCode::UNKNOWN_ERROR), "Failed to commit alter table", MYF(0));
return true;
}
Expand All @@ -1553,7 +1559,7 @@ bool TianmuHandler::commit_inplace_alter_table([[maybe_unused]] TABLE *altered_t

*/
void TianmuHandler::key_convert(const uchar *key, uint key_len, std::vector<uint> cols,
std::vector<std::string_view> &keys) {
std::vector<std::string_view> &keys) {
key_restore(table->record[0], (uchar *)key, &table->key_info[active_index], key_len);

Field **field = table->field;
Expand Down
7 changes: 4 additions & 3 deletions storage/tianmu/handler/tianmu_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class TianmuHandler final : public handler {
uint max_supported_record_length() const override { return HA_MAX_REC_LENGTH; }
uint max_supported_keys() const override { return MAX_INDEXES; }
uint max_supported_key_parts() const override { return MAX_REF_PARTS; }
uint max_supported_key_length() const override { return 1024; }
uint max_supported_key_length() const override { return 16 * 1024; }
uint max_supported_key_part_length([[maybe_unused]] HA_CREATE_INFO *create_info) const override;
/*
Called in test_quick_select to determine if indexes should be used.
*/
Expand Down Expand Up @@ -148,8 +149,8 @@ class TianmuHandler final : public handler {
void cond_pop() override {}
int reset() override;

my_bool register_query_cache_table(THD *thd, char *table_key, size_t key_length,
qc_engine_callback *engine_callback, ulonglong *engine_data) override;
my_bool register_query_cache_table(THD *thd, char *table_key, size_t key_length, qc_engine_callback *engine_callback,
ulonglong *engine_data) override;
void update_create_info(HA_CREATE_INFO *create_info) override;
int fill_row_by_id(uchar *buf, uint64_t rowid);
void key_convert(const uchar *key, uint key_len, std::vector<uint> cols, std::vector<std::string_view> &keys);
Expand Down
Loading