Skip to content

Commit 3121f52

Browse files
committed
Bug#33814035: Remove unused code in Query_result
Removed send_error() and row_count(), which have multiple implementations, but no callers. Removed begin_dataset(), which has been a no-op since the embedded library was removed. Removed Query_result_union::m_rows_in_table, which was written to, but never read. Cleaned up #include statements with IWYU in the changed files. Change-Id: Ie088d43210c712703ca763d41d88403ac24414d1
1 parent 497e40d commit 3121f52

9 files changed

+45
-117
lines changed

sql/query_result.cc

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -54,6 +54,7 @@
5454
#include "sql/sql_error.h"
5555
#include "sql/sql_exchange.h"
5656
#include "sql/system_variables.h"
57+
#include "sql/visible_fields.h"
5758
#include "sql_string.h"
5859
#include "template_utils.h" // pointer_cast
5960

@@ -143,17 +144,6 @@ bool sql_exchange::escaped_given(void) {
143144
Handling writing to file
144145
************************************************************************/
145146

146-
void Query_result_to_file::send_error(THD *, uint errcode, const char *err) {
147-
my_message(errcode, err, MYF(0));
148-
if (file > 0) {
149-
(void)end_io_cache(&cache);
150-
mysql_file_close(file, MYF(0));
151-
/* Delete file on error */
152-
mysql_file_delete(key_select_to_file, path, MYF(0));
153-
file = -1;
154-
}
155-
}
156-
157147
bool Query_result_to_file::send_eof(THD *thd) {
158148
bool error = (end_io_cache(&cache) != 0);
159149
if (mysql_file_close(file, MYF(MY_WME)) || thd->is_error()) error = true;

sql/query_result.h

+3-19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2015, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -26,12 +26,7 @@
2626
#include <assert.h>
2727
#include <sys/types.h>
2828

29-
#include <cstddef>
30-
31-
#include "m_ctype.h"
32-
#include "mem_root_deque.h"
3329
#include "my_base.h"
34-
#include "my_compiler.h" // MY_ATTRIBUTE
3530

3631
#include "my_inttypes.h"
3732
#include "my_io.h"
@@ -47,6 +42,8 @@ class Query_expression;
4742
class THD;
4843
struct CHARSET_INFO;
4944
struct TABLE_LIST;
45+
template <class Element_type>
46+
class mem_root_deque;
5047

5148
/*
5249
This is used to get result from a query
@@ -130,9 +127,6 @@ class Query_result {
130127
const mem_root_deque<Item *> &list,
131128
uint flags) = 0;
132129
virtual bool send_data(THD *thd, const mem_root_deque<Item *> &items) = 0;
133-
virtual void send_error(THD *, uint errcode, const char *err) {
134-
my_message(errcode, err, MYF(0));
135-
}
136130
virtual bool send_eof(THD *thd) = 0;
137131
/**
138132
Check if this query returns a result set and therefore is allowed in
@@ -162,15 +156,6 @@ class Query_result {
162156
virtual void cleanup(THD *) { /* do nothing */
163157
}
164158

165-
void begin_dataset() {}
166-
167-
/// @returns Pointer to count of rows retained by this result.
168-
virtual const ha_rows *row_count() const /* purecov: inspected */
169-
{
170-
assert(false);
171-
return nullptr;
172-
} /* purecov: inspected */
173-
174159
/**
175160
Checks if this Query_result intercepts and transforms the result set.
176161
@@ -246,7 +231,6 @@ class Query_result_to_file : public Query_result_interceptor {
246231

247232
bool needs_file_privilege() const override { return true; }
248233

249-
void send_error(THD *thd, uint errcode, const char *err) override;
250234
bool send_eof(THD *thd) override;
251235
void cleanup(THD *thd) override;
252236
};

sql/sql_cursor.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2005, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2005, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -400,7 +400,6 @@ bool Materialized_cursor::fetch(ulong num_rows) {
400400
THD *thd = current_thd;
401401

402402
int res = 0;
403-
result->begin_dataset();
404403
for (fetch_limit += num_rows; fetch_count < fetch_limit; fetch_count++) {
405404
if ((res = table->file->ha_rnd_next(table->record[0]))) break;
406405
/* Send data only if the read was successful. */

sql/sql_insert.cc

+15-42
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,46 @@
3131
#include <string.h>
3232

3333
#include <atomic>
34+
#include <iterator>
3435
#include <map>
3536
#include <utility>
3637

38+
#include "field_types.h"
3739
#include "lex_string.h"
3840
#include "m_ctype.h"
3941
#include "m_string.h"
4042
#include "my_alloc.h"
4143
#include "my_base.h"
4244
#include "my_bitmap.h"
43-
#include "my_compiler.h"
4445
#include "my_dbug.h"
46+
#include "my_psi_config.h"
4547
#include "my_sys.h"
4648
#include "my_table_map.h"
4749
#include "my_thread_local.h"
4850
#include "mysql/components/services/bits/psi_bits.h"
49-
#include "mysql/psi/mysql_table.h"
51+
#include "mysql/mysql_lex_string.h"
5052
#include "mysql/service_mysql_alloc.h"
51-
#include "mysql/udf_registration_types.h"
5253
#include "mysql_com.h"
5354
#include "mysqld_error.h"
55+
#include "pfs_table_provider.h"
5456
#include "prealloced_array.h"
5557
#include "sql/auth/auth_acls.h"
5658
#include "sql/auth/auth_common.h" // check_grant_all_columns
5759
#include "sql/binlog.h"
5860
#include "sql/create_field.h"
5961
#include "sql/dd/cache/dictionary_client.h"
60-
#include "sql/dd/dd.h" // dd::get_dictionary
61-
#include "sql/dd/dictionary.h" // dd::Dictionary
62-
#include "sql/dd/types/column.h" // dd::Column
63-
#include "sql/dd/types/table.h" // dd::Table
64-
#include "sql/dd_sql_view.h" // update_referencing_views_metadata
65-
#include "sql/debug_sync.h" // DEBUG_SYNC
66-
#include "sql/derror.h" // ER_THD
62+
#include "sql/dd/dd.h" // dd::get_dictionary
63+
#include "sql/dd/dictionary.h" // dd::Dictionary
64+
#include "sql/dd_sql_view.h" // update_referencing_views_metadata
65+
#include "sql/debug_sync.h" // DEBUG_SYNC
66+
#include "sql/derror.h" // ER_THD
6767
#include "sql/discrete_interval.h"
6868
#include "sql/field.h"
6969
#include "sql/handler.h"
7070
#include "sql/item.h"
7171
#include "sql/key.h"
7272
#include "sql/lock.h" // mysql_unlock_tables
73+
#include "sql/locked_tables_list.h"
7374
#include "sql/mdl.h"
7475
#include "sql/mysqld.h" // stage_update
7576
#include "sql/nested_join.h"
@@ -80,26 +81,28 @@
8081
#include "sql/query_options.h"
8182
#include "sql/rpl_replica.h" // rpl_master_has_bug
8283
#include "sql/rpl_rli.h" // Relay_log_info
84+
#include "sql/select_lex_visitor.h"
8385
#include "sql/sql_alter.h"
8486
#include "sql/sql_array.h"
8587
#include "sql/sql_base.h" // setup_fields
8688
#include "sql/sql_class.h"
8789
#include "sql/sql_const.h"
8890
#include "sql/sql_error.h"
8991
#include "sql/sql_lex.h"
92+
#include "sql/sql_list.h"
9093
#include "sql/sql_resolver.h" // validate_gc_assignment
9194
#include "sql/sql_select.h" // check_privileges_for_list
9295
#include "sql/sql_show.h" // store_create_info
9396
#include "sql/sql_table.h" // quick_rm_table
94-
#include "sql/sql_update.h" // records_are_comparable
9597
#include "sql/sql_view.h" // check_key_in_view
98+
#include "sql/stateless_allocator.h"
9699
#include "sql/system_variables.h"
97100
#include "sql/table_trigger_dispatcher.h" // Table_trigger_dispatcher
98101
#include "sql/thd_raii.h"
99-
#include "sql/thr_malloc.h"
100102
#include "sql/transaction.h" // trans_commit_stmt
101103
#include "sql/transaction_info.h"
102104
#include "sql/trigger_def.h"
105+
#include "sql/visible_fields.h"
103106
#include "sql_string.h"
104107
#include "template_utils.h"
105108
#include "thr_lock.h"
@@ -2442,12 +2445,6 @@ void Query_result_insert::store_values(THD *thd,
24422445
check_that_all_fields_are_given_values(thd, table, table_list);
24432446
}
24442447

2445-
void Query_result_insert::send_error(THD *, uint errcode, const char *err) {
2446-
DBUG_TRACE;
2447-
2448-
my_message(errcode, err, MYF(0));
2449-
}
2450-
24512448
bool Query_result_insert::stmt_binlog_is_trans() const {
24522449
return table->file->has_transactions();
24532450
}
@@ -3070,30 +3067,6 @@ void Query_result_create::store_values(THD *thd,
30703067
TRG_EVENT_INSERT, table->s->fields);
30713068
}
30723069

3073-
void Query_result_create::send_error(THD *thd, uint errcode, const char *err) {
3074-
DBUG_TRACE;
3075-
3076-
DBUG_PRINT("info",
3077-
("Current statement %s row-based",
3078-
thd->is_current_stmt_binlog_format_row() ? "is" : "is NOT"));
3079-
DBUG_PRINT("info",
3080-
("Current table (at %p) %s a temporary (or non-existant) table",
3081-
table, table && !table->s->tmp_table ? "is NOT" : "is"));
3082-
/*
3083-
This will execute any rollbacks that are necessary before writing
3084-
the transcation cache.
3085-
3086-
We disable the binary log since nothing should be written to the
3087-
binary log. This disabling is important, since we potentially do
3088-
a "roll back" of non-transactional tables by removing the table,
3089-
and the actual rollback might generate events that should not be
3090-
written to the binary log.
3091-
3092-
*/
3093-
Disable_binlog_guard binlog_guard(thd);
3094-
Query_result_insert::send_error(thd, errcode, err);
3095-
}
3096-
30973070
bool Query_result_create::stmt_binlog_is_trans() const {
30983071
/*
30993072
Binary logging code assumes that CREATE TABLE statements are

sql/sql_insert.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2006, 2021, Oracle and/or its affiliates.
1+
/* Copyright (c) 2006, 2022, Oracle and/or its affiliates.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -24,25 +24,27 @@
2424
#define SQL_INSERT_INCLUDED
2525

2626
#include <assert.h>
27-
#include <stddef.h>
2827
#include <sys/types.h>
2928

29+
#include "mem_root_deque.h"
3030
#include "my_inttypes.h"
3131
#include "my_sqlcommand.h"
32-
#include "sql/current_thd.h"
3332
#include "sql/query_result.h" // Query_result_interceptor
3433
#include "sql/sql_cmd_dml.h" // Sql_cmd_dml
3534
#include "sql/sql_data_change.h" // enum_duplicates
36-
#include "sql/sql_list.h"
3735
#include "sql/table.h"
36+
#include "sql/thr_malloc.h"
3837

3938
class Alter_info;
4039
class Field;
4140
class Item;
4241
class Query_expression;
42+
class Select_lex_visitor;
4343
class THD;
4444
struct HA_CREATE_INFO;
4545
struct handlerton;
46+
struct MYSQL_LEX_CSTRING;
47+
struct MY_BITMAP;
4648

4749
using List_item = mem_root_deque<Item *>;
4850
struct MYSQL_LOCK;
@@ -148,7 +150,6 @@ are found inside the COPY_INFO.
148150
bool start_execution(THD *thd) override;
149151
bool send_data(THD *thd, const mem_root_deque<Item *> &items) override;
150152
virtual void store_values(THD *thd, const mem_root_deque<Item *> &values);
151-
void send_error(THD *thd, uint errcode, const char *err) override;
152153
bool send_eof(THD *thd) override;
153154
void abort_result_set(THD *thd) override;
154155
void cleanup(THD *thd) override;
@@ -197,7 +198,6 @@ class Query_result_create final : public Query_result_insert {
197198
bool prepare(THD *thd, const mem_root_deque<Item *> &list,
198199
Query_expression *u) override;
199200
void store_values(THD *thd, const mem_root_deque<Item *> &values) override;
200-
void send_error(THD *thd, uint errcode, const char *err) override;
201201
bool send_eof(THD *thd) override;
202202
void abort_result_set(THD *thd) override;
203203
bool create_table_for_query_block(THD *thd) override;

sql/sql_union.cc

+5-11
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@
3838

3939
#include <algorithm>
4040
#include <atomic>
41+
#include <cassert>
4142
#include <cstdio>
42-
#include <cstdlib> // abort
4343
#include <memory>
4444
#include <string>
4545
#include <utility>
4646
#include <vector>
4747

48+
#include "mem_root_deque.h"
4849
#include "my_alloc.h"
4950
#include "my_base.h"
5051
#include "my_dbug.h"
@@ -61,21 +62,19 @@
6162
#include "sql/handler.h"
6263
#include "sql/item.h"
6364
#include "sql/item_subselect.h"
64-
#include "sql/item_sum.h"
65-
#include "sql/iterators/basic_row_iterators.h"
66-
#include "sql/iterators/composite_iterators.h"
6765
#include "sql/iterators/row_iterator.h"
68-
#include "sql/iterators/timing_iterator.h"
6966
#include "sql/join_optimizer/access_path.h"
7067
#include "sql/join_optimizer/explain_access_path.h"
7168
#include "sql/join_optimizer/join_optimizer.h"
69+
#include "sql/join_optimizer/materialize_path_parameters.h"
7270
#include "sql/mem_root_array.h"
7371
#include "sql/mysqld.h"
7472
#include "sql/opt_explain.h" // explain_no_table
7573
#include "sql/opt_explain_format.h"
7674
#include "sql/opt_trace.h"
7775
#include "sql/parse_tree_node_base.h"
7876
#include "sql/parse_tree_nodes.h" // PT_with_clause
77+
#include "sql/parser_yystype.h"
7978
#include "sql/pfs_batch_mode.h"
8079
#include "sql/protocol.h"
8180
#include "sql/query_options.h"
@@ -92,6 +91,7 @@
9291
#include "sql/sql_tmp_table.h" // tmp tables
9392
#include "sql/table_function.h" // Table_function
9493
#include "sql/thd_raii.h"
94+
#include "sql/visible_fields.h"
9595
#include "sql/window.h" // Window
9696
#include "template_utils.h"
9797

@@ -118,7 +118,6 @@ bool Query_result_union::send_data(THD *thd,
118118

119119
const int error = table->file->ha_write_row(table->record[0]);
120120
if (!error) {
121-
m_rows_in_table++;
122121
return false;
123122
}
124123
// create_ondisk_from_heap will generate error if needed
@@ -129,7 +128,6 @@ bool Query_result_union::send_data(THD *thd,
129128
return true; /* purecov: inspected */
130129
// Table's engine changed, index is not initialized anymore
131130
if (table->hash_field) table->file->ha_index_init(0, false);
132-
if (!is_duplicate) m_rows_in_table++;
133131
}
134132
return false;
135133
}
@@ -216,7 +214,6 @@ bool Query_result_union::create_result_table(
216214
*/
217215

218216
bool Query_result_union::reset() {
219-
m_rows_in_table = 0;
220217
return table ? table->empty_result_table() : false;
221218
}
222219

@@ -271,9 +268,6 @@ class Query_result_union_direct final : public Query_result_union {
271268
execution_started = true;
272269
return result->start_execution(thd);
273270
}
274-
void send_error(THD *thd, uint errcode, const char *err) override {
275-
result->send_error(thd, errcode, err); /* purecov: inspected */
276-
}
277271
bool send_eof(THD *) override {
278272
// Should never be called.
279273
my_abort();

0 commit comments

Comments
 (0)