Skip to content

Commit

Permalink
Merge 10.5 into 10.6
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed Mar 15, 2022
2 parents dafc5fb + 73fee39 commit 4ef44cc
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 43 deletions.
2 changes: 1 addition & 1 deletion mysql-test/lib/mtr_cases.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ sub get_tags_from_file($$) {
}

# Check for a sourced include file.
if ($line =~ /^(--)?[[:space:]]*source[[:space:]]+([^;[:space:]]+)/)
if ($line =~ /^[[:space:]]*(--)?[[:space:]]*source[[:space:]]+([^;[:space:]]+)/)
{
my $include= $2;
# The rules below must match open_file() function of mysqltest.cc
Expand Down
24 changes: 24 additions & 0 deletions mysql-test/main/sql_safe_updates.result
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
#
# MDEV-14429 sql_safe_updates in my.cnf not work
#
select @@sql_safe_updates;
@@sql_safe_updates
1
#
# MDEV-18304 sql_safe_updates does not work with OR clauses
#
create table t1 (a int, b int, primary key (a), key (b));
update t1 set b=2 where a=1 or b=2;
ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
explain update t1 set b=2 where a=1 or b=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 1 Using where
delete from t1 where a=1 or b=2;
ERROR HY000: You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column
explain delete from t1 where a=1 or b=2;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 ALL NULL NULL NULL NULL 1 Using where
insert into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8);
update t1 set b=2 where a=1 or b=2;
delete from t1 where a=1 or b=2;
drop table t1;
#
# End of 10.3 tests
#
25 changes: 22 additions & 3 deletions mysql-test/main/sql_safe_updates.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
#
# MDEV-14429 sql_safe_updates in my.cnf not work
#
--echo #
--echo # MDEV-14429 sql_safe_updates in my.cnf not work
--echo #
select @@sql_safe_updates;

--echo #
--echo # MDEV-18304 sql_safe_updates does not work with OR clauses
--echo #
create table t1 (a int, b int, primary key (a), key (b));
--error ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE
update t1 set b=2 where a=1 or b=2;
explain update t1 set b=2 where a=1 or b=2;
--error ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE
delete from t1 where a=1 or b=2;
explain delete from t1 where a=1 or b=2;
insert into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8);
update t1 set b=2 where a=1 or b=2;
delete from t1 where a=1 or b=2;
drop table t1;

--echo #
--echo # End of 10.3 tests
--echo #
9 changes: 9 additions & 0 deletions mysql-test/suite/innodb/r/instant_alter_bugs.result
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,13 @@ ALTER TABLE t ADD d INT;
affected rows: 0
info: Records: 0 Duplicates: 0 Warnings: 0
DROP TABLE t;
#
# MDEV-28060 Online DDL fails while checking for instant
# alter condition
#
CREATE TABLE t1(f1 CHAR(10) NOT NULL)ROW_FORMAT=REDUNDANT,ENGINE=InnoDB;
ALTER TABLE t1 ADD COLUMN(f2 INT NOT NULL, f3 INT NOT NULL,
f4 INT NOT NULL, f5 INT NOT NULL),
CHANGE COLUMN f1 f1 CHAR(10) DEFAULT NULL;
DROP TABLE t1;
SET GLOBAL innodb_purge_rseg_truncate_frequency=@save_frequency;
2 changes: 2 additions & 0 deletions mysql-test/suite/innodb/r/undo_truncate.result
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ connection con2;
commit;
disconnect con2;
connection default;
SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
SET GLOBAL innodb_max_purge_lag_wait=0;
set global innodb_fast_shutdown=0;
# restart
drop table t1, t2;
9 changes: 9 additions & 0 deletions mysql-test/suite/innodb/t/instant_alter_bugs.test
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,13 @@ ALTER TABLE t ADD d INT;
--disable_info
DROP TABLE t;

--echo #
--echo # MDEV-28060 Online DDL fails while checking for instant
--echo # alter condition
--echo #
CREATE TABLE t1(f1 CHAR(10) NOT NULL)ROW_FORMAT=REDUNDANT,ENGINE=InnoDB;
ALTER TABLE t1 ADD COLUMN(f2 INT NOT NULL, f3 INT NOT NULL,
f4 INT NOT NULL, f5 INT NOT NULL),
CHANGE COLUMN f1 f1 CHAR(10) DEFAULT NULL;
DROP TABLE t1;
SET GLOBAL innodb_purge_rseg_truncate_frequency=@save_frequency;
2 changes: 2 additions & 0 deletions mysql-test/suite/innodb/t/undo_truncate.test
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ connection default;
let $trx_before= `SHOW ENGINE INNODB STATUS`;
let $trx_before= `select substr('$trx_before',9)+2`;

SET GLOBAL innodb_purge_rseg_truncate_frequency=1;
SET GLOBAL innodb_max_purge_lag_wait=0;
set global innodb_fast_shutdown=0;
--source include/restart_mysqld.inc
--replace_regex /.*Trx id counter ([0-9]+).*/\1/
Expand Down
7 changes: 4 additions & 3 deletions sql/sql_delete.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright (c) 2000, 2019, Oracle and/or its affiliates.
Copyright (c) 2010, 2021, MariaDB
Copyright (c) 2010, 2022, MariaDB
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
Expand Down Expand Up @@ -417,7 +417,8 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
DBUG_RETURN(TRUE);

const_cond= (!conds || conds->const_item());
safe_update= MY_TEST(thd->variables.option_bits & OPTION_SAFE_UPDATES);
safe_update= (thd->variables.option_bits & OPTION_SAFE_UPDATES) &&
!thd->lex->describe;
if (safe_update && const_cond)
{
my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
Expand Down Expand Up @@ -542,7 +543,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds,
}

/* If running in safe sql mode, don't allow updates without keys */
if (table->opt_range_keys.is_clear_all())
if (!select || !select->quick)
{
thd->set_status_no_index_used();
if (safe_update && !using_limit)
Expand Down
7 changes: 4 additions & 3 deletions sql/sql_update.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates.
Copyright (c) 2011, 2021, MariaDB
Copyright (c) 2011, 2022, MariaDB
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
Expand Down Expand Up @@ -370,7 +370,8 @@ int mysql_update(THD *thd,
ha_rows *found_return, ha_rows *updated_return)
{
bool using_limit= limit != HA_POS_ERROR;
bool safe_update= thd->variables.option_bits & OPTION_SAFE_UPDATES;
bool safe_update= (thd->variables.option_bits & OPTION_SAFE_UPDATES)
&& !thd->lex->describe;
bool used_key_is_modified= FALSE, transactional_table;
bool will_batch= FALSE;
bool can_compare_record;
Expand Down Expand Up @@ -597,7 +598,7 @@ int mysql_update(THD *thd,
}

/* If running in safe sql mode, don't allow updates without keys */
if (table->opt_range_keys.is_clear_all())
if (!select || !select->quick)
{
thd->set_status_no_index_used();
if (safe_update && !using_limit)
Expand Down
101 changes: 71 additions & 30 deletions storage/innobase/buf/buf0flu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1006,42 +1006,52 @@ static page_id_t buf_flush_check_neighbors(const fil_space_t &space,
return i;
}

MY_ATTRIBUTE((nonnull))
MY_ATTRIBUTE((nonnull, warn_unused_result))
/** Write punch-hole or zeroes of the freed ranges when
innodb_immediate_scrub_data_uncompressed from the freed ranges.
@param space tablespace which may contain ranges of freed pages */
static void buf_flush_freed_pages(fil_space_t *space)
@param space tablespace which may contain ranges of freed pages
@param writable whether the tablespace is writable
@return number of pages written or hole-punched */
static uint32_t buf_flush_freed_pages(fil_space_t *space, bool writable)
{
const bool punch_hole= space->chain.start->punch_hole == 1;
if (!punch_hole && !srv_immediate_scrub_data_uncompressed)
return;
lsn_t flush_to_disk_lsn= log_sys.get_flushed_lsn();
return 0;

mysql_mutex_assert_not_owner(&buf_pool.flush_list_mutex);
mysql_mutex_assert_not_owner(&buf_pool.mutex);

std::unique_lock<std::mutex> freed_lock(space->freed_range_mutex);
if (space->freed_ranges.empty()
|| flush_to_disk_lsn < space->get_last_freed_lsn())
space->freed_range_mutex.lock();
if (space->freed_ranges.empty() ||
log_sys.get_flushed_lsn() < space->get_last_freed_lsn())
{
freed_lock.unlock();
return;
space->freed_range_mutex.unlock();
return 0;
}

const unsigned physical_size{space->physical_size()};

range_set freed_ranges= std::move(space->freed_ranges);
freed_lock.unlock();
uint32_t written= 0;

for (const auto &range : freed_ranges)
if (!writable);
else if (punch_hole)
{
const ulint physical_size= space->physical_size();

if (punch_hole)
for (const auto &range : freed_ranges)
{
written+= range.last - range.first + 1;
space->reacquire();
space->io(IORequest(IORequest::PUNCH_RANGE),
os_offset_t{range.first} * physical_size,
(range.last - range.first + 1) * physical_size,
nullptr);
}
else
}
else
{
for (const auto &range : freed_ranges)
{
written+= range.last - range.first + 1;
for (os_offset_t i= range.first; i <= range.last; i++)
{
space->reacquire();
Expand All @@ -1050,8 +1060,10 @@ static void buf_flush_freed_pages(fil_space_t *space)
const_cast<byte*>(field_ref_zero));
}
}
buf_pool.stat.n_pages_written+= (range.last - range.first + 1);
}

space->freed_range_mutex.unlock();
return written;
}

/** Flushes to disk all flushable pages within the flush area
Expand Down Expand Up @@ -1174,14 +1186,12 @@ static ulint buf_free_from_unzip_LRU_list_batch(ulint max)

/** Start writing out pages for a tablespace.
@param id tablespace identifier
@return tablespace
@retval nullptr if the pages for this tablespace should be discarded */
static fil_space_t *buf_flush_space(const uint32_t id)
@return tablespace and number of pages written */
static std::pair<fil_space_t*, uint32_t> buf_flush_space(const uint32_t id)
{
fil_space_t *space= fil_space_t::get(id);
if (space)
buf_flush_freed_pages(space);
return space;
if (fil_space_t *space= fil_space_t::get(id))
return {space, buf_flush_freed_pages(space, true)};
return {nullptr, 0};
}

struct flush_counters_t
Expand Down Expand Up @@ -1242,6 +1252,7 @@ static void buf_flush_LRU_list_batch(ulint max, flush_counters_t *n)
n->flushed + n->evicted < max) ||
recv_recovery_is_on()); ++scanned)
{
retry:
buf_page_t *prev= UT_LIST_GET_PREV(LRU, bpage);
const lsn_t oldest_modification= bpage->oldest_modification();
buf_pool.lru_hp.set(prev);
Expand All @@ -1267,10 +1278,18 @@ static void buf_flush_LRU_list_batch(ulint max, flush_counters_t *n)
{
if (last_space_id != space_id)
{
buf_pool.lru_hp.set(bpage);
mysql_mutex_unlock(&buf_pool.mutex);
if (space)
space->release();
space= buf_flush_space(space_id);
auto p= buf_flush_space(space_id);
space= p.first;
last_space_id= space_id;
mysql_mutex_lock(&buf_pool.mutex);
if (p.second)
buf_pool.stat.n_pages_written+= p.second;
bpage= buf_pool.lru_hp.get();
goto retry;
}
else
ut_ad(!space);
Expand Down Expand Up @@ -1405,10 +1424,28 @@ static ulint buf_do_flush_list_batch(ulint max_n, lsn_t lsn)
{
if (last_space_id != space_id)
{
mysql_mutex_lock(&buf_pool.flush_list_mutex);
buf_pool.flush_hp.set(bpage);
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
mysql_mutex_unlock(&buf_pool.mutex);
if (space)
space->release();
space= buf_flush_space(space_id);
auto p= buf_flush_space(space_id);
space= p.first;
last_space_id= space_id;
mysql_mutex_lock(&buf_pool.mutex);
if (p.second)
buf_pool.stat.n_pages_written+= p.second;
mysql_mutex_lock(&buf_pool.flush_list_mutex);
bpage= buf_pool.flush_hp.get();
if (!bpage)
break;
if (bpage->id() != page_id)
continue;
buf_pool.flush_hp.set(UT_LIST_GET_PREV(list, bpage));
if (bpage->oldest_modification() <= 1 || !bpage->ready_for_flush())
goto next;
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
}
else
ut_ad(!space);
Expand Down Expand Up @@ -1436,6 +1473,7 @@ static ulint buf_do_flush_list_batch(ulint max_n, lsn_t lsn)
}

mysql_mutex_lock(&buf_pool.flush_list_mutex);
next:
bpage= buf_pool.flush_hp.get();
}

Expand Down Expand Up @@ -1532,11 +1570,14 @@ bool buf_flush_list_space(fil_space_t *space, ulint *n_flushed)
bool may_have_skipped= false;
ulint max_n_flush= srv_io_capacity;

mysql_mutex_lock(&buf_pool.mutex);
mysql_mutex_lock(&buf_pool.flush_list_mutex);

bool acquired= space->acquire();
buf_flush_freed_pages(space);
{
const uint32_t written{buf_flush_freed_pages(space, acquired)};
mysql_mutex_lock(&buf_pool.mutex);
if (written)
buf_pool.stat.n_pages_written+= written;
}
mysql_mutex_lock(&buf_pool.flush_list_mutex);

for (buf_page_t *bpage= UT_LIST_GET_LAST(buf_pool.flush_list); bpage; )
{
Expand Down
8 changes: 6 additions & 2 deletions storage/innobase/fil/fil0fil.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1995, 2021, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2014, 2021, MariaDB Corporation.
Copyright (c) 2014, 2022, 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 the Free Software
Expand Down Expand Up @@ -86,7 +86,9 @@ bool fil_space_t::try_to_close(bool print_info)
of fil_system.space_list, so that they would be less likely to be
closed here. */
fil_node_t *node= UT_LIST_GET_FIRST(space.chain);
ut_ad(node);
if (!node)
/* fil_ibd_create() did not invoke fil_space_t::add() yet */
continue;
ut_ad(!UT_LIST_GET_NEXT(chain, node));

if (!node->is_open())
Expand Down Expand Up @@ -446,6 +448,8 @@ static bool fil_node_open_file(fil_node_t *node)
/* Flush tablespaces so that we can close modified files. */
fil_flush_file_spaces();
mysql_mutex_lock(&fil_system.mutex);
if (node->is_open())
return true;
}
}

Expand Down
7 changes: 6 additions & 1 deletion storage/innobase/handler/handler0alter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1760,8 +1760,13 @@ instant_alter_column_possible(
Field** af = altered_table->field;
Field** const end = altered_table->field
+ altered_table->s->fields;
List_iterator_fast<Create_field> cf_it(
ha_alter_info->alter_info->create_list);
for (unsigned c = 0; af < end; af++) {
if (!(*af)->stored_in_db()) {
const Create_field* cf = cf_it++;
if (!cf->field || !(*af)->stored_in_db()) {
/* Ignore virtual or newly created
column */
continue;
}

Expand Down

0 comments on commit 4ef44cc

Please sign in to comment.