Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix keep order in table scan is lost when remote read of PartitionTableScan #7529

Merged
merged 5 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dbms/src/Flash/Coprocessor/TiDBTableScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ TiDBTableScan::TiDBTableScan(
, keep_order(!is_partition_table_scan && (table_scan->tbl_scan().keep_order() || !table_scan->tbl_scan().has_keep_order()))
, is_fast_scan(is_partition_table_scan ? table_scan->partition_table_scan().is_fast_scan() : table_scan->tbl_scan().is_fast_scan())
{
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");

if (is_partition_table_scan)
{
if (table_scan->partition_table_scan().has_table_id())
Expand Down Expand Up @@ -79,6 +81,7 @@ void TiDBTableScan::constructTableScanForRemoteRead(tipb::TableScan * tipb_table
for (auto id : partition_table_scan.primary_prefix_column_ids())
tipb_table_scan->add_primary_prefix_column_ids(id);
tipb_table_scan->set_is_fast_scan(partition_table_scan.is_fast_scan());
tipb_table_scan->set_keep_order(false);
Copy link
Contributor

@JaySon-Huang JaySon-Huang May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also pick this change back to release-6.5 branch @Lloyd-Pottiger

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

}
else
{
Expand Down
2 changes: 1 addition & 1 deletion dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ BlockInputStreams DeltaMergeStore::read(const Context & db_context,
auto log_tracing_id = getLogTracingId(*dm_context);
auto tracing_logger = log->getChild(log_tracing_id);
LOG_INFO(tracing_logger,
"Read create segment snapshot done, keep_order={} dt_enable_read_thread={} enable_read_thread={}, is_fast_scan={}, is_push_down_filter_empty={}",
"Read create segment snapshot done, keep_order={} dt_enable_read_thread={} enable_read_thread={} is_fast_scan={} is_push_down_filter_empty={}",
keep_order,
db_context.getSettingsRef().dt_enable_read_thread,
enable_read_thread,
Expand Down
88 changes: 88 additions & 0 deletions tests/fullstack-test/issues/issue_7519.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright 2023 PingCAP, Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Preparation.
=> DBGInvoke __init_fail_point()

mysql> drop table if exists test.t
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));

mysql> insert into test.t values (1, 'a', 1, '700:11:11.1234'), (2, 'b', 2, '711:12:12.1234');
mysql> insert into test.t select * from test.t;
mysql> insert into test.t select * from test.t;
mysql> insert into test.t select * from test.t;
mysql> insert into test.t select * from test.t;
mysql> insert into test.t select * from test.t;
mysql> insert into test.t select * from test.t;
mysql> insert into test.t select * from test.t;
mysql> insert into test.t select * from test.t;
mysql> insert into test.t select * from test.t;
mysql> insert into test.t select * from test.t;
mysql> insert into test.t select * from test.t;
mysql> insert into test.t select * from test.t;
mysql> insert into test.t select * from test.t;
mysql> insert into test.t values (8, 'c', 8, '500:21:21.1234');

mysql> alter table test.t set tiflash replica 1;
func> wait_table test t
mysql> analyze table test.t;

mysql> set tidb_partition_prune_mode=dynamic; set tidb_enforce_mpp=1; select count(*) from test.t;
+----------+
| count(*) |
+----------+
| 16385 |
+----------+

mysql> set tidb_partition_prune_mode=dynamic; set tidb_enforce_mpp=1; select * from test.t where x >= 5 and x < 10;
+------+------+------+-----------+
| x | a | y | t |
+------+------+------+-----------+
| 8 | c | 8 | 500:21:21 |
+------+------+------+-----------+

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;
+------+------+------+---------+
| x | a | y | hour(t) |
+------+------+------+---------+
| 8 | c | 8 | 500 |
+------+------+------+---------+

=> DBGInvoke __enable_fail_point(force_remote_read_for_batch_cop)

mysql> set tidb_partition_prune_mode=dynamic; set tidb_enforce_mpp=1; select count(*) from test.t;
+----------+
| count(*) |
+----------+
| 16385 |
+----------+

mysql> set tidb_partition_prune_mode=dynamic; set tidb_enforce_mpp=1; select * from test.t where x >= 5 and x < 10;
+------+------+------+-----------+
| x | a | y | t |
+------+------+------+-----------+
| 8 | c | 8 | 500:21:21 |
+------+------+------+-----------+

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;
+------+------+------+---------+
| x | a | y | hour(t) |
+------+------+------+---------+
| 8 | c | 8 | 500 |
+------+------+------+---------+

=> DBGInvoke __disable_fail_point(force_remote_read_for_batch_cop)

# Clean up.
mysql> drop table if exists test.t;