From 1538335ebeb3615284e36bc99adf247a9b2082ff Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Thu, 7 Dec 2023 13:41:00 +0800 Subject: [PATCH 1/8] add test Signed-off-by: Lloyd-Pottiger --- .../mpp/apply_with_late_materialization.test | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/fullstack-test/mpp/apply_with_late_materialization.test diff --git a/tests/fullstack-test/mpp/apply_with_late_materialization.test b/tests/fullstack-test/mpp/apply_with_late_materialization.test new file mode 100644 index 00000000000..82b78905537 --- /dev/null +++ b/tests/fullstack-test/mpp/apply_with_late_materialization.test @@ -0,0 +1,62 @@ +# Copyright 2023 PingCAP, Inc. +# +# 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. + + +# https://github.com/pingcap/tidb/issues/49241 +# Preparation. +mysql> drop table if exists t; +mysql> drop table if exists t1; +mysql> create table t(id int, value int); +mysql> create table t1(id int, value int); +mysql> insert into t values(10,5),(9,5),(8,5),(7,5),(6,5),(5,5),(4,5),(3,5),(2,5),(1,5); +mysql> insert into t1 values(2,5); +mysql> insert into t select * from t; +mysql> insert into t select * from t; +mysql> insert into t select * from t; +mysql> insert into t select * from t; +mysql> insert into t select * from t; +mysql> insert into t select * from t; +mysql> insert into t select * from t; +mysql> insert into t select * from t; +mysql> insert into t select * from t; +mysql> insert into t select * from t; +mysql> insert into t select * from t; +mysql> alter table t set tiflash replica 1; +mysql> alter table t1 set tiflash replica 1; + +# Test. +mysql> set @@tidb_allow_mpp=1; set @@tidb_opt_enable_late_materialization=1; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; ++------+ +| xx | ++------+ +| 5 | ++------+ +mysql> set @@tidb_allow_mpp=1; set @@tidb_opt_enable_late_materialization=0; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; ++------+ +| xx | ++------+ +| 5 | ++------+ +mysql> set @@tidb_allow_mpp=0; set @@tidb_opt_enable_late_materialization=1; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; ++------+ +| xx | ++------+ +| 5 | ++------+ +mysql> set @@tidb_allow_mpp=0; set @@tidb_opt_enable_late_materialization=0; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; ++------+ +| xx | ++------+ +| 5 | ++------+ \ No newline at end of file From ad5aff0f410dd40c467a5539693c3182cd422f79 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Thu, 7 Dec 2023 13:41:14 +0800 Subject: [PATCH 2/8] add test Signed-off-by: Lloyd-Pottiger --- tests/fullstack-test/mpp/apply_with_late_materialization.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fullstack-test/mpp/apply_with_late_materialization.test b/tests/fullstack-test/mpp/apply_with_late_materialization.test index 82b78905537..267a0a413a4 100644 --- a/tests/fullstack-test/mpp/apply_with_late_materialization.test +++ b/tests/fullstack-test/mpp/apply_with_late_materialization.test @@ -59,4 +59,4 @@ mysql> set @@tidb_allow_mpp=0; set @@tidb_opt_enable_late_materialization=0; sel | xx | +------+ | 5 | -+------+ \ No newline at end of file ++------+ From c75e0dd28769498eaf8f9220abd909e954f40f89 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Thu, 7 Dec 2023 14:12:42 +0800 Subject: [PATCH 3/8] refine Signed-off-by: Lloyd-Pottiger --- .../mpp/apply_with_late_materialization.test | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/fullstack-test/mpp/apply_with_late_materialization.test b/tests/fullstack-test/mpp/apply_with_late_materialization.test index 267a0a413a4..75ec02ccaab 100644 --- a/tests/fullstack-test/mpp/apply_with_late_materialization.test +++ b/tests/fullstack-test/mpp/apply_with_late_materialization.test @@ -21,19 +21,16 @@ mysql> create table t(id int, value int); mysql> create table t1(id int, value int); mysql> insert into t values(10,5),(9,5),(8,5),(7,5),(6,5),(5,5),(4,5),(3,5),(2,5),(1,5); mysql> insert into t1 values(2,5); -mysql> insert into t select * from t; -mysql> insert into t select * from t; -mysql> insert into t select * from t; -mysql> insert into t select * from t; -mysql> insert into t select * from t; -mysql> insert into t select * from t; -mysql> insert into t select * from t; -mysql> insert into t select * from t; -mysql> insert into t select * from t; -mysql> insert into t select * from t; -mysql> insert into t select * from t; +# insert more than 8192 rows to make sure late materialization is enabled. +mysql> insert into t select * from t; insert into t select * from t; insert into t select * from t; insert into t select * from t; +mysql> insert into t select * from t; insert into t select * from t; insert into t select * from t; insert into t select * from t; +mysql> insert into t select * from t; insert into t select * from t; insert into t select * from t; mysql> alter table t set tiflash replica 1; mysql> alter table t1 set tiflash replica 1; +mysql> analyze table t; + +func> wait_table test t t +func> wait_table test t t1 # Test. mysql> set @@tidb_allow_mpp=1; set @@tidb_opt_enable_late_materialization=1; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; @@ -60,3 +57,7 @@ mysql> set @@tidb_allow_mpp=0; set @@tidb_opt_enable_late_materialization=0; sel +------+ | 5 | +------+ + +# Clean up. +mysql> drop table if exists t; +mysql> drop table if exists t1; From 5c221dd0e2c51f4b8890a0bc03b2b8a6c0f3514f Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Wed, 13 Dec 2023 12:57:21 +0800 Subject: [PATCH 4/8] test cop/batchcop Signed-off-by: Lloyd-Pottiger --- .../mpp/apply_with_late_materialization.test | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/fullstack-test/mpp/apply_with_late_materialization.test b/tests/fullstack-test/mpp/apply_with_late_materialization.test index 75ec02ccaab..56b83e00da1 100644 --- a/tests/fullstack-test/mpp/apply_with_late_materialization.test +++ b/tests/fullstack-test/mpp/apply_with_late_materialization.test @@ -33,6 +33,8 @@ func> wait_table test t t func> wait_table test t t1 # Test. + +# MPP mysql> set @@tidb_allow_mpp=1; set @@tidb_opt_enable_late_materialization=1; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +------+ | xx | @@ -45,13 +47,29 @@ mysql> set @@tidb_allow_mpp=1; set @@tidb_opt_enable_late_materialization=0; sel +------+ | 5 | +------+ -mysql> set @@tidb_allow_mpp=0; set @@tidb_opt_enable_late_materialization=1; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; + +# BatchCop +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 1; set @@tidb_opt_enable_late_materialization=1; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; ++------+ +| xx | ++------+ +| 5 | ++------+ +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 1; set @@tidb_opt_enable_late_materialization=0; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; ++------+ +| xx | ++------+ +| 5 | ++------+ + +# Cop +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 0; set @@tidb_opt_enable_late_materialization=1; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +------+ | xx | +------+ | 5 | +------+ -mysql> set @@tidb_allow_mpp=0; set @@tidb_opt_enable_late_materialization=0; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 0; set @@tidb_opt_enable_late_materialization=0; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +------+ | xx | +------+ From 2d0c4edcdbf19b2029299035438a01437ecf5659 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Wed, 13 Dec 2023 13:30:29 +0800 Subject: [PATCH 5/8] tidb_allow_batch_cop = 2 Signed-off-by: Lloyd-Pottiger --- tests/fullstack-test/mpp/apply_with_late_materialization.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/fullstack-test/mpp/apply_with_late_materialization.test b/tests/fullstack-test/mpp/apply_with_late_materialization.test index 56b83e00da1..3abacb377d4 100644 --- a/tests/fullstack-test/mpp/apply_with_late_materialization.test +++ b/tests/fullstack-test/mpp/apply_with_late_materialization.test @@ -49,13 +49,13 @@ mysql> set @@tidb_allow_mpp=1; set @@tidb_opt_enable_late_materialization=0; sel +------+ # BatchCop -mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 1; set @@tidb_opt_enable_late_materialization=1; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 2; set @@tidb_opt_enable_late_materialization=1; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +------+ | xx | +------+ | 5 | +------+ -mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 1; set @@tidb_opt_enable_late_materialization=0; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 2; set @@tidb_opt_enable_late_materialization=0; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +------+ | xx | +------+ From 998f714794dddc2d93821f18a367cc0827fa5668 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Thu, 14 Dec 2023 15:11:07 +0800 Subject: [PATCH 6/8] fix not database selected Signed-off-by: Lloyd-Pottiger --- .../mpp/apply_with_late_materialization.test | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/fullstack-test/mpp/apply_with_late_materialization.test b/tests/fullstack-test/mpp/apply_with_late_materialization.test index 3abacb377d4..f9888b1eb17 100644 --- a/tests/fullstack-test/mpp/apply_with_late_materialization.test +++ b/tests/fullstack-test/mpp/apply_with_late_materialization.test @@ -15,19 +15,19 @@ # https://github.com/pingcap/tidb/issues/49241 # Preparation. -mysql> drop table if exists t; -mysql> drop table if exists t1; -mysql> create table t(id int, value int); -mysql> create table t1(id int, value int); -mysql> insert into t values(10,5),(9,5),(8,5),(7,5),(6,5),(5,5),(4,5),(3,5),(2,5),(1,5); -mysql> insert into t1 values(2,5); +mysql> drop table if exists test.t; +mysql> drop table if exists test.t1; +mysql> create table test.t(id int, value int); +mysql> create table test.t1(id int, value int); +mysql> insert into test.t values(10,5),(9,5),(8,5),(7,5),(6,5),(5,5),(4,5),(3,5),(2,5),(1,5); +mysql> insert into test.t1 values(2,5); # insert more than 8192 rows to make sure late materialization is enabled. -mysql> insert into t select * from t; insert into t select * from t; insert into t select * from t; insert into t select * from t; -mysql> insert into t select * from t; insert into t select * from t; insert into t select * from t; insert into t select * from t; -mysql> insert into t select * from t; insert into t select * from t; insert into t select * from t; -mysql> alter table t set tiflash replica 1; -mysql> alter table t1 set tiflash replica 1; -mysql> analyze table t; +mysql> insert into test.t select * from test.t; insert into test.t select * from test.t; insert into test.t select * from test.t; insert into test.t select * from test.t; +mysql> insert into test.t select * from test.t; insert into test.t select * from test.t; insert into test.t select * from test.t; insert into test.t select * from test.t; +mysql> insert into test.t select * from test.t; insert into test.t select * from test.t; insert into test.t select * from test.t; +mysql> alter table test.t set tiflash replica 1; +mysql> alter table test.t1 set tiflash replica 1; +mysql> analyze table test.t; func> wait_table test t t func> wait_table test t t1 @@ -35,13 +35,13 @@ func> wait_table test t t1 # Test. # MPP -mysql> set @@tidb_allow_mpp=1; set @@tidb_opt_enable_late_materialization=1; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=1; set @@tidb_opt_enable_late_materialization=1; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +------+ | xx | +------+ | 5 | +------+ -mysql> set @@tidb_allow_mpp=1; set @@tidb_opt_enable_late_materialization=0; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=1; set @@tidb_opt_enable_late_materialization=0; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +------+ | xx | +------+ @@ -49,13 +49,13 @@ mysql> set @@tidb_allow_mpp=1; set @@tidb_opt_enable_late_materialization=0; sel +------+ # BatchCop -mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 2; set @@tidb_opt_enable_late_materialization=1; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 2; set @@tidb_opt_enable_late_materialization=1; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +------+ | xx | +------+ | 5 | +------+ -mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 2; set @@tidb_opt_enable_late_materialization=0; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 2; set @@tidb_opt_enable_late_materialization=0; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +------+ | xx | +------+ @@ -63,13 +63,13 @@ mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allo +------+ # Cop -mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 0; set @@tidb_opt_enable_late_materialization=1; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 0; set @@tidb_opt_enable_late_materialization=1; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +------+ | xx | +------+ | 5 | +------+ -mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 0; set @@tidb_opt_enable_late_materialization=0; select (select t.value from t where t.id = t1.id order by t.value limit 1) xx from t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 0; set @@tidb_opt_enable_late_materialization=0; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +------+ | xx | +------+ @@ -77,5 +77,5 @@ mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allo +------+ # Clean up. -mysql> drop table if exists t; -mysql> drop table if exists t1; +mysql> drop table if exists test.t; +mysql> drop table if exists test.t1; From 33d1738aac1bb2b18f51cec33aff34fb81987db7 Mon Sep 17 00:00:00 2001 From: JaySon Date: Thu, 14 Dec 2023 16:25:14 +0800 Subject: [PATCH 7/8] fix wait table --- tests/fullstack-test/mpp/apply_with_late_materialization.test | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/fullstack-test/mpp/apply_with_late_materialization.test b/tests/fullstack-test/mpp/apply_with_late_materialization.test index f9888b1eb17..c62df328813 100644 --- a/tests/fullstack-test/mpp/apply_with_late_materialization.test +++ b/tests/fullstack-test/mpp/apply_with_late_materialization.test @@ -29,7 +29,6 @@ mysql> alter table test.t set tiflash replica 1; mysql> alter table test.t1 set tiflash replica 1; mysql> analyze table test.t; -func> wait_table test t t func> wait_table test t t1 # Test. From ac7d122422359570db6ee96bd1144bc7a8c337d1 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Fri, 15 Dec 2023 17:14:30 +0800 Subject: [PATCH 8/8] fix Signed-off-by: Lloyd-Pottiger --- .../mpp/apply_with_late_materialization.test | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/fullstack-test/mpp/apply_with_late_materialization.test b/tests/fullstack-test/mpp/apply_with_late_materialization.test index c62df328813..9b27f32f6a4 100644 --- a/tests/fullstack-test/mpp/apply_with_late_materialization.test +++ b/tests/fullstack-test/mpp/apply_with_late_materialization.test @@ -48,13 +48,13 @@ mysql> set @@tidb_allow_mpp=1; set @@tidb_opt_enable_late_materialization=0; sel +------+ # BatchCop -mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 2; set @@tidb_opt_enable_late_materialization=1; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_batch_cop = 2; set @@tidb_opt_enable_late_materialization=1; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +------+ | xx | +------+ | 5 | +------+ -mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 2; set @@tidb_opt_enable_late_materialization=0; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_batch_cop = 2; set @@tidb_opt_enable_late_materialization=0; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +------+ | xx | +------+ @@ -62,13 +62,13 @@ mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allo +------+ # Cop -mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 0; set @@tidb_opt_enable_late_materialization=1; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_batch_cop = 0; set @@tidb_opt_enable_late_materialization=1; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +------+ | xx | +------+ | 5 | +------+ -mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_tiflash_cop = 1; set @@tidb_allow_batch_cop = 0; set @@tidb_opt_enable_late_materialization=0; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +mysql> set @@tidb_allow_mpp=0; set @@tidb_allow_batch_cop = 0; set @@tidb_opt_enable_late_materialization=0; select (select t.value from test.t where t.id = t1.id order by t.value limit 1) xx from test.t1 order by t1.value limit 5; +------+ | xx | +------+