summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2019-05-05 10:23:14 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2019-05-05 10:23:14 +0300
commitb132b8895e2e59df457e063451f186b53576b034 (patch)
tree565a5529facdca326b36d4418fae3522d8715e02 /sql
parent27980b0f83529725435dc8f37cb51878eb074d1d (diff)
parent4d59f45260547b3230f177498b6fa07a12647fdc (diff)
downloadmariadb-git-b132b8895e2e59df457e063451f186b53576b034.tar.gz
Merge 10.3 into 10.4
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 bb97302c0b9..12a05aba90d 100644
--- a/sql/handler.cc
+++ b/sql/handler.cc
@@ -2835,8 +2835,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); })
@@ -3515,6 +3514,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);
@@ -3524,6 +3527,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;
}
@@ -3570,6 +3577,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 2b1c4c174c7..e32a730214a 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -5876,12 +5876,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;
}
@@ -6329,7 +6333,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 bbc24d336f0..6b66ccc8fe7 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -1293,7 +1293,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 70f0e6c2623..1246330f7bb 100644
--- a/sql/log_event.cc
+++ b/sql/log_event.cc
@@ -13502,6 +13502,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))
{
@@ -13509,6 +13515,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 77a83f2de45..e5d33b91804 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
@@ -885,7 +885,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
@@ -948,7 +953,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++))
{
@@ -1105,7 +1113,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();
@@ -1748,6 +1760,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;
}
@@ -3283,6 +3296,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
@@ -3457,6 +3473,8 @@ bool Delayed_insert::handle_inserts(void)
}
}
+ table->file->ha_rnd_end();
+
if (WSREP((&thd)))
thd_proc_info(&thd, "Insert done");
else
@@ -3758,7 +3776,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);
@@ -3938,6 +3961,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);
@@ -4049,6 +4075,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
@@ -4464,7 +4495,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);
@@ -4656,9 +4692,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)
@@ -4734,13 +4767,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;
@@ -4751,9 +4777,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 0228bf62708..ba1403837b8 100644
--- a/sql/sql_load.cc
+++ b/sql/sql_load.cc
@@ -647,6 +647,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))
{
@@ -666,6 +670,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 5f1867bd5c0..e61a9675e65 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -616,7 +616,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 088d6224d6b..9e5e4bf4ee5 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -21619,6 +21619,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 */
@@ -21632,6 +21641,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 cf1b5ac3892..723a3f26dc9 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -273,6 +273,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 8b9377dbff9..016fe91c805 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -2212,7 +2212,8 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
goto err;
vcol_info= new (&share->mem_root) Virtual_column_info();
uint 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;;