Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions mysql-test/main/opt_context_replay_basic.result
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ select context into dumpfile "../../tmp/dump1.sql"
from information_schema.optimizer_context;
set optimizer_record_context=OFF;
drop table t1;
set optimizer_replay_context='';
drop table t1;
#
# MDEV-39409: Context replay doesnt handle MIN/MAX optimization
Expand All @@ -272,5 +273,26 @@ set optimizer_replay_context='opt_context';
EXPLAIN SELECT MAX(a) FROM t1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
set optimizer_replay_context='';
drop table t1;
#
# MDEV-39505: Explain delete all from table shows difference in number of rows
#
create table t1 (c1 integer);
insert into t1 values (1), (2), (3);
set optimizer_record_context=1;
explain delete from t1 order by c1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL 3 Deleting all rows
select context into dumpfile "../../tmp/dump1.sql"
from information_schema.optimizer_context;
set optimizer_record_context=0;
drop table t1;
set optimizer_replay_context='opt_context';
# Same query as above, must have same explain:
explain delete from t1 order by c1;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL 3 Deleting all rows
set optimizer_replay_context='';
drop table t1;
drop database db1;
28 changes: 28 additions & 0 deletions mysql-test/main/opt_context_replay_basic.test
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ drop table t1;
--enable_query_log
--enable_result_log

set optimizer_replay_context='';
--remove_file "$MYSQLTEST_VARDIR/tmp/dump1.sql"
drop table t1;

Expand All @@ -116,6 +117,33 @@ set optimizer_replay_context='opt_context';
--echo # Same query as above, must have same explain:
EXPLAIN SELECT MAX(a) FROM t1;

set optimizer_replay_context='';
--remove_file "$MYSQLTEST_VARDIR/tmp/dump1.sql"
drop table t1;

--echo #
--echo # MDEV-39505: Explain delete all from table shows difference in number of rows
--echo #
create table t1 (c1 integer);
insert into t1 values (1), (2), (3);

set optimizer_record_context=1;
explain delete from t1 order by c1;

select context into dumpfile "../../tmp/dump1.sql"
from information_schema.optimizer_context;
set optimizer_record_context=0;
drop table t1;
--disable_query_log
--disable_result_log
--source "$MYSQLTEST_VARDIR/tmp/dump1.sql"
--enable_query_log
--enable_result_log
set optimizer_replay_context='opt_context';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The context name 'opt_context' used here appears to be carried over from the previous test case (see line 115, not shown in this diff). Since the current test records the context using set optimizer_record_context=1 at line 130 (which uses the default empty name), this command might be replaying the wrong context from a previous query instead of the DELETE query just recorded. To ensure test isolation and validity, please use the default name for both recording and replaying, or use a unique name for both.

set optimizer_replay_context='';

--echo # Same query as above, must have same explain:
explain delete from t1 order by c1;

set optimizer_replay_context='';
--remove_file "$MYSQLTEST_VARDIR/tmp/dump1.sql"
drop table t1;

Expand Down
1 change: 1 addition & 0 deletions sql/sql_delete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ bool Sql_cmd_delete::delete_from_single_table(THD *thd)
{
/* Update the table->file->stats.records number */
table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK);
set_statistics_for_table(thd, table);
ha_rows const maybe_deleted= table->file->stats.records;
DBUG_PRINT("debug", ("Trying to use delete_all_rows()"));

Expand Down
Loading