From ea9869504d4bd47e111fe2aab99f85b60946f648 Mon Sep 17 00:00:00 2001 From: Brandon Nesterenko Date: Thu, 20 Jun 2024 12:21:48 -0600 Subject: [PATCH 01/12] MDEV-33921: Replication breaks when filtering two-phase XA transactions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are two problems. First, replication fails when XA transactions are used where the slave has replicate_do_db set and the client has touched a different database when running DML such as inserts. This is because XA commands are not treated as keywords, and are thereby not exempt from the replication filter. The effect of this is that during an XA transaction, if its logged “use db” from the master is filtered out by the replication filter, then XA END will be ignored, yet its corresponding XA PREPARE will be executed in an invalid state, thereby breaking replication. Second, if the slave replicates an XA transaction which results in an empty transaction, the XA START through XA PREPARE first phase of the transaction won’t be binlogged, yet the XA COMMIT will be binlogged. This will break replication in chain configurations. The first problem is fixed by treating XA commands in Query_log_event as keywords, thus allowing them to bypass the replication filter. Note that Query_log_event::is_trans_keyword() is changed to accept a new parameter to define its mode, to either check for XA commands or regular transaction commands, but not both. In addition, mysqlbinlog is adapted to use this mode so its --database filter does not remove XA commands from its output. The second problem fixed by overwriting the XA state in the XID cache to be XA_ROLLBACK_ONLY, so at commit time, the server knows to rollback the transaction and skip its binlogging. If the xid cache is cleared before an XA transaction receives its completion command (e.g. on server shutdown), then before reporting ER_XAER_NOTA when the completion command is executed, the filter is first checked if the database is ignored, and if so, the error is ignored. Reviewed By: ============ Kristian Nielsen Andrei Elkin --- client/mysqlbinlog.cc | 2 +- .../rpl/r/rpl_xa_empty_transaction.result | 78 +++++++++++ .../suite/rpl/t/rpl_xa_empty_transaction.test | 127 ++++++++++++++++++ sql/handler.cc | 16 +++ sql/log_event.h | 14 +- sql/log_event_client.cc | 10 +- sql/log_event_server.cc | 18 ++- sql/rpl_filter.cc | 7 + sql/rpl_filter.h | 1 + sql/xa.cc | 24 +++- sql/xa.h | 1 + 11 files changed, 287 insertions(+), 11 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 6324e5a7242..3621a3dfef5 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -1071,7 +1071,7 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, case QUERY_COMPRESSED_EVENT: { Query_log_event *qe= (Query_log_event*)ev; - if (!qe->is_trans_keyword()) + if (!qe->is_trans_keyword(print_event_info->is_xa_trans())) { if (shall_skip_database(qe->db)) goto end; diff --git a/mysql-test/suite/rpl/r/rpl_xa_empty_transaction.result b/mysql-test/suite/rpl/r/rpl_xa_empty_transaction.result index f3ea53c219a..b84e427095c 100644 --- a/mysql-test/suite/rpl/r/rpl_xa_empty_transaction.result +++ b/mysql-test/suite/rpl/r/rpl_xa_empty_transaction.result @@ -1164,6 +1164,84 @@ include/sync_with_master_gtid.inc connection server_1; set @@binlog_format = @sav_binlog_format; set @@global.binlog_format = @sav_binlog_format; +# +# MDEV-33921.1: If a slave's replication of an XA transaction results in +# an empty transaction, e.g. due to replication filters, the slave +# should not binlog any part of the XA transaction. +connection server_1; +create database db1; +create database db2; +create table db1.t1 (a int) engine=innodb; +include/save_master_gtid.inc +connection server_3; +include/sync_with_master_gtid.inc +include/stop_slave.inc +connection server_2; +include/stop_slave.inc +SET @@GLOBAL.replicate_ignore_db= ""; +SET @@GLOBAL.replicate_do_db= "db2"; +include/start_slave.inc +connection server_1; +use db1; +XA START "x1"; +insert into db1.t1 values (1); +XA END "x1"; +XA PREPARE "x1"; +XA COMMIT "x1"; +include/save_master_gtid.inc +connection server_2; +include/sync_with_master_gtid.inc +connection server_2; +include/save_master_gtid.inc +connection server_3; +include/start_slave.inc +include/sync_with_master_gtid.inc +# +# 33921.2: If the slave shuts down after "preparing" a filtered-to-empty +# XA transaction (and not completing it), then when the respective +# XA completion (COMMIT in this test) command is replicated, the slave +# should not throw ER_XAER_NOTA. Note that internally, the error is +# thrown, but it is ignored because the target db is filtered. +connection server_3; +include/stop_slave.inc +connection server_1; +use db1; +XA START "x2"; +insert into db1.t1 values (2); +XA END "x2"; +XA PREPARE "x2"; +include/save_master_gtid.inc +connection server_2; +include/sync_with_master_gtid.inc +# Connection named slave is needed for reconnection +connect slave,localhost,root,,; +connect slave1,localhost,root,,; +include/rpl_restart_server.inc [server_number=2] +connection server_2; +include/stop_slave.inc +SET @@GLOBAL.replicate_do_db= "db2"; +include/start_slave.inc +connection server_1; +XA COMMIT "x2"; +connection server_2; +include/sync_with_master_gtid.inc +include/save_master_gtid.inc +connection server_3; +include/start_slave.inc +include/sync_with_master_gtid.inc +# +# 33921.3: Ensure XA commands are not considered by mysqlbinlog's +# --database filter +connection server_1; +# MYSQL_BINLOG datadir/binlog_file --start-position=pre_xa_pos --database=db2 --result-file=assert_file +include/assert_grep.inc [Mysqlbinlog should output all XA commands from the filtered transaction] +connection server_2; +include/stop_slave.inc +SET @@GLOBAL.replicate_do_db=""; +include/start_slave.inc +connection server_1; +drop database db1; +drop database db2; connection server_1; include/rpl_end.inc # End of rpl_xa_empty_transaction.test diff --git a/mysql-test/suite/rpl/t/rpl_xa_empty_transaction.test b/mysql-test/suite/rpl/t/rpl_xa_empty_transaction.test index 61cc0621d5a..e3364cd4f48 100644 --- a/mysql-test/suite/rpl/t/rpl_xa_empty_transaction.test +++ b/mysql-test/suite/rpl/t/rpl_xa_empty_transaction.test @@ -32,6 +32,10 @@ # MDEV-25616: Binlog event for XA COMMIT is generated without matching # XA START, replication aborts # +# MDEV-33921: Replication fails when XA transactions are used where the slave +# has replicate_do_db set and the client has touched a different +# database when running DML such as inserts. +# --source include/have_log_bin.inc --let $rpl_server_count= 3 @@ -167,6 +171,129 @@ set @@global.binlog_format = row; set @@binlog_format = @sav_binlog_format; set @@global.binlog_format = @sav_binlog_format; + +--echo # +--echo # MDEV-33921.1: If a slave's replication of an XA transaction results in +--echo # an empty transaction, e.g. due to replication filters, the slave +--echo # should not binlog any part of the XA transaction. +# +# Note that the MDEV-33921 report is actually about that XA END is filtered +# out (not executed), and then its corresponding XA PREPARE errors because the +# XA state of the transaction is incorrect. This test case inherently tests +# both bugs. + +--connection server_1 +create database db1; +create database db2; +create table db1.t1 (a int) engine=innodb; +--source include/save_master_gtid.inc +--connection server_3 +--source include/sync_with_master_gtid.inc +--source include/stop_slave.inc + +--connection server_2 +--source include/stop_slave.inc +SET @@GLOBAL.replicate_ignore_db= ""; +SET @@GLOBAL.replicate_do_db= "db2"; +--source include/start_slave.inc + +--connection server_1 +--let $pre_xa_gtid= `SELECT @@global.gtid_binlog_pos` +use db1; +XA START "x1"; +insert into db1.t1 values (1); +XA END "x1"; +XA PREPARE "x1"; +XA COMMIT "x1"; +--source include/save_master_gtid.inc + +--connection server_2 +--source include/sync_with_master_gtid.inc +--let $slave_binlogged_gtid= `SELECT @@global.gtid_binlog_pos` +if (`SELECT strcmp("$slave_binlogged_gtid","$pre_xa_gtid")`) +{ + --die Slave binlogged an empty XA transaction yet should not have +} + +--connection server_2 +--source include/save_master_gtid.inc + +--connection server_3 +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc + +--echo # +--echo # 33921.2: If the slave shuts down after "preparing" a filtered-to-empty +--echo # XA transaction (and not completing it), then when the respective +--echo # XA completion (COMMIT in this test) command is replicated, the slave +--echo # should not throw ER_XAER_NOTA. Note that internally, the error is +--echo # thrown, but it is ignored because the target db is filtered. + +--connection server_3 +--source include/stop_slave.inc + +--connection server_1 +--let $pre_xa_gtid= `SELECT @@global.gtid_binlog_pos` + +# Used by mysqlbinlog in part 3 +--let $pre_xa_pos = query_get_value(SHOW MASTER STATUS, Position, 1) + +use db1; +XA START "x2"; +insert into db1.t1 values (2); +XA END "x2"; +XA PREPARE "x2"; +--source include/save_master_gtid.inc + +--connection server_2 +--source include/sync_with_master_gtid.inc +--let $rpl_server_number= 2 +--echo # Connection named slave is needed for reconnection +--connect(slave,localhost,root,,) +--connect(slave1,localhost,root,,) +--source include/rpl_restart_server.inc + +--connection server_2 +--source include/stop_slave.inc +SET @@GLOBAL.replicate_do_db= "db2"; +--source include/start_slave.inc + +--connection server_1 +XA COMMIT "x2"; + +--connection server_2 +--source include/sync_with_master_gtid.inc +--source include/save_master_gtid.inc + +--connection server_3 +--source include/start_slave.inc +--source include/sync_with_master_gtid.inc + +--echo # +--echo # 33921.3: Ensure XA commands are not considered by mysqlbinlog's +--echo # --database filter +--connection server_1 +--let $datadir= `select @@datadir` +--let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) +--let assert_file= $MYSQLTEST_VARDIR/tmp/binlog_decoded.out +--echo # MYSQL_BINLOG datadir/binlog_file --start-position=pre_xa_pos --database=db2 --result-file=assert_file +--exec $MYSQL_BINLOG $datadir/$binlog_file --start-position=$pre_xa_pos --database=db2 --result-file=$assert_file + +--let assert_text= Mysqlbinlog should output all XA commands from the filtered transaction +--let assert_count= 4 +--let assert_select= XA START|XA END|XA PREPARE|XA COMMIT +--source include/assert_grep.inc + +--connection server_2 +--source include/stop_slave.inc +SET @@GLOBAL.replicate_do_db=""; +--source include/start_slave.inc + +--connection server_1 +drop database db1; +drop database db2; + + # # Cleanup --connection server_1 diff --git a/sql/handler.cc b/sql/handler.cc index 6fc74fc1fbc..66c85f07574 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -1444,6 +1444,22 @@ int ha_prepare(THD *thd) error=1; } } + else if (thd->rgi_slave) + { + /* + Slave threads will always process XA COMMITs in the binlog handler (see + MDEV-25616 and MDEV-30423), so if this is a slave thread preparing a + transaction which proved empty during replication (e.g. because of + replication filters) then mark it as XA_ROLLBACK_ONLY so the follow up + XA COMMIT will know to roll it back, rather than try to commit and binlog + a standalone XA COMMIT (without its preceding XA START - XA PREPARE). + + If the xid_cache is cleared before the completion event comes, before + issuing ER_XAER_NOTA, first check if the event targets an ignored + database, and ignore the error if so. + */ + thd->transaction->xid_state.set_rollback_only(); + } DBUG_RETURN(error); } diff --git a/sql/log_event.h b/sql/log_event.h index 5cd061df110..a869c6e04f1 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -845,6 +845,7 @@ typedef struct st_print_event_info uint lc_time_names_number; uint charset_database_number; uint verbose; + uchar gtid_ev_flags2; uint32 flags2; uint32 server_id; uint32 domain_id; @@ -916,6 +917,8 @@ typedef struct st_print_event_info copy_event_cache_to_file_and_reinit(&body_cache, file); fflush(file); } + + my_bool is_xa_trans(); } PRINT_EVENT_INFO; #endif // MYSQL_CLIENT @@ -2173,7 +2176,7 @@ public: /* !!! Public in this patch to allow old usage */ If true, the event always be applied by slave SQL thread or be printed by mysqlbinlog */ - bool is_trans_keyword() + bool is_trans_keyword(bool is_xa) { /* Before the patch for bug#50407, The 'SAVEPOINT and ROLLBACK TO' @@ -2186,10 +2189,11 @@ public: /* !!! Public in this patch to allow old usage */ but we don't handle these cases and after the patch, both quiries are binlogged in upper case with no comments. */ - return !strncmp(query, "BEGIN", q_len) || - !strncmp(query, "COMMIT", q_len) || - !strncasecmp(query, "SAVEPOINT", 9) || - !strncasecmp(query, "ROLLBACK", 8); + return is_xa ? !strncasecmp(query, C_STRING_WITH_LEN("XA ")) + : (!strncmp(query, "BEGIN", q_len) || + !strncmp(query, "COMMIT", q_len) || + !strncasecmp(query, "SAVEPOINT", 9) || + !strncasecmp(query, "ROLLBACK", 8)); } virtual bool is_begin() { return !strcmp(query, "BEGIN"); } virtual bool is_commit() { return !strcmp(query, "COMMIT"); } diff --git a/sql/log_event_client.cc b/sql/log_event_client.cc index 052110fa235..654701afaa0 100644 --- a/sql/log_event_client.cc +++ b/sql/log_event_client.cc @@ -1835,7 +1835,7 @@ bool Query_log_event::print_query_header(IO_CACHE* file, if ((flags & LOG_EVENT_SUPPRESS_USE_F)) { - if (!is_trans_keyword()) + if (!is_trans_keyword(print_event_info->is_xa_trans())) print_event_info->db[0]= '\0'; } else if (db) @@ -3762,6 +3762,7 @@ st_print_event_info::st_print_event_info() bzero(time_zone_str, sizeof(time_zone_str)); delimiter[0]= ';'; delimiter[1]= 0; + gtid_ev_flags2= 0; flags2_inited= 0; flags2= 0; sql_mode_inited= 0; @@ -3795,6 +3796,11 @@ st_print_event_info::st_print_event_info() #endif } +my_bool st_print_event_info::is_xa_trans() +{ + return (gtid_ev_flags2 & + (Gtid_log_event::FL_PREPARED_XA | Gtid_log_event::FL_COMPLETED_XA)); +} bool copy_event_cache_to_string_and_reinit(IO_CACHE *cache, LEX_STRING *to) { @@ -3906,6 +3912,8 @@ Gtid_log_event::print(FILE *file, PRINT_EVENT_INFO *print_event_info) goto err; } + print_event_info->gtid_ev_flags2= flags2; + return cache.flush_data(); err: return 1; diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index 3aacc4154d9..d8056fd4378 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -1437,7 +1437,7 @@ Query_log_event::Query_log_event(THD* thd_arg, const char* query_arg, is created we create tables with thd->variables.wsrep_on=false to avoid replicating wsrep_schema tables to other nodes. */ - if (WSREP_ON && !is_trans_keyword()) + if (WSREP_ON && !is_trans_keyword(false)) { thd->wsrep_PA_safe= false; } @@ -1715,7 +1715,11 @@ int Query_log_event::do_apply_event(rpl_group_info *rgi, ::do_apply_event(), then the companion SET also have so we don't need to reset_one_shot_variables(). */ - if (is_trans_keyword() || rpl_filter->db_ok(thd->db.str)) + if (rpl_filter->is_db_empty() || + is_trans_keyword( + (rgi->gtid_ev_flags2 & (Gtid_log_event::FL_PREPARED_XA | + Gtid_log_event::FL_COMPLETED_XA))) || + rpl_filter->db_ok(thd->db.str)) { #ifdef WITH_WSREP if (!wsrep_thd_is_applying(thd)) @@ -2040,6 +2044,16 @@ compare_errors: actual_error == ER_CONNECTION_KILLED) thd->reset_killed(); } + else if (actual_error == ER_XAER_NOTA && !rpl_filter->db_ok(get_db())) + { + /* + If there is an XA query whos XID cannot be found, if the replication + filter is active and filters the target database, assume that the XID + cache has been cleared (e.g. by server restart) since it was prepared, + so we can just ignore this event. + */ + thd->clear_error(1); + } /* Other cases: mostly we expected no error and get one. */ diff --git a/sql/rpl_filter.cc b/sql/rpl_filter.cc index 5c4a4d9f58a..39bdde9ce76 100644 --- a/sql/rpl_filter.cc +++ b/sql/rpl_filter.cc @@ -268,6 +268,13 @@ Rpl_filter::is_on() } +bool +Rpl_filter::is_db_empty() +{ + return do_db.is_empty() && ignore_db.is_empty(); +} + + /** Parse and add the given comma-separated sequence of filter rules. diff --git a/sql/rpl_filter.h b/sql/rpl_filter.h index f22ec8a0ce4..5e9497ed771 100644 --- a/sql/rpl_filter.h +++ b/sql/rpl_filter.h @@ -56,6 +56,7 @@ public: bool db_ok_with_wild_table(const char *db); bool is_on(); + bool is_db_empty(); /* Setters - add filtering rules */ diff --git a/sql/xa.cc b/sql/xa.cc index c4cd548b132..972121a1ee7 100644 --- a/sql/xa.cc +++ b/sql/xa.cc @@ -180,6 +180,13 @@ void XID_STATE::set_error(uint error) xid_cache_element->rm_error= error; } +void XID_STATE::set_rollback_only() +{ + xid_cache_element->xa_state= XA_ROLLBACK_ONLY; + if (current_thd) + MYSQL_SET_TRANSACTION_XA_STATE(current_thd->m_transaction_psi, + XA_ROLLBACK_ONLY); +} void XID_STATE::er_xaer_rmfail() const { @@ -547,8 +554,21 @@ bool trans_xa_prepare(THD *thd) } else { - thd->transaction->xid_state.xid_cache_element->xa_state= XA_PREPARED; - MYSQL_SET_TRANSACTION_XA_STATE(thd->m_transaction_psi, XA_PREPARED); + if (thd->transaction->xid_state.xid_cache_element->xa_state != + XA_ROLLBACK_ONLY) + { + thd->transaction->xid_state.xid_cache_element->xa_state= XA_PREPARED; + MYSQL_SET_TRANSACTION_XA_STATE(thd->m_transaction_psi, XA_PREPARED); + } + else + { + /* + In the non-err case, XA_ROLLBACK_ONLY should only be set by a slave + thread which prepared an empty transaction, to prevent binlogging a + standalone XA COMMIT. + */ + DBUG_ASSERT(thd->rgi_slave && !(thd->transaction->all.ha_list)); + } res= thd->variables.pseudo_slave_mode || thd->slave_thread ? slave_applier_reset_xa_trans(thd) : 0; } diff --git a/sql/xa.h b/sql/xa.h index 0b2d0696642..5f21e9e9b55 100644 --- a/sql/xa.h +++ b/sql/xa.h @@ -34,6 +34,7 @@ struct XID_STATE { bool check_has_uncommitted_xa() const; bool is_explicit_XA() const { return xid_cache_element != 0; } void set_error(uint error); + void set_rollback_only(); void er_xaer_rmfail() const; XID *get_xid() const; enum xa_states get_state_code() const; From eaf7c0cbead56f61d4cecfa88fc0971a9d917002 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 11 Jul 2024 16:51:39 +1000 Subject: [PATCH 02/12] mtr: remove not_valgrind_build The version test on not_valgrind_build.inc was broken as in BB the sp-no-valgrind.test was executed. The implication that it wouldn't work on ASAN was also incorrect as ASAN tests show it running fine there. Correct sp-no-valgrind.test for not_valgrind.inc. --- mysql-test/include/not_valgrind_build.inc | 4 ---- mysql-test/main/sp-no-valgrind.test | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 mysql-test/include/not_valgrind_build.inc diff --git a/mysql-test/include/not_valgrind_build.inc b/mysql-test/include/not_valgrind_build.inc deleted file mode 100644 index b62a1bc953b..00000000000 --- a/mysql-test/include/not_valgrind_build.inc +++ /dev/null @@ -1,4 +0,0 @@ -if (`select version() like '%valgrind%' || version() like '%asan%'`) -{ - skip Does not run with binaries built with valgrind or asan; -} diff --git a/mysql-test/main/sp-no-valgrind.test b/mysql-test/main/sp-no-valgrind.test index 6bacc7b150c..1b4a0f84f1e 100644 --- a/mysql-test/main/sp-no-valgrind.test +++ b/mysql-test/main/sp-no-valgrind.test @@ -1,5 +1,5 @@ --source include/not_msan.inc ---source include/not_valgrind_build.inc +--source include/not_valgrind.inc --echo # MDEV-20699 do not cache SP in SHOW CREATE --echo # Warmup round, this might allocate some memory for session variable From a5e4c34991ed98357fafd6821eb756ad37ee0353 Mon Sep 17 00:00:00 2001 From: Galina Shalygina Date: Tue, 9 Jul 2024 17:37:04 +0200 Subject: [PATCH 03/12] MDEV-32608: Expression with constant subquery causes a crash in pushdown from HAVING The bug is caused by refixing of the constant subquery in pushdown from HAVING into WHERE optimization. Similarly to MDEV-29363 in the problematic query two references of the constant subquery are used. After the pushdown one of the references of the subquery is pushed into WHERE-clause and the second one remains as the part of the HAVING-clause. Before the represented fix, the constant subquery reference that was going to be pushed into WHERE was cleaned up and fixed. That caused the changes of the subquery itself and, therefore, changes for the second reference that remained in HAVING. These changes caused a crash. To fix this problem all constant objects that are going to be pushed into WHERE should be marked with an IMMUTABLE_FL flag. Objects marked with this flag are not cleaned up or fixed in the pushdown optimization. Approved by Igor Babaev --- mysql-test/main/having_cond_pushdown.result | 87 +++++++++++++++++++++ mysql-test/main/having_cond_pushdown.test | 26 ++++++ sql/item.cc | 19 +++++ sql/item.h | 3 +- sql/sql_lex.cc | 10 +-- 5 files changed, 138 insertions(+), 7 deletions(-) diff --git a/mysql-test/main/having_cond_pushdown.result b/mysql-test/main/having_cond_pushdown.result index e5e99fe2381..9713f014f43 100644 --- a/mysql-test/main/having_cond_pushdown.result +++ b/mysql-test/main/having_cond_pushdown.result @@ -5092,4 +5092,91 @@ SELECT * FROM v1 GROUP BY a HAVING a = (a IS NULL OR a IS NULL); a DROP VIEW v1; +# +# MDEV-32608: Expression with constant subquery causes a crash +# in pushdown from HAVING +# +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (2, 1), (3, 2); +EXPLAIN FORMAT=JSON SELECT * FROM t1 +GROUP BY b +HAVING (SELECT MAX(b) FROM t1) = a AND a + b = 3; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "having_condition": "t1.a = (subquery#2)", + "filesort": { + "sort_key": "t1.b", + "temporary_table": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 2, + "filtered": 100, + "attached_condition": "(subquery#2) + t1.b = 3" + }, + "subqueries": [ + { + "query_block": { + "select_id": 2, + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 2, + "filtered": 100 + } + } + } + ] + } + } + } +} +SELECT * FROM t1 +GROUP BY b +HAVING (SELECT MAX(b) FROM t1) = a AND a + b = 3; +a b +2 1 +EXPLAIN FORMAT=JSON SELECT * FROM t1 +GROUP BY b +HAVING (SELECT MAX(b) FROM t1) = a AND a > b; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "having_condition": "t1.a = (subquery#2)", + "filesort": { + "sort_key": "t1.b", + "temporary_table": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 2, + "filtered": 100, + "attached_condition": "(subquery#2) > t1.b" + }, + "subqueries": [ + { + "query_block": { + "select_id": 2, + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 2, + "filtered": 100 + } + } + } + ] + } + } + } +} +SELECT * FROM t1 +GROUP BY b +HAVING (SELECT MAX(b) FROM t1) = a AND a > b; +a b +2 1 +DROP TABLE t1; End of 10.5 tests diff --git a/mysql-test/main/having_cond_pushdown.test b/mysql-test/main/having_cond_pushdown.test index f2812fb14f2..fd414e62a8c 100644 --- a/mysql-test/main/having_cond_pushdown.test +++ b/mysql-test/main/having_cond_pushdown.test @@ -1558,4 +1558,30 @@ SELECT * FROM v1 DROP VIEW v1; +--echo # +--echo # MDEV-32608: Expression with constant subquery causes a crash +--echo # in pushdown from HAVING +--echo # + +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (2, 1), (3, 2); + +let $q= +SELECT * FROM t1 +GROUP BY b +HAVING (SELECT MAX(b) FROM t1) = a AND a + b = 3; + +eval EXPLAIN FORMAT=JSON $q; +eval $q; + +let $q= +SELECT * FROM t1 +GROUP BY b +HAVING (SELECT MAX(b) FROM t1) = a AND a > b; + +eval EXPLAIN FORMAT=JSON $q; +eval $q; + +DROP TABLE t1; + --echo End of 10.5 tests diff --git a/sql/item.cc b/sql/item.cc index 55960ab8739..e1ad7e7d13b 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1272,6 +1272,25 @@ bool Item::eq(const Item *item, bool binary_cmp) const } +Item *Item::multiple_equality_transformer(THD *thd, uchar *arg) +{ + if (const_item()) + { + /* + Mark constant item in the condition with the IMMUTABLE_FL flag. + It is needed to prevent cleanup of the sub-items of this item and following + fix_fields() call that can cause a crash on this step of the optimization. + This flag will be removed at the end of the pushdown optimization by + remove_immutable_flag_processor processor. + */ + int new_flag= IMMUTABLE_FL; + this->walk(&Item::set_extraction_flag_processor, false, + (void*)&new_flag); + } + return this; +} + + Item *Item::safe_charset_converter(THD *thd, CHARSET_INFO *tocs) { if (!needs_charset_converter(tocs)) diff --git a/sql/item.h b/sql/item.h index 73c775a849d..6e8bcd347a4 100644 --- a/sql/item.h +++ b/sql/item.h @@ -2295,8 +2295,7 @@ public: { return this; } virtual Item *field_transformer_for_having_pushdown(THD *thd, uchar *arg) { return this; } - virtual Item *multiple_equality_transformer(THD *thd, uchar *arg) - { return this; } + virtual Item *multiple_equality_transformer(THD *thd, uchar *arg); virtual bool expr_cache_is_needed(THD *) { return FALSE; } virtual Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs); bool needs_charset_converter(uint32 length, CHARSET_INFO *tocs) const diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index e114d6de5e1..2dc5d119fd5 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -10902,7 +10902,11 @@ void mark_or_conds_to_avoid_pushdown(Item *cond) (if cond is marked with FULL_EXTRACTION_FL or cond is an AND condition and some of its parts are marked with FULL_EXTRACTION_FL) - In this case condition is transformed and pushed into attach_to_conds + + In this case condition is transformed with multiple_equality_transformer + transformer. It transforms all multiple equalities in the extracted + condition into the set of equalities. + After that the transformed condition is attached into attach_to_conds list. 2. Part of some other condition c1 that can't be entirely pushed (if с1 isn't marked with any flag). @@ -10919,10 +10923,6 @@ void mark_or_conds_to_avoid_pushdown(Item *cond) In this case build_pushable_cond() is called for c1. This method builds a clone of the c1 part that can be pushed. - Transformation mentioned above is made with multiple_equality_transformer - transformer. It transforms all multiple equalities in the extracted - condition into the set of equalities. - @note Conditions that can be pushed are collected in attach_to_conds in this way: 1. if cond is an AND condition its parts that can be pushed into WHERE From aae3233c4f8cb0a4b7e232f60b3451d86bccc1ff Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Sat, 4 May 2024 19:50:55 +0700 Subject: [PATCH 04/12] MDEV-34041 Display additional information for materialized subqueries in EXPLAIN/ANALYZE FORMAT=JSON This commits adds the "materialization" block to the output of EXPLAIN/ANALYZE FORMAT=JSON when materialized subqueries are involved into processing. In the case of ANALYZE additional runtime information is displayed, such as: - chosen strategy of materialization - number of partial match/index lookup loops - sizes of partial match buffers --- mysql-test/include/analyze-format.inc | 2 +- mysql-test/main/analyze_format_json.result | 30 +- mysql-test/main/derived_cond_pushdown.result | 210 ++-- mysql-test/main/explain_json.result | 34 +- mysql-test/main/having_cond_pushdown.result | 84 +- mysql-test/main/in_subq_cond_pushdown.result | 966 ++++++++++-------- .../main/subselect_mat_analyze_json.result | 945 +++++++++++++++++ .../main/subselect_mat_analyze_json.test | 99 ++ sql/item_subselect.cc | 47 +- sql/item_subselect.h | 119 ++- sql/sql_array.h | 12 + sql/sql_explain.cc | 55 + sql/sql_explain.h | 31 + sql/sql_select.cc | 5 + 14 files changed, 2024 insertions(+), 615 deletions(-) create mode 100644 mysql-test/main/subselect_mat_analyze_json.result create mode 100644 mysql-test/main/subselect_mat_analyze_json.test diff --git a/mysql-test/include/analyze-format.inc b/mysql-test/include/analyze-format.inc index 330be82ef96..89d290a87ea 100644 --- a/mysql-test/include/analyze-format.inc +++ b/mysql-test/include/analyze-format.inc @@ -1,3 +1,3 @@ # The time on ANALYSE FORMAT=JSON is rather variable ---replace_regex /("(r_[a-z_]*_time_ms|r_buffer_size)": )[^, \n]*/\1"REPLACED"/ +--replace_regex /("(r_[a-z_]*_time_ms|r_buffer_size|r_partial_match_buffer_size)": )[^, \n]*/\1"REPLACED"/ diff --git a/mysql-test/main/analyze_format_json.result b/mysql-test/main/analyze_format_json.result index 5b125b26e18..8c4fc5d051a 100644 --- a/mysql-test/main/analyze_format_json.result +++ b/mysql-test/main/analyze_format_json.result @@ -659,20 +659,24 @@ ANALYZE }, "subqueries": [ { - "query_block": { - "select_id": 2, - "r_loops": 1, - "r_total_time_ms": "REPLACED", - "table": { - "table_name": "t1", - "access_type": "ALL", + "materialization": { + "r_strategy": "index_lookup", + "r_loops": 2, + "query_block": { + "select_id": 2, "r_loops": 1, - "rows": 2, - "r_rows": 2, - "r_table_time_ms": "REPLACED", - "r_other_time_ms": "REPLACED", - "filtered": 100, - "r_filtered": 100 + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } } } } diff --git a/mysql-test/main/derived_cond_pushdown.result b/mysql-test/main/derived_cond_pushdown.result index 9932eb04024..f13f04a26dc 100644 --- a/mysql-test/main/derived_cond_pushdown.result +++ b/mysql-test/main/derived_cond_pushdown.result @@ -7671,10 +7671,12 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "table": { - "message": "Select tables optimized away" + "materialization": { + "query_block": { + "select_id": 2, + "table": { + "message": "Select tables optimized away" + } } } } @@ -7731,10 +7733,12 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "table": { - "message": "Select tables optimized away" + "materialization": { + "query_block": { + "select_id": 2, + "table": { + "message": "Select tables optimized away" + } } } } @@ -7815,10 +7819,12 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 3, - "table": { - "message": "Select tables optimized away" + "materialization": { + "query_block": { + "select_id": 3, + "table": { + "message": "Select tables optimized away" + } } } } @@ -7872,10 +7878,12 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 3, - "table": { - "message": "Select tables optimized away" + "materialization": { + "query_block": { + "select_id": 3, + "table": { + "message": "Select tables optimized away" + } } } } @@ -7924,10 +7932,12 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 3, - "table": { - "message": "Select tables optimized away" + "materialization": { + "query_block": { + "select_id": 3, + "table": { + "message": "Select tables optimized away" + } } } } @@ -7976,10 +7986,12 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 3, - "table": { - "message": "Select tables optimized away" + "materialization": { + "query_block": { + "select_id": 3, + "table": { + "message": "Select tables optimized away" + } } } } @@ -8030,10 +8042,12 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 3, - "table": { - "message": "Select tables optimized away" + "materialization": { + "query_block": { + "select_id": 3, + "table": { + "message": "Select tables optimized away" + } } } } @@ -8082,10 +8096,12 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 3, - "table": { - "message": "Select tables optimized away" + "materialization": { + "query_block": { + "select_id": 3, + "table": { + "message": "Select tables optimized away" + } } } } @@ -8134,10 +8150,12 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 3, - "table": { - "message": "Select tables optimized away" + "materialization": { + "query_block": { + "select_id": 3, + "table": { + "message": "Select tables optimized away" + } } } } @@ -8223,10 +8241,12 @@ EXPLAIN }, "subqueries": [ { - "query_block": { - "select_id": 2, - "table": { - "message": "Impossible WHERE" + "materialization": { + "query_block": { + "select_id": 2, + "table": { + "message": "Impossible WHERE" + } } } } @@ -9294,27 +9314,29 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "", - "access_type": "ALL", - "rows": 5, - "filtered": 100, - "attached_condition": "d_tab.e > 1", - "materialized": { - "query_block": { - "select_id": 3, - "filesort": { - "sort_key": "t2.e", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 5, - "filtered": 100, - "attached_condition": "t2.e > 1" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 5, + "filtered": 100, + "attached_condition": "d_tab.e > 1", + "materialized": { + "query_block": { + "select_id": 3, + "filesort": { + "sort_key": "t2.e", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 5, + "filtered": 100, + "attached_condition": "t2.e > 1" + } } } } @@ -9396,27 +9418,29 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "", - "access_type": "ALL", - "rows": 5, - "filtered": 100, - "attached_condition": "d_tab.max_f > 20", - "materialized": { - "query_block": { - "select_id": 3, - "having_condition": "max_f > 20", - "filesort": { - "sort_key": "t2.e", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 5, - "filtered": 100 + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 5, + "filtered": 100, + "attached_condition": "d_tab.max_f > 20", + "materialized": { + "query_block": { + "select_id": 3, + "having_condition": "max_f > 20", + "filesort": { + "sort_key": "t2.e", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 5, + "filtered": 100 + } } } } @@ -10826,16 +10850,18 @@ EXPLAIN "attached_condition": "t4.c = ``.`sum(b)`", "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "`f1(a)` > 1 and `sum(b)` > 123", - "temporary_table": { - "table": { - "table_name": "t1", - "access_type": "ALL", - "rows": 3, - "filtered": 100, - "attached_condition": "t1.a + 1 > 10" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "`f1(a)` > 1 and `sum(b)` > 123", + "temporary_table": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 3, + "filtered": 100, + "attached_condition": "t1.a + 1 > 10" + } } } } diff --git a/mysql-test/main/explain_json.result b/mysql-test/main/explain_json.result index 0bf565b701d..e93d62426af 100644 --- a/mysql-test/main/explain_json.result +++ b/mysql-test/main/explain_json.result @@ -574,14 +574,16 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t1", - "access_type": "ALL", - "rows": 10, - "filtered": 100 + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 10, + "filtered": 100 + } } } } @@ -906,13 +908,15 @@ EXPLAIN }, "subqueries": [ { - "query_block": { - "select_id": 2, - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 2, - "filtered": 100 + "materialization": { + "query_block": { + "select_id": 2, + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 2, + "filtered": 100 + } } } } diff --git a/mysql-test/main/having_cond_pushdown.result b/mysql-test/main/having_cond_pushdown.result index 9713f014f43..3531c855781 100644 --- a/mysql-test/main/having_cond_pushdown.result +++ b/mysql-test/main/having_cond_pushdown.result @@ -1134,15 +1134,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 4, - "filtered": 100, - "attached_condition": "t2.x < 5 and t2.x > 1" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 4, + "filtered": 100, + "attached_condition": "t2.x < 5 and t2.x > 1" + } } } } @@ -1183,15 +1185,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 3, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 4, - "filtered": 100, - "attached_condition": "t2.x < 5 and t2.x > 1" + "materialization": { + "query_block": { + "select_id": 3, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 4, + "filtered": 100, + "attached_condition": "t2.x < 5 and t2.x > 1" + } } } } @@ -1257,16 +1261,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "`MAX(t2.y)` < 14", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 4, - "filtered": 100, - "attached_condition": "t2.x < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "`MAX(t2.y)` < 14", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 4, + "filtered": 100, + "attached_condition": "t2.x < 5" + } } } } @@ -1307,16 +1313,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 3, - "having_condition": "`MAX(t2.y)` < 14", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 4, - "filtered": 100, - "attached_condition": "t2.x < 5" + "materialization": { + "query_block": { + "select_id": 3, + "having_condition": "`MAX(t2.y)` < 14", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 4, + "filtered": 100, + "attached_condition": "t2.x < 5" + } } } } diff --git a/mysql-test/main/in_subq_cond_pushdown.result b/mysql-test/main/in_subq_cond_pushdown.result index eef320d2d04..0e1d1df1875 100644 --- a/mysql-test/main/in_subq_cond_pushdown.result +++ b/mysql-test/main/in_subq_cond_pushdown.result @@ -70,16 +70,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "`MAX(t2.g)` < 25", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "`MAX(t2.g)` < 25", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5" + } } } } @@ -159,16 +161,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "`MAX(t2.g)` > 55 and t2.f < 4", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "`MAX(t2.g)` > 55 and t2.f < 4", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5" + } } } } @@ -250,16 +254,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "`MAX(t2.g)` > 60 or `MAX(t2.g)` < 25", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "`MAX(t2.g)` > 60 or `MAX(t2.g)` < 25", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5" + } } } } @@ -339,16 +345,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "(`MAX(t2.g)` > 60 or `MAX(t2.g)` < 25) and t2.f > 2", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "(`MAX(t2.g)` > 60 or `MAX(t2.g)` < 25) and t2.f > 2", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5" + } } } } @@ -430,16 +438,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "t2.f > 1", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "t2.f > 1", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5" + } } } } @@ -519,16 +529,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "`MAX(v1_y)` > 20", - "temporary_table": { - "table": { - "table_name": "t3", - "access_type": "ALL", - "rows": 8, - "filtered": 100, - "attached_condition": "t3.x > 1 and t3.x <= 3" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "`MAX(v1_y)` > 20", + "temporary_table": { + "table": { + "table_name": "t3", + "access_type": "ALL", + "rows": 8, + "filtered": 100, + "attached_condition": "t3.x > 1 and t3.x <= 3" + } } } } @@ -621,16 +633,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "`MAX(t2.g)` > 20", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "`MAX(t2.g)` > 20", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5" + } } } } @@ -712,15 +726,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.e < 2" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.e < 2" + } } } } @@ -802,15 +818,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.e > 2 and t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.e > 2 and t2.e < 5" + } } } } @@ -894,15 +912,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and (t2.e < 2 or t2.e >= 4)" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and (t2.e < 2 or t2.e >= 4)" + } } } } @@ -982,15 +1002,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and (t2.e < 2 or t2.e = 5) and t2.f > 3" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and (t2.e < 2 or t2.e = 5) and t2.f > 3" + } } } } @@ -1070,15 +1092,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and (t2.e < 2 or t2.e = 5) and t2.f > 3" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and (t2.e < 2 or t2.e = 5) and t2.f > 3" + } } } } @@ -1158,15 +1182,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.e < 2" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.e < 2" + } } } } @@ -1246,14 +1272,16 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e = 1" + "materialization": { + "query_block": { + "select_id": 2, + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e = 1" + } } } } @@ -1332,15 +1360,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.e > 1" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.e > 1" + } } } } @@ -1418,15 +1448,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t3", - "access_type": "ALL", - "rows": 8, - "filtered": 100, - "attached_condition": "t3.x > 1 and t3.x <= 3 and t3.x < 3" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t3", + "access_type": "ALL", + "rows": 8, + "filtered": 100, + "attached_condition": "t3.x > 1 and t3.x <= 3 and t3.x < 3" + } } } } @@ -1521,15 +1553,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.e <= 3" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.e <= 3" + } } } } @@ -1610,16 +1644,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "t2.f < 3 or t2.f = 4", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.e < 3" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "t2.f < 3 or t2.f = 4", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.e < 3" + } } } } @@ -1699,16 +1735,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "t2.e + `MAX(t2.g)` > 41", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "t2.e + `MAX(t2.g)` > 41", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5" + } } } } @@ -1790,16 +1828,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "`MAX(t2.g)` - t2.e < 35", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "`MAX(t2.g)` - t2.e < 35", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5" + } } } } @@ -1879,16 +1919,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "`MAX(t2.g)` * t2.e > 100", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "`MAX(t2.g)` * t2.e > 100", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5" + } } } } @@ -1972,16 +2014,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "`MAX(t2.g)` / t2.e > 30", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "`MAX(t2.g)` / t2.e > 30", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5" + } } } } @@ -2061,16 +2105,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "`MAX(t2.g)` between 50 and 100", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "`MAX(t2.g)` between 50 and 100", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5" + } } } } @@ -2150,15 +2196,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.e + t2.f > 5" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.e + t2.f > 5" + } } } } @@ -2238,15 +2286,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.e - t2.f > 0" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.e - t2.f > 0" + } } } } @@ -2326,15 +2376,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.e * t2.f > 6" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.e * t2.f > 6" + } } } } @@ -2416,15 +2468,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.f / t2.e > 2" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.f / t2.e > 2" + } } } } @@ -2510,15 +2564,17 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.e between 1 and 3" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.e between 1 and 3" + } } } } @@ -2602,29 +2658,31 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "v2.max_g > 3", - "temporary_table": { - "table": { - "table_name": "", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "v2.e < 5", - "materialized": { - "query_block": { - "select_id": 3, - "having_condition": "max_g > 25", - "filesort": { - "sort_key": "t2.e", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "v2.max_g > 3", + "temporary_table": { + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "v2.e < 5", + "materialized": { + "query_block": { + "select_id": 3, + "having_condition": "max_g > 25", + "filesort": { + "sort_key": "t2.e", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5" + } } } } @@ -2712,28 +2770,30 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "v2.e < 5 and v2.e > 1", - "materialized": { - "query_block": { - "select_id": 3, - "having_condition": "max_g > 25", - "filesort": { - "sort_key": "t2.e", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.e > 1" + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "v2.e < 5 and v2.e > 1", + "materialized": { + "query_block": { + "select_id": 3, + "having_condition": "max_g > 25", + "filesort": { + "sort_key": "t2.e", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.e > 1" + } } } } @@ -2822,29 +2882,31 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "having_condition": "v2.max_g < 100", - "temporary_table": { - "table": { - "table_name": "", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "v2.e < 5 and v2.e > 1", - "materialized": { - "query_block": { - "select_id": 3, - "having_condition": "max_g > 25", - "filesort": { - "sort_key": "t2.e", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.e > 1" + "materialization": { + "query_block": { + "select_id": 2, + "having_condition": "v2.max_g < 100", + "temporary_table": { + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "v2.e < 5 and v2.e > 1", + "materialized": { + "query_block": { + "select_id": 3, + "having_condition": "max_g > 25", + "filesort": { + "sort_key": "t2.e", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.e > 1" + } } } } @@ -2956,27 +3018,29 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "d_tab.e < 5 and d_tab.e > 1", - "materialized": { - "query_block": { - "select_id": 3, - "having_condition": "max_g > 25 and t2.e < 5 and t2.e > 1", - "filesort": { - "sort_key": "t2.f", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100 + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "d_tab.e < 5 and d_tab.e > 1", + "materialized": { + "query_block": { + "select_id": 3, + "having_condition": "max_g > 25 and t2.e < 5 and t2.e > 1", + "filesort": { + "sort_key": "t2.f", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100 + } } } } @@ -3107,27 +3171,29 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "d_tab.e < 5 and d_tab.e > 1", - "materialized": { - "query_block": { - "select_id": 3, - "having_condition": "max_g > 25 and t2.e < 5 and t2.e > 1", - "filesort": { - "sort_key": "t2.f", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100 + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "d_tab.e < 5 and d_tab.e > 1", + "materialized": { + "query_block": { + "select_id": 3, + "having_condition": "max_g > 25 and t2.e < 5 and t2.e > 1", + "filesort": { + "sort_key": "t2.f", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100 + } } } } @@ -3259,27 +3325,29 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "temporary_table": { - "table": { - "table_name": "", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "d_tab.e < 5 and d_tab.e > 1", - "materialized": { - "query_block": { - "select_id": 3, - "having_condition": "max_g > 25 and t2.e < 5 and t2.e > 1", - "filesort": { - "sort_key": "t2.f", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100 + "materialization": { + "query_block": { + "select_id": 2, + "temporary_table": { + "table": { + "table_name": "", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "d_tab.e < 5 and d_tab.e > 1", + "materialized": { + "query_block": { + "select_id": 3, + "having_condition": "max_g > 25 and t2.e < 5 and t2.e > 1", + "filesort": { + "sort_key": "t2.f", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100 + } } } } @@ -3418,16 +3486,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 3, - "having_condition": "t2.f < 5", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e > 1 and t2.e < 5" + "materialization": { + "query_block": { + "select_id": 3, + "having_condition": "t2.f < 5", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e > 1 and t2.e < 5" + } } } } @@ -3587,16 +3657,18 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 3, - "having_condition": "t2.f < 5", - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e > 1 and t2.e < 5" + "materialization": { + "query_block": { + "select_id": 3, + "having_condition": "t2.f < 5", + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e > 1 and t2.e < 5" + } } } } @@ -3684,21 +3756,23 @@ EXPLAIN "filtered": 100, "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "window_functions_computation": { - "sorts": { - "filesort": { - "sort_key": "t2.f" - } - }, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.f > 1" + "materialization": { + "query_block": { + "select_id": 2, + "window_functions_computation": { + "sorts": { + "filesort": { + "sort_key": "t2.f" + } + }, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.f > 1" + } } } } @@ -3777,21 +3851,23 @@ EXPLAIN "attached_condition": "t1.c = ``.`CAST(SUM(t2.g) OVER (PARTITION BY t2.f) AS INT)`", "materialized": { "unique": 1, - "query_block": { - "select_id": 2, - "window_functions_computation": { - "sorts": { - "filesort": { - "sort_key": "t2.f" - } - }, - "temporary_table": { - "table": { - "table_name": "t2", - "access_type": "ALL", - "rows": 12, - "filtered": 100, - "attached_condition": "t2.e < 5 and t2.f > 1" + "materialization": { + "query_block": { + "select_id": 2, + "window_functions_computation": { + "sorts": { + "filesort": { + "sort_key": "t2.f" + } + }, + "temporary_table": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 12, + "filtered": 100, + "attached_condition": "t2.e < 5 and t2.f > 1" + } } } } diff --git a/mysql-test/main/subselect_mat_analyze_json.result b/mysql-test/main/subselect_mat_analyze_json.result new file mode 100644 index 00000000000..454204edbd1 --- /dev/null +++ b/mysql-test/main/subselect_mat_analyze_json.result @@ -0,0 +1,945 @@ +set @save_optimizer_switch=@@optimizer_switch; +create table t1 (a int); +create table t2 (b int); +insert into t1 values (null), (1), (2), (3); +insert into t2 values (3), (4); +set @@optimizer_switch = "materialization=on,in_to_exists=off,semijoin=off"; +explain format=json select * from t1 where a in (select b from t2); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "t1", + "access_type": "ALL", + "rows": 4, + "filtered": 100, + "attached_condition": "(t1.a,t1.a in (subquery#2))" + }, + "subqueries": [ + { + "materialization": { + "query_block": { + "select_id": 2, + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 2, + "filtered": 100 + } + } + } + } + ] + } +} +# "Complete match" execution strategy +analyze format=json select * from t1 where a in (select b from t2); +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 25, + "attached_condition": "(t1.a,t1.a in (subquery#2))" + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup", + "r_loops": 3, + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } +} +# "Partial match" is used due to NOT IN +# Force rowid-merge partial partial matching +set @@optimizer_switch="partial_match_rowid_merge=on,partial_match_table_scan=off"; +analyze format=json select * from t1 where a not in (select b from t2); +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 50, + "attached_condition": "!(t1.a,t1.a in (subquery#2))" + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;array merge for partial match", + "r_loops": 4, + "r_index_lookups": 3, + "r_partial_matches": 1, + "r_partial_match_buffer_size": "REPLACED", + "r_partial_match_array_sizes": ["2"], + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } +} +# Force table scan partial matching +set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=on"; +analyze format=json select * from t1 where a not in (select b from t2); +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 50, + "attached_condition": "!(t1.a,t1.a in (subquery#2))" + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;full scan for partial match", + "r_loops": 4, + "r_index_lookups": 3, + "r_partial_matches": 1, + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } +} +# Subselect in GROUP BY +analyze format=json select a from t1 group by a in (select b from t2); +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "filesort": { + "sort_key": "(t1.a,t1.a in (subquery#2))", + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "r_used_priority_queue": false, + "r_output_rows": 3, + "r_buffer_size": "REPLACED", + "r_sort_mode": "sort_key,rowid", + "temporary_table": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;full scan for partial match", + "r_loops": 4, + "r_index_lookups": 3, + "r_partial_matches": 1, + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } + } + } +} +set @@optimizer_switch="partial_match_rowid_merge=on,partial_match_table_scan=off"; +analyze format=json select a from t1 group by a not in (select b from t2); +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "filesort": { + "sort_key": "!(t1.a,t1.a in (subquery#2))", + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "r_used_priority_queue": false, + "r_output_rows": 3, + "r_buffer_size": "REPLACED", + "r_sort_mode": "sort_key,rowid", + "temporary_table": { + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;array merge for partial match", + "r_loops": 4, + "r_index_lookups": 3, + "r_partial_matches": 1, + "r_partial_match_buffer_size": "REPLACED", + "r_partial_match_array_sizes": ["2"], + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } + } + } +} +set @@optimizer_switch="partial_match_rowid_merge=on,partial_match_table_scan=on"; +# Subselect in ORDER BY +analyze format=json select a from t1 order by a in (select b from t2); +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "read_sorted_file": { + "r_rows": 4, + "filesort": { + "sort_key": "(t1.a,t1.a in (subquery#2))", + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "r_used_priority_queue": false, + "r_output_rows": 4, + "r_buffer_size": "REPLACED", + "r_sort_mode": "sort_key,addon_fields", + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;full scan for partial match", + "r_loops": 4, + "r_index_lookups": 3, + "r_partial_matches": 1, + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } +} +# Subselect in HAVING +analyze format=json select a from t1 having a not in (select b from t2); +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "having_condition": "!(t1.a,t1.a in (subquery#2))", + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;full scan for partial match", + "r_loops": 4, + "r_index_lookups": 3, + "r_partial_matches": 1, + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } +} +# Nested IN +analyze format=json select a from t1 where a in (select a from t1 where a in (select b from t2)); +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 25, + "attached_condition": "(t1.a,t1.a in (subquery#2))" + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup", + "r_loops": 3, + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 25, + "attached_condition": "(t1.a,t1.a in (subquery#3))" + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup", + "r_loops": 3, + "query_block": { + "select_id": 3, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } + } + } + ] + } +} +create table t3 (c int); +insert into t3 (c) values (3), (null), (4); +# Subquery in ON-clause of outer join +analyze format=json select a from t1 left join t2 on a not in (select c from t3); +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "const_condition": "1", + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + }, + "block-nl-join": { + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + }, + "buffer_type": "flat", + "buffer_size": "87", + "join_type": "BNL", + "attached_condition": "trigcond(trigcond(!(t1.a,t1.a in (subquery#2))))", + "r_filtered": 50, + "r_unpack_time_ms": "REPLACED" + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;full scan for partial match", + "r_loops": 4, + "r_index_lookups": 3, + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t3", + "access_type": "ALL", + "r_loops": 1, + "rows": 3, + "r_rows": 3, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } +} +analyze format=json +select (b, b + 1, b + 2) not in +(select count(distinct a), a + 1, a + 2 from t1 group by a + 1, a + 2) +from t2; +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 2, + "r_rows": 2, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;full scan for partial match", + "r_loops": 2, + "r_index_lookups": 2, + "r_partial_matches": 2, + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "read_sorted_file": { + "r_rows": 4, + "filesort": { + "sort_key": "t1.a + 1, t1.a + 2", + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "r_used_priority_queue": false, + "r_output_rows": 4, + "r_buffer_size": "REPLACED", + "r_sort_mode": "sort_key,addon_fields", + "table": { + "table_name": "t1", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + } + } + ] + } +} +drop table t1, t2, t3; +# +# Tables with more than one column +# +create table t1 (a1 char(1), a2 char(1)); +insert into t1 values (null, 'b'); +create table t2 (b1 char(1), b2 char(2)); +insert into t2 values ('a','b'), ('c', 'd'), (null, 'e'), ('f', 'g'); +set @@optimizer_switch="partial_match_rowid_merge=on,partial_match_table_scan=off"; +explain format=json select * from t1 where (a1, a2) not in (select b1, b2 from t2); +EXPLAIN +{ + "query_block": { + "select_id": 1, + "const_condition": "!((NULL,'b'),(NULL,'b') in (subquery#2))", + "table": { + "table_name": "t1", + "access_type": "system", + "rows": 1, + "filtered": 100 + }, + "subqueries": [ + { + "materialization": { + "query_block": { + "select_id": 2, + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 4, + "filtered": 100 + } + } + } + } + ] + } +} +analyze format=json select * from t1 where (a1, a2) not in (select b1, b2 from t2); +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "const_condition": "!((NULL,'b'),(NULL,'b') in (subquery#2))", + "table": { + "table_name": "t1", + "access_type": "system", + "r_loops": 0, + "rows": 1, + "r_rows": null, + "filtered": 100, + "r_filtered": null + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;array merge for partial match", + "r_loops": 1, + "r_partial_matches": 1, + "r_partial_match_buffer_size": "REPLACED", + "r_partial_match_array_sizes": ["4", "3"], + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } +} +set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=on"; +analyze format=json select * from t1 where (a1, a2) not in (select b1, b2 from t2); +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "const_condition": "!((NULL,'b'),(NULL,'b') in (subquery#2))", + "table": { + "table_name": "t1", + "access_type": "system", + "r_loops": 0, + "rows": 1, + "r_rows": null, + "filtered": 100, + "r_filtered": null + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;full scan for partial match", + "r_loops": 1, + "r_partial_matches": 1, + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } +} +# Subquery in SELECT list +explain format=json select t1.*, (a1, a2) in (select * from t2) as in_res from t1; +EXPLAIN +{ + "query_block": { + "select_id": 1, + "table": { + "table_name": "t1", + "access_type": "system", + "rows": 1, + "filtered": 100 + }, + "subqueries": [ + { + "materialization": { + "query_block": { + "select_id": 2, + "table": { + "table_name": "t2", + "access_type": "ALL", + "rows": 4, + "filtered": 100 + } + } + } + } + ] + } +} +analyze format=json select t1.*, (a1, a2) in (select * from t2) as in_res from t1; +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "access_type": "system", + "r_loops": 0, + "rows": 1, + "r_rows": null, + "filtered": 100, + "r_filtered": null + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;full scan for partial match", + "r_loops": 1, + "r_partial_matches": 1, + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } +} +analyze format=json select t1.*, (a1, a2) not in (select * from t2) as in_res from t1; +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "access_type": "system", + "r_loops": 0, + "rows": 1, + "r_rows": null, + "filtered": 100, + "r_filtered": null + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;full scan for partial match", + "r_loops": 1, + "r_partial_matches": 1, + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } +} +set @@optimizer_switch="partial_match_rowid_merge=on,partial_match_table_scan=off"; +analyze format=json select t1.*, (a1, a2) in (select * from t2) as in_res from t1; +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "access_type": "system", + "r_loops": 0, + "rows": 1, + "r_rows": null, + "filtered": 100, + "r_filtered": null + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;array merge for partial match", + "r_loops": 1, + "r_partial_matches": 1, + "r_partial_match_buffer_size": "REPLACED", + "r_partial_match_array_sizes": ["4", "3"], + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } +} +analyze format=json select t1.*, (a1, a2) not in (select * from t2) as in_res from t1; +ANALYZE +{ + "query_block": { + "select_id": 1, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t1", + "access_type": "system", + "r_loops": 0, + "rows": 1, + "r_rows": null, + "filtered": 100, + "r_filtered": null + }, + "subqueries": [ + { + "materialization": { + "r_strategy": "index_lookup;array merge for partial match", + "r_loops": 1, + "r_partial_matches": 1, + "r_partial_match_buffer_size": "REPLACED", + "r_partial_match_array_sizes": ["4", "3"], + "query_block": { + "select_id": 2, + "r_loops": 1, + "r_total_time_ms": "REPLACED", + "table": { + "table_name": "t2", + "access_type": "ALL", + "r_loops": 1, + "rows": 4, + "r_rows": 4, + "r_table_time_ms": "REPLACED", + "r_other_time_ms": "REPLACED", + "filtered": 100, + "r_filtered": 100 + } + } + } + } + ] + } +} +drop table t1,t2; +set @@optimizer_switch=@save_optimizer_switch; diff --git a/mysql-test/main/subselect_mat_analyze_json.test b/mysql-test/main/subselect_mat_analyze_json.test new file mode 100644 index 00000000000..d949b9523bd --- /dev/null +++ b/mysql-test/main/subselect_mat_analyze_json.test @@ -0,0 +1,99 @@ +set @save_optimizer_switch=@@optimizer_switch; + +create table t1 (a int); +create table t2 (b int); +insert into t1 values (null), (1), (2), (3); +insert into t2 values (3), (4); + +set @@optimizer_switch = "materialization=on,in_to_exists=off,semijoin=off"; + +explain format=json select * from t1 where a in (select b from t2); +--echo # "Complete match" execution strategy +--source include/analyze-format.inc +analyze format=json select * from t1 where a in (select b from t2); + +--echo # "Partial match" is used due to NOT IN +--echo # Force rowid-merge partial partial matching +set @@optimizer_switch="partial_match_rowid_merge=on,partial_match_table_scan=off"; +--source include/analyze-format.inc +analyze format=json select * from t1 where a not in (select b from t2); + +--echo # Force table scan partial matching +set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=on"; +--source include/analyze-format.inc +analyze format=json select * from t1 where a not in (select b from t2); + +--echo # Subselect in GROUP BY +--source include/analyze-format.inc +analyze format=json select a from t1 group by a in (select b from t2); + +set @@optimizer_switch="partial_match_rowid_merge=on,partial_match_table_scan=off"; +--source include/analyze-format.inc +analyze format=json select a from t1 group by a not in (select b from t2); + +set @@optimizer_switch="partial_match_rowid_merge=on,partial_match_table_scan=on"; +--echo # Subselect in ORDER BY +--source include/analyze-format.inc +analyze format=json select a from t1 order by a in (select b from t2); + +--echo # Subselect in HAVING +--source include/analyze-format.inc +analyze format=json select a from t1 having a not in (select b from t2); + +--echo # Nested IN +--source include/analyze-format.inc +analyze format=json select a from t1 where a in (select a from t1 where a in (select b from t2)); + +create table t3 (c int); +insert into t3 (c) values (3), (null), (4); + +--echo # Subquery in ON-clause of outer join +--source include/analyze-format.inc +analyze format=json select a from t1 left join t2 on a not in (select c from t3); + +--source include/analyze-format.inc +analyze format=json +select (b, b + 1, b + 2) not in + (select count(distinct a), a + 1, a + 2 from t1 group by a + 1, a + 2) +from t2; + +drop table t1, t2, t3; + + +--echo # +--echo # Tables with more than one column +--echo # +create table t1 (a1 char(1), a2 char(1)); +insert into t1 values (null, 'b'); +create table t2 (b1 char(1), b2 char(2)); +insert into t2 values ('a','b'), ('c', 'd'), (null, 'e'), ('f', 'g'); + +set @@optimizer_switch="partial_match_rowid_merge=on,partial_match_table_scan=off"; +explain format=json select * from t1 where (a1, a2) not in (select b1, b2 from t2); +--source include/analyze-format.inc +analyze format=json select * from t1 where (a1, a2) not in (select b1, b2 from t2); + +set @@optimizer_switch="partial_match_rowid_merge=off,partial_match_table_scan=on"; +--source include/analyze-format.inc +analyze format=json select * from t1 where (a1, a2) not in (select b1, b2 from t2); + +--echo # Subquery in SELECT list +explain format=json select t1.*, (a1, a2) in (select * from t2) as in_res from t1; + +--source include/analyze-format.inc +analyze format=json select t1.*, (a1, a2) in (select * from t2) as in_res from t1; + +--source include/analyze-format.inc +analyze format=json select t1.*, (a1, a2) not in (select * from t2) as in_res from t1; + +set @@optimizer_switch="partial_match_rowid_merge=on,partial_match_table_scan=off"; +--source include/analyze-format.inc +analyze format=json select t1.*, (a1, a2) in (select * from t2) as in_res from t1; + +--source include/analyze-format.inc +analyze format=json select t1.*, (a1, a2) not in (select * from t2) as in_res from t1; + +drop table t1,t2; + + +set @@optimizer_switch=@save_optimizer_switch; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 8ff9850e1b3..7f6e0fbfafc 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -42,6 +42,7 @@ #include "sql_parse.h" // check_stack_overrun #include "sql_cte.h" #include "sql_test.h" +#include "my_json_writer.h" double get_post_group_estimate(JOIN* join, double join_op_rows); @@ -192,6 +193,7 @@ void Item_in_subselect::cleanup() in_strategy&= ~SUBS_STRATEGY_CHOSEN; */ first_execution= TRUE; + materialization_tracker= NULL; pushed_cond_guards= NULL; Item_subselect::cleanup(); DBUG_VOID_RETURN; @@ -1602,6 +1604,7 @@ Item_in_subselect::Item_in_subselect(THD *thd, Item * left_exp, st_select_lex *select_lex): Item_exists_subselect(thd), left_expr_cache(0), first_execution(TRUE), in_strategy(SUBS_NOT_TRANSFORMED), + materialization_tracker(NULL), pushed_cond_guards(NULL), do_not_convert_to_sj(FALSE), is_jtbm_merged(FALSE), is_jtbm_const_tab(FALSE), is_flattenable_semijoin(FALSE), is_registered_semijoin(FALSE), @@ -3648,6 +3651,26 @@ bool Item_in_subselect::init_cond_guards() return FALSE; } +/** + Initialize the tracker which will be used to provide information for + the output of EXPLAIN and ANALYZE +*/ +void Item_in_subselect::init_subq_materialization_tracker(THD *thd) +{ + if (test_strategy(SUBS_MATERIALIZATION | SUBS_PARTIAL_MATCH_ROWID_MERGE | + SUBS_PARTIAL_MATCH_TABLE_SCAN)) + { + Explain_query *qw= thd->lex->explain; + DBUG_ASSERT(qw); + Explain_node *node= qw->get_node(unit->first_select()->select_number); + if (!node) + return; + node->subq_materialization= new(qw->mem_root) + Explain_subq_materialization(qw->mem_root); + materialization_tracker= node->subq_materialization->get_tracker(); + } +} + bool Item_allany_subselect::select_transformer(JOIN *join) @@ -4245,11 +4268,13 @@ int subselect_uniquesubquery_engine::exec() empty_result_set= TRUE; table->status= 0; Item_in_subselect *in_subs= item->get_IN_subquery(); + Subq_materialization_tracker *tracker= in_subs->get_materialization_tracker(); DBUG_ASSERT(in_subs); if (!tab->preread_init_done && tab->preread_init()) DBUG_RETURN(1); - + if (tracker) + tracker->increment_loops_count(); if (in_subs->left_expr_has_null()) { /* @@ -5002,6 +5027,9 @@ subselect_hash_sj_engine::choose_partial_match_strategy( partial_match_key_parts_arg); if (pm_buff_size > thd->variables.rowid_merge_buff_size) strategy= PARTIAL_MATCH_SCAN; + else + item->get_IN_subquery()->get_materialization_tracker()-> + report_partial_match_buffer_size(pm_buff_size); } } @@ -5777,6 +5805,7 @@ int subselect_hash_sj_engine::exec() } } + item_in->get_materialization_tracker()->report_exec_strategy(strategy); if (pm_engine) lookup_engine= pm_engine; item_in->change_engine(lookup_engine); @@ -6247,6 +6276,9 @@ int subselect_partial_match_engine::exec() DBUG_ASSERT(!(item_in->left_expr_has_null() && item_in->is_top_level_item())); + Subq_materialization_tracker *tracker= item_in->get_materialization_tracker(); + tracker->increment_loops_count(); + if (!item_in->left_expr_has_null()) { /* Try to find a matching row by index lookup. */ @@ -6260,6 +6292,7 @@ int subselect_partial_match_engine::exec() else { /* Search for a complete match. */ + tracker->increment_index_lookups(); if ((lookup_res= lookup_engine->index_lookup())) { /* An error occurred during lookup(). */ @@ -6304,6 +6337,7 @@ int subselect_partial_match_engine::exec() if (tmp_table->file->inited) tmp_table->file->ha_index_end(); + tracker->increment_partial_matches(); if (partial_match()) { /* The result of IN is UNKNOWN. */ @@ -6510,6 +6544,8 @@ subselect_rowid_merge_engine::init(MY_BITMAP *non_null_key_parts, 0, 0)) return TRUE; + item->get_IN_subquery()->get_materialization_tracker()-> + report_partial_merge_keys(merge_keys, merge_keys_count); return FALSE; } @@ -6966,3 +7002,12 @@ void Item_subselect::init_expr_cache_tracker(THD *thd) DBUG_ASSERT(expr_cache->type() == Item::EXPR_CACHE_ITEM); node->cache_tracker= ((Item_cache_wrapper *)expr_cache)->init_tracker(qw->mem_root); } + + +void Subq_materialization_tracker::report_partial_merge_keys( + Ordered_key **merge_keys, uint merge_keys_count) +{ + partial_match_array_sizes.resize(merge_keys_count, 0); + for (uint i= 0; i < merge_keys_count; i++) + partial_match_array_sizes[i]= merge_keys[i]->get_key_buff_elements(); +} diff --git a/sql/item_subselect.h b/sql/item_subselect.h index c1b531dc361..f976d905951 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -18,6 +18,7 @@ /* subselect Item */ +#include "item.h" #ifdef USE_PRAGMA_INTERFACE #pragma interface /* gcc class implementation */ #endif @@ -43,6 +44,8 @@ typedef class st_select_lex SELECT_LEX; */ typedef Comp_creator* (*chooser_compare_func_creator)(bool invert); class Cached_item; +class Subq_materialization_tracker; +class Explain_subq_materialization; /* base class for subselects */ @@ -501,6 +504,8 @@ protected: bool was_null; /* A bitmap of possible execution strategies for an IN predicate. */ uchar in_strategy; + /* Tracker collecting execution parameters of a materialized subquery */ + Subq_materialization_tracker *materialization_tracker; protected: /* Used to trigger on/off conditions that were pushed down to subselect */ bool *pushed_cond_guards; @@ -525,6 +530,7 @@ protected: left_expr could later be changed to something on the execution arena. */ Item *left_expr_orig; + public: /* Priority of this predicate in the convert-to-semi-join-nest process. */ int sj_convert_priority; @@ -626,7 +632,7 @@ public: Item_in_subselect(THD *thd_arg, Item * left_expr, st_select_lex *select_lex); Item_in_subselect(THD *thd_arg): Item_exists_subselect(thd_arg), left_expr_cache(0), first_execution(TRUE), - in_strategy(SUBS_NOT_TRANSFORMED), + in_strategy(SUBS_NOT_TRANSFORMED), materialization_tracker(NULL), pushed_cond_guards(NULL), func(NULL), do_not_convert_to_sj(FALSE), is_jtbm_merged(FALSE), is_jtbm_const_tab(FALSE), upper_item(0), converted_from_in_predicate(FALSE) {} @@ -778,6 +784,9 @@ public: { return left_expr; } inline Item* left_exp_orig() const { return left_expr_orig; } + void init_subq_materialization_tracker(THD *thd); + Subq_materialization_tracker *get_materialization_tracker() const + { return materialization_tracker; } friend class Item_ref_null_helper; friend class Item_is_not_null_test; @@ -1159,6 +1168,15 @@ public: select_result_interceptor *result, bool temp= FALSE) override; bool no_tables() const override;//=>base class + /* Possible execution strategies that can be used to compute hash semi-join.*/ + enum exec_strategy { + UNDEFINED= 0, + COMPLETE_MATCH, /* Use regular index lookups. */ + PARTIAL_MATCH, /* Use some partial matching strategy. */ + PARTIAL_MATCH_MERGE, /* Use partial matching through index merging. */ + PARTIAL_MATCH_SCAN, /* Use partial matching through table scan. */ + IMPOSSIBLE /* Subquery materialization is not applicable. */ + }; protected: /* The engine used to compute the IN predicate. */ @@ -1170,15 +1188,6 @@ protected: uint count_partial_match_columns; uint count_null_only_columns; uint count_columns_with_nulls; - /* Possible execution strategies that can be used to compute hash semi-join.*/ - enum exec_strategy { - UNDEFINED, - COMPLETE_MATCH, /* Use regular index lookups. */ - PARTIAL_MATCH, /* Use some partial matching strategy. */ - PARTIAL_MATCH_MERGE, /* Use partial matching through index merging. */ - PARTIAL_MATCH_SCAN, /* Use partial matching through table scan. */ - IMPOSSIBLE /* Subquery materialization is not applicable. */ - }; /* The chosen execution strategy. Computed after materialization. */ exec_strategy strategy; exec_strategy get_strategy_using_schema(); @@ -1311,6 +1320,7 @@ public: rownum_t get_max_null_row() { return max_null_row; } MY_BITMAP * get_null_key() { return &null_key; } ha_rows get_null_count() { return null_count; } + ha_rows get_key_buff_elements() { return key_buff_elements; } /* Get the search key element that corresponds to the i-th key part of this index. @@ -1548,4 +1558,93 @@ public: void cleanup() override; enum_engine_type engine_type() override { return TABLE_SCAN_ENGINE; } }; + +/** + @brief Subquery materialization tracker + + @details + Used to track various parameters of the materialized subquery execution, + such as the execution strategy, sizes of buffers employed, etc +*/ +class Subq_materialization_tracker +{ +public: + using Strategy = subselect_hash_sj_engine::exec_strategy; + + Subq_materialization_tracker(MEM_ROOT *mem_root) + : exec_strategy(Strategy::UNDEFINED), + partial_match_buffer_size(0), + partial_match_array_sizes(mem_root), + loops_count(0), + index_lookups_count(0), + partial_matches_count(0) + {} + + void report_partial_merge_keys(Ordered_key **merge_keys, + uint merge_keys_count); + + void report_exec_strategy(Strategy es) + { + exec_strategy= es; + } + + void report_partial_match_buffer_size(longlong sz) + { + partial_match_buffer_size= sz; + } + + void increment_loops_count() + { + loops_count++; + } + + void increment_index_lookups() + { + index_lookups_count++; + } + + void increment_partial_matches() + { + partial_matches_count++; + } + + void print_json_members(Json_writer *writer) const; +private: + Strategy exec_strategy; + ulonglong partial_match_buffer_size; + Dynamic_array partial_match_array_sizes; + + /* Number of times subquery predicate was evaluated */ + ulonglong loops_count; + + /* + Number of times we made a lookup in the materialized temptable + (we do this when all parts of left_expr are not NULLs) + */ + ulonglong index_lookups_count; + + /* + Number of times we had to check for a partial match (either by + scanning the materialized subquery or by doing a merge) + */ + ulonglong partial_matches_count; + + const char *get_exec_strategy() const + { + switch (exec_strategy) + { + case Strategy::UNDEFINED: + return "undefined"; + case Strategy::COMPLETE_MATCH: + return "index_lookup"; + case Strategy::PARTIAL_MATCH_MERGE: + return "index_lookup;array merge for partial match"; + case Strategy::PARTIAL_MATCH_SCAN: + return "index_lookup;full scan for partial match"; + default: + return "unsupported"; + } + } +}; + #endif /* ITEM_SUBSELECT_INCLUDED */ diff --git a/sql/sql_array.h b/sql/sql_array.h index b6de1b18d78..bc4afa8906f 100644 --- a/sql/sql_array.h +++ b/sql/sql_array.h @@ -140,12 +140,24 @@ public: DBUG_ASSERT(idx < array.elements); return *(((Elem*)array.buffer) + idx); } + /// Const variant of at(), which cannot change data const Elem& at(size_t idx) const { return *(((Elem*)array.buffer) + idx); } + Elem& operator[](size_t idx) + { + return at(idx); + } + + /// Const variant of operator[] + const Elem& operator[](size_t idx) const + { + return at(idx); + } + /// @returns pointer to first element Elem *front() { diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 3d97645d212..bfd73074f76 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -24,6 +24,7 @@ #include "my_json_writer.h" #include "opt_range.h" #include "sql_expression_cache.h" +#include "item_subselect.h" const char * STR_DELETING_ALL_ROWS= "Deleting all rows"; const char * STR_IMPOSSIBLE_WHERE= "Impossible WHERE"; @@ -782,6 +783,18 @@ bool Explain_node::print_explain_json_cache(Json_writer *writer, } +bool Explain_node::print_explain_json_subq_materialization(Json_writer *writer, + bool is_analyze) +{ + if (subq_materialization) + { + subq_materialization->print_explain_json(writer, is_analyze); + return true; + } + return false; +} + + Explain_basic_join::~Explain_basic_join() { if (join_tabs) @@ -929,6 +942,8 @@ void Explain_select::print_explain_json(Explain_query *query, Json_writer_nesting_guard guard(writer); bool started_cache= print_explain_json_cache(writer, is_analyze); + bool started_subq_mat= print_explain_json_subq_materialization(writer, + is_analyze); if (message || select_type == pushed_derived_text || @@ -1032,6 +1047,8 @@ void Explain_select::print_explain_json(Explain_query *query, writer->end_object(); } + if (started_subq_mat) + writer->end_object(); if (started_cache) writer->end_object(); } @@ -2693,3 +2710,41 @@ void Explain_range_checked_fer::print_json(Json_writer *writer, writer->end_object(); } } + + +void Explain_subq_materialization::print_explain_json(Json_writer *writer, + bool is_analyze) +{ + writer->add_member("materialization").start_object(); + if (is_analyze) + tracker.print_json_members(writer); +} + + +void Subq_materialization_tracker::print_json_members(Json_writer *writer) const +{ + writer->add_member("r_strategy").add_str(get_exec_strategy()); + if (loops_count) + writer->add_member("r_loops").add_ull(loops_count); + + if (index_lookups_count) + writer->add_member("r_index_lookups").add_ull(index_lookups_count); + + if (partial_matches_count) + writer->add_member("r_partial_matches").add_ull(partial_matches_count); + + if (partial_match_buffer_size) + { + writer->add_member("r_partial_match_buffer_size"). + add_size(partial_match_buffer_size); + } + + if (partial_match_array_sizes.elements()) + { + writer->add_member("r_partial_match_array_sizes").start_array(); + for(size_t i= 0; i < partial_match_array_sizes.elements(); i++) + writer->add_ull(partial_match_array_sizes[i]); + writer->end_array(); + } +} + diff --git a/sql/sql_explain.h b/sql/sql_explain.h index e7b054ed75b..cf960f75da4 100644 --- a/sql/sql_explain.h +++ b/sql/sql_explain.h @@ -86,6 +86,7 @@ class Explain_node : public Sql_alloc public: Explain_node(MEM_ROOT *root) : cache_tracker(NULL), + subq_materialization(NULL), connection_type(EXPLAIN_NODE_OTHER), children(root) {} @@ -115,6 +116,12 @@ public: */ Expression_cache_tracker* cache_tracker; + /** + If not NULL, this node is a SELECT (or UNION) in a materialized + IN-subquery. + */ + Explain_subq_materialization* subq_materialization; + /* How this node is connected to its parent. (NOTE: EXPLAIN_NODE_NON_MERGED_SJ is set very late currently) @@ -143,6 +150,8 @@ public: void print_explain_json_for_children(Explain_query *query, Json_writer *writer, bool is_analyze); bool print_explain_json_cache(Json_writer *writer, bool is_analyze); + bool print_explain_json_subq_materialization(Json_writer *writer, + bool is_analyze); virtual ~Explain_node() = default; }; @@ -1003,4 +1012,26 @@ public: }; +/* + EXPLAIN data structure for subquery materialization. + + All decisions are made at execution time so here we just store the tracker + that has all the info. +*/ + +class Explain_subq_materialization : public Sql_alloc +{ +public: + Explain_subq_materialization(MEM_ROOT *mem_root) + : tracker(mem_root) + {} + + Subq_materialization_tracker *get_tracker() { return &tracker; } + + void print_explain_json(Json_writer *writer, bool is_analyze); + +private: + Subq_materialization_tracker tracker; +}; + #endif //SQL_EXPLAIN_INCLUDED diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 2ab1736891c..b86ffed8619 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1729,6 +1729,11 @@ bool JOIN::build_explain() curr_tab->tracker= tmp->get_using_temporary_read_tracker(); } } + if (is_in_subquery()) + { + Item_in_subselect *subq= unit->item->get_IN_subquery(); + subq->init_subq_materialization_tracker(thd); + } DBUG_RETURN(0); } From e8bcc4e4556ca3536559ffc76103c9f2dd890837 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Thu, 11 Jul 2024 17:35:13 +1000 Subject: [PATCH 05/12] MDEV-34568 rpl.rpl_mdev12179 - correct for Windows Simplify in an attempt to avoid: mysqltest: At line 275: File already exist: on the write_file lines. Using write_line as that's what a lot of other tests do for writing small bits to a expect file. Review thanks Valdislav Vaintroub --- mysql-test/suite/rpl/t/rpl_mdev12179.test | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/mysql-test/suite/rpl/t/rpl_mdev12179.test b/mysql-test/suite/rpl/t/rpl_mdev12179.test index 6d2dda1044f..fc3457252e1 100644 --- a/mysql-test/suite/rpl/t/rpl_mdev12179.test +++ b/mysql-test/suite/rpl/t/rpl_mdev12179.test @@ -55,9 +55,7 @@ SET sql_log_bin=1; # Restart the slave mysqld server, and verify that the GTID position is # read correctly from the new mysql.gtid_slave_pos_innodb table. ---write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect -wait -EOF +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.2.expect --shutdown_server --source include/wait_until_disconnected.inc @@ -94,9 +92,7 @@ DROP TABLE mysql.gtid_slave_pos; RENAME TABLE mysql.gtid_slave_pos_innodb TO mysql.gtid_slave_pos; SET sql_log_bin=1; ---write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect -wait -EOF +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.2.expect --shutdown_server --source include/wait_until_disconnected.inc @@ -132,9 +128,7 @@ SET sql_log_bin=0; ALTER TABLE mysql.gtid_slave_pos ENGINE=Aria; SET sql_log_bin=1; ---write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect -wait -EOF +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.2.expect --shutdown_server --source include/wait_until_disconnected.inc @@ -176,9 +170,7 @@ INSERT INTO mysql.gtid_slave_pos SELECT * FROM mysql.gtid_slave_pos_InnoDB; DROP TABLE mysql.gtid_slave_pos_InnoDB; SET sql_log_bin=1; ---write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect -wait -EOF +--write_line "wait" $MYSQLTEST_VARDIR/tmp/mysqld.2.expect --shutdown_server --source include/wait_until_disconnected.inc @@ -272,9 +264,7 @@ while (!$done) # MDEV-15373 engine gtid_slave_pos table name disobeys lower-case-table-names # This snippet verifies that engine gtid_slave_pos table is found, # its data are up-to-date. ---write_file $MYSQLTEST_VARDIR/tmp/mysqld.2.expect -wait -EOF +--write_line wait $MYSQLTEST_VARDIR/tmp/mysqld.2.expect --connection server_2 --shutdown_server --source include/wait_until_disconnected.inc From 3662f8ca8940663bf687e1b1fdf15fdc74025dcc Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Fri, 12 Jul 2024 12:45:11 +0530 Subject: [PATCH 06/12] MDEV-34543 Shutdown hangs while freeing the asynchronous i/o slots Problem: ======== - During shutdown, InnoDB tries to free the asynchronous I/O slots and hangs. The reason is that InnoDB disables asynchronous I/O before waiting for pending asynchronous I/O to finish. buf_load(): InnoDB aborts the buffer pool load due to user requested shutdown and doesn't wait for the asynchronous read to get completed. This could lead to debug assertion in buf_flush_buffer_pool() during shutdown Fix: === os_aio_free(): Should wait all read_slots and write_slots to finish before disabling the aio. buf_load(): Should wait for pending read request to complete even though it was aborted. --- storage/innobase/buf/buf0dump.cc | 4 +--- storage/innobase/os/os0file.cc | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/storage/innobase/buf/buf0dump.cc b/storage/innobase/buf/buf0dump.cc index 269ef448c31..d610463b8a3 100644 --- a/storage/innobase/buf/buf0dump.cc +++ b/storage/innobase/buf/buf0dump.cc @@ -643,9 +643,7 @@ buf_load() ut_free(dump); - if (i == dump_n) { - os_aio_wait_until_no_pending_reads(); - } + os_aio_wait_until_no_pending_reads(); ut_sprintf_timestamp(now); diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index ce4eafafcd5..beaf2c172d7 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -3752,11 +3752,11 @@ disable: void os_aio_free() { - srv_thread_pool->disable_aio(); delete read_slots; delete write_slots; read_slots= nullptr; write_slots= nullptr; + srv_thread_pool->disable_aio(); } /** Wait until there are no pending asynchronous writes. */ From 00d2c7f7f480c58c5e406c7c1a875f83bd3bb1fc Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Wed, 10 Jul 2024 19:34:53 +0530 Subject: [PATCH 07/12] MDEV-34542 Assertion `lock_trx_has_sys_table_locks(trx) == __null' failed in void row_mysql_unfreeze_data_dictionary(trx_t*) - During XA PREPARE, InnoDB releases the non-exclusive locks. But it fails to remove the non-exclusive table lock from the transaction table locks. In the mean time, main thread evicts the table from the LRU cache. While rollbacking the XA transaction, InnoDB iterates through the table locks to check whether it holds lock on any system tables and wrongly assumes the evicted table as system table since the table id is 0 Fix: === During XA PREPARE, remove the table locks of the transaction while releasing the non-exclusive locks. --- mysql-test/suite/innodb/r/lock_release.result | 23 +++ mysql-test/suite/innodb/t/lock_release.test | 26 +++ storage/innobase/lock/lock0lock.cc | 149 +++++++++--------- 3 files changed, 124 insertions(+), 74 deletions(-) create mode 100644 mysql-test/suite/innodb/r/lock_release.result create mode 100644 mysql-test/suite/innodb/t/lock_release.test diff --git a/mysql-test/suite/innodb/r/lock_release.result b/mysql-test/suite/innodb/r/lock_release.result new file mode 100644 index 00000000000..6bafe79a36c --- /dev/null +++ b/mysql-test/suite/innodb/r/lock_release.result @@ -0,0 +1,23 @@ +# +# MDEV-34542 Assertion `lock_trx_has_sys_table_locks(trx) == __null' +# failed in void row_mysql_unfreeze_data_dictionary(trx_t*) +# +# +CREATE TABLE t1 (c1 CHAR(1) ,c2 INT) ENGINE=INNODB +PARTITION BY LINEAR HASH ((c2)) PARTITIONS 512; +CREATE TABLE t2 (a INT) ENGINE=INNODB; +set @old_table_open_cache= @@table_open_cache; +XA START 'a'; +INSERT INTO mysql.innodb_index_stats SELECT * FROM mysql.innodb_index_stats WHERE table_name=''; +SET GLOBAL table_open_cache=10; +INSERT into t2 (a) VALUES (1); +SELECT * FROM t1; +c1 c2 +XA END 'a'; +XA PREPARE 'a'; +SELECT sleep(3); +sleep(3) +0 +XA ROLLBACK 'a'; +DROP TABLE t1, t2; +SET GLOBAL table_open_cache=@old_table_open_cache; diff --git a/mysql-test/suite/innodb/t/lock_release.test b/mysql-test/suite/innodb/t/lock_release.test new file mode 100644 index 00000000000..6620bf69d14 --- /dev/null +++ b/mysql-test/suite/innodb/t/lock_release.test @@ -0,0 +1,26 @@ +--source include/have_innodb.inc +--source include/have_partition.inc + +--echo # +--echo # MDEV-34542 Assertion `lock_trx_has_sys_table_locks(trx) == __null' +--echo # failed in void row_mysql_unfreeze_data_dictionary(trx_t*) +--echo # +--echo # +CREATE TABLE t1 (c1 CHAR(1) ,c2 INT) ENGINE=INNODB + PARTITION BY LINEAR HASH ((c2)) PARTITIONS 512; +CREATE TABLE t2 (a INT) ENGINE=INNODB; + +set @old_table_open_cache= @@table_open_cache; +XA START 'a'; +INSERT INTO mysql.innodb_index_stats SELECT * FROM mysql.innodb_index_stats WHERE table_name=''; +SET GLOBAL table_open_cache=10; +INSERT into t2 (a) VALUES (1); +SELECT * FROM t1; +XA END 'a'; +XA PREPARE 'a'; +# Added sleep to make sure that InnoDB main thread is to remove +# the innodb_index_stats from table cache +SELECT sleep(3); +XA ROLLBACK 'a'; +DROP TABLE t1, t2; +SET GLOBAL table_open_cache=@old_table_open_cache; diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index d0b4105d9c6..3dd4b5fa6f6 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -4382,80 +4382,6 @@ static void lock_rec_unlock_supremum(lock_t *lock) trx_mutex_exit(lock->trx); } -/** Release non-exclusive locks on XA PREPARE, -and release possible other transactions waiting because of these locks. */ -void lock_release_on_prepare(trx_t *trx) -{ - trx->set_skip_lock_inheritance(); - - ulint count= 0; - lock_mutex_enter(); - ut_ad(!trx_mutex_own(trx)); - - for (lock_t *lock= UT_LIST_GET_LAST(trx->lock.trx_locks); lock; ) - { - ut_ad(lock->trx == trx); - - if (lock_get_type_low(lock) == LOCK_REC) - { - ut_ad(!lock->index->table->is_temporary()); - if ((lock->type_mode & (LOCK_MODE_MASK | LOCK_GAP)) != LOCK_X) - lock_rec_dequeue_from_page(lock); - else if (lock_rec_get_nth_bit(lock, PAGE_HEAP_NO_SUPREMUM)) - lock_rec_unlock_supremum(lock); - else - { - ut_ad(trx->dict_operation || - lock->index->table->id >= DICT_HDR_FIRST_ID); - ut_ad(lock->trx->isolation_level > TRX_ISO_READ_COMMITTED || - /* Insert-intention lock is valid for supremum for isolation - level > TRX_ISO_READ_COMMITTED */ - lock_get_mode(lock) == LOCK_X || - !lock_rec_get_nth_bit(lock, PAGE_HEAP_NO_SUPREMUM)); -retain_lock: - lock= UT_LIST_GET_PREV(trx_locks, lock); - continue; - } - } - else - { - ut_ad(lock_get_type_low(lock) & LOCK_TABLE); - ut_d(dict_table_t *table= lock->un_member.tab_lock.table); - ut_ad(!table->is_temporary()); - - switch (lock_get_mode(lock)) { - case LOCK_IS: - case LOCK_S: - lock_table_dequeue(lock); - break; - case LOCK_IX: - case LOCK_X: - ut_ad(table->id >= DICT_HDR_FIRST_ID || trx->dict_operation); - /* fall through */ - default: - goto retain_lock; - } - } - - if (++count == LOCK_RELEASE_INTERVAL) - { - lock_mutex_exit(); - count= 0; - lock_mutex_enter(); - } - - lock= UT_LIST_GET_LAST(trx->lock.trx_locks); - } - - lock_mutex_exit(); - -} - -/* True if a lock mode is S or X */ -#define IS_LOCK_S_OR_X(lock) \ - (lock_get_mode(lock) == LOCK_S \ - || lock_get_mode(lock) == LOCK_X) - /*********************************************************************//** Removes table locks of the transaction on a table to be dropped. */ static @@ -4502,6 +4428,81 @@ lock_trx_table_locks_remove( ut_error; } +/** Release non-exclusive locks on XA PREPARE, +and release possible other transactions waiting because of these locks. */ +void lock_release_on_prepare(trx_t *trx) +{ + trx->set_skip_lock_inheritance(); + + ulint count= 0; + lock_mutex_enter(); + ut_ad(!trx_mutex_own(trx)); + + for (lock_t *lock= UT_LIST_GET_LAST(trx->lock.trx_locks); lock; ) + { + ut_ad(lock->trx == trx); + + if (lock_get_type_low(lock) == LOCK_REC) + { + ut_ad(!lock->index->table->is_temporary()); + if ((lock->type_mode & (LOCK_MODE_MASK | LOCK_GAP)) != LOCK_X) + lock_rec_dequeue_from_page(lock); + else if (lock_rec_get_nth_bit(lock, PAGE_HEAP_NO_SUPREMUM)) + lock_rec_unlock_supremum(lock); + else + { + ut_ad(trx->dict_operation || + lock->index->table->id >= DICT_HDR_FIRST_ID); + ut_ad(lock->trx->isolation_level > TRX_ISO_READ_COMMITTED || + /* Insert-intention lock is valid for supremum for isolation + level > TRX_ISO_READ_COMMITTED */ + lock_get_mode(lock) == LOCK_X || + !lock_rec_get_nth_bit(lock, PAGE_HEAP_NO_SUPREMUM)); +retain_lock: + lock= UT_LIST_GET_PREV(trx_locks, lock); + continue; + } + } + else + { + ut_ad(lock_get_type_low(lock) & LOCK_TABLE); + ut_d(dict_table_t *table= lock->un_member.tab_lock.table); + ut_ad(!table->is_temporary()); + + switch (lock_get_mode(lock)) { + case LOCK_IS: + case LOCK_S: + lock_table_dequeue(lock); + lock_trx_table_locks_remove(lock); + break; + case LOCK_IX: + case LOCK_X: + ut_ad(table->id >= DICT_HDR_FIRST_ID || trx->dict_operation); + /* fall through */ + default: + goto retain_lock; + } + } + + if (++count == LOCK_RELEASE_INTERVAL) + { + lock_mutex_exit(); + count= 0; + lock_mutex_enter(); + } + + lock= UT_LIST_GET_LAST(trx->lock.trx_locks); + } + + lock_mutex_exit(); + +} + +/* True if a lock mode is S or X */ +#define IS_LOCK_S_OR_X(lock) \ + (lock_get_mode(lock) == LOCK_S \ + || lock_get_mode(lock) == LOCK_X) + /*===================== VALIDATION AND DEBUGGING ====================*/ /** Print info of a table lock. From 3c508d4c71c8bf27c6ecceba53ab9d4325a1bd6c Mon Sep 17 00:00:00 2001 From: Ian Gilfillan Date: Fri, 12 Jul 2024 21:37:48 +0200 Subject: [PATCH 08/12] MDEV-34581: Fix flashback mode man pages --- man/mysqlbinlog.1 | 16 ++++++++++++++++ man/mysqldump.1 | 16 ---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/man/mysqlbinlog.1 b/man/mysqlbinlog.1 index ca41a7b768a..f4de16856e6 100644 --- a/man/mysqlbinlog.1 +++ b/man/mysqlbinlog.1 @@ -573,6 +573,22 @@ privilege\&. .sp -1 .IP \(bu 2.3 .\} +.\" mysqlbinlog: flashback option +.\" flashback option: mysqlbinlog +\fB\-\-flashback\fR, +\fB\-B\fR +.sp +Support flashback mode\&. +.RE +.sp +.RS 4 +.ie n \{\ +\h'-04'\(bu\h'+03'\c +.\} +.el \{\ +.sp -1 +.IP \(bu 2.3 +.\} .\" mysqlbinlog: force-if-open option .\" force-if-open option: mysqlbinlog \fB\-\-force\-if\-open\fR diff --git a/man/mysqldump.1 b/man/mysqldump.1 index f23c7e2491b..cf279599c31 100644 --- a/man/mysqldump.1 +++ b/man/mysqldump.1 @@ -894,22 +894,6 @@ instead\&. .sp -1 .IP \(bu 2.3 .\} -.\" mysqldump: flashback option -.\" flashback option: mysqldump -\fB\-\-flashback\fR, -\fB\-B\fR -.sp -Support flashback mode\&. -.RE -.sp -.RS 4 -.ie n \{\ -\h'-04'\(bu\h'+03'\c -.\} -.el \{\ -.sp -1 -.IP \(bu 2.3 -.\} .\" mysqldump: flush-logs option .\" flush-logs option: mysqldump \fB\-\-flush\-logs\fR, From 3b956f832996f2a133e07afba93d7ae324028b8c Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Wed, 3 Jul 2024 10:22:13 +0800 Subject: [PATCH 09/12] MDEV-34449 Default ha_spider::bulk_size to 0. This fixes a valgrind failure where the bulk_size is used before initialised in ha_spider::end_bulk_insert(). --- storage/spider/ha_spider.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage/spider/ha_spider.h b/storage/spider/ha_spider.h index def8ee169ed..54e14760bcf 100644 --- a/storage/spider/ha_spider.h +++ b/storage/spider/ha_spider.h @@ -151,7 +151,7 @@ public: #ifdef HANDLER_HAS_CAN_USE_FOR_AUTO_INC_INIT bool auto_inc_temporary; #endif - int bulk_size; + int bulk_size= 0; int direct_dup_insert; int store_error_num; uint dup_key_idx; From 46d95ae265bc08063d9636309901e7603b2a9229 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Mon, 15 Jul 2024 14:44:59 +0530 Subject: [PATCH 10/12] MDEV-34474 InnoDB: Failing assertion: stat_n_leaf_pages > 0 in ha_innobase::estimate_rows_upper_bound - Fixing the compilation issue. --- storage/innobase/dict/dict0stats.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/storage/innobase/dict/dict0stats.cc b/storage/innobase/dict/dict0stats.cc index 8ab8cec47e3..496a1a5e6f0 100644 --- a/storage/innobase/dict/dict0stats.cc +++ b/storage/innobase/dict/dict0stats.cc @@ -2670,7 +2670,8 @@ dict_stats_fetch_table_stats_step( ut_a(len == 8); table->stat_clustered_index_size - = std::max(mach_read_from_8(data), 1); + = std::max( + (ulint) mach_read_from_8(data), 1); break; } @@ -2688,7 +2689,7 @@ dict_stats_fetch_table_stats_step( } table->stat_sum_of_other_index_sizes = std::max( - mach_read_from_8(data), + (ulint) mach_read_from_8(data), UT_LIST_GET_LEN(table->indexes) - 1); break; @@ -2876,13 +2877,13 @@ dict_stats_fetch_index_stats_step( if (stat_name_len == 4 /* strlen("size") */ && strncasecmp("size", stat_name, stat_name_len) == 0) { index->stat_index_size - = std::max(stat_value, 1); + = std::max((ulint) stat_value, 1); arg->stats_were_modified = true; } else if (stat_name_len == 12 /* strlen("n_leaf_pages") */ && strncasecmp("n_leaf_pages", stat_name, stat_name_len) == 0) { index->stat_n_leaf_pages - = std::max(stat_value, 1); + = std::max((ulint) stat_value, 1); arg->stats_were_modified = true; } else if (stat_name_len == 12 /* strlen("n_page_split") */ && strncasecmp("n_page_split", stat_name, stat_name_len) From 405613ebb5f2f66e6c0d3f6ff4059b63170dfd11 Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Wed, 3 Jul 2024 15:42:21 +0700 Subject: [PATCH 11/12] MDEV-34490 get_copy() and build_clone() may return an instance of an ancestor class instead of a copy/clone The `Item` class methods `get_copy()`, `build_clone()`, and `clone_item()` face an issue where they may be defined in a descendant class (e.g., `Item_func`) but not in a further descendant (e.g., `Item_func_child`). This can lead to scenarios where `build_clone()`, when operating on an instance of `Item_func_child` with a pointer to the base class (`Item`), returns an instance of `Item_func` instead of `Item_func_child`. Since this limitation cannot be resolved at compile time, this commit introduces runtime type checks for the copy/clone operations. A debug assertion will now trigger in case of a type mismatch. `get_copy()`, `build_clone()`, and `clone_item()` are no more virtual, but virtual `do_get_copy()`, `do_build_clone()`, and `do_clone_item()` are added to the protected section of the class `Item`. Additionally, const qualifiers have been added to certain methods to enhance code reliability. Reviewer: Oleksandr Byelkin --- plugin/func_test/plugin.cc | 2 +- plugin/type_inet/item_inetfunc.h | 16 +- plugin/type_inet/sql_type_inet.cc | 11 +- sql/item.cc | 39 ++--- sql/item.h | 251 ++++++++++++++++++++++-------- sql/item_cmpfunc.cc | 9 +- sql/item_cmpfunc.h | 94 +++++------ sql/item_func.h | 173 ++++++++++---------- sql/item_geofunc.h | 86 +++++----- sql/item_jsonfunc.h | 50 +++--- sql/item_row.cc | 2 +- sql/item_row.h | 4 +- sql/item_strfunc.h | 162 +++++++++---------- sql/item_subselect.h | 4 +- sql/item_sum.h | 44 +++--- sql/item_timefunc.h | 96 ++++++------ sql/item_vers.h | 8 +- sql/item_windowfunc.h | 28 ++-- sql/item_xmlfunc.cc | 34 ++-- sql/item_xmlfunc.h | 4 +- sql/procedure.h | 6 +- sql/sql_list.h | 7 +- sql/sql_select.cc | 4 +- sql/sql_string.h | 2 +- 24 files changed, 632 insertions(+), 504 deletions(-) diff --git a/plugin/func_test/plugin.cc b/plugin/func_test/plugin.cc index 00fc0039de8..c120cfd6993 100644 --- a/plugin/func_test/plugin.cc +++ b/plugin/func_test/plugin.cc @@ -37,7 +37,7 @@ public: } const char *func_name() const override { return "sysconst_test"; } const char *fully_qualified_func_name() const override { return "sysconst_test()"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; diff --git a/plugin/type_inet/item_inetfunc.h b/plugin/type_inet/item_inetfunc.h index 813181b065a..dc783d0328d 100644 --- a/plugin/type_inet/item_inetfunc.h +++ b/plugin/type_inet/item_inetfunc.h @@ -41,7 +41,7 @@ public: unsigned_flag= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -64,7 +64,7 @@ public: maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -108,7 +108,7 @@ public: maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } String *val_str(String *to) override; @@ -143,7 +143,7 @@ public: return FALSE; } String *val_str_ascii(String *to) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -162,7 +162,7 @@ public: public: const char *func_name() const override { return "is_ipv4"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } longlong val_int() override; @@ -182,7 +182,7 @@ public: const char *func_name() const override { return "is_ipv6"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } longlong val_int() override; @@ -201,7 +201,7 @@ public: { } const char *func_name() const override { return "is_ipv4_compat"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } longlong val_int() override; }; @@ -219,7 +219,7 @@ public: { } const char *func_name() const override { return "is_ipv4_mapped"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } longlong val_int() override; }; diff --git a/plugin/type_inet/sql_type_inet.cc b/plugin/type_inet/sql_type_inet.cc index 880cf50c98a..b566e3c1f9d 100644 --- a/plugin/type_inet/sql_type_inet.cc +++ b/plugin/type_inet/sql_type_inet.cc @@ -1090,7 +1090,7 @@ public: Inet6_null tmp(args[0]); return null_value= tmp.is_null() || tmp.to_native(to); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1102,8 +1102,9 @@ public: Item_cache_inet6(THD *thd) :Item_cache(thd, &type_handler_inet6) { } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } bool cache_value() override { if (!example) @@ -1225,8 +1226,9 @@ public: str->append(tmp); str->append('\''); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } // Non-overriding methods void set_value(const Inet6 &value) @@ -1282,8 +1284,9 @@ public: { return Item::save_in_field(field, no_conversions); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; diff --git a/sql/item.cc b/sql/item.cc index e1ad7e7d13b..063003ee6bf 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -2715,7 +2715,7 @@ bool Type_std_attributes::agg_item_set_converter(const DTCollation &coll, @retval 0 on a failure */ -Item* Item_func_or_sum::build_clone(THD *thd) +Item* Item_func_or_sum::do_build_clone(THD *thd) const { Item *copy_tmp_args[2]= {0,0}; Item **copy_args= copy_tmp_args; @@ -3035,7 +3035,7 @@ Item_sp::init_result_field(THD *thd, uint max_length, uint maybe_null, 0 if an error occurred */ -Item* Item_ref::build_clone(THD *thd) +Item* Item_ref::do_build_clone(THD *thd) const { Item_ref *copy= (Item_ref *) get_copy(thd); if (unlikely(!copy) || @@ -3847,7 +3847,7 @@ void Item_decimal::set_decimal_value(my_decimal *value_par) } -Item *Item_decimal::clone_item(THD *thd) +Item *Item_decimal::do_clone_const_item(THD *thd) const { return new (thd->mem_root) Item_decimal(thd, name.str, &decimal_value, decimals, max_length); @@ -3868,7 +3868,7 @@ my_decimal *Item_float::val_decimal(my_decimal *decimal_value) } -Item *Item_float::clone_item(THD *thd) +Item *Item_float::do_clone_const_item(THD *thd) const { return new (thd->mem_root) Item_float(thd, name.str, value, decimals, max_length); @@ -4032,7 +4032,7 @@ Item *Item_null::safe_charset_converter(THD *thd, CHARSET_INFO *tocs) return this; } -Item *Item_null::clone_item(THD *thd) +Item *Item_null::do_clone_const_item(THD *thd) const { return new (thd->mem_root) Item_null(thd, name.str); } @@ -4837,7 +4837,7 @@ bool Item_param::basic_const_item() const } -Item *Item_param::value_clone_item(THD *thd) +Item *Item_param::value_clone_item(THD *thd) const { MEM_ROOT *mem_root= thd->mem_root; switch (value.type_handler()->cmp_type()) { @@ -4851,12 +4851,15 @@ Item *Item_param::value_clone_item(THD *thd) case DECIMAL_RESULT: return 0; // Should create Item_decimal. See MDEV-11361. case STRING_RESULT: + { + String value_copy = value.m_string; // to preserve constness of the func return new (mem_root) Item_string(thd, name, - Lex_cstring(value.m_string.c_ptr_quick(), - value.m_string.length()), - value.m_string.charset(), + Lex_cstring(value_copy.c_ptr_quick(), + value_copy.length()), + value_copy.charset(), collation.derivation, collation.repertoire); + } case TIME_RESULT: break; case ROW_RESULT: @@ -4870,7 +4873,7 @@ Item *Item_param::value_clone_item(THD *thd) /* see comments in the header file */ Item * -Item_param::clone_item(THD *thd) +Item_param::do_clone_const_item(THD *thd) const { // There's no "default". See comments in Item_param::save_in_field(). switch (state) { @@ -6950,7 +6953,7 @@ int Item_string::save_in_field(Field *field, bool no_conversions) } -Item *Item_string::clone_item(THD *thd) +Item *Item_string::do_clone_const_item(THD *thd) const { LEX_CSTRING val; str_value.get_value(&val); @@ -7014,7 +7017,7 @@ int Item_int::save_in_field(Field *field, bool no_conversions) } -Item *Item_int::clone_item(THD *thd) +Item *Item_int::do_clone_const_item(THD *thd) const { return new (thd->mem_root) Item_int(thd, name.str, value, max_length, unsigned_flag); } @@ -7043,7 +7046,7 @@ int Item_decimal::save_in_field(Field *field, bool no_conversions) } -Item *Item_int_with_ref::clone_item(THD *thd) +Item *Item_int_with_ref::do_clone_const_item(THD *thd) const { DBUG_ASSERT(ref->const_item()); /* @@ -7139,7 +7142,7 @@ Item *Item_uint::neg(THD *thd) } -Item *Item_uint::clone_item(THD *thd) +Item *Item_uint::do_clone_const_item(THD *thd) const { return new (thd->mem_root) Item_uint(thd, name.str, value, max_length); } @@ -7379,7 +7382,7 @@ void Item_date_literal::print(String *str, enum_query_type query_type) } -Item *Item_date_literal::clone_item(THD *thd) +Item *Item_date_literal::do_clone_const_item(THD *thd) const { return new (thd->mem_root) Item_date_literal(thd, &cached_time); } @@ -7404,7 +7407,7 @@ void Item_datetime_literal::print(String *str, enum_query_type query_type) } -Item *Item_datetime_literal::clone_item(THD *thd) +Item *Item_datetime_literal::do_clone_const_item(THD *thd) const { return new (thd->mem_root) Item_datetime_literal(thd, &cached_time, decimals); } @@ -7429,7 +7432,7 @@ void Item_time_literal::print(String *str, enum_query_type query_type) } -Item *Item_time_literal::clone_item(THD *thd) +Item *Item_time_literal::do_clone_const_item(THD *thd) const { return new (thd->mem_root) Item_time_literal(thd, &cached_time, decimals); } @@ -10388,7 +10391,7 @@ void Item_cache_temporal::store_packed(longlong val_arg, Item *example_arg) } -Item *Item_cache_temporal::clone_item(THD *thd) +Item *Item_cache_temporal::do_clone_const_item(THD *thd) const { Item_cache *tmp= type_handler()->Item_get_cache(thd, this); Item_cache_temporal *item= static_cast(tmp); diff --git a/sql/item.h b/sql/item.h index 6e8bcd347a4..19f95c5875f 100644 --- a/sql/item.h +++ b/sql/item.h @@ -30,6 +30,7 @@ #include "sql_time.h" #include "sql_schema.h" #include "mem_root_array.h" +#include C_MODE_START #include @@ -1658,10 +1659,61 @@ public: raise_error_not_evaluable(); return true; // Error } - /* cloning of constant items (0 if it is not const) */ - virtual Item *clone_item(THD *thd) { return 0; } - /* deep copy item */ - virtual Item* build_clone(THD *thd) { return get_copy(thd); } + + /* + Create a shallow copy of the item (usually invoking copy constructor). + For deep copying see build_clone(). + + Return value: + - pointer to a copy of the Item + - nullptr if the item is not copyable + */ + Item *get_copy(THD *thd) const + { + Item *copy= do_get_copy(thd); + if (copy) + { + // Make sure the copy is of same type as this item + DBUG_ASSERT(typeid(*copy) == typeid(*this)); + } + return copy; + } + + /* + Creates a clone of the item by deep copying. + + Return value: + - pointer to a clone of the Item + - nullptr if the item is not clonable + */ + Item* build_clone(THD *thd) const + { + Item *clone= do_build_clone(thd); + if (clone) + { + // Make sure the clone is of same type as this item + DBUG_ASSERT(typeid(*clone) == typeid(*this)); + } + return clone; + } + + /* + Clones the constant item + + Return value: + - pointer to a clone of the Item + - nullptr if the item is not clonable */ + Item *clone_const_item(THD *thd) const + { + Item *clone= do_clone_const_item(thd); + if (clone) + { + // Make sure the clone is of same type as this item + DBUG_ASSERT(typeid(*clone) == typeid(*this)); + } + return clone; + } + virtual cond_result eq_cmp_result() const { return COND_OK; } inline uint float_length(uint decimals_par) const { return decimals < FLOATING_POINT_DECIMALS ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;} @@ -2189,12 +2241,6 @@ public: */ virtual bool find_not_null_fields(table_map allowed) { return false; } - /* - Does not guarantee deep copy (depends on copy ctor). - See build_clone() for deep copy. - */ - virtual Item *get_copy(THD *thd)=0; - bool cache_const_expr_analyzer(uchar **arg); Item* cache_const_expr_transformer(THD *thd, uchar *arg); @@ -2527,12 +2573,33 @@ public: DBUG_ASSERT(is_fixed()); return false; } + +protected: + /* + Service function for public method get_copy(). See comments for get_copy() + above. Override this method in derived classes to create shallow copies of + the item + */ + virtual Item *do_get_copy(THD *thd) const = 0; + + /* + Service function for public method build_clone(). See comments for + build_clone() above. Override this method in derived classes to create + deep copies (clones) of the item where possible + */ + virtual Item* do_build_clone(THD *thd) const = 0; + + /* + Service function for public method clone_const_item(). See comments for + clone_const_item() above + */ + virtual Item *do_clone_const_item(THD *thd) const { return nullptr; } }; MEM_ROOT *get_thd_memroot(THD *thd); template -inline Item* get_item_copy (THD *thd, T* item) +inline Item* get_item_copy (THD *thd, const T* item) { Item *copy= new (get_thd_memroot(thd)) T(*item); if (likely(copy)) @@ -3040,7 +3107,8 @@ public: bool append_for_log(THD *thd, String *str) override; - Item *get_copy(THD *) override { return nullptr; } + Item *do_get_copy(THD *) const override { return nullptr; } + Item *do_build_clone(THD *thd) const override { return nullptr; } /* Override the inherited create_field_for_create_select(), @@ -3085,6 +3153,9 @@ public: :Item_splocal(thd, rh, sp_var_name, sp_var_idx, &type_handler_null, pos_in_q, len_in_q) { } + + Item *do_get_copy(THD *) const override { return nullptr; } + Item *do_build_clone(THD *thd) const override { return nullptr; } }; @@ -3117,6 +3188,9 @@ public: Item **this_item_addr(THD *thd, Item **) override; bool append_for_log(THD *thd, String *str) override; void print(String *str, enum_query_type query_type) override; + + Item *do_get_copy(THD *) const override { return nullptr; } + Item *do_build_clone(THD *thd) const override { return nullptr; } }; @@ -3137,6 +3211,9 @@ public: { } bool fix_fields(THD *thd, Item **it) override; void print(String *str, enum_query_type query_type) override; + + Item *do_get_copy(THD *) const override { return nullptr; } + Item *do_build_clone(THD *thd) const override { return nullptr; } }; @@ -3180,7 +3257,8 @@ public: purposes. */ void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *) override { return nullptr; } + Item *do_get_copy(THD *) const override { return nullptr; } + Item *do_build_clone(THD *thd) const override { return nullptr; } private: uint m_case_expr_id; @@ -3260,8 +3338,9 @@ public: { return mark_unsupported_function("name_const()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -3627,8 +3706,9 @@ public: bool cleanup_excluding_const_fields_processor(void *arg) override { return field && const_item() ? 0 : cleanup_processor(arg); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item* do_build_clone(THD *thd) const override { return get_copy(thd); } bool is_outer_field() const override { DBUG_ASSERT(fixed); @@ -3652,7 +3732,7 @@ public: :Item_field(thd, field), Item_args() { } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } const Type_handler *type_handler() const override @@ -3740,7 +3820,7 @@ public: const Type_handler *type_handler() const override { return &type_handler_null; } bool basic_const_item() const override { return true; } - Item *clone_item(THD *thd) override; + Item *do_clone_const_item(THD *thd) const override; bool const_is_null() const override { return true; } bool is_null() override { return true; } @@ -3754,8 +3834,9 @@ public: Item_basic_constant *make_string_literal_concat(THD *thd, const LEX_CSTRING *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; class Item_null_result :public Item_null @@ -3964,7 +4045,7 @@ class Item_param :public Item_basic_value, PValue value; const String *value_query_val_str(THD *thd, String* str) const; - Item *value_clone_item(THD *thd); + Item *value_clone_item(THD *thd) const; bool is_evaluable_expression() const override; bool can_return_value() const; @@ -4189,7 +4270,7 @@ public: basic_const_item returned TRUE. */ Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs) override; - Item *clone_item(THD *thd) override; + Item *do_clone_const_item(THD *thd) const override; void set_param_type_and_swap_value(Item_param *from); Rewritable_query_parameter *get_rewritable_query_parameter() override @@ -4199,7 +4280,8 @@ public: bool append_for_log(THD *thd, String *str) override; bool check_vcol_func_processor(void *) override { return false; } - Item *get_copy(THD *) override { return nullptr; } + Item *do_get_copy(THD *thd) const override { return nullptr; } + Item *do_build_clone(THD *thd) const override { return nullptr; } bool add_as_clone(THD *thd); void sync_clones(); @@ -4287,13 +4369,14 @@ public: String *val_str(String*) override; int save_in_field(Field *field, bool no_conversions) override; bool is_order_clause_position() const override { return true; } - Item *clone_item(THD *thd) override; + Item *do_clone_const_item(THD *thd) const override; void print(String *str, enum_query_type query_type) override; Item *neg(THD *thd) override; uint decimal_precision() const override { return (uint) (max_length - MY_TEST(value < 0)); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -4321,6 +4404,9 @@ public: predicate at various condition optimization stages in sql_select. */ } + Item *do_get_copy(THD *thd) const override + { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -4331,10 +4417,10 @@ public: Item_uint(THD *thd, ulonglong i): Item_int(thd, i, 10) {} Item_uint(THD *thd, const char *str_arg, longlong i, uint length); double val_real() override { return ulonglong2double((ulonglong)value); } - Item *clone_item(THD *thd) override; + Item *do_clone_const_item(THD *thd) const override; Item *neg(THD *thd) override; uint decimal_precision() const override { return max_length; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -4382,7 +4468,7 @@ public: const my_decimal *const_ptr_my_decimal() const override { return &decimal_value; } int save_in_field(Field *field, bool no_conversions) override; - Item *clone_item(THD *thd) override; + Item *do_clone_const_item(THD *thd) const override; void print(String *str, enum_query_type query_type) override { decimal_value.to_string(&str_value); @@ -4391,8 +4477,9 @@ public: Item *neg(THD *thd) override; uint decimal_precision() const override { return decimal_value.precision(); } void set_decimal_value(my_decimal *value_par); - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -4434,11 +4521,12 @@ public: } String *val_str(String*) override; my_decimal *val_decimal(my_decimal *) override; - Item *clone_item(THD *thd) override; + Item *do_clone_const_item(THD *thd) const override; Item *neg(THD *thd) override; void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -4556,7 +4644,7 @@ public: int save_in_field(Field *field, bool no_conversions) override; const Type_handler *type_handler() const override { return &type_handler_varchar; } - Item *clone_item(THD *thd) override; + Item *do_clone_const_item(THD *thd) const override; Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs) override { return const_charset_converter(thd, tocs, true); @@ -4600,8 +4688,9 @@ public: override; Item *make_odbc_literal(THD *thd, const LEX_CSTRING *typestr) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -4621,6 +4710,9 @@ public: { return true; } + Item *do_get_copy(THD *thd) const override + { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -4809,8 +4901,9 @@ public: return field->store_hex_hybrid(str_value.ptr(), str_value.length()); } void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -4848,8 +4941,9 @@ public: collation.collation); } void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -4905,8 +4999,9 @@ public: { m_value= value; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -4972,7 +5067,7 @@ public: { return cached_time.get_mysql_time(); } - Item *clone_item(THD *thd) override; + Item *do_clone_const_item(THD *thd) const override; longlong val_int() override { return update_null() ? 0 : cached_time.to_longlong(); @@ -4994,8 +5089,9 @@ public: return update_null() ? 0 : cached_time.valid_date_to_packed(); } bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -5021,7 +5117,7 @@ public: { return cached_time.get_mysql_time(); } - Item *clone_item(THD *thd) override; + Item *do_clone_const_item(THD *thd) const override; longlong val_int() override { return cached_time.to_longlong(); } double val_real() override { return cached_time.to_double(); } String *val_str(String *to) override @@ -5037,8 +5133,9 @@ public: { return Time(thd, this).to_native(to, decimals); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -5071,7 +5168,7 @@ public: { return cached_time.get_mysql_time(); } - Item *clone_item(THD *thd) override; + Item *do_clone_const_item(THD *thd) const override; longlong val_int() override { return update_null() ? 0 : cached_time.to_longlong(); @@ -5093,8 +5190,9 @@ public: return update_null() ? 0 : cached_time.valid_datetime_to_packed(); } bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -5355,7 +5453,7 @@ public: virtual bool fix_length_and_dec()= 0; bool const_item() const override { return const_item_cache; } table_map used_tables() const override { return used_tables_cache; } - Item* build_clone(THD *thd) override; + Item* do_build_clone(THD *thd) const override; Sql_mode_dependency value_depends_on_sql_mode() const override { return Item_args::value_depends_on_sql_mode_bit_or().soft_to_hard(); @@ -5602,13 +5700,13 @@ public: return (*ref)->is_outer_field(); } - Item* build_clone(THD *thd) override; + Item *do_build_clone(THD *thd) const override; /** Checks if the item tree that ref points to contains a subquery. */ bool with_subquery() const override { return (*ref)->with_subquery(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } bool excl_dep_on_table(table_map tab_map) override { @@ -5691,7 +5789,7 @@ public: longlong val_datetime_packed(THD *) override; longlong val_time_packed(THD *) override; Ref_Type ref_type() override { return DIRECT_REF; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } Item *remove_item_direct_ref() override { return (*ref)->remove_item_direct_ref(); } @@ -5859,9 +5957,9 @@ public: { return mark_unsupported_function("cache", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } - Item *build_clone(THD *) override { return nullptr; } + Item *do_build_clone(THD *) const override { return nullptr; } }; @@ -6073,7 +6171,7 @@ public: my_decimal *val_decimal_result(my_decimal *val) override; bool val_bool_result() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } Item *field_transformer_for_having_pushdown(THD *, uchar *) override { return this; } @@ -6136,6 +6234,9 @@ public: table_map not_null_tables() const override { return 0; } Ref_Type ref_type() override { return OUTER_REF; } bool check_inner_refs_processor(void * arg) override; + Item *do_get_copy(THD *thd) const override + { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -6172,7 +6273,7 @@ public: bool val_native(THD *thd, Native *to) override; void print(String *str, enum_query_type query_type) override; table_map used_tables() const override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -6198,7 +6299,7 @@ public: { return ref->save_in_field(field, no_conversions); } - Item *clone_item(THD *thd) override; + Item *do_clone_const_item(THD *thd) const override; Item *real_item() override { return ref; } }; @@ -6335,8 +6436,9 @@ public: { return get_date_from_string(thd, ltime, fuzzydate); } void copy() override; int save_in_field(Field *field, bool no_conversions) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -6406,8 +6508,9 @@ public: DBUG_ASSERT(sane()); return null_value || m_value.to_native(to, decimals); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -6687,8 +6790,9 @@ public: param->set_default(); return false; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -6721,8 +6825,9 @@ public: return false; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -7064,8 +7169,9 @@ public: bool cache_value() override; int save_in_field(Field *field, bool no_conversions) override; Item *convert_to_basic_const_item(THD *thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -7078,6 +7184,7 @@ public: { return type_handler_year.Item_get_date_with_warn(thd, this, to, mode); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -7102,7 +7209,7 @@ public: is a constant and need not be optimized further. Important when storing packed datetime values. */ - Item *clone_item(THD *thd) override; + Item *do_clone_const_item(THD *thd) const override; Item *convert_to_basic_const_item(THD *thd) override; virtual Item *make_literal(THD *) =0; }; @@ -7114,7 +7221,7 @@ public: Item_cache_time(THD *thd) :Item_cache_temporal(thd, &type_handler_time2) { } bool cache_value() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } Item *make_literal(THD *) override; longlong val_datetime_packed(THD *thd) override @@ -7154,7 +7261,7 @@ class Item_cache_datetime: public Item_cache_temporal public: Item_cache_datetime(THD *thd) :Item_cache_temporal(thd, &type_handler_datetime2) { } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } Item *make_literal(THD *) override; longlong val_datetime_packed(THD *) override @@ -7189,7 +7296,7 @@ class Item_cache_date: public Item_cache_temporal public: Item_cache_date(THD *thd) :Item_cache_temporal(thd, &type_handler_newdate) { } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } Item *make_literal(THD *) override; longlong val_datetime_packed(THD *) override @@ -7222,8 +7329,9 @@ class Item_cache_timestamp: public Item_cache public: Item_cache_timestamp(THD *thd) :Item_cache(thd, &type_handler_timestamp2) { } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } bool cache_value() override; String* val_str(String *to) override { @@ -7282,8 +7390,9 @@ public: :Item_cache_real(thd, &type_handler_double) { } String* val_str(String *str) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -7294,8 +7403,9 @@ public: :Item_cache_real(thd, &type_handler_float) { } String* val_str(String *str) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -7317,8 +7427,9 @@ public: } bool cache_value() override; Item *convert_to_basic_const_item(THD *thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -7347,8 +7458,9 @@ public: int save_in_field(Field *field, bool no_conversions) override; bool cache_value() override; Item *convert_to_basic_const_item(THD *thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -7372,8 +7484,9 @@ public: */ return Item::safe_charset_converter(thd, tocs); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -7449,8 +7562,9 @@ public: } bool cache_value() override; void set_null() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -7531,7 +7645,8 @@ public: make_and_init_table_field(root, &name, Record_addr(maybe_null), *this, table); } - Item* get_copy(THD *) override { return nullptr; } + Item *do_get_copy(THD *thd) const override { return nullptr; } + Item *do_build_clone(THD *thd) const override { return nullptr; } }; @@ -7686,7 +7801,7 @@ public: Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs) override; Item *get_tmp_table_item(THD *thd) override { return m_item->get_tmp_table_item(thd); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } COND *build_equal_items(THD *thd, COND_EQUAL *inherited, bool link_item_fields, @@ -7756,7 +7871,7 @@ public: { return m_item->excl_dep_on_grouping_fields(sel); } bool is_expensive() override { return m_item->is_expensive(); } void set_item(Item *item) { m_item= item; } - Item *build_clone(THD *thd) override + Item *do_build_clone(THD *thd) const override { Item *clone_item= m_item->build_clone(thd); if (clone_item) diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index c17a7d57545..2f9da57cdba 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -5465,17 +5465,16 @@ void Item_cond::neg_arguments(THD *thd) 0 if an error occurred */ -Item *Item_cond::build_clone(THD *thd) +Item *Item_cond::do_build_clone(THD *thd) const { - List_iterator_fast li(list); - Item *item; Item_cond *copy= (Item_cond *) get_copy(thd); if (!copy) return 0; copy->list.empty(); - while ((item= li++)) + + for (const Item &item : list) { - Item *arg_clone= item->build_clone(thd); + Item *arg_clone= item.build_clone(thd); if (!arg_clone) return 0; if (copy->list.push_back(arg_clone, thd->mem_root)) diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index e2e743fa075..d394d932adf 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -288,7 +288,7 @@ public: Item_func_istrue(THD *thd, Item *a): Item_func_truth(thd, a, true, true) {} ~Item_func_istrue() = default; const char* func_name() const override { return "istrue"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -305,7 +305,7 @@ public: ~Item_func_isnottrue() = default; const char* func_name() const override { return "isnottrue"; } bool find_not_null_fields(table_map allowed) override { return false; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } bool eval_not_null_tables(void *) override { not_null_tables_cache= 0; return false; } }; @@ -321,7 +321,7 @@ public: Item_func_isfalse(THD *thd, Item *a): Item_func_truth(thd, a, false, true) {} ~Item_func_isfalse() = default; const char* func_name() const override { return "isfalse"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -338,7 +338,7 @@ public: ~Item_func_isnotfalse() = default; const char* func_name() const override { return "isnotfalse"; } bool find_not_null_fields(table_map allowed) override { return false; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } bool eval_not_null_tables(void *) override { not_null_tables_cache= 0; return false; } }; @@ -408,7 +408,7 @@ public: void restore_first_argument(); Item* get_wrapped_in_subselect_item() { return args[1]; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } enum precedence precedence() const override { return args[1]->precedence(); } }; @@ -579,10 +579,10 @@ public: return add_key_fields_optimize_op(join, key_fields, and_level, usable_tables, sargables, false); } - Item *build_clone(THD *thd) override + Item *do_build_clone(THD *thd) const override { Item_bool_rowready_func2 *clone= - (Item_bool_rowready_func2 *) Item_func::build_clone(thd); + (Item_bool_rowready_func2 *) Item_func::do_build_clone(thd); if (clone) { clone->cmp.comparators= 0; @@ -613,7 +613,7 @@ public: Item_args::propagate_equal_fields(thd, Context_boolean(), cond); return this; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -633,7 +633,7 @@ public: Item *neg_transformer(THD *thd) override; bool fix_fields(THD *, Item **) override; void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -682,7 +682,7 @@ public: void add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level, table_map usable_tables, SARGABLE_PARAM **sargables) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -722,7 +722,7 @@ public: longlong val_int() override; const char *func_name() const override { return ""; } Item *neg_transformer(THD *thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -763,7 +763,7 @@ public: uint in_equality_no; uint exists2in_reserved_items() override { return 1; }; friend class Arg_comparator; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -788,7 +788,7 @@ public: return add_key_fields_optimize_op(join, key_fields, and_level, usable_tables, sargables, true); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -804,7 +804,7 @@ public: cond_result eq_cmp_result() const override { return COND_TRUE; } const char *func_name() const override { return ">="; } Item *negated_item(THD *thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -820,7 +820,7 @@ public: cond_result eq_cmp_result() const override { return COND_FALSE; } const char *func_name() const override { return ">"; } Item *negated_item(THD *thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -836,7 +836,7 @@ public: cond_result eq_cmp_result() const override { return COND_TRUE; } const char *func_name() const override { return "<="; } Item *negated_item(THD *thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -852,7 +852,7 @@ public: cond_result eq_cmp_result() const override { return COND_FALSE; } const char *func_name() const override { return "<"; } Item *negated_item(THD *thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -873,7 +873,7 @@ public: Item *negated_item(THD *thd) override; void add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level, table_map usable_tables, SARGABLE_PARAM **sargables) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -968,7 +968,7 @@ public: cond); return this; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } longlong val_int_cmp_string(); @@ -1000,7 +1000,7 @@ public: fix_char_length(2); // returns "1" or "0" or "-1" return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1035,7 +1035,7 @@ public: str->append(func_name()); print_args(str, 0, query_type); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1063,7 +1063,7 @@ public: } const char *func_name() const override { return "coalesce"; } table_map not_null_tables() const override { return 0; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1154,7 +1154,7 @@ public: const char *func_name() const override { return "ifnull"; } table_map not_null_tables() const override { return 0; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1227,7 +1227,7 @@ public: const char *func_name() const override { return "if"; } bool eval_not_null_tables(void *opt_arg) override; void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } private: void cache_type_info(Item *source); @@ -1248,7 +1248,7 @@ public: { return fix_length_and_dec2_eliminate_null(args + 1); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1337,7 +1337,7 @@ public: cond, &args[2]); return this; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } Item *derived_field_transformer_for_having(THD *thd, uchar *arg) override { reset_first_arg_if_needed(); return this; } @@ -2273,7 +2273,7 @@ public: return this; } Item *find_item() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2321,7 +2321,7 @@ public: bool fix_length_and_dec() override; Item *propagate_equal_fields(THD *thd, const Context &ctx, COND_EQUAL *cond) override; Item *find_item() override; - Item *build_clone(THD *thd) override + Item *do_build_clone(THD *thd) const override { Item_func_case_simple *clone= (Item_func_case_simple *) Item_func_case::build_clone(thd); @@ -2330,7 +2330,7 @@ public: return NULL; return clone; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2346,7 +2346,7 @@ public: void print(String *str, enum_query_type query_type) override; bool fix_length_and_dec() override; Item *find_item() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2511,11 +2511,11 @@ public: bool find_not_null_fields(table_map allowed) override; void fix_after_pullout(st_select_lex *new_parent, Item **ref, bool merge) override; bool count_sargable_conds(void *arg) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } - Item *build_clone(THD *thd) override + Item *do_build_clone(THD *thd) const override { - Item_func_in *clone= (Item_func_in *) Item_func::build_clone(thd); + Item_func_in *clone= (Item_func_in *) Item_func::do_build_clone(thd); if (clone) { clone->array= 0; @@ -2655,7 +2655,7 @@ public: table_map not_null_tables() const override { return 0; } bool find_not_null_fields(table_map allowed) override; Item *neg_transformer(THD *thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2703,7 +2703,7 @@ public: Item *neg_transformer(THD *thd) override; void print(String *str, enum_query_type query_type) override; void top_level_item() override { abort_on_null=1; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2856,7 +2856,7 @@ public: bool find_selective_predicates_list_processor(void *arg) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2949,7 +2949,7 @@ public: bool fix_length_and_dec() override; const char *func_name() const override { return "regexp"; } enum precedence precedence() const override { return IN_PRECEDENCE; } - Item *get_copy(THD *) override { return 0; } + Item *do_get_copy(THD *thd) const override { return 0; } void print(String *str, enum_query_type query_type) override { print_op(str, query_type); @@ -2988,7 +2988,7 @@ public: longlong val_int() override; bool fix_length_and_dec() override; const char *func_name() const override { return "regexp_instr"; } - Item *get_copy(THD *thd) override { return 0; } + Item *do_get_copy(THD *thd) const override { return 0; } }; @@ -3084,7 +3084,7 @@ public: } bool eval_not_null_tables(void *opt_arg) override; bool find_not_null_fields(table_map allowed) override; - Item *build_clone(THD *thd) override; + Item *do_build_clone(THD *thd) const override; bool excl_dep_on_table(table_map tab_map) override; bool excl_dep_on_grouping_fields(st_select_lex *sel) override; @@ -3268,7 +3268,7 @@ public: void set_context_field(Item_field *ctx_field) { context_field= ctx_field; } void set_link_equal_fields(bool flag) { link_equal_fields= flag; } - Item* get_copy(THD *thd) override { return 0; } + Item* do_get_copy(THD *thd) const override { return 0; } /* This does not comply with the specification of the virtual method, but Item_equal items are processed distinguishly anyway @@ -3433,7 +3433,7 @@ public: void add_key_fields(JOIN *join, KEY_FIELD **key_fields, uint *and_level, table_map usable_tables, SARGABLE_PARAM **sargables) override; SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param, Item **cond_ptr) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3457,7 +3457,7 @@ public: table_map not_null_tables() const override { return and_tables_cache; } Item *copy_andor_structure(THD *thd) override; Item *neg_transformer(THD *thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3468,7 +3468,7 @@ public: longlong val_int() override; const char *func_name() const override { return "column_check"; } bool need_parentheses_in_default() override { return false; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3480,7 +3480,7 @@ public: longlong val_int() override; const char *func_name() const override { return "column_exists"; } bool need_parentheses_in_default() override { return false; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3509,7 +3509,7 @@ public: :Item_func_cursor_bool_attr(thd, name, offset) { } const char *func_name() const override { return "%ISOPEN"; } longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3521,7 +3521,7 @@ public: :Item_func_cursor_bool_attr(thd, name, offset) { maybe_null= true; } const char *func_name() const override { return "%FOUND"; } longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3533,7 +3533,7 @@ public: :Item_func_cursor_bool_attr(thd, name, offset) { maybe_null= true; } const char *func_name() const override { return "%NOTFOUND"; } longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; diff --git a/sql/item_func.h b/sql/item_func.h index 015f6ca8106..9e6ab703dad 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1265,7 +1265,7 @@ public: longlong val_int() override; bool fix_length_and_dec() override; const Type_handler *type_handler() const override { return &type_handler_slong; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } const char *func_name() const override { return ""; } }; @@ -1277,7 +1277,7 @@ public: :Item_func_hash(thd, item) {} longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } const char *func_name() const override { return ""; } }; @@ -1332,7 +1332,7 @@ public: { return Cursor_ref::print_func(str, func_name()); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1352,7 +1352,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1419,7 +1419,7 @@ public: void print(String *str, enum_query_type query_type) override; uint decimal_precision() const override { return args[0]->decimal_precision(); } bool need_parentheses_in_default() override { return true; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1450,7 +1450,7 @@ public: } uint decimal_precision() const override { return max_length; } void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1486,7 +1486,7 @@ public: const char *func_name() const override { return "decimal_typecast"; } void print(String *str, enum_query_type query_type) override; bool need_parentheses_in_default() override { return true; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1533,7 +1533,7 @@ public: nr.to_string(str, decimals); return str; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1551,7 +1551,7 @@ public: } const char *func_name() const override { return "double_typecast"; } double val_real() override { return val_real_with_truncate(DBL_MAX); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1577,7 +1577,7 @@ public: longlong int_op() override; double real_op() override; my_decimal *decimal_op(my_decimal *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1612,7 +1612,7 @@ public: Item_func_additive_op::fix_length_and_dec_int(); fix_unsigned_flag(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1631,7 +1631,7 @@ public: bool fix_length_and_dec() override; bool check_partition_func_processor(void *int_arg) override {return FALSE;} bool check_vcol_func_processor(void *arg) override { return FALSE;} - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1650,7 +1650,7 @@ public: void fix_length_and_dec_double(); void fix_length_and_dec_int(); void result_precision() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1674,7 +1674,7 @@ public: bool check_partition_func_processor(void *int_arg) override {return FALSE;} bool check_vcol_func_processor(void *arg) override { return FALSE;} bool need_parentheses_in_default() override { return true; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1708,7 +1708,7 @@ public: } bool check_partition_func_processor(void *int_arg) override {return FALSE;} bool check_vcol_func_processor(void *arg) override { return FALSE;} - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1734,7 +1734,7 @@ public: bool fix_length_and_dec() override; uint decimal_precision() const override { return args[0]->decimal_precision(); } bool need_parentheses_in_default() override { return true; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1752,7 +1752,7 @@ public: void fix_length_and_dec_double(); void fix_length_and_dec_decimal(); bool fix_length_and_dec() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1779,7 +1779,7 @@ public: Item_func_exp(THD *thd, Item *a): Item_dec_func(thd, a) {} double val_real() override; const char *func_name() const override { return "exp"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1790,7 +1790,7 @@ public: Item_func_ln(THD *thd, Item *a): Item_dec_func(thd, a) {} double val_real() override; const char *func_name() const override { return "ln"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1802,7 +1802,7 @@ public: Item_func_log(THD *thd, Item *a, Item *b): Item_dec_func(thd, a, b) {} double val_real() override; const char *func_name() const override { return "log"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1813,7 +1813,7 @@ public: Item_func_log2(THD *thd, Item *a): Item_dec_func(thd, a) {} double val_real() override; const char *func_name() const override { return "log2"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1824,7 +1824,7 @@ public: Item_func_log10(THD *thd, Item *a): Item_dec_func(thd, a) {} double val_real() override; const char *func_name() const override { return "log10"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1835,7 +1835,7 @@ public: Item_func_sqrt(THD *thd, Item *a): Item_dec_func(thd, a) {} double val_real() override; const char *func_name() const override { return "sqrt"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1846,7 +1846,7 @@ public: Item_func_pow(THD *thd, Item *a, Item *b): Item_dec_func(thd, a, b) {} double val_real() override; const char *func_name() const override { return "pow"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1857,7 +1857,7 @@ public: Item_func_acos(THD *thd, Item *a): Item_dec_func(thd, a) {} double val_real() override; const char *func_name() const override { return "acos"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1867,7 +1867,7 @@ public: Item_func_asin(THD *thd, Item *a): Item_dec_func(thd, a) {} double val_real() override; const char *func_name() const override { return "asin"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1878,7 +1878,7 @@ public: Item_func_atan(THD *thd, Item *a, Item *b): Item_dec_func(thd, a, b) {} double val_real() override; const char *func_name() const override { return "atan"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1888,7 +1888,7 @@ public: Item_func_cos(THD *thd, Item *a): Item_dec_func(thd, a) {} double val_real() override; const char *func_name() const override { return "cos"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1898,7 +1898,7 @@ public: Item_func_sin(THD *thd, Item *a): Item_dec_func(thd, a) {} double val_real() override; const char *func_name() const override { return "sin"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1908,7 +1908,7 @@ public: Item_func_tan(THD *thd, Item *a): Item_dec_func(thd, a) {} double val_real() override; const char *func_name() const override { return "tan"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1918,7 +1918,7 @@ public: Item_func_cot(THD *thd, Item *a): Item_dec_func(thd, a) {} double val_real() override; const char *func_name() const override { return "cot"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1960,7 +1960,7 @@ public: my_decimal *decimal_op(my_decimal *) override; bool date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) override; bool time_op(THD *thd, MYSQL_TIME *ltime) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1976,7 +1976,7 @@ public: my_decimal *decimal_op(my_decimal *) override; bool date_op(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) override; bool time_op(THD *thd, MYSQL_TIME *ltime) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2021,7 +2021,7 @@ public: */ return args[0]->real_type_handler()->Item_func_round_fix_length_and_dec(this); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2047,7 +2047,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2062,7 +2062,7 @@ public: uint decimal_precision() const override { return 1; } bool fix_length_and_dec() override { fix_char_length(2); return FALSE; } longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2085,7 +2085,7 @@ public: max_length= float_length(decimals); return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2187,7 +2187,7 @@ class Item_func_min :public Item_func_min_max public: Item_func_min(THD *thd, List &list): Item_func_min_max(thd, list, 1) {} const char *func_name() const override { return "least"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2196,7 +2196,7 @@ class Item_func_max :public Item_func_min_max public: Item_func_max(THD *thd, List &list): Item_func_min_max(thd, list, -1) {} const char *func_name() const override { return "greatest"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2230,7 +2230,7 @@ public: Type_std_attributes::set(*args[0]); return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2252,7 +2252,7 @@ public: Item_func_octet_length(THD *thd, Item *a): Item_long_func_length(thd, a) {} longlong val_int() override; const char *func_name() const override { return "octet_length"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2268,7 +2268,7 @@ public: } longlong val_int() override; const char *func_name() const override { return "bit_length"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2279,7 +2279,7 @@ public: Item_func_char_length(THD *thd, Item *a): Item_long_func_length(thd, a) {} longlong val_int() override; const char *func_name() const override { return "char_length"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2304,7 +2304,7 @@ public: Item* propagate_equal_fields(THD *thd, const Context &ctx, COND_EQUAL *cond) override { return this; } bool const_item() const override { return true; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2337,7 +2337,7 @@ public: return agg_arg_charsets_for_comparison(cmp_collation, args, 2); } void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2352,7 +2352,7 @@ public: longlong val_int() override; const char *func_name() const override { return "field"; } bool fix_length_and_dec() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2367,7 +2367,7 @@ public: longlong val_int() override; const char *func_name() const override { return "ascii"; } bool fix_length_and_dec() override { max_length=3; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2381,7 +2381,7 @@ public: bool fix_length_and_dec() override { fix_char_length(7); return FALSE; } longlong val_int() override; const char *func_name() const override { return "ord"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2399,7 +2399,7 @@ public: longlong val_int() override; const char *func_name() const override { return "find_in_set"; } bool fix_length_and_dec() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2441,7 +2441,7 @@ public: bool fix_length_and_dec() override; const char *func_name() const override { return "|"; } enum precedence precedence() const override { return BITOR_PRECEDENCE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2453,7 +2453,7 @@ public: bool fix_length_and_dec() override; const char *func_name() const override { return "&"; } enum precedence precedence() const override { return BITAND_PRECEDENCE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2465,7 +2465,7 @@ public: Item_func_bit_count(THD *thd, Item *a): Item_handled_func(thd, a) {} const char *func_name() const override { return "bit_count"; } bool fix_length_and_dec() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2477,7 +2477,7 @@ public: bool fix_length_and_dec() override; const char *func_name() const override { return "<<"; } enum precedence precedence() const override { return SHIFT_PRECEDENCE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2489,7 +2489,7 @@ public: bool fix_length_and_dec() override; const char *func_name() const override { return ">>"; } enum precedence precedence() const override { return SHIFT_PRECEDENCE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2505,7 +2505,7 @@ public: str->append(func_name()); args[0]->print_parenthesised(str, query_type, precedence()); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2531,7 +2531,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2555,7 +2555,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2582,7 +2582,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2733,7 +2733,7 @@ class Item_func_udf_float :public Item_udf_func String *val_str(String *str) override; const Type_handler *type_handler() const override { return &type_handler_double; } bool fix_length_and_dec() override { fix_num_length_and_dec(); return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2760,7 +2760,7 @@ public: return &type_handler_slonglong; } bool fix_length_and_dec() override { decimals= 0; max_length= 21; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2787,7 +2787,7 @@ public: } const Type_handler *type_handler() const override { return &type_handler_newdecimal; } bool fix_length_and_dec() override { fix_num_length_and_dec(); return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2826,7 +2826,7 @@ public: } const Type_handler *type_handler() const override { return string_type_handler(); } bool fix_length_and_dec() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2919,7 +2919,7 @@ class Item_func_get_lock final :public Item_func_lock longlong val_int() override final; const char *func_name() const override final { return "get_lock"; } bool fix_length_and_dec() override { max_length= 1; maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override final + Item *do_get_copy(THD *thd) const override final { return get_item_copy(thd, this); } }; @@ -2931,7 +2931,7 @@ public: { unsigned_flag= 1; } longlong val_int() override final; const char *func_name() const override final { return "release_all_locks"; } - Item *get_copy(THD *thd) override final + Item *do_get_copy(THD *thd) const override final { return get_item_copy(thd, this); } }; @@ -2946,7 +2946,7 @@ public: longlong val_int() override final; const char *func_name() const override { return "release_lock"; } bool fix_length_and_dec() override { max_length= 1; maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override final + Item *do_get_copy(THD *thd) const override final { return get_item_copy(thd, this); } }; @@ -2978,7 +2978,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3003,7 +3003,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3119,7 +3119,7 @@ public: bool register_field_in_bitmap(void *arg) override; bool set_entry(THD *thd, bool create_if_not_exists); void cleanup() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } bool excl_dep_on_table(table_map tab_map) override { return false; } }; @@ -3148,7 +3148,7 @@ public: table_map used_tables() const override { return const_item() ? 0 : RAND_TABLE_BIT; } bool eq(const Item *item, bool binary_cmp) const override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } private: bool set_value(THD *thd, sp_rcontext *ctx, Item **it) override; @@ -3230,8 +3230,9 @@ public: void set_null_value(CHARSET_INFO* cs); void set_value(const char *str, uint length, CHARSET_INFO* cs); const Type_handler *type_handler() const override { return &type_handler_double; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -3289,7 +3290,7 @@ public: void cleanup() override; bool check_vcol_func_processor(void *arg) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3348,9 +3349,9 @@ public: { return mark_unsupported_function("match ... against()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } - Item *build_clone(THD *thd) override { return 0; } + Item *do_build_clone(THD *thd) const override { return nullptr; } private: /** Check whether storage engine for given table, @@ -3396,7 +3397,7 @@ public: bool fix_length_and_dec() override; const char *func_name() const override { return "^"; } enum precedence precedence() const override { return BITXOR_PRECEDENCE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3418,7 +3419,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3440,7 +3441,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3492,7 +3493,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3630,7 +3631,7 @@ public: { return TRUE; } - Item *get_copy(THD *) override { return 0; } + Item *do_get_copy(THD *thd) const override { return 0; } bool eval_not_null_tables(void *opt_arg) override { not_null_tables_cache= 0; @@ -3656,7 +3657,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3675,7 +3676,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3700,7 +3701,7 @@ public: max_length= 11; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3721,7 +3722,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_NON_DETERMINISTIC); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3757,7 +3758,7 @@ public: Item_func::update_used_tables(); maybe_null= last_value->maybe_null; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3798,7 +3799,7 @@ public: } } bool const_item() const override { return 0; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } void print(String *str, enum_query_type query_type) override; bool check_vcol_func_processor(void *arg) override @@ -3817,7 +3818,7 @@ public: Item_func_nextval(thd, table_list_arg) {} longlong val_int() override; const char *func_name() const override { return "lastval"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -3838,7 +3839,7 @@ public: longlong val_int() override; const char *func_name() const override { return "setval"; } void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; diff --git a/sql/item_geofunc.h b/sql/item_geofunc.h index 6c57ac52563..2eed5dba629 100644 --- a/sql/item_geofunc.h +++ b/sql/item_geofunc.h @@ -214,7 +214,7 @@ public: Item_geometry_func(thd, a, srid) {} const char *func_name() const override { return "st_geometryfromtext"; } String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -232,7 +232,7 @@ public: Item_geometry_func(thd, a, srid) {} const char *func_name() const override { return "st_geometryfromwkb"; } String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -254,7 +254,7 @@ public: Item_geometry_func(thd, js, opt, srid) {} const char *func_name() const override { return "st_geomfromgeojson"; } String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -267,7 +267,7 @@ public: const char *func_name() const override { return "st_astext"; } String *val_str_ascii(String *) override; bool fix_length_and_dec() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -287,7 +287,7 @@ public: maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -310,7 +310,7 @@ public: const char *func_name() const override { return "st_asgeojson"; } bool fix_length_and_dec() override; String *val_str_ascii(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -329,7 +329,7 @@ public: maybe_null= 1; return FALSE; }; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -364,7 +364,7 @@ public: {} const char *func_name() const override { return "st_convexhull"; } String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -380,7 +380,7 @@ public: { return &type_handler_point; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -395,7 +395,7 @@ public: { return &type_handler_polygon; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -429,7 +429,7 @@ public: :Item_geometry_func_args_geometry(thd, a) {} const char *func_name() const override { return "st_boundary"; } String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -448,7 +448,7 @@ public: { return &type_handler_point; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -474,7 +474,7 @@ public: } } String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -507,7 +507,7 @@ public: } } String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -563,7 +563,7 @@ public: return &type_handler_geometrycollection; } const char *func_name() const override { return "geometrycollection"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -578,7 +578,7 @@ public: { } const Type_handler *type_handler() const override { return &type_handler_linestring; } const char *func_name() const override { return "linestring"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -593,7 +593,7 @@ public: { } const Type_handler *type_handler() const override { return &type_handler_polygon; } const char *func_name() const override { return "polygon"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -611,7 +611,7 @@ public: return &type_handler_multilinestring; } const char *func_name() const override { return "multilinestring"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -629,7 +629,7 @@ public: return &type_handler_multipoint; } const char *func_name() const override { return "multipoint"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -647,7 +647,7 @@ public: return &type_handler_multipolygon; } const char *func_name() const override { return "multipolygon"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -699,7 +699,7 @@ public: usable_tables, sargables, false); } bool need_parentheses_in_default() override { return false; } - Item *build_clone(THD *thd) override { return 0; } + Item *do_build_clone(THD *thd) const override { return nullptr; } }; @@ -711,7 +711,7 @@ public: { } longlong val_int() override; const char *func_name() const override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -727,7 +727,7 @@ public: { } longlong val_int() override; const char *func_name() const override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -750,7 +750,7 @@ public: longlong val_int() override; const char *func_name() const override { return "st_relate"; } bool need_parentheses_in_default() override { return false; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -787,7 +787,7 @@ public: { Item_func::print(str, query_type); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -844,7 +844,7 @@ public: :Item_geometry_func_args_geometry(thd, obj, distance) {} const char *func_name() const override { return "st_buffer"; } String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -858,7 +858,7 @@ public: const char *func_name() const override { return "st_isempty"; } bool fix_length_and_dec() override { maybe_null= 1; return FALSE; } bool need_parentheses_in_default() override { return false; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -875,7 +875,7 @@ public: const char *func_name() const override { return "st_issimple"; } bool fix_length_and_dec() override { decimals=0; max_length=2; return FALSE; } uint decimal_precision() const override { return 1; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -888,7 +888,7 @@ public: const char *func_name() const override { return "st_isclosed"; } bool fix_length_and_dec() override { decimals=0; max_length=2; return FALSE; } uint decimal_precision() const override { return 1; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -898,7 +898,7 @@ public: Item_func_isring(THD *thd, Item *a): Item_func_issimple(thd, a) {} longlong val_int() override; const char *func_name() const override { return "st_isring"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -910,7 +910,7 @@ public: longlong val_int() override; const char *func_name() const override { return "st_dimension"; } bool fix_length_and_dec() override { max_length= 10; maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -928,7 +928,7 @@ public: maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -946,7 +946,7 @@ public: maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -959,7 +959,7 @@ public: longlong val_int() override; const char *func_name() const override { return "st_numgeometries"; } bool fix_length_and_dec() override { max_length= 10; maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -972,7 +972,7 @@ public: longlong val_int() override; const char *func_name() const override { return "st_numinteriorrings"; } bool fix_length_and_dec() override { max_length= 10; maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -985,7 +985,7 @@ public: longlong val_int() override; const char *func_name() const override { return "st_numpoints"; } bool fix_length_and_dec() override { max_length= 10; maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1003,7 +1003,7 @@ public: maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1023,7 +1023,7 @@ public: maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1036,7 +1036,7 @@ public: longlong val_int() override; const char *func_name() const override { return "srid"; } bool fix_length_and_dec() override { max_length= 10; maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1053,7 +1053,7 @@ public: :Item_real_func_args_geometry_geometry(thd, a, b) {} double val_real() override; const char *func_name() const override { return "st_distance"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1067,7 +1067,7 @@ public: Item_real_func(thd, list) {} double val_real() override; const char *func_name() const override { return "st_distance_sphere"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1087,7 +1087,7 @@ public: { return &type_handler_point; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1105,7 +1105,7 @@ class Item_func_gis_debug: public Item_long_func { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; #endif diff --git a/sql/item_jsonfunc.h b/sql/item_jsonfunc.h index b96189b3c8f..ba1f31b1ab7 100644 --- a/sql/item_jsonfunc.h +++ b/sql/item_jsonfunc.h @@ -89,7 +89,7 @@ public: static const Lex_cstring fmt(STRING_WITH_LEN("json")); return to->set_format_name(fmt); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } enum Functype functype() const override { return JSON_VALID_FUNC; } }; @@ -106,7 +106,7 @@ public: Item_bool_func(thd, js, i_path) {} const char *func_name() const override { return "json_exists"; } bool fix_length_and_dec() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } longlong val_int() override; }; @@ -150,7 +150,7 @@ public: { return je->check_and_get_value_scalar(res, error); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -174,7 +174,7 @@ public: { return je->check_and_get_value_complex(res, error); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -189,7 +189,7 @@ public: const char *func_name() const override { return "json_quote"; } bool fix_length_and_dec() override; String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -204,7 +204,7 @@ public: const char *func_name() const override { return "json_unquote"; } bool fix_length_and_dec() override; String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -255,7 +255,7 @@ public: double val_real() override; my_decimal *val_decimal(my_decimal *) override; uint get_n_paths() const override { return arg_count - 1; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -274,7 +274,7 @@ public: const char *func_name() const override { return "json_contains"; } bool fix_length_and_dec() override; longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -297,7 +297,7 @@ public: bool fix_fields(THD *thd, Item **ref) override; bool fix_length_and_dec() override; longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -315,7 +315,7 @@ public: String *val_str(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "json_array"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -332,7 +332,7 @@ public: String *val_str(String *) override; uint get_n_paths() const override { return arg_count/2; } const char *func_name() const override { return "json_array_append"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -344,7 +344,7 @@ public: Item_func_json_array_append(thd, list) {} String *val_str(String *) override; const char *func_name() const override { return "json_array_insert"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -358,7 +358,7 @@ public: Item_func_json_array(thd, list) {} String *val_str(String *) override; const char *func_name() const override { return "json_object"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -372,7 +372,7 @@ public: Item_func_json_array(thd, list) {} String *val_str(String *) override; const char *func_name() const override { return "json_merge_preserve"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -383,7 +383,7 @@ public: Item_func_json_merge(thd, list) {} const char *func_name() const override { return "json_merge_patch"; } String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -410,7 +410,7 @@ public: const char *func_name() const override { return "json_length"; } bool fix_length_and_dec() override; longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -426,7 +426,7 @@ public: const char *func_name() const override { return "json_depth"; } bool fix_length_and_dec() override { max_length= 10; return FALSE; } longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -440,7 +440,7 @@ public: const char *func_name() const override { return "json_type"; } bool fix_length_and_dec() override; String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -463,7 +463,7 @@ public: return mode_insert ? (mode_replace ? "json_set" : "json_insert") : "json_replace"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -479,7 +479,7 @@ public: String *val_str(String *) override; uint get_n_paths() const override { return arg_count - 1; } const char *func_name() const override { return "json_remove"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -496,7 +496,7 @@ public: const char *func_name() const override { return "json_keys"; } bool fix_length_and_dec() override; String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -521,7 +521,7 @@ public: bool fix_length_and_dec() override; String *val_str(String *) override; uint get_n_paths() const override { return arg_count > 4 ? arg_count - 4 : 0; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -549,7 +549,7 @@ public: bool fix_length_and_dec() override; String *val_str(String *str) override; String *val_json(String *str) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -591,7 +591,7 @@ public: String* val_str(String *str) override; Item *copy_or_same(THD* thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -636,7 +636,7 @@ public: String* val_str(String* str) override; Item *copy_or_same(THD* thd) override; void no_rows_in_result() override {} - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; diff --git a/sql/item_row.cc b/sql/item_row.cc index 767787497ce..2a5c3a09ce5 100644 --- a/sql/item_row.cc +++ b/sql/item_row.cc @@ -183,7 +183,7 @@ void Item_row::bring_value() } -Item* Item_row::build_clone(THD *thd) +Item* Item_row::do_build_clone(THD *thd) const { Item **copy_args= static_cast (alloc_root(thd->mem_root, sizeof(Item*) * arg_count)); diff --git a/sql/item_row.h b/sql/item_row.h index 3c004e96341..9740da8e4a5 100644 --- a/sql/item_row.h +++ b/sql/item_row.h @@ -152,9 +152,9 @@ public: } bool check_vcol_func_processor(void *arg) override {return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } - Item *build_clone(THD *thd) override; + Item *do_build_clone(THD *thd) const override; }; #endif /* ITEM_ROW_INCLUDED */ diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 42a41242e01..c713534e42d 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -150,7 +150,7 @@ public: return FALSE; } const char *func_name() const override { return "md5"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -162,7 +162,7 @@ public: String *val_str_ascii(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "sha"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -174,7 +174,7 @@ public: String *val_str_ascii(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "sha2"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -187,7 +187,7 @@ public: String *val_str_ascii(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "to_base64"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -200,7 +200,7 @@ public: String *val_str(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "from_base64"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -227,7 +227,7 @@ public: :Item_aes_crypt(thd, a, b) {} bool fix_length_and_dec() override; const char *func_name() const override { return "aes_encrypt"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -238,7 +238,7 @@ public: Item_aes_crypt(thd, a, b) {} bool fix_length_and_dec() override; const char *func_name() const override { return "aes_decrypt"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -268,7 +268,7 @@ public: print_args_parenthesized(str, query_type); } const char *func_name() const override { return "concat"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -299,7 +299,7 @@ public: print_sql_mode_qualified_name(str, query_type); print_args_parenthesized(str, query_type); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } @@ -320,7 +320,7 @@ public: return FALSE; } const char *func_name() const override { return "decode_histogram"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -333,7 +333,7 @@ public: bool fix_length_and_dec() override; const char *func_name() const override { return "concat_ws"; } table_map not_null_tables() const override { return 0; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -345,7 +345,7 @@ public: String *val_str(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "reverse"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -367,7 +367,7 @@ public: print_args_parenthesized(str, query_type); } const char *func_name() const override { return "replace"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -391,7 +391,7 @@ public: print_sql_mode_qualified_name(str, query_type); print_args_parenthesized(str, query_type); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -427,7 +427,7 @@ public: } bool fix_length_and_dec() override; const char *func_name() const override { return "regexp_replace"; } - Item *get_copy(THD *thd) override { return 0;} + Item *do_get_copy(THD *thd) const override { return 0;} }; @@ -468,7 +468,7 @@ public: String *val_str(String *str) override; bool fix_length_and_dec() override; const char *func_name() const override { return "regexp_substr"; } - Item *get_copy(THD *thd) override { return 0; } + Item *do_get_copy(THD *thd) const override { return 0; } }; @@ -482,7 +482,7 @@ public: String *val_str(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "insert"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -505,7 +505,7 @@ public: Item_func_lcase(THD *thd, Item *item): Item_str_conv(thd, item) {} const char *func_name() const override { return "lcase"; } bool fix_length_and_dec() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -515,7 +515,7 @@ public: Item_func_ucase(THD *thd, Item *item): Item_str_conv(thd, item) {} const char *func_name() const override { return "ucase"; } bool fix_length_and_dec() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -529,7 +529,7 @@ public: String *val_str(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "left"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -542,7 +542,7 @@ public: String *val_str(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "right"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -567,7 +567,7 @@ public: print_args_parenthesized(str, query_type); } const char *func_name() const override { return "substr"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -603,7 +603,7 @@ public: print_sql_mode_qualified_name(str, query_type); print_args_parenthesized(str, query_type); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -616,7 +616,7 @@ public: String *val_str(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "substring_index"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -655,7 +655,7 @@ public: const char *func_name() const override { return "trim"; } void print(String *str, enum_query_type query_type) override; virtual const char *mode_name() const { return "both"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -676,7 +676,7 @@ public: maybe_null= true; return res; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -694,7 +694,7 @@ public: const Schema *schema() const override { return &mariadb_schema; } const char *func_name() const override { return "ltrim"; } const char *mode_name() const override { return "leading"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -715,7 +715,7 @@ public: maybe_null= true; return res; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -729,7 +729,7 @@ public: const Schema *schema() const override { return &mariadb_schema; } const char *func_name() const override { return "rtrim"; } const char *mode_name() const override { return "trailing"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -750,7 +750,7 @@ public: maybe_null= true; return res; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -789,7 +789,7 @@ public: "password" : "old_password"); } static char *alloc(THD *thd, const char *password, size_t pass_len, enum PW_Alg al); - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -812,7 +812,7 @@ public: return FALSE; } const char *func_name() const override { return "des_encrypt"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -835,7 +835,7 @@ public: return FALSE; } const char *func_name() const override { return "des_decrypt"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -871,7 +871,7 @@ public: { return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -891,7 +891,7 @@ public: String *val_str(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "encode"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } protected: virtual void crypto_transform(String *); @@ -912,7 +912,7 @@ public: print_args_parenthesized(str, query_type); } const char *func_name() const override { return "decode"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } protected: void crypto_transform(String *) override; @@ -953,7 +953,7 @@ public: } const char *func_name() const override { return "database"; } const char *fully_qualified_func_name() const override { return "database()"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -975,7 +975,7 @@ public: null_value= maybe_null= false; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1008,7 +1008,7 @@ public: { return save_str_value_in_field(field, &str_value); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1061,7 +1061,7 @@ public: return mark_unsupported_function(fully_qualified_func_name(), arg, VCOL_SESSION_FUNC); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1074,7 +1074,7 @@ public: String *val_str(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "soundex"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1088,7 +1088,7 @@ public: String *val_str(String *str) override; bool fix_length_and_dec() override; const char *func_name() const override { return "elt"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1102,7 +1102,7 @@ public: String *val_str(String *str) override; bool fix_length_and_dec() override; const char *func_name() const override { return "make_set"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1119,7 +1119,7 @@ public: String *val_str_ascii(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "format"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1144,7 +1144,7 @@ public: } const char *func_name() const override { return "char"; } void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1160,7 +1160,7 @@ public: return FALSE; } const char *func_name() const override { return "chr"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1173,7 +1173,7 @@ public: String *val_str(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "repeat"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1185,7 +1185,7 @@ public: String *val_str(String *) override; bool fix_length_and_dec() override; const char *func_name() const override { return "space"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1202,7 +1202,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1240,7 +1240,7 @@ public: } const char *func_name() const override { return "rpad"; } Sql_mode_dependency value_depends_on_sql_mode() const override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1274,7 +1274,7 @@ public: print_sql_mode_qualified_name(str, query_type); print_args_parenthesized(str, query_type); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1296,7 +1296,7 @@ public: print_args_parenthesized(str, query_type); } const char *func_name() const override { return "lpad"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1330,7 +1330,7 @@ public: print_sql_mode_qualified_name(str, query_type); print_args_parenthesized(str, query_type); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1349,7 +1349,7 @@ public: maybe_null= 1; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1395,7 +1395,7 @@ public: fix_char_length(char_length); return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1417,7 +1417,7 @@ public: max_length=(1+args[0]->max_length)/2; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1450,7 +1450,7 @@ public: Item_func_like_range_min(THD *thd, Item *a, Item *b): Item_func_like_range(thd, a, b, true) { } const char *func_name() const override { return "like_range_min"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1461,7 +1461,7 @@ public: Item_func_like_range_max(THD *thd, Item *a, Item *b): Item_func_like_range(thd, a, b, false) { } const char *func_name() const override { return "like_range_max"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; #endif @@ -1489,7 +1489,7 @@ public: void print(String *str, enum_query_type query_type) override; const char *func_name() const override { return "cast_as_binary"; } bool need_parentheses_in_default() override { return true; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1512,7 +1512,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_IMPOSSIBLE); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1529,7 +1529,7 @@ class Item_func_export_set: public Item_str_func String *val_str(String *str) override; bool fix_length_and_dec() override; const char *func_name() const override { return "export_set"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1552,7 +1552,7 @@ public: max_length= (uint32) MY_MIN(max_result_length, MAX_BLOB_WIDTH); return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1644,7 +1644,7 @@ public: bool fix_length_and_dec() override; const char *func_name() const override { return "convert"; } void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1667,7 +1667,7 @@ public: return args[0]->field_for_view_update(); } bool need_parentheses_in_default() override { return true; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1697,7 +1697,7 @@ public: :Item_func_expr_str_metadata(thd, a) { } String *val_str(String *) override; const char *func_name() const override { return "charset"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1709,7 +1709,7 @@ public: :Item_func_expr_str_metadata(thd, a) {} String *val_str(String *) override; const char *func_name() const override { return "collation"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1744,7 +1744,7 @@ public: Item* propagate_equal_fields(THD *thd, const Context &ctx, COND_EQUAL *cond) override { return this; } void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1759,7 +1759,7 @@ public: const char *func_name() const override { return "crc32"; } bool fix_length_and_dec() override { max_length=10; return FALSE; } longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1772,7 +1772,7 @@ public: const char *func_name() const override{return "uncompressed_length";} bool fix_length_and_dec() override { max_length=10; maybe_null= true; return FALSE; } longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1795,7 +1795,7 @@ public: } const char *func_name() const override{return "compress";} String *val_str(String *) override ZLIB_DEPENDED_FUNCTION - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1812,7 +1812,7 @@ public: } const char *func_name() const override{return "uncompress";} String *val_str(String *) override ZLIB_DEPENDED_FUNCTION - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1835,7 +1835,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_NON_DETERMINISTIC); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1858,7 +1858,7 @@ public: String *val_str(String *) override; void print(String *str, enum_query_type query_type) override; enum Functype functype() const override { return DYNCOL_FUNC; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1872,7 +1872,7 @@ public: const char *func_name() const override{ return "column_add"; } String *val_str(String *) override; void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1890,7 +1890,7 @@ public: decimals= 0; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1932,7 +1932,7 @@ public: bool get_dyn_value(THD *thd, DYNAMIC_COLUMN_VALUE *val, String *tmp); bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) override; void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1946,7 +1946,7 @@ public: { maybe_null= 1; max_length= MAX_BLOB_WIDTH; return FALSE; }; const char *func_name() const override{ return "column_list"; } String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1967,7 +1967,7 @@ public: enum Functype functype() const override { return TEMPTABLE_ROWID; } const char *func_name() const override { return ""; } bool fix_length_and_dec() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; #ifdef WITH_WSREP @@ -1987,7 +1987,7 @@ public: maybe_null= true; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2004,7 +2004,7 @@ public: maybe_null= true; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2017,7 +2017,7 @@ public: const Type_handler *type_handler() const override { return &type_handler_string; } const char *func_name() const override { return "wsrep_sync_wait_upto_gtid"; } longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; #endif /* WITH_WSREP */ diff --git a/sql/item_subselect.h b/sql/item_subselect.h index f976d905951..e971a57d850 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -281,8 +281,8 @@ public: void register_as_with_rec_ref(With_element *with_elem); void init_expr_cache_tracker(THD *thd); - Item* build_clone(THD *thd) override { return 0; } - Item* get_copy(THD *thd) override { return 0; } + Item* do_build_clone(THD *thd) const override { return nullptr; } + Item *do_get_copy(THD *thd) const override { return 0; } st_select_lex *wrap_tvc_into_select(THD *thd, st_select_lex *tvc_sl); diff --git a/sql/item_sum.h b/sql/item_sum.h index d46c0561c91..d7feb622aa8 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -855,7 +855,7 @@ public: } Item *copy_or_same(THD* thd) override; void remove() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } bool supports_removal() const override @@ -927,7 +927,7 @@ public: return has_with_distinct() ? "count(distinct " : "count("; } Item *copy_or_same(THD* thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } bool supports_removal() const override @@ -983,7 +983,7 @@ public: count= 0; Item_sum_sum::cleanup(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } bool supports_removal() const override @@ -1068,7 +1068,7 @@ public: m_stddev= Stddev(); Item_sum_double::cleanup(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1090,7 +1090,7 @@ class Item_sum_std final :public Item_sum_variance const char *func_name() const override final { return sample ? "stddev_samp(" : "std("; } Item *copy_or_same(THD* thd) override final; - Item *get_copy(THD *thd) override final + Item *do_get_copy(THD *thd) const override final { return get_item_copy(thd, this); } }; @@ -1187,7 +1187,7 @@ public: bool add() override; const char *func_name() const override { return "min("; } Item *copy_or_same(THD* thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1202,7 +1202,7 @@ public: bool add() override; const char *func_name() const override { return "max("; } Item *copy_or_same(THD* thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1289,7 +1289,7 @@ public: bool add() override; const char *func_name() const override { return "bit_or("; } Item *copy_or_same(THD* thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } private: @@ -1306,7 +1306,7 @@ public: bool add() override; const char *func_name() const override { return "bit_and("; } Item *copy_or_same(THD* thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } private: @@ -1321,7 +1321,7 @@ public: bool add() override; const char *func_name() const override { return "bit_xor("; } Item *copy_or_same(THD* thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } private: @@ -1465,7 +1465,7 @@ public: { return sp_result_field; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } Item *copy_or_same(THD *thd) override; }; @@ -1528,8 +1528,9 @@ public: my_decimal *val_decimal(my_decimal *dec) override { return val_decimal_from_real(dec); } String *val_str(String *str) override { return val_string_from_real(str); } double val_real() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -1557,8 +1558,9 @@ public: return VDec(this).to_string_round(str, decimals); } my_decimal *val_decimal(my_decimal *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -1578,8 +1580,9 @@ public: { return val_decimal_from_real(dec_buf); } bool is_null() override { update_null_value(); return null_value; } const Type_handler *type_handler() const override { return &type_handler_double; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -1591,8 +1594,9 @@ public: { } enum Type type() const override { return FIELD_STD_ITEM; } double val_real() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } + Item *do_build_clone(THD *thd) const override { return get_copy(thd); } }; @@ -1684,7 +1688,7 @@ class Item_sum_udf_float :public Item_udf_sum const Type_handler *type_handler() const override { return &type_handler_double; } bool fix_length_and_dec() override { fix_num_length_and_dec(); return FALSE; } Item *copy_or_same(THD* thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1711,7 +1715,7 @@ public: } bool fix_length_and_dec() override { decimals=0; max_length=21; return FALSE; } Item *copy_or_same(THD* thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1752,7 +1756,7 @@ public: const Type_handler *type_handler() const override { return string_type_handler(); } bool fix_length_and_dec() override; Item *copy_or_same(THD* thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1782,7 +1786,7 @@ public: const Type_handler *type_handler() const override { return &type_handler_newdecimal; } bool fix_length_and_dec() override { fix_num_length_and_dec(); return FALSE; } Item *copy_or_same(THD* thd) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -2037,7 +2041,7 @@ public: void print(String *str, enum_query_type query_type) override; bool change_context_processor(void *cntx) override { context= (Name_resolution_context *)cntx; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } qsort_cmp2 get_comparator_function_for_distinct(); qsort_cmp2 get_comparator_function_for_order_by(); diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 6ef2d02238e..443648b9a1b 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -63,7 +63,7 @@ public: max_length=6*MY_CHARSET_BIN_MB_MAXLEN; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -82,7 +82,7 @@ public: max_length=6*MY_CHARSET_BIN_MB_MAXLEN; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -108,7 +108,7 @@ public: { return !has_date_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -137,7 +137,7 @@ public: { return !has_date_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -161,7 +161,7 @@ public: { return !has_date_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -186,7 +186,7 @@ public: { return !has_date_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -208,7 +208,7 @@ public: { return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -232,7 +232,7 @@ public: { return !has_date_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -256,7 +256,7 @@ public: { return !has_time_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -280,7 +280,7 @@ public: { return !has_time_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -304,7 +304,7 @@ public: { return !has_date_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -328,7 +328,7 @@ public: { return !has_time_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -362,7 +362,7 @@ public: { return arg_count == 2; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -391,7 +391,7 @@ public: { return !has_date_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -417,7 +417,7 @@ public: { return !has_date_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -450,7 +450,7 @@ public: { return !has_date_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -472,7 +472,7 @@ class Item_func_dayname :public Item_str_func { return !has_date_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -537,7 +537,7 @@ public: } longlong int_op() override; my_decimal *decimal_op(my_decimal* buf) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -561,7 +561,7 @@ public: } longlong int_op() override; my_decimal *decimal_op(my_decimal* buf) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -653,7 +653,7 @@ public: Item_func_curtime_local(THD *thd, uint dec): Item_func_curtime(thd, dec) {} const char *func_name() const override { return "curtime"; } void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -664,7 +664,7 @@ public: Item_func_curtime_utc(THD *thd, uint dec): Item_func_curtime(thd, dec) {} const char *func_name() const override { return "utc_time"; } void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -692,7 +692,7 @@ public: Item_func_curdate_local(THD *thd): Item_func_curdate(thd) {} const char *func_name() const override { return "curdate"; } void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -703,7 +703,7 @@ public: Item_func_curdate_utc(THD *thd): Item_func_curdate(thd) {} const char *func_name() const override { return "utc_date"; } void store_now_in_TIME(THD* thd, MYSQL_TIME *now_time) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -742,7 +742,7 @@ public: int save_in_field(Field *field, bool no_conversions) override; void store_now_in_TIME(THD *thd, MYSQL_TIME *now_time) override; enum Functype functype() const override { return NOW_FUNC; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -759,7 +759,7 @@ public: return mark_unsupported_function(func_name(), "()", arg, VCOL_TIME_FUNC | VCOL_NON_DETERMINISTIC); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -783,7 +783,7 @@ public: VCOL_TIME_FUNC | VCOL_NON_DETERMINISTIC); } enum Functype functype() const override { return SYSDATE_FUNC; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -802,7 +802,7 @@ public: { return has_date_args() || has_time_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -835,7 +835,7 @@ public: return false; return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -846,7 +846,7 @@ public: Item_func_date_format(thd, a, b) { is_time_format= true; } const char *func_name() const override { return "time_format"; } bool check_vcol_func_processor(void *arg) override { return false; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -865,7 +865,7 @@ class Item_func_from_unixtime :public Item_datetimefunc { return mark_unsupported_function(func_name(), "()", arg, VCOL_SESSION_FUNC); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -911,7 +911,7 @@ class Item_func_convert_tz :public Item_datetimefunc } bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate) override; void cleanup() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -930,7 +930,7 @@ public: return FALSE; } const char *func_name() const override { return "sec_to_time"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -950,7 +950,7 @@ public: void print(String *str, enum_query_type query_type) override; enum precedence precedence() const override { return INTERVAL_PRECEDENCE; } bool need_parentheses_in_default() override { return true; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1058,7 +1058,7 @@ class Item_extract :public Item_int_func, } return true; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1101,7 +1101,7 @@ public: } void print(String *str, enum_query_type query_type) override; bool need_parentheses_in_default() override { return true; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1138,7 +1138,7 @@ public: { return args[0]->type_handler()->Item_date_typecast_fix_length_and_dec(this); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1160,7 +1160,7 @@ public: Item_time_typecast_fix_length_and_dec(this); } Sql_mode_dependency value_depends_on_sql_mode() const override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1182,7 +1182,7 @@ public: Item_datetime_typecast_fix_length_and_dec(this); } Sql_mode_dependency value_depends_on_sql_mode() const override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1196,7 +1196,7 @@ public: Item_datefunc(thd, a, b) {} const char *func_name() const override { return "makedate"; } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1233,7 +1233,7 @@ public: return (null_value= Sec6_add(dt.get_mysql_time(), it.get_mysql_time(), 1). to_datetime(ltime)); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1260,7 +1260,7 @@ public: { } bool fix_length_and_dec() override; const char *func_name() const override { return sign > 0 ? "addtime" : "subtime"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1282,7 +1282,7 @@ public: return FALSE; } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1305,7 +1305,7 @@ public: } const char *func_name() const override { return "maketime"; } bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1329,7 +1329,7 @@ public: { return !has_time_args(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1354,7 +1354,7 @@ public: return FALSE; } void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1381,7 +1381,7 @@ public: return FALSE; } void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1401,7 +1401,7 @@ public: timestamp_type); const char *func_name() const override { return "str_to_date"; } bool fix_length_and_dec() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -1414,7 +1414,7 @@ public: Item_func_last_day(THD *thd, Item *a): Item_datefunc(thd, a) {} const char *func_name() const override { return "last_day"; } bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; diff --git a/sql/item_vers.h b/sql/item_vers.h index cff0133ffb3..0ea791f0422 100644 --- a/sql/item_vers.h +++ b/sql/item_vers.h @@ -48,7 +48,7 @@ public: } const char* func_name() const override { return "is_history"; } void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -66,7 +66,7 @@ public: return "trt_commit_ts"; } bool get_date(THD *thd, MYSQL_TIME *res, date_mode_t fuzzydate) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } bool fix_length_and_dec() override { fix_attributes_datetime(decimals); return FALSE; } @@ -108,7 +108,7 @@ public: } longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -124,7 +124,7 @@ public: return "trt_trx_sees"; } longlong val_int() override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h index 336ff037fad..4d213582c8b 100644 --- a/sql/item_windowfunc.h +++ b/sql/item_windowfunc.h @@ -148,7 +148,7 @@ public: return "row_number"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -221,7 +221,7 @@ public: } Item_sum_int::cleanup(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -292,7 +292,7 @@ class Item_sum_dense_rank: public Item_sum_int } Item_sum_int::cleanup(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -355,7 +355,7 @@ class Item_sum_first_value : public Item_sum_hybrid_simple return "first_value"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -381,7 +381,7 @@ class Item_sum_last_value : public Item_sum_hybrid_simple return "last_value"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -401,7 +401,7 @@ class Item_sum_nth_value : public Item_sum_hybrid_simple return "nth_value"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -421,7 +421,7 @@ class Item_sum_lead : public Item_sum_hybrid_simple return "lead"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -441,7 +441,7 @@ class Item_sum_lag : public Item_sum_hybrid_simple return "lag"; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -554,7 +554,7 @@ class Item_sum_percent_rank: public Item_sum_double, Partition_row_count::set_partition_row_count(count); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } private: @@ -640,7 +640,7 @@ class Item_sum_cume_dist: public Item_sum_double, Partition_row_count::set_partition_row_count(count); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -715,7 +715,7 @@ class Item_sum_ntile : public Item_sum_int, Partition_row_count::set_partition_row_count(count); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } private: @@ -878,7 +878,7 @@ public: Partition_row_count::set_partition_row_count(count); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } void setup_window_func(THD *thd, Window_spec *window_spec) override; void setup_hybrid(THD *thd, Item *item); @@ -1014,7 +1014,7 @@ public: Partition_row_count::set_partition_row_count(count); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } void setup_window_func(THD *thd, Window_spec *window_spec) override; void setup_hybrid(THD *thd, Item *item); @@ -1365,7 +1365,7 @@ public: void print(String *str, enum_query_type query_type) override; - Item *get_copy(THD *thd) override { return 0; } + Item *do_get_copy(THD *thd) const override { return 0; } }; diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc index 78429e2fe5a..8a270b5d1aa 100644 --- a/sql/item_xmlfunc.cc +++ b/sql/item_xmlfunc.cc @@ -215,7 +215,7 @@ public: Item_nodeset_func(thd, pxml) {} const char *func_name() const override { return "xpath_rootelement"; } bool val_native(THD *thd, Native *nodeset) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -228,7 +228,7 @@ public: Item_nodeset_func(thd, a, b, pxml) {} const char *func_name() const override { return "xpath_union"; } bool val_native(THD *thd, Native *nodeset) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -262,7 +262,7 @@ public: Item_nodeset_func_axisbyname(thd, a, n_arg, l_arg, pxml) {} const char *func_name() const override { return "xpath_selfbyname"; } bool val_native(THD *thd, Native *nodeset) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -276,7 +276,7 @@ public: Item_nodeset_func_axisbyname(thd, a, n_arg, l_arg, pxml) {} const char *func_name() const override { return "xpath_childbyname"; } bool val_native(THD *thd, Native *nodeset) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -292,7 +292,7 @@ public: need_self(need_self_arg) {} const char *func_name() const override { return "xpath_descendantbyname"; } bool val_native(THD *thd, Native *nodeset) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -308,7 +308,7 @@ public: need_self(need_self_arg) {} const char *func_name() const override { return "xpath_ancestorbyname"; } bool val_native(THD *thd, Native *nodeset) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -322,7 +322,7 @@ public: Item_nodeset_func_axisbyname(thd, a, n_arg, l_arg, pxml) {} const char *func_name() const override { return "xpath_parentbyname"; } bool val_native(THD *thd, Native *nodeset) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -336,7 +336,7 @@ public: Item_nodeset_func_axisbyname(thd, a, n_arg, l_arg, pxml) {} const char *func_name() const override { return "xpath_attributebyname"; } bool val_native(THD *thd, Native *nodeset) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -353,7 +353,7 @@ public: Item_nodeset_func(thd, a, b, pxml) {} const char *func_name() const override { return "xpath_predicate"; } bool val_native(THD *thd, Native *nodeset) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -366,7 +366,7 @@ public: Item_nodeset_func(thd, a, b, pxml) { } const char *func_name() const override { return "xpath_elementbyindex"; } bool val_native(THD *thd, Native *nodeset) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -394,7 +394,7 @@ public: } return args[0]->val_real() ? 1 : 0; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -408,7 +408,7 @@ public: Item_xpath_cast_number(THD *thd, Item *a): Item_real_func(thd, a) {} const char *func_name() const override { return "xpath_cast_number"; } double val_real() override { return args[0]->val_real(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -427,7 +427,7 @@ public: return nodeset->copy(*native_cache); } bool fix_length_and_dec() override { max_length= MAX_BLOB_WIDTH;; return FALSE; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -448,7 +448,7 @@ public: return tmp_native_value.element(0).pos + 1; return 0; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -471,7 +471,7 @@ public: return predicate_supplied_context_size; return tmp_native_value.elements(); } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -516,7 +516,7 @@ public: } return sum; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -598,7 +598,7 @@ public: } return 0; } - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; diff --git a/sql/item_xmlfunc.h b/sql/item_xmlfunc.h index 992d09b9c74..dc52395321d 100644 --- a/sql/item_xmlfunc.h +++ b/sql/item_xmlfunc.h @@ -133,7 +133,7 @@ public: Item_xml_str_func(thd, a, b) {} const char *func_name() const override { return "extractvalue"; } String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; @@ -150,7 +150,7 @@ public: Item_xml_str_func(thd, a, b, c) {} const char *func_name() const override { return "updatexml"; } String *val_str(String *) override; - Item *get_copy(THD *thd) override + Item *do_get_copy(THD *thd) const override { return get_item_copy(thd, this); } }; diff --git a/sql/procedure.h b/sql/procedure.h index 3a390c62ae1..2153a70c6d0 100644 --- a/sql/procedure.h +++ b/sql/procedure.h @@ -70,7 +70,7 @@ public: { return type_handler()->Item_get_date_with_warn(thd, this, ltime, fuzzydate); } - Item* get_copy(THD *thd) override { return 0; } + Item* do_get_copy(THD *thd) const override { return 0; } }; class Item_proc_real :public Item_proc @@ -123,6 +123,8 @@ public: String *val_str(String *s) override { s->set(value, default_charset()); return s; } my_decimal *val_decimal(my_decimal *) override; unsigned int size_of() { return sizeof(*this);} + Item *do_get_copy(THD *thd) const override { return nullptr; } + Item *do_build_clone(THD *thd) const override { return nullptr; } }; @@ -156,6 +158,8 @@ public: } my_decimal *val_decimal(my_decimal *) override; unsigned int size_of() { return sizeof(*this);} + Item *do_get_copy(THD *thd) const override { return nullptr; } + Item *do_build_clone(THD *thd) const override { return nullptr; } }; /* The procedure class definitions */ diff --git a/sql/sql_list.h b/sql/sql_list.h index a9ab5415d5a..277d5bc3808 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -537,10 +537,9 @@ public: class Iterator; using value_type= T; using iterator= Iterator; - using const_iterator= const Iterator; - Iterator begin() const { return Iterator(first); } - Iterator end() const { return Iterator(); } + iterator begin() const { return iterator(first); } + iterator end() const { return iterator(); } class Iterator { @@ -561,7 +560,7 @@ public: return *this; } - T operator++(int) + Iterator operator++(int) { Iterator tmp(*this); operator++(); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index b86ffed8619..92f0a8fa578 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -16632,7 +16632,7 @@ change_cond_ref_to_const(THD *thd, I_List *save_list, if (can_change_cond_ref_to_const(func, right_item, left_item, field_value_owner, field, value)) { - Item *tmp=value->clone_item(thd); + Item *tmp=value->clone_const_item(thd); if (tmp) { tmp->collation.set(right_item->collation); @@ -16662,7 +16662,7 @@ change_cond_ref_to_const(THD *thd, I_List *save_list, else if (can_change_cond_ref_to_const(func, left_item, right_item, field_value_owner, field, value)) { - Item *tmp= value->clone_item(thd); + Item *tmp= value->clone_const_item(thd); if (tmp) { tmp->collation.set(left_item->collation); diff --git a/sql/sql_string.h b/sql/sql_string.h index 0475b2d1f6e..c618990e84e 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -577,7 +577,7 @@ public: LEX_CSTRING tmp= {Ptr, str_length}; return tmp; } - inline LEX_CSTRING *get_value(LEX_CSTRING *res) + inline LEX_CSTRING *get_value(LEX_CSTRING *res) const { res->str= Ptr; res->length= str_length; From cf1c381bb899186c936614d93faa31d85e917499 Mon Sep 17 00:00:00 2001 From: Daniel Black Date: Fri, 5 Jul 2024 14:26:13 +1000 Subject: [PATCH 12/12] MDEV-34099: AddressSanitizer running out of memory regardless of stack_thread size Address Sanitizer's know how to detect stack overrun, so there's no point in us doing it. As evidenced by perfschema tests where signficant test failures because this function failed under ASAN (MDEV-33210). Also, so since clang-16, we cannot assume much about how local variables are allocated on the stack (MDEV-31605). Disabling check idea thanks to Sanja. --- sql/sql_parse.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index e0180b035d4..8a218290114 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7614,6 +7614,7 @@ __attribute__((optimize("-O0"))) #endif check_stack_overrun(THD *thd, long margin, uchar *buf __attribute__((unused))) { +#ifndef __SANITIZE_ADDRESS__ long stack_used; DBUG_ASSERT(thd == current_thd); if ((stack_used= available_stack_size(thd->thread_stack, &stack_used)) >= @@ -7636,6 +7637,7 @@ check_stack_overrun(THD *thd, long margin, uchar *buf __attribute__((unused))) #ifndef DBUG_OFF max_stack_used= MY_MAX(max_stack_used, stack_used); #endif +#endif /* __SANITIZE_ADDRESS__ */ return 0; }