summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorAleksey Midenkov <midenok@gmail.com>2019-12-02 12:51:53 +0300
committerAleksey Midenkov <midenok@gmail.com>2019-12-02 12:51:53 +0300
commit0b8b11b0b15f2d3d20dc801e50fa2beedc080dad (patch)
tree7a7b9f8ec419bff57b3b0258293d91f180908037 /sql
parent1d46923a0f6508d52d7ce679a7dd8e7e0e957ae4 (diff)
parentdb32d9457edbcb23b45f433cfcdfc5d86232bbb0 (diff)
downloadmariadb-git-0b8b11b0b15f2d3d20dc801e50fa2beedc080dad.tar.gz
Merge 10.3 into 10.4
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_partition.cc15
-rw-r--r--sql/proxy_protocol.cc2
-rw-r--r--sql/sql_derived.cc23
-rw-r--r--sql/sql_insert.cc2
-rw-r--r--sql/sql_update.cc15
-rw-r--r--sql/table.cc17
-rw-r--r--sql/table.h13
7 files changed, 66 insertions, 21 deletions
diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc
index d4d411f1ad3..c9e12f861af 100644
--- a/sql/ha_partition.cc
+++ b/sql/ha_partition.cc
@@ -10830,8 +10830,8 @@ int ha_partition::indexes_are_disabled(void)
@param repair If true, move misplaced rows to correct partition.
@return Operation status.
- @retval 0 Success
- @retval != 0 Error
+ @retval HA_ADMIN_OK Success
+ @retval != HA_ADMIN_OK Error
*/
int ha_partition::check_misplaced_rows(uint read_part_id, bool do_repair)
@@ -10845,6 +10845,17 @@ int ha_partition::check_misplaced_rows(uint read_part_id, bool do_repair)
DBUG_ASSERT(m_file);
+ if (m_part_info->vers_info &&
+ read_part_id != m_part_info->vers_info->now_part->id &&
+ !m_part_info->vers_info->interval.is_set())
+ {
+ print_admin_msg(ha_thd(), MYSQL_ERRMSG_SIZE, "note",
+ table_share->db.str, table->alias,
+ opt_op_name[CHECK_PARTS],
+ "Not supported for non-INTERVAL history partitions");
+ DBUG_RETURN(HA_ADMIN_NOT_IMPLEMENTED);
+ }
+
if (do_repair)
{
/* We must read the full row, if we need to move it! */
diff --git a/sql/proxy_protocol.cc b/sql/proxy_protocol.cc
index b54af619487..550813c6457 100644
--- a/sql/proxy_protocol.cc
+++ b/sql/proxy_protocol.cc
@@ -470,7 +470,7 @@ static int compare_bits(const void *s1, const void *s2, int bit_count)
int byte_count= bit_count / 8;
if (byte_count && (result= memcmp(s1, s2, byte_count)))
return result;
- int rem= byte_count % 8;
+ int rem= bit_count % 8;
if (rem)
{
// compare remaining bits i.e partial bytes.
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc
index 06a3e8a108f..3f955c16eb3 100644
--- a/sql/sql_derived.cc
+++ b/sql/sql_derived.cc
@@ -726,12 +726,27 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived)
{
/*
System versioned tables may still require to get versioning conditions
- (when updating view). See vers_setup_conds().
+ when modifying view (see vers_setup_conds()). Only UPDATE and DELETE are
+ affected because they use WHERE condition.
*/
if (!unit->prepared &&
derived->table->versioned() &&
- (res= unit->prepare(derived, derived->derived_result, 0)))
- goto exit;
+ derived->merge_underlying_list &&
+ /* choose only those merged views that do not select from other views */
+ !derived->merge_underlying_list->merge_underlying_list)
+ {
+ switch (thd->lex->sql_command)
+ {
+ case SQLCOM_DELETE:
+ case SQLCOM_DELETE_MULTI:
+ case SQLCOM_UPDATE:
+ case SQLCOM_UPDATE_MULTI:
+ if ((res= unit->prepare(derived, derived->derived_result, 0)))
+ goto exit;
+ default:
+ break;
+ }
+ }
DBUG_RETURN(FALSE);
}
@@ -881,7 +896,7 @@ exit:
{
if (!derived->is_with_table_recursive_reference())
{
- if (derived->table)
+ if (derived->table && derived->table->s->tmp_table)
free_tmp_table(thd, derived->table);
delete derived->derived_result;
}
diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc
index af8c29c309e..ad552928e7c 100644
--- a/sql/sql_insert.cc
+++ b/sql/sql_insert.cc
@@ -1670,6 +1670,8 @@ static int last_uniq_key(TABLE *table,uint keynr)
int vers_insert_history_row(TABLE *table)
{
DBUG_ASSERT(table->versioned(VERS_TIMESTAMP));
+ if (!table->vers_write)
+ return 0;
restore_record(table,record[1]);
// Set Sys_end to now()
diff --git a/sql/sql_update.cc b/sql/sql_update.cc
index 68b402dc925..8ecac25e162 100644
--- a/sql/sql_update.cc
+++ b/sql/sql_update.cc
@@ -206,10 +206,10 @@ static bool check_fields(THD *thd, TABLE_LIST *table, List<Item> &items,
return FALSE;
}
-static bool check_has_vers_fields(TABLE *table, List<Item> &items)
+bool TABLE::vers_check_update(List<Item> &items)
{
List_iterator<Item> it(items);
- if (!table->versioned())
+ if (!versioned_write())
return false;
while (Item *item= it++)
@@ -217,8 +217,11 @@ static bool check_has_vers_fields(TABLE *table, List<Item> &items)
if (Item_field *item_field= item->field_for_view_update())
{
Field *field= item_field->field;
- if (field->table == table && !field->vers_update_unversioned())
+ if (field->table == this && !field->vers_update_unversioned())
+ {
+ no_cache= true;
return true;
+ }
}
}
return false;
@@ -481,7 +484,7 @@ int mysql_update(THD *thd,
{
DBUG_RETURN(1);
}
- bool has_vers_fields= check_has_vers_fields(table, fields);
+ bool has_vers_fields= table->vers_check_update(fields);
if (check_key_in_view(thd, table_list))
{
my_error(ER_NON_UPDATABLE_TABLE, MYF(0), table_list->alias.str, "UPDATE");
@@ -2254,7 +2257,7 @@ multi_update::initialize_tables(JOIN *join)
if (safe_update_on_fly(thd, join->join_tab, table_ref, all_tables))
{
table_to_update= table; // Update table on the fly
- has_vers_fields= check_has_vers_fields(table, *fields);
+ has_vers_fields= table->vers_check_update(*fields);
continue;
}
}
@@ -2723,7 +2726,7 @@ int multi_update::do_updates()
if (table->vfield)
empty_record(table);
- has_vers_fields= check_has_vers_fields(table, *fields);
+ has_vers_fields= table->vers_check_update(*fields);
check_opt_it.rewind();
while(TABLE *tbl= check_opt_it++)
diff --git a/sql/table.cc b/sql/table.cc
index 055f02ef267..1d5aaf7e574 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -5110,6 +5110,7 @@ void TABLE::init(THD *thd, TABLE_LIST *tl)
check_unique_buf= NULL;
vers_write= s->versioned;
quick_condition_rows=0;
+ no_cache= false;
initialize_quick_structures();
#ifdef HAVE_REPLICATION
/* used in RBR Triggers */
@@ -7027,12 +7028,8 @@ void TABLE::mark_columns_needed_for_update()
/*
For System Versioning we have to read all columns since we store
a copy of previous row with modified row_end back to a table.
-
- Without write_set versioning.rpl,row is unstable until MDEV-16370 is
- applied.
*/
bitmap_union(read_set, &s->all_set);
- bitmap_union(write_set, &s->all_set);
need_signal= true;
}
if (check_constraints)
@@ -7195,8 +7192,16 @@ void TABLE::mark_columns_per_binlog_row_image()
binary log will include all columns read anyway.
*/
mark_columns_used_by_index_no_reset(s->primary_key, read_set);
- /* Only write columns that have changed */
- rpl_write_set= write_set;
+ if (versioned())
+ {
+ // TODO: After MDEV-18432 we don't pass history rows, so remove this:
+ rpl_write_set= &s->all_set;
+ }
+ else
+ {
+ /* Only write columns that have changed */
+ rpl_write_set= write_set;
+ }
break;
default:
diff --git a/sql/table.h b/sql/table.h
index 6b125fe43ad..458482315c3 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -324,7 +324,7 @@ typedef struct st_grant_info
enum tmp_table_type
{
- NO_TMP_TABLE, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE,
+ NO_TMP_TABLE= 0, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE,
INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE
};
enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP };
@@ -1589,9 +1589,16 @@ public:
return s->versioned == type;
}
- bool versioned_write(vers_sys_type_t type= VERS_UNDEFINED) const
+ bool versioned_write() const
{
DBUG_ASSERT(versioned() || !vers_write);
+ return versioned() ? vers_write : false;
+ }
+
+ bool versioned_write(vers_sys_type_t type) const
+ {
+ DBUG_ASSERT(type);
+ DBUG_ASSERT(versioned() || !vers_write);
return versioned(type) ? vers_write : false;
}
@@ -1614,6 +1621,8 @@ public:
int period_make_insert(Item *src, Field *dst);
int insert_portion_of_time(THD *thd, const vers_select_conds_t &period_conds,
ha_rows *rows_inserted);
+ bool vers_check_update(List<Item> &items);
+
int delete_row();
void vers_update_fields();
void vers_update_end();