Skip to content

Commit cffc61e

Browse files
fix keep order in table scan is lost when remote read of PartitionTableScan(release-7.1) (#7526)
close #7519, close #7527
1 parent d649184 commit cffc61e

File tree

3 files changed

+103
-7
lines changed

3 files changed

+103
-7
lines changed

dbms/src/Flash/Coprocessor/TiDBTableScan.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ TiDBTableScan::TiDBTableScan(
2929
// Only No-partition table need keep order when tablescan executor required keep order.
3030
// If keep_order is not set, keep order for safety.
3131
, keep_order(!is_partition_table_scan && (table_scan->tbl_scan().keep_order() || !table_scan->tbl_scan().has_keep_order()))
32-
, is_fast_scan(table_scan->tbl_scan().is_fast_scan())
32+
, is_fast_scan(is_partition_table_scan ? table_scan->partition_table_scan().is_fast_scan() : table_scan->tbl_scan().is_fast_scan())
3333
{
34+
RUNTIME_CHECK_MSG(!keep_order || pushed_down_filters.empty(), "Bad TiDB table scan executor: push down filter is not empty when keep order is true");
35+
3436
if (is_partition_table_scan)
3537
{
3638
if (table_scan->partition_table_scan().has_table_id())
@@ -79,6 +81,7 @@ void TiDBTableScan::constructTableScanForRemoteRead(tipb::TableScan * tipb_table
7981
for (auto id : partition_table_scan.primary_prefix_column_ids())
8082
tipb_table_scan->add_primary_prefix_column_ids(id);
8183
tipb_table_scan->set_is_fast_scan(partition_table_scan.is_fast_scan());
84+
tipb_table_scan->set_keep_order(false);
8285
}
8386
else
8487
{

dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,10 @@ static ReadMode getReadModeImpl(const Context & db_context, bool is_fast_scan, b
10201020
ReadMode DeltaMergeStore::getReadMode(const Context & db_context, bool is_fast_scan, bool keep_order, const PushDownFilterPtr & filter)
10211021
{
10221022
auto read_mode = getReadModeImpl(db_context, is_fast_scan, keep_order);
1023-
RUNTIME_CHECK_MSG(!filter || !filter->before_where || read_mode == ReadMode::Bitmap, "Push down filters needs bitmap");
1023+
RUNTIME_CHECK_MSG(!filter || !filter->before_where || read_mode == ReadMode::Bitmap,
1024+
"Push down filters needs bitmap, push down filters is empty: {}, read mode: {}",
1025+
filter == nullptr || filter->before_where == nullptr,
1026+
magic_enum::enum_name(read_mode));
10241027
return read_mode;
10251028
}
10261029

@@ -1050,11 +1053,13 @@ BlockInputStreams DeltaMergeStore::read(const Context & db_context,
10501053
SegmentReadTasks tasks = getReadTasksByRanges(*dm_context, sorted_ranges, num_streams, read_segments, /*try_split_task =*/!enable_read_thread);
10511054
auto log_tracing_id = getLogTracingId(*dm_context);
10521055
auto tracing_logger = log->getChild(log_tracing_id);
1053-
LOG_DEBUG(tracing_logger,
1054-
"Read create segment snapshot done, keep_order={} dt_enable_read_thread={} enable_read_thread={}",
1055-
keep_order,
1056-
db_context.getSettingsRef().dt_enable_read_thread,
1057-
enable_read_thread);
1056+
LOG_INFO(tracing_logger,
1057+
"Read create segment snapshot done, keep_order={} dt_enable_read_thread={} enable_read_thread={} is_fast_scan={} is_push_down_filter_empty={}",
1058+
keep_order,
1059+
db_context.getSettingsRef().dt_enable_read_thread,
1060+
enable_read_thread,
1061+
is_fast_scan,
1062+
filter == nullptr || filter->before_where == nullptr);
10581063

10591064
auto after_segment_read = [&](const DMContextPtr & dm_context_, const SegmentPtr & segment_) {
10601065
// TODO: Update the tracing_id before checkSegmentUpdate?
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright 2023 PingCAP, Ltd.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Preparation.
16+
=> DBGInvoke __init_fail_point()
17+
18+
mysql> drop table if exists test.t
19+
mysql> create table test.t (x int, a varchar(50), y int, t time) partition by range (x) (partition p0 values less than (5), partition p1 values less than (10));
20+
21+
mysql> insert into test.t values (1, 'a', 1, '700:11:11.1234'), (2, 'b', 2, '711:12:12.1234');
22+
mysql> insert into test.t select * from test.t;
23+
mysql> insert into test.t select * from test.t;
24+
mysql> insert into test.t select * from test.t;
25+
mysql> insert into test.t select * from test.t;
26+
mysql> insert into test.t select * from test.t;
27+
mysql> insert into test.t select * from test.t;
28+
mysql> insert into test.t select * from test.t;
29+
mysql> insert into test.t select * from test.t;
30+
mysql> insert into test.t select * from test.t;
31+
mysql> insert into test.t select * from test.t;
32+
mysql> insert into test.t select * from test.t;
33+
mysql> insert into test.t select * from test.t;
34+
mysql> insert into test.t select * from test.t;
35+
mysql> insert into test.t values (8, 'c', 8, '500:21:21.1234');
36+
37+
mysql> alter table test.t set tiflash replica 1;
38+
func> wait_table test t
39+
mysql> analyze table test.t;
40+
41+
mysql> set tidb_partition_prune_mode=dynamic; set tidb_enforce_mpp=1; select count(*) from test.t;
42+
+----------+
43+
| count(*) |
44+
+----------+
45+
| 16385 |
46+
+----------+
47+
48+
mysql> set tidb_partition_prune_mode=dynamic; set tidb_enforce_mpp=1; select * from test.t where x >= 5 and x < 10;
49+
+------+------+------+-----------+
50+
| x | a | y | t |
51+
+------+------+------+-----------+
52+
| 8 | c | 8 | 500:21:21 |
53+
+------+------+------+-----------+
54+
55+
mysql> set tidb_partition_prune_mode=dynamic; set tidb_enforce_mpp=1; select x, a, y, hour(t) from test.t where x >= 5 and x < 10;
56+
+------+------+------+---------+
57+
| x | a | y | hour(t) |
58+
+------+------+------+---------+
59+
| 8 | c | 8 | 500 |
60+
+------+------+------+---------+
61+
62+
=> DBGInvoke __enable_fail_point(force_remote_read_for_batch_cop)
63+
64+
mysql> set tidb_partition_prune_mode=dynamic; set tidb_enforce_mpp=1; select count(*) from test.t;
65+
+----------+
66+
| count(*) |
67+
+----------+
68+
| 16385 |
69+
+----------+
70+
71+
mysql> set tidb_partition_prune_mode=dynamic; set tidb_enforce_mpp=1; select * from test.t where x >= 5 and x < 10;
72+
+------+------+------+-----------+
73+
| x | a | y | t |
74+
+------+------+------+-----------+
75+
| 8 | c | 8 | 500:21:21 |
76+
+------+------+------+-----------+
77+
78+
mysql> set tidb_partition_prune_mode=dynamic; set tidb_enforce_mpp=1; select x, a, y, hour(t) from test.t where x >= 5 and x < 10;
79+
+------+------+------+---------+
80+
| x | a | y | hour(t) |
81+
+------+------+------+---------+
82+
| 8 | c | 8 | 500 |
83+
+------+------+------+---------+
84+
85+
=> DBGInvoke __disable_fail_point(force_remote_read_for_batch_cop)
86+
87+
# Clean up.
88+
mysql> drop table if exists test.t;

0 commit comments

Comments
 (0)