summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Malyavin <nikitamalyavin@gmail.com>2020-01-10 20:39:20 +1000
committerNikita Malyavin <nikitamalyavin@gmail.com>2020-02-21 02:40:17 +1000
commit6e41e83372da4edc304c9fc5779c1dd02e81b834 (patch)
treedf5543fe23ed95363d218ca7923495a9a22820f3
parentb227a5bbfa330e6aaacdc1728deac6b26cd38552 (diff)
downloadmariadb-git-6e41e83372da4edc304c9fc5779c1dd02e81b834.tar.gz
extract common code with sachin's blob keys
-rw-r--r--sql/handler.cc60
-rw-r--r--sql/handler.h7
-rw-r--r--sql/sql_base.cc3
-rw-r--r--sql/sql_select.cc1
-rw-r--r--sql/table.cc30
-rw-r--r--sql/table.h3
-rw-r--r--sql/temporary_tables.cc2
7 files changed, 38 insertions, 68 deletions
diff --git a/sql/handler.cc b/sql/handler.cc
index b9690c35775..1dadafc8ff4 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -6407,11 +6407,11 @@ int handler::ha_external_lock(THD *thd, int lock_type)
mysql_audit_external_lock(thd, table_share, lock_type);
}
- if (lock_type == F_UNLCK && check_overlaps_handler)
+ if (lock_type == F_UNLCK && lookup_handler)
{
- check_overlaps_handler->ha_external_lock(table->in_use, F_UNLCK);
- check_overlaps_handler->close();
- check_overlaps_handler= NULL;
+ lookup_handler->ha_external_lock(table->in_use, F_UNLCK);
+ lookup_handler->close();
+ lookup_handler= NULL;
overlaps_error_key= -1;
}
@@ -6576,10 +6576,12 @@ exit:
unique constraint on long columns.
@returns 0 if no duplicate else returns error
*/
-static int check_duplicate_long_entries(TABLE *table, handler *h,
- const uchar *new_rec)
+int handler::check_duplicate_long_entries(const uchar *new_rec)
{
- table->file->errkey= -1;
+ if (this->inited == RND)
+ create_lookup_handler();
+ handler *h= lookup_handler ? lookup_handler : table->file;
+ errkey= -1;
int result;
for (uint i= 0; i < table->s->keys; i++)
{
@@ -6604,7 +6606,7 @@ static int check_duplicate_long_entries(TABLE *table, handler *h,
key as a parameter in normal insert key should be -1
@returns 0 if no duplicate else returns error
*/
-static int check_duplicate_long_entries_update(TABLE *table, handler *h, uchar *new_rec)
+int handler::check_duplicate_long_entries_update(const uchar *new_rec)
{
Field *field;
uint key_parts;
@@ -6616,7 +6618,8 @@ static int check_duplicate_long_entries_update(TABLE *table, handler *h, uchar *
with respect to fields in hash_str
*/
uint reclength= (uint) (table->record[1] - table->record[0]);
- table->clone_handler_for_update();
+ error= create_lookup_handler();
+
for (uint i= 0; i < table->s->keys; i++)
{
keyinfo= table->key_info + i;
@@ -6630,8 +6633,8 @@ static int check_duplicate_long_entries_update(TABLE *table, handler *h, uchar *
/* Compare fields if they are different then check for duplicates*/
if(field->cmp_binary_offset(reclength))
{
- if((error= check_duplicate_long_entry_key(table, table->update_handler,
- new_rec, i)))
+ if((error= check_duplicate_long_entry_key(table, lookup_handler,
+ new_rec, i)))
goto exit;
/*
break because check_duplicate_long_entries_key will
@@ -6665,10 +6668,7 @@ int handler::ha_write_row(const uchar *buf)
if (table->s->long_unique_table)
{
- if (this->inited == RND)
- table->clone_handler_for_update();
- handler *h= table->update_handler ? table->update_handler : table->file;
- if ((error= check_duplicate_long_entries(table, h, buf)))
+ if ((error= check_duplicate_long_entries(buf)))
DBUG_RETURN(error);
}
TABLE_IO_WAIT(tracker, m_psi, PSI_TABLE_WRITE_ROW, MAX_KEY, 0,
@@ -6715,7 +6715,7 @@ int handler::ha_update_row(const uchar *old_data, const uchar *new_data)
mark_trx_read_write();
increment_statistics(&SSV::ha_update_count);
if (table->s->long_unique_table &&
- (error= check_duplicate_long_entries_update(table, table->file, (uchar *)new_data)))
+ (error= check_duplicate_long_entries_update(new_data)))
{
return error;
}
@@ -6956,6 +6956,21 @@ void handler::set_lock_type(enum thr_lock_type lock)
table->reginfo.lock_type= lock;
}
+/**
+ @brief clone of current handler.
+ Creates a clone of handler used for unique hash key and WITHOUT OVERLAPS.
+ @return error code
+*/
+int handler::create_lookup_handler()
+{
+ if (lookup_handler)
+ return 0;
+ lookup_handler= clone(table_share->normalized_path.str,
+ table->in_use->mem_root);
+ int error= lookup_handler->ha_external_lock(table->in_use, F_RDLCK);
+ return error;
+}
+
int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
{
DBUG_ASSERT(new_data);
@@ -6973,17 +6988,8 @@ int handler::ha_check_overlaps(const uchar *old_data, const uchar* new_data)
auto *handler= this;
if (handler->inited != NONE)
{
- if (!check_overlaps_handler)
- {
- check_overlaps_handler= clone(table_share->normalized_path.str,
- &table_share->mem_root);
- int error= -1;
- if (check_overlaps_handler != NULL)
- error= check_overlaps_handler->ha_external_lock(table->in_use, F_RDLCK);
- if (error)
- return error;
- }
- handler= check_overlaps_handler;
+ create_lookup_handler();
+ handler= lookup_handler;
// Needs to compare record refs later is old_row_found()
if (is_update)
diff --git a/sql/handler.h b/sql/handler.h
index c51952c16b2..8db23fcb905 100644
--- a/sql/handler.h
+++ b/sql/handler.h
@@ -3003,7 +3003,7 @@ protected:
ha_rows estimation_rows_to_insert;
uchar *check_overlaps_buffer;
- handler *check_overlaps_handler;
+ handler *lookup_handler;
int overlaps_error_key;
public:
handlerton *ht; /* storage engine of this handler */
@@ -3151,7 +3151,7 @@ public:
handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
:table_share(share_arg), table(0),
estimation_rows_to_insert(0),
- check_overlaps_buffer(NULL), check_overlaps_handler(NULL),
+ check_overlaps_buffer(NULL), lookup_handler(NULL),
overlaps_error_key(-1),
ht(ht_arg), ref(0), end_range(NULL),
implicit_emptied(0),
@@ -3263,6 +3263,9 @@ public:
DBUG_ASSERT(cached_table_flags < (HA_LAST_TABLE_FLAG << 1));
return cached_table_flags;
}
+ int check_duplicate_long_entries(const uchar *new_rec);
+ int check_duplicate_long_entries_update(const uchar *new_rec);
+ int create_lookup_handler();
/** PRIMARY KEY/UNIQUE WITHOUT OVERLAPS check */
int ha_check_overlaps(const uchar *old_data, const uchar* new_data);
/**
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index c88aef09c96..98958c635e6 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -891,9 +891,6 @@ void close_thread_tables(THD *thd)
for (table= thd->open_tables; table; table= table->next)
{
- if (table->update_handler)
- table->delete_update_handler();
-
/* Table might be in use by some outer statement. */
DBUG_PRINT("tcache", ("table: '%s' query_id: %lu",
table->s->table_name.str, (ulong) table->query_id));
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 09a15aaf7df..5919a39f1c8 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -18267,7 +18267,6 @@ TABLE *Create_tmp_table::start(THD *thd,
table->copy_blobs= 1;
table->in_use= thd;
table->no_rows_with_nulls= param->force_not_null_cols;
- table->update_handler= NULL;
table->check_unique_buf= NULL;
table->s= share;
diff --git a/sql/table.cc b/sql/table.cc
index 39048b0962f..da153d1ad33 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -5258,7 +5258,6 @@ void TABLE::init(THD *thd, TABLE_LIST *tl)
range_rowid_filter_cost_info_elems= 0;
range_rowid_filter_cost_info_ptr= NULL;
range_rowid_filter_cost_info= NULL;
- update_handler= NULL;
check_unique_buf= NULL;
vers_write= s->versioned;
quick_condition_rows=0;
@@ -9270,35 +9269,6 @@ void re_setup_keyinfo_hash(KEY *key_info)
key_info->ext_key_parts= 1;
key_info->flags&= ~HA_NOSAME;
}
-/**
- @brief clone of current handler.
- Creates a clone of handler used in update for
- unique hash key.
-*/
-void TABLE::clone_handler_for_update()
-{
- if (this->update_handler)
- return;
- handler *update_handler= NULL;
- if (!s->long_unique_table)
- return;
- update_handler= file->clone(s->normalized_path.str,
- in_use->mem_root);
- update_handler->ha_external_lock(in_use, F_RDLCK);
- this->update_handler= update_handler;
- return;
-}
-
-/**
- @brief Deletes update handler object
-*/
-void TABLE::delete_update_handler()
-{
- update_handler->ha_external_lock(in_use, F_UNLCK);
- update_handler->ha_close();
- delete update_handler;
- this->update_handler= NULL;
-}
LEX_CSTRING *fk_option_name(enum_fk_option opt)
{
diff --git a/sql/table.h b/sql/table.h
index 311d51f34ee..e19335c3713 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -1154,7 +1154,6 @@ public:
uchar *record[3]; /* Pointer to records */
/* record buf to resolve hash collisions for long UNIQUE constraints */
uchar *check_unique_buf;
- handler *update_handler; /* Handler used in case of update */
uchar *write_row_record; /* Used as optimisation in
THD::write_row */
uchar *insert_values; /* used by INSERT ... UPDATE */
@@ -1648,8 +1647,6 @@ public:
void vers_update_fields();
void vers_update_end();
void find_constraint_correlated_indexes();
- void clone_handler_for_update();
- void delete_update_handler();
/** Number of additional fields used in versioned tables */
#define VERSIONING_FIELDS 2
diff --git a/sql/temporary_tables.cc b/sql/temporary_tables.cc
index 2e0f0a4918e..337684395c9 100644
--- a/sql/temporary_tables.cc
+++ b/sql/temporary_tables.cc
@@ -749,8 +749,6 @@ void THD::mark_tmp_tables_as_free_for_reuse()
{
if ((table->query_id == query_id) && !table->open_by_handler)
{
- if (table->update_handler)
- table->delete_update_handler();
mark_tmp_table_as_free_for_reuse(table);
}
}