MDEV-39505: Diff in rows column of explain plan for delete table stmt#5063
Conversation
Although, number of rows for a table got recorded in the context, for a delete from table statement, but when replayed explain plan showed only 1 in the rows column. There was no call being made to set_statistics_for_table() from delete_from_single_table() when all rows are deleted from a table.
There was a problem hiding this comment.
Code Review
This pull request addresses MDEV-39505 by ensuring table statistics are correctly initialized in Sql_cmd_delete::delete_from_single_table before they are used to estimate deleted rows. It also adds a regression test and ensures the optimizer_replay_context is reset between test cases. A review comment points out that the new test case should use the default empty context name to correctly replay the recorded optimizer state and maintain test isolation.
| --source "$MYSQLTEST_VARDIR/tmp/dump1.sql" | ||
| --enable_query_log | ||
| --enable_result_log | ||
| set optimizer_replay_context='opt_context'; |
There was a problem hiding this comment.
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='';
Although, number of rows for a table got recorded in the context, for a delete from table statement, but when replayed explain plan showed only 1 in the rows column.
There was no call being made to set_statistics_for_table() from delete_from_single_table() when all rows are deleted from a table.