From 385d6453d3a589bbc9034c96d8c95b6115eef7b9 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Thu, 7 Dec 2023 13:41:00 +0800 Subject: [PATCH 1/7] 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 2a062d6474f78fbbb64ee54e9f3ce35c0bc6cbd9 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Thu, 7 Dec 2023 13:41:14 +0800 Subject: [PATCH 2/7] 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 f034ef2b373b633e5a0ee494d2a1397a20e7ced3 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Thu, 7 Dec 2023 14:12:42 +0800 Subject: [PATCH 3/7] 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 41ab6d8a9da35d95807ea46728629c31d5884038 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Wed, 13 Dec 2023 12:57:21 +0800 Subject: [PATCH 4/7] 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 8da85e4c41384a741423897716a55679412b054f Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Wed, 13 Dec 2023 13:30:29 +0800 Subject: [PATCH 5/7] 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 0a0e019f49c53126abbd37443c591c0c48861297 Mon Sep 17 00:00:00 2001 From: Lloyd-Pottiger Date: Thu, 14 Dec 2023 15:11:07 +0800 Subject: [PATCH 6/7] 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 aae7146f4dbd31ea0779c599ae8f364aec749b90 Mon Sep 17 00:00:00 2001 From: JaySon Date: Thu, 14 Dec 2023 16:25:14 +0800 Subject: [PATCH 7/7] 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.