summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2019-04-27 20:41:31 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2019-04-27 20:41:31 +0300
commit4d59f45260547b3230f177498b6fa07a12647fdc (patch)
treec39c6757a7a7ddbc4849769b288c0131da74803d /sql
parentacf6f92aa936fbfe7524617ae57d011ab8f1f96d (diff)
parent00377147e3029b982cbc29d3f4477362c6e6fdb4 (diff)
downloadmariadb-git-4d59f45260547b3230f177498b6fa07a12647fdc.tar.gz
Merge 10.2 into 10.3
Diffstat (limited to 'sql')
-rw-r--r--sql/handler.cc15
-rw-r--r--sql/item_subselect.cc9
-rw-r--r--sql/item_subselect.h2
-rw-r--r--sql/log_event.cc7
-rw-r--r--sql/sql_insert.cc62
-rw-r--r--sql/sql_load.cc7
-rw-r--r--sql/sql_parse.cc3
-rw-r--r--sql/sql_select.cc16
-rw-r--r--sql/sql_update.cc8
-rw-r--r--sql/table.cc3
10 files changed, 113 insertions, 19 deletions
diff --git a/sql/handler.cc b/sql/handler.cc
index 6329774668f..f39cb55c7f6 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -2841,8 +2841,7 @@ int handler::ha_rnd_pos(uchar *buf, uchar *pos)
DBUG_ENTER("handler::ha_rnd_pos");
DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
m_lock_type != F_UNLCK);
- /* TODO: Find out how to solve ha_rnd_pos when finding duplicate update. */
- /* DBUG_ASSERT(inited == RND); */
+ DBUG_ASSERT(inited == RND);
TABLE_IO_WAIT(tracker, m_psi, PSI_TABLE_FETCH_ROW, MAX_KEY, 0,
{ result= rnd_pos(buf, pos); })
@@ -3521,6 +3520,10 @@ void handler::get_auto_increment(ulonglong offset, ulonglong increment,
ulonglong nr;
int error;
MY_BITMAP *old_read_set;
+ bool rnd_inited= (inited == RND);
+
+ if (rnd_inited && ha_rnd_end())
+ return;
old_read_set= table->prepare_for_keyread(table->s->next_number_index);
@@ -3530,6 +3533,10 @@ void handler::get_auto_increment(ulonglong offset, ulonglong increment,
DBUG_ASSERT(0);
(void) extra(HA_EXTRA_NO_KEYREAD);
*first_value= ULONGLONG_MAX;
+ if (rnd_inited && ha_rnd_init_with_error(0))
+ {
+ //TODO: it would be nice to return here an error
+ }
return;
}
@@ -3576,6 +3583,10 @@ void handler::get_auto_increment(ulonglong offset, ulonglong increment,
ha_index_end();
table->restore_column_maps_after_keyread(old_read_set);
*first_value= nr;
+ if (rnd_inited && ha_rnd_init_with_error(0))
+ {
+ //TODO: it would be nice to return here an error
+ }
return;
}
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index cd411c5d4c1..99bba5a98d5 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -5844,12 +5844,16 @@ Ordered_key::cmp_keys_by_row_data_and_rownum(Ordered_key *key,
}
-void Ordered_key::sort_keys()
+bool Ordered_key::sort_keys()
{
+ if (tbl->file->ha_rnd_init_with_error(0))
+ return TRUE;
my_qsort2(key_buff, (size_t) key_buff_elements, sizeof(rownum_t),
(qsort2_cmp) &cmp_keys_by_row_data_and_rownum, (void*) this);
/* Invalidate the current row position. */
cur_key_idx= HA_POS_ERROR;
+ tbl->file->ha_rnd_end();
+ return FALSE;
}
@@ -6297,7 +6301,8 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts,
/* Sort the keys in each of the indexes. */
for (uint i= 0; i < merge_keys_count; i++)
- merge_keys[i]->sort_keys();
+ if (merge_keys[i]->sort_keys())
+ return TRUE;
if (init_queue(&pq, merge_keys_count, 0, FALSE,
subselect_rowid_merge_engine::cmp_keys_by_cur_rownum, NULL,
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index 363dbba4ddd..e0b09b9484b 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -1283,7 +1283,7 @@ public:
++cur_key_idx;
}
- void sort_keys();
+ bool sort_keys();
double null_selectivity();
/*
diff --git a/sql/log_event.cc b/sql/log_event.cc
index 28ac34c8a0f..52556cddd12 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -13477,6 +13477,12 @@ Rows_log_event::write_row(rpl_group_info *rgi,
if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
{
DBUG_PRINT("info",("Locating offending record using rnd_pos()"));
+
+ if ((error= table->file->ha_rnd_init_with_error(0)))
+ {
+ DBUG_RETURN(error);
+ }
+
error= table->file->ha_rnd_pos(table->record[1], table->file->dup_ref);
if (unlikely(error))
{
@@ -13484,6 +13490,7 @@ Rows_log_event::write_row(rpl_group_info *rgi,
table->file->print_error(error, MYF(0));
DBUG_RETURN(error);
}
+ table->file->ha_rnd_end();
}
else
{
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index abe4254db3e..b1f68e049cf 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2016, Oracle and/or its affiliates.
- Copyright (c) 2010, 2018, MariaDB Corporation
+ Copyright (c) 2010, 2019, MariaDB Corporation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -881,7 +881,12 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
#endif /* EMBEDDED_LIBRARY */
{
if (duplic != DUP_ERROR || ignore)
+ {
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
+ if (table->file->ha_table_flags() & HA_DUPLICATE_POS &&
+ table->file->ha_rnd_init_with_error(0))
+ goto abort;
+ }
/**
This is a simple check for the case when the table has a trigger
that reads from it, or when the statement invokes a stored function
@@ -944,7 +949,10 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
{
DBUG_PRINT("info", ("iteration %llu", iteration));
if (iteration && bulk_parameters_set(thd))
- goto abort;
+ {
+ error= 1;
+ goto values_loop_end;
+ }
while ((values= its++))
{
@@ -1101,7 +1109,11 @@ values_loop_end:
error=1;
}
if (duplic != DUP_ERROR || ignore)
+ {
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
+ if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
+ table->file->ha_rnd_end();
+ }
transactional_table= table->file->has_transactions();
@@ -1744,6 +1756,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info)
goto err;
if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
{
+ DBUG_ASSERT(table->file->inited == handler::RND);
if (table->file->ha_rnd_pos(table->record[1],table->file->dup_ref))
goto err;
}
@@ -3271,6 +3284,9 @@ bool Delayed_insert::handle_inserts(void)
max_rows= ULONG_MAX; // Do as much as possible
}
+ if (table->file->ha_rnd_init_with_error(0))
+ goto err;
+
/*
We can't use row caching when using the binary log because if
we get a crash, then binary log will contain rows that are not yet
@@ -3445,6 +3461,8 @@ bool Delayed_insert::handle_inserts(void)
}
}
+ table->file->ha_rnd_end();
+
if (WSREP((&thd)))
thd_proc_info(&thd, "Insert done");
else
@@ -3742,7 +3760,12 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
thd->cuted_fields=0;
if (info.ignore || info.handle_duplicates != DUP_ERROR)
+ {
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
+ if (table->file->ha_table_flags() & HA_DUPLICATE_POS &&
+ table->file->ha_rnd_init_with_error(0))
+ DBUG_RETURN(1);
+ }
if (info.handle_duplicates == DUP_REPLACE &&
(!table->triggers || !table->triggers->has_delete_triggers()))
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
@@ -3919,6 +3942,9 @@ bool select_insert::prepare_eof()
if (likely(!error) && unlikely(thd->is_error()))
error= thd->get_stmt_da()->sql_errno();
+ if (info.ignore || info.handle_duplicates != DUP_ERROR)
+ if (table->file->ha_table_flags() & HA_DUPLICATE_POS)
+ table->file->ha_rnd_end();
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
@@ -4030,6 +4056,11 @@ void select_insert::abort_result_set() {
if (thd->locked_tables_mode <= LTM_LOCK_TABLES)
table->file->ha_end_bulk_insert();
+ if (table->file->inited)
+ table->file->ha_rnd_end();
+ table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
+ table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
+
/*
If at least one row has been inserted/modified and will stay in
the table (the table doesn't have transactions) we must write to
@@ -4450,7 +4481,12 @@ select_create::prepare(List<Item> &_values, SELECT_LEX_UNIT *u)
restore_record(table,s->default_values); // Get empty record
thd->cuted_fields=0;
if (info.ignore || info.handle_duplicates != DUP_ERROR)
+ {
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
+ if (table->file->ha_table_flags() & HA_DUPLICATE_POS &&
+ table->file->ha_rnd_init_with_error(0))
+ DBUG_RETURN(1);
+ }
if (info.handle_duplicates == DUP_REPLACE &&
(!table->triggers || !table->triggers->has_delete_triggers()))
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
@@ -4631,9 +4667,6 @@ bool select_create::send_eof()
*/
exit_done= 1; // Avoid double calls
- table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
- table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
-
send_ok_packet();
if (m_plock)
@@ -4709,13 +4742,6 @@ void select_create::abort_result_set()
thd->locked_tables_list.unlock_locked_table(thd,
create_info->mdl_ticket);
}
- if (m_plock)
- {
- mysql_unlock_tables(thd, *m_plock);
- *m_plock= NULL;
- m_plock= NULL;
- }
-
if (table)
{
bool tmp_table= table->s->tmp_table;
@@ -4726,9 +4752,21 @@ void select_create::abort_result_set()
thd->restore_tmp_table_share(saved_tmp_table_share);
}
+ if (table->file->inited &&
+ (info.ignore || info.handle_duplicates != DUP_ERROR) &&
+ (table->file->ha_table_flags() & HA_DUPLICATE_POS))
+ table->file->ha_rnd_end();
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
table->auto_increment_field_not_null= FALSE;
+
+ if (m_plock)
+ {
+ mysql_unlock_tables(thd, *m_plock);
+ *m_plock= NULL;
+ m_plock= NULL;
+ }
+
drop_open_table(thd, table, &create_table->db, &create_table->table_name);
table=0; // Safety
if (thd->log_current_statement && mysql_bin_log.is_open())
diff --git a/sql/sql_load.cc b/sql/sql_load.cc
index 92ef222c8b7..8631569a30b 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -663,6 +663,10 @@ int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list,
thd->abort_on_warning= !ignore && thd->is_strict_mode();
+ if ((table_list->table->file->ha_table_flags() & HA_DUPLICATE_POS) &&
+ (error= table_list->table->file->ha_rnd_init_with_error(0)))
+ goto err;
+
thd_progress_init(thd, 2);
if (table_list->table->validate_default_values_of_unset_fields(thd))
{
@@ -682,6 +686,9 @@ int mysql_load(THD *thd, const sql_exchange *ex, TABLE_LIST *table_list,
set_fields, set_values, read_info,
*ex->enclosed, skip_lines, ignore);
+ if (table_list->table->file->ha_table_flags() & HA_DUPLICATE_POS)
+ table_list->table->file->ha_rnd_end();
+
thd_proc_info(thd, "End bulk insert");
if (likely(!error))
thd_progress_next_stage(thd);
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index a0aaec9927a..ab649f23160 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -615,7 +615,8 @@ void init_update_queries(void)
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
CF_CAN_BE_EXPLAINED |
- CF_INSERTS_DATA | CF_SP_BULK_SAFE;
+ CF_INSERTS_DATA | CF_SP_BULK_SAFE |
+ CF_SP_BULK_OPTIMIZED;
sql_command_flags[SQLCOM_REPLACE_SELECT]= CF_CHANGES_DATA | CF_REEXECUTION_FRAGILE |
CF_CAN_GENERATE_ROW_EVENTS |
CF_OPTIMIZER_TRACE |
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 1ecc964c04b..7b98a235ab0 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -20967,6 +20967,15 @@ end_unique_update(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
table->file->print_error(error,MYF(0)); /* purecov: inspected */
DBUG_RETURN(NESTED_LOOP_ERROR); /* purecov: inspected */
}
+ /* Prepare table for random positioning */
+ bool rnd_inited= (table->file->inited == handler::RND);
+ if (!rnd_inited &&
+ ((error= table->file->ha_index_end()) ||
+ (error= table->file->ha_rnd_init(0))))
+ {
+ table->file->print_error(error, MYF(0));
+ DBUG_RETURN(NESTED_LOOP_ERROR);
+ }
if (unlikely(table->file->ha_rnd_pos(table->record[1],table->file->dup_ref)))
{
table->file->print_error(error,MYF(0)); /* purecov: inspected */
@@ -20980,6 +20989,13 @@ end_unique_update(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
table->file->print_error(error,MYF(0)); /* purecov: inspected */
DBUG_RETURN(NESTED_LOOP_ERROR); /* purecov: inspected */
}
+ if (!rnd_inited &&
+ ((error= table->file->ha_rnd_end()) ||
+ (error= table->file->ha_index_init(0, 0))))
+ {
+ table->file->print_error(error, MYF(0));
+ DBUG_RETURN(NESTED_LOOP_ERROR);
+ }
}
if (unlikely(join->thd->check_killed()))
{
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 0d02e9e6fee..497f419c1db 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -256,6 +256,14 @@ static void prepare_record_for_error_message(int error, TABLE *table)
bitmap_union(table->read_set, &unique_map);
/* Tell the engine about the new set. */
table->file->column_bitmaps_signal();
+
+ if ((error= table->file->ha_index_or_rnd_end()) ||
+ (error= table->file->ha_rnd_init(0)))
+ {
+ table->file->print_error(error, MYF(0));
+ DBUG_VOID_RETURN;
+ }
+
/* Read record that is identified by table->file->ref. */
(void) table->file->ha_rnd_pos(table->record[1], table->file->ref);
/* Copy the newly read columns into the new record. */
diff --git a/sql/table.cc b/sql/table.cc
index 80995abc1f9..b4dcbaea6dc 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -1895,7 +1895,8 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
goto err;
vcol_info= new (&share->mem_root) Virtual_column_info();
vcol_info_length= uint2korr(vcol_screen_pos + 1);
- DBUG_ASSERT(vcol_info_length);
+ if (!vcol_info_length) // Expect non-empty expression
+ goto err;
vcol_info->stored_in_db= vcol_screen_pos[3];
vcol_info->utf8= 0;
vcol_screen_pos+= vcol_info_length + MYSQL57_GCOL_HEADER_SIZE;;