Skip to content

Commit 2dfe5e3

Browse files
author
Steinar H. Gunderson
committed
Bug #33334918: Move iterators into one place
Move all the row iterators (which now essentially is _the_ execution machinery) into one directory, instead of being spread out in e.g. records.cc, sql_executor.cc and various *_iterator.cc files in sql/. Change-Id: Iae328d3ae0eb72c83ffb61475a5cd72d70ea5a25
1 parent 0115ba6 commit 2dfe5e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1256
-1227
lines changed

sql/CMakeLists.txt

+10-9
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,10 @@ SET(SQL_SHARED_SOURCES
365365
auth/sha2_password_common.cc
366366
auth/sha2_password.cc
367367
ssl_wrapper_service.cc
368-
bka_iterator.cc
369368
bootstrap.cc
370369
check_stack.cc
371370
conn_handler/connection_handler_manager.cc
372371
clone_handler.cc
373-
composite_iterators.cc
374372
create_field.cc
375373
current_thd.cc
376374
dd_sql_view.cc
@@ -387,9 +385,6 @@ SET(SQL_SHARED_SOURCES
387385
aggregate_check.cc
388386
gstream.cc
389387
handler.cc
390-
hash_join_buffer.cc
391-
hash_join_chunk.cc
392-
hash_join_iterator.cc
393388
histograms/equi_height.cc
394389
histograms/equi_height_bucket.cc
395390
histograms/histogram.cc
@@ -414,6 +409,15 @@ SET(SQL_SHARED_SOURCES
414409
item_timefunc.cc
415410
item_xmlfunc.cc
416411
item_inetfunc.cc
412+
iterators/basic_row_iterators.cc
413+
iterators/bka_iterator.cc
414+
iterators/composite_iterators.cc
415+
iterators/hash_join_buffer.cc
416+
iterators/hash_join_chunk.cc
417+
iterators/hash_join_iterator.cc
418+
iterators/ref_row_iterators.cc
419+
iterators/sorting_iterator.cc
420+
iterators/window_iterators.cc
417421
join_optimizer/access_path.cc
418422
join_optimizer/build_interesting_orders.cc
419423
join_optimizer/common_subexpression_elimination.cc
@@ -494,7 +498,6 @@ SET(SQL_SHARED_SOURCES
494498
range_optimizer/rowid_ordered_retrieval.cc
495499
range_optimizer/rowid_ordered_retrieval_plan.cc
496500
range_optimizer/tree.cc
497-
records.cc
498501
regexp/errors.cc
499502
regexp/regexp_engine.cc
500503
regexp/regexp_facade.cc
@@ -512,7 +515,6 @@ SET(SQL_SHARED_SOURCES
512515
sdi_utils.cc
513516
session_tracker.cc
514517
set_var.cc
515-
sorting_iterator.cc
516518
sp.cc
517519
sp_cache.cc
518520
sp_head.cc
@@ -620,7 +622,6 @@ SET(SQL_SHARED_SOURCES
620622
trigger_chain.cc
621623
tztime.cc
622624
uniques.cc
623-
window_iterators.cc
624625
xa.cc
625626
daemon_proxy_keyring/daemon_proxy_keyring.cc
626627
)
@@ -806,7 +807,7 @@ MY_ADD_COMPILE_DEFINITIONS(
806807

807808
ADD_COMPILE_FLAGS(
808809
${BUNDLED_LZ4_PATH}/xxhash.c
809-
hash_join_iterator.cc
810+
iterators/hash_join_iterator.cc
810811
rpl_write_set_handler.cc
811812
COMPILE_FLAGS -I${CMAKE_SOURCE_DIR}/extra/lz4 -I${BUNDLED_LZ4_PATH}
812813
)

sql/auth/acl_table_user.cc

+6-6
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
5555
#include "sql/field.h" /* Field, Field_json, Field_enum, TYPE_OK */
5656
#include "sql/handler.h" /* handler, DB_TYPE_NDBCLUSTER, handlerton */
5757
#include "sql/item_func.h" /* mqh_used */
58-
#include "sql/key.h" /* key_copy, KEY */
59-
#include "sql/mysqld.h" /* specialflag */
60-
#include "sql/records.h"
61-
#include "sql/row_iterator.h" /* RowIterator */
62-
#include "sql/sql_class.h" /* THD */
63-
#include "sql/sql_const.h" /* ACL_ALLOC_BLOCK_SIZE, MAX_KEY_LENGTH */
58+
#include "sql/iterators/row_iterator.h" /* RowIterator */
59+
#include "sql/key.h" /* key_copy, KEY */
60+
#include "sql/mysqld.h" /* specialflag */
61+
#include "sql/sql_class.h" /* THD */
62+
#include "sql/sql_const.h" /* ACL_ALLOC_BLOCK_SIZE, MAX_KEY_LENGTH */
63+
#include "sql/sql_executor.h"
6464
#include "sql/sql_lex.h" /* LEX */
6565
#include "sql/sql_plugin.h" /* plugin_unlock, my_plugin_lock_by_name */
6666
#include "sql/sql_plugin_ref.h" /* plugin_decl, plugin_ref */

sql/auth/dynamic_privilege_table.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
4848
#include "sql/current_thd.h"
4949
#include "sql/field.h"
5050
#include "sql/handler.h"
51+
#include "sql/iterators/row_iterator.h"
5152
#include "sql/key.h"
52-
#include "sql/records.h"
53-
#include "sql/row_iterator.h"
5453
#include "sql/sql_const.h"
54+
#include "sql/sql_executor.h"
5555
#include "sql/table.h"
5656

5757
class THD;

sql/auth/role_tables.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@
4343
#include "sql/auth/sql_user_table.h"
4444
#include "sql/field.h"
4545
#include "sql/handler.h"
46+
#include "sql/iterators/row_iterator.h"
4647
#include "sql/key.h"
4748
#include "sql/mdl.h"
4849
#include "sql/mysqld.h"
49-
#include "sql/records.h"
50-
#include "sql/row_iterator.h"
5150
#include "sql/sql_base.h"
5251
#include "sql/sql_const.h"
52+
#include "sql/sql_executor.h"
5353
#include "sql/table.h"
5454
#include "sql_string.h"
5555
#include "thr_lock.h"

sql/auth/sql_auth_cache.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@
5757
#include "sql/error_handler.h" // Internal_error_handler
5858
#include "sql/field.h" // Field
5959
#include "sql/handler.h"
60+
#include "sql/iterators/row_iterator.h"
6061
#include "sql/key.h"
6162
#include "sql/mdl.h"
6263
#include "sql/mysqld.h" // my_localhost
6364
#include "sql/psi_memory_key.h" // key_memory_acl_mem
64-
#include "sql/records.h" // unique_ptr_destroy_only<RowIterator>
65-
#include "sql/row_iterator.h"
6665
#include "sql/set_var.h"
6766
#include "sql/sql_audit.h"
6867
#include "sql/sql_base.h" // open_and_lock_tables
6968
#include "sql/sql_class.h" // THD
7069
#include "sql/sql_const.h"
7170
#include "sql/sql_error.h"
71+
#include "sql/sql_executor.h" // unique_ptr_destroy_only<RowIterator>
7272
#include "sql/sql_lex.h"
7373
#include "sql/sql_plugin.h" // my_plugin_lock_by_name
7474
#include "sql/sql_plugin_ref.h"

sql/filesort.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
#include "sql/handler.h"
8383
#include "sql/item.h"
8484
#include "sql/item_subselect.h"
85+
#include "sql/iterators/row_iterator.h"
86+
#include "sql/iterators/sorting_iterator.h"
8587
#include "sql/json_dom.h" // Json_wrapper
8688
#include "sql/key_spec.h"
8789
#include "sql/malloc_allocator.h"
@@ -93,9 +95,7 @@
9395
#include "sql/opt_trace_context.h"
9496
#include "sql/pfs_batch_mode.h"
9597
#include "sql/psi_memory_key.h"
96-
#include "sql/row_iterator.h"
9798
#include "sql/sort_param.h"
98-
#include "sql/sorting_iterator.h"
9999
#include "sql/sql_array.h"
100100
#include "sql/sql_base.h"
101101
#include "sql/sql_bitmap.h"

sql/item_subselect.cc

+10-10
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,20 @@
5252
#include "mysql_com.h"
5353
#include "mysqld_error.h"
5454
#include "scope_guard.h"
55-
#include "sql/basic_row_iterators.h" // ZeroRowsIterator
5655
#include "sql/check_stack.h"
57-
#include "sql/composite_iterators.h" // FilterIterator
58-
#include "sql/current_thd.h" // current_thd
59-
#include "sql/debug_sync.h" // DEBUG_SYNC
60-
#include "sql/derror.h" // ER_THD
56+
#include "sql/current_thd.h" // current_thd
57+
#include "sql/debug_sync.h" // DEBUG_SYNC
58+
#include "sql/derror.h" // ER_THD
6159
#include "sql/field.h"
6260
#include "sql/handler.h"
6361
#include "sql/item_cmpfunc.h"
6462
#include "sql/item_func.h"
65-
#include "sql/item_sum.h" // Item_sum_max
63+
#include "sql/item_sum.h" // Item_sum_max
64+
#include "sql/iterators/basic_row_iterators.h" // ZeroRowsIterator
65+
#include "sql/iterators/composite_iterators.h" // FilterIterator
66+
#include "sql/iterators/ref_row_iterators.h"
67+
#include "sql/iterators/row_iterator.h" // RowIterator
68+
#include "sql/iterators/timing_iterator.h"
6669
#include "sql/join_optimizer/access_path.h"
6770
#include "sql/join_optimizer/join_optimizer.h"
6871
#include "sql/key.h"
@@ -74,9 +77,7 @@
7477
#include "sql/parse_tree_nodes.h" // PT_subquery
7578
#include "sql/query_options.h"
7679
#include "sql/query_result.h"
77-
#include "sql/ref_row_iterators.h"
78-
#include "sql/row_iterator.h" // RowIterator
79-
#include "sql/sql_class.h" // THD
80+
#include "sql/sql_class.h" // THD
8081
#include "sql/sql_const.h"
8182
#include "sql/sql_error.h"
8283
#include "sql/sql_executor.h"
@@ -92,7 +93,6 @@
9293
#include "sql/table.h"
9394
#include "sql/temp_table_param.h"
9495
#include "sql/thd_raii.h"
95-
#include "sql/timing_iterator.h"
9696
#include "sql/window.h"
9797
#include "sql_string.h"
9898
#include "template_utils.h"

sql/item_subselect.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
#include "mysql_time.h"
4343
#include "sql/comp_creator.h"
4444
#include "sql/enum_query_type.h"
45-
#include "sql/item.h" // Item_result_field
46-
#include "sql/parse_location.h" // POS
45+
#include "sql/item.h" // Item_result_field
46+
#include "sql/iterators/row_iterator.h" // IWYU pragma: keep
47+
#include "sql/parse_location.h" // POS
4748
#include "sql/parse_tree_node_base.h"
48-
#include "sql/row_iterator.h" // IWYU pragma: keep
4949
#include "sql/sql_const.h"
5050
#include "sql/sql_opt_exec_shared.h"
5151
#include "template_utils.h"

sql/records.cc sql/iterators/basic_row_iterators.cc

+15-89
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,35 @@
2727
in some way). See row_iterator.h.
2828
*/
2929

30-
#include "sql/records.h"
31-
32-
#include <string.h>
33-
#include <algorithm>
30+
#include <assert.h>
3431
#include <atomic>
35-
#include <new>
32+
#include <memory>
33+
#include <string>
34+
#include <utility>
35+
#include <vector>
3636

37+
#include "my_alloc.h"
3738
#include "my_base.h"
3839
#include "my_dbug.h"
3940
#include "my_inttypes.h"
4041
#include "my_sys.h"
42+
#include "mysqld_error.h"
4143
#include "sql/debug_sync.h"
4244
#include "sql/handler.h"
43-
#include "sql/item.h"
45+
#include "sql/iterators/basic_row_iterators.h"
46+
#include "sql/iterators/row_iterator.h"
47+
#include "sql/iterators/timing_iterator.h"
4448
#include "sql/join_optimizer/access_path.h"
45-
#include "sql/join_optimizer/bit_utils.h"
46-
#include "sql/key.h"
47-
#include "sql/opt_explain.h"
49+
#include "sql/mem_root_array.h"
50+
#include "sql/sql_bitmap.h"
4851
#include "sql/sql_class.h" // THD
49-
#include "sql/sql_const.h"
5052
#include "sql/sql_executor.h"
51-
#include "sql/sql_optimizer.h"
5253
#include "sql/sql_sort.h"
5354
#include "sql/sql_tmp_table.h"
55+
#include "sql/system_variables.h"
5456
#include "sql/table.h"
55-
#include "sql/timing_iterator.h"
57+
58+
struct POSITION;
5659

5760
using std::string;
5861
using std::vector;
@@ -136,83 +139,6 @@ int IndexScanIterator<true>::Read() { // Backward read.
136139
template class IndexScanIterator<true>;
137140
template class IndexScanIterator<false>;
138141

139-
/**
140-
create_table_access_path is used to scan by using a number of different
141-
methods. Which method to use is set-up in this call so that you can
142-
create an iterator from the returned access path and fetch rows through
143-
said iterator afterwards.
144-
145-
@param thd Thread handle
146-
@param table Table the data [originally] comes from
147-
@param range_scan AccessPath to scan the table with, or nullptr
148-
@param table_ref
149-
Position for the table, must be non-nullptr for
150-
WITH RECURSIVE
151-
@param position Place to get cost information from, or nullptr
152-
@param count_examined_rows
153-
See AccessPath::count_examined_rows.
154-
*/
155-
AccessPath *create_table_access_path(THD *thd, TABLE *table,
156-
AccessPath *range_scan,
157-
TABLE_LIST *table_ref, POSITION *position,
158-
bool count_examined_rows) {
159-
AccessPath *path;
160-
if (range_scan != nullptr) {
161-
range_scan->count_examined_rows = count_examined_rows;
162-
path = range_scan;
163-
} else if (table_ref != nullptr && table_ref->is_recursive_reference()) {
164-
path = NewFollowTailAccessPath(thd, table, count_examined_rows);
165-
} else {
166-
path = NewTableScanAccessPath(thd, table, count_examined_rows);
167-
}
168-
if (position != nullptr) {
169-
SetCostOnTableAccessPath(*thd->cost_model(), position,
170-
/*is_after_filter=*/false, path);
171-
}
172-
return path;
173-
}
174-
175-
unique_ptr_destroy_only<RowIterator> init_table_iterator(
176-
THD *thd, TABLE *table, AccessPath *range_scan, TABLE_LIST *table_ref,
177-
POSITION *position, bool ignore_not_found_rows, bool count_examined_rows) {
178-
unique_ptr_destroy_only<RowIterator> iterator;
179-
180-
empty_record(table);
181-
182-
if (table->unique_result.io_cache &&
183-
my_b_inited(table->unique_result.io_cache)) {
184-
DBUG_PRINT("info", ("using SortFileIndirectIterator"));
185-
iterator = NewIterator<SortFileIndirectIterator>(
186-
thd, thd->mem_root, Mem_root_array<TABLE *>{table},
187-
table->unique_result.io_cache, ignore_not_found_rows,
188-
/*has_null_flags=*/false,
189-
/*examined_rows=*/nullptr);
190-
table->unique_result.io_cache =
191-
nullptr; // Now owned by SortFileIndirectIterator.
192-
} else if (table->unique_result.has_result_in_memory()) {
193-
/*
194-
The Unique class never puts its results into table->sort's
195-
Filesort_buffer.
196-
*/
197-
assert(!table->unique_result.sorted_result_in_fsbuf);
198-
DBUG_PRINT("info", ("using SortBufferIndirectIterator (unique)"));
199-
iterator = NewIterator<SortBufferIndirectIterator>(
200-
thd, thd->mem_root, Mem_root_array<TABLE *>{table},
201-
&table->unique_result, ignore_not_found_rows, /*has_null_flags=*/false,
202-
/*examined_rows=*/nullptr);
203-
} else {
204-
AccessPath *path = create_table_access_path(
205-
thd, table, range_scan, table_ref, position, count_examined_rows);
206-
iterator = CreateIteratorFromAccessPath(thd, path,
207-
/*join=*/nullptr,
208-
/*eligible_for_batch_mode=*/false);
209-
}
210-
if (iterator->Init()) {
211-
return nullptr;
212-
}
213-
return iterator;
214-
}
215-
216142
/**
217143
The default implementation of unlock-row method of RowIterator,
218144
used in all access methods except EQRefIterator.

sql/basic_row_iterators.h sql/iterators/basic_row_iterators.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef SQL_BASIC_ROW_ITERATORS_H_
2-
#define SQL_BASIC_ROW_ITERATORS_H_
1+
#ifndef SQL_ITERATORS_BASIC_ROW_ITERATORS_H_
2+
#define SQL_ITERATORS_BASIC_ROW_ITERATORS_H_
33

44
/* Copyright (c) 2018, 2021, Oracle and/or its affiliates.
55
@@ -38,8 +38,8 @@
3838
#include "my_alloc.h"
3939
#include "my_base.h"
4040
#include "my_inttypes.h"
41+
#include "sql/iterators/row_iterator.h"
4142
#include "sql/mem_root_array.h"
42-
#include "sql/row_iterator.h"
4343
#include "sql/sql_list.h"
4444

4545
class Filesort_info;
@@ -512,4 +512,4 @@ class TableValueConstructorIterator final : public RowIterator {
512512
mem_root_deque<Item *> *const m_output_refs;
513513
};
514514

515-
#endif // SQL_BASIC_ROW_ITERATORS_H_
515+
#endif // SQL_ITERATORS_BASIC_ROW_ITERATORS_H_

sql/bka_iterator.cc sql/iterators/bka_iterator.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
along with this program; if not, write to the Free Software
2121
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2222

23-
#include "sql/bka_iterator.h"
23+
#include "sql/iterators/bka_iterator.h"
2424

2525
#include <assert.h>
2626
#include <math.h>
@@ -40,10 +40,10 @@
4040
#include "my_sys.h"
4141
#include "mysqld_error.h"
4242
#include "sql/handler.h"
43-
#include "sql/hash_join_buffer.h"
4443
#include "sql/item.h"
44+
#include "sql/iterators/hash_join_buffer.h"
45+
#include "sql/iterators/row_iterator.h"
4546
#include "sql/psi_memory_key.h"
46-
#include "sql/row_iterator.h"
4747
#include "sql/sql_executor.h"
4848
#include "sql/sql_opt_exec_shared.h"
4949
#include "sql/table.h"

0 commit comments

Comments
 (0)