-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
executor: add some test cases about dynamic-mode and apply operator #24683
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ab2a29f
add some cases about apply
qw4990 8738669
add random queries
qw4990 997b059
make linter happy
qw4990 8b30588
Merge branch 'master' into dynamicmode-apply
qw4990 ba8aaa0
Merge branch 'master' into dynamicmode-apply
qw4990 5a13489
Merge branch 'master' into dynamicmode-apply
ti-chi-bot acc2c8a
Merge branch 'master' into dynamicmode-apply
ti-chi-bot 22f19cc
Merge branch 'master' into dynamicmode-apply
ti-chi-bot 0e4870d
Merge branch 'master' into dynamicmode-apply
ti-chi-bot 3e78cf7
Merge branch 'master' into dynamicmode-apply
ti-chi-bot 7d92d58
Merge branch 'master' into dynamicmode-apply
ti-chi-bot 28436d5
Merge branch 'master' into dynamicmode-apply
ti-chi-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,8 +240,8 @@ func (s *partitionTableSuite) TestOrderByandLimit(c *C) { | |
|
||
// range partition table | ||
tk.MustExec(`create table trange(a int, b int, index idx_a(a)) partition by range(a) ( | ||
partition p0 values less than(300), | ||
partition p1 values less than (500), | ||
partition p0 values less than(300), | ||
partition p1 values less than (500), | ||
partition p2 values less than(1100));`) | ||
|
||
// hash partition table | ||
|
@@ -1298,6 +1298,146 @@ func (s *partitionTableSuite) TestSplitRegion(c *C) { | |
tk.MustPartition(`select * from thash where a in (1, 10001, 20001)`, "p1").Sort().Check(result) | ||
} | ||
|
||
func (s *partitionTableSuite) TestParallelApply(c *C) { | ||
if israce.RaceEnabled { | ||
c.Skip("exhaustive types test, skip race test") | ||
} | ||
|
||
tk := testkit.NewTestKitWithInit(c, s.store) | ||
tk.MustExec("create database test_parallel_apply") | ||
tk.MustExec("use test_parallel_apply") | ||
tk.MustExec("set @@tidb_partition_prune_mode = 'dynamic'") | ||
tk.MustExec("set tidb_enable_parallel_apply=true") | ||
|
||
tk.MustExec(`create table touter (a int, b int)`) | ||
tk.MustExec(`create table tinner (a int, b int, key(a))`) | ||
tk.MustExec(`create table thash (a int, b int, key(a)) partition by hash(a) partitions 4`) | ||
tk.MustExec(`create table trange (a int, b int, key(a)) partition by range(a) ( | ||
partition p0 values less than(10000), | ||
partition p1 values less than(20000), | ||
partition p2 values less than(30000), | ||
partition p3 values less than(40000))`) | ||
|
||
vouter := make([]string, 0, 100) | ||
for i := 0; i < 100; i++ { | ||
vouter = append(vouter, fmt.Sprintf("(%v, %v)", rand.Intn(40000), rand.Intn(40000))) | ||
} | ||
tk.MustExec("insert into touter values " + strings.Join(vouter, ", ")) | ||
|
||
vals := make([]string, 0, 2000) | ||
for i := 0; i < 100; i++ { | ||
vals = append(vals, fmt.Sprintf("(%v, %v)", rand.Intn(40000), rand.Intn(40000))) | ||
} | ||
tk.MustExec("insert into tinner values " + strings.Join(vals, ", ")) | ||
tk.MustExec("insert into thash values " + strings.Join(vals, ", ")) | ||
tk.MustExec("insert into trange values " + strings.Join(vals, ", ")) | ||
|
||
// parallel apply + hash partition + IndexReader as its inner child | ||
tk.MustQuery(`explain format='brief' select * from touter where touter.a > (select sum(thash.a) from thash use index(a) where thash.a>touter.b)`).Check(testkit.Rows( | ||
`Projection 10000.00 root test_parallel_apply.touter.a, test_parallel_apply.touter.b`, | ||
`└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(cast(test_parallel_apply.touter.a, decimal(20,0) BINARY), Column#7)`, | ||
` ├─TableReader(Build) 10000.00 root data:TableFullScan`, | ||
` │ └─TableFullScan 10000.00 cop[tikv] table:touter keep order:false, stats:pseudo`, | ||
` └─StreamAgg(Probe) 1.00 root funcs:sum(Column#9)->Column#7`, | ||
` └─IndexReader 1.00 root partition:all index:StreamAgg`, // IndexReader is a inner child of Apply | ||
` └─StreamAgg 1.00 cop[tikv] funcs:sum(test_parallel_apply.thash.a)->Column#9`, | ||
` └─Selection 8000.00 cop[tikv] gt(test_parallel_apply.thash.a, test_parallel_apply.touter.b)`, | ||
` └─IndexFullScan 10000.00 cop[tikv] table:thash, index:a(a) keep order:false, stats:pseudo`)) | ||
tk.MustQuery(`select * from touter where touter.a > (select sum(thash.a) from thash use index(a) where thash.a>touter.b)`).Sort().Check( | ||
tk.MustQuery(`select * from touter where touter.a > (select sum(tinner.a) from tinner use index(a) where tinner.a>touter.b)`).Sort().Rows()) | ||
|
||
// parallel apply + hash partition + TableReader as its inner child | ||
tk.MustQuery(`explain format='brief' select * from touter where touter.a > (select sum(thash.b) from thash ignore index(a) where thash.a>touter.b)`).Check(testkit.Rows( | ||
`Projection 10000.00 root test_parallel_apply.touter.a, test_parallel_apply.touter.b`, | ||
`└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(cast(test_parallel_apply.touter.a, decimal(20,0) BINARY), Column#7)`, | ||
` ├─TableReader(Build) 10000.00 root data:TableFullScan`, | ||
` │ └─TableFullScan 10000.00 cop[tikv] table:touter keep order:false, stats:pseudo`, | ||
` └─StreamAgg(Probe) 1.00 root funcs:sum(Column#9)->Column#7`, | ||
` └─TableReader 1.00 root partition:all data:StreamAgg`, // TableReader is a inner child of Apply | ||
` └─StreamAgg 1.00 cop[tikv] funcs:sum(test_parallel_apply.thash.b)->Column#9`, | ||
` └─Selection 8000.00 cop[tikv] gt(test_parallel_apply.thash.a, test_parallel_apply.touter.b)`, | ||
` └─TableFullScan 10000.00 cop[tikv] table:thash keep order:false, stats:pseudo`)) | ||
tk.MustQuery(`select * from touter where touter.a > (select sum(thash.b) from thash ignore index(a) where thash.a>touter.b)`).Sort().Check( | ||
tk.MustQuery(`select * from touter where touter.a > (select sum(tinner.b) from tinner ignore index(a) where tinner.a>touter.b)`).Sort().Rows()) | ||
|
||
// parallel apply + hash partition + IndexLookUp as its inner child | ||
tk.MustQuery(`explain format='brief' select * from touter where touter.a > (select sum(tinner.b) from tinner use index(a) where tinner.a>touter.b)`).Check(testkit.Rows( | ||
`Projection 10000.00 root test_parallel_apply.touter.a, test_parallel_apply.touter.b`, | ||
`└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(cast(test_parallel_apply.touter.a, decimal(20,0) BINARY), Column#7)`, | ||
` ├─TableReader(Build) 10000.00 root data:TableFullScan`, | ||
` │ └─TableFullScan 10000.00 cop[tikv] table:touter keep order:false, stats:pseudo`, | ||
` └─HashAgg(Probe) 1.00 root funcs:sum(Column#9)->Column#7`, | ||
` └─IndexLookUp 1.00 root `, // IndexLookUp is a inner child of Apply | ||
` ├─Selection(Build) 8000.00 cop[tikv] gt(test_parallel_apply.tinner.a, test_parallel_apply.touter.b)`, | ||
` │ └─IndexFullScan 10000.00 cop[tikv] table:tinner, index:a(a) keep order:false, stats:pseudo`, | ||
` └─HashAgg(Probe) 1.00 cop[tikv] funcs:sum(test_parallel_apply.tinner.b)->Column#9`, | ||
` └─TableRowIDScan 8000.00 cop[tikv] table:tinner keep order:false, stats:pseudo`)) | ||
tk.MustQuery(`select * from touter where touter.a > (select sum(thash.b) from thash use index(a) where thash.a>touter.b)`).Sort().Check( | ||
tk.MustQuery(`select * from touter where touter.a > (select sum(tinner.b) from tinner use index(a) where tinner.a>touter.b)`).Sort().Rows()) | ||
|
||
// parallel apply + range partition + IndexReader as its inner child | ||
tk.MustQuery(`explain format='brief' select * from touter where touter.a > (select sum(trange.a) from trange use index(a) where trange.a>touter.b)`).Check(testkit.Rows( | ||
`Projection 10000.00 root test_parallel_apply.touter.a, test_parallel_apply.touter.b`, | ||
`└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(cast(test_parallel_apply.touter.a, decimal(20,0) BINARY), Column#7)`, | ||
` ├─TableReader(Build) 10000.00 root data:TableFullScan`, | ||
` │ └─TableFullScan 10000.00 cop[tikv] table:touter keep order:false, stats:pseudo`, | ||
` └─StreamAgg(Probe) 1.00 root funcs:sum(Column#9)->Column#7`, | ||
` └─IndexReader 1.00 root partition:all index:StreamAgg`, // IndexReader is a inner child of Apply | ||
` └─StreamAgg 1.00 cop[tikv] funcs:sum(test_parallel_apply.trange.a)->Column#9`, | ||
` └─Selection 8000.00 cop[tikv] gt(test_parallel_apply.trange.a, test_parallel_apply.touter.b)`, | ||
` └─IndexFullScan 10000.00 cop[tikv] table:trange, index:a(a) keep order:false, stats:pseudo`)) | ||
tk.MustQuery(`select * from touter where touter.a > (select sum(trange.a) from trange use index(a) where trange.a>touter.b)`).Sort().Check( | ||
tk.MustQuery(`select * from touter where touter.a > (select sum(tinner.a) from tinner use index(a) where tinner.a>touter.b)`).Sort().Rows()) | ||
|
||
// parallel apply + range partition + TableReader as its inner child | ||
tk.MustQuery(`explain format='brief' select * from touter where touter.a > (select sum(trange.b) from trange ignore index(a) where trange.a>touter.b)`).Check(testkit.Rows( | ||
`Projection 10000.00 root test_parallel_apply.touter.a, test_parallel_apply.touter.b`, | ||
`└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(cast(test_parallel_apply.touter.a, decimal(20,0) BINARY), Column#7)`, | ||
` ├─TableReader(Build) 10000.00 root data:TableFullScan`, | ||
` │ └─TableFullScan 10000.00 cop[tikv] table:touter keep order:false, stats:pseudo`, | ||
` └─StreamAgg(Probe) 1.00 root funcs:sum(Column#9)->Column#7`, | ||
` └─TableReader 1.00 root partition:all data:StreamAgg`, // TableReader is a inner child of Apply | ||
` └─StreamAgg 1.00 cop[tikv] funcs:sum(test_parallel_apply.trange.b)->Column#9`, | ||
` └─Selection 8000.00 cop[tikv] gt(test_parallel_apply.trange.a, test_parallel_apply.touter.b)`, | ||
` └─TableFullScan 10000.00 cop[tikv] table:trange keep order:false, stats:pseudo`)) | ||
tk.MustQuery(`select * from touter where touter.a > (select sum(trange.b) from trange ignore index(a) where trange.a>touter.b)`).Sort().Check( | ||
tk.MustQuery(`select * from touter where touter.a > (select sum(tinner.b) from tinner ignore index(a) where tinner.a>touter.b)`).Sort().Rows()) | ||
|
||
// parallel apply + range partition + IndexLookUp as its inner child | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
tk.MustQuery(`explain format='brief' select * from touter where touter.a > (select sum(tinner.b) from tinner use index(a) where tinner.a>touter.b)`).Check(testkit.Rows( | ||
`Projection 10000.00 root test_parallel_apply.touter.a, test_parallel_apply.touter.b`, | ||
`└─Apply 10000.00 root CARTESIAN inner join, other cond:gt(cast(test_parallel_apply.touter.a, decimal(20,0) BINARY), Column#7)`, | ||
` ├─TableReader(Build) 10000.00 root data:TableFullScan`, | ||
` │ └─TableFullScan 10000.00 cop[tikv] table:touter keep order:false, stats:pseudo`, | ||
` └─HashAgg(Probe) 1.00 root funcs:sum(Column#9)->Column#7`, | ||
` └─IndexLookUp 1.00 root `, // IndexLookUp is a inner child of Apply | ||
` ├─Selection(Build) 8000.00 cop[tikv] gt(test_parallel_apply.tinner.a, test_parallel_apply.touter.b)`, | ||
` │ └─IndexFullScan 10000.00 cop[tikv] table:tinner, index:a(a) keep order:false, stats:pseudo`, | ||
` └─HashAgg(Probe) 1.00 cop[tikv] funcs:sum(test_parallel_apply.tinner.b)->Column#9`, | ||
` └─TableRowIDScan 8000.00 cop[tikv] table:tinner keep order:false, stats:pseudo`)) | ||
tk.MustQuery(`select * from touter where touter.a > (select sum(trange.b) from trange use index(a) where trange.a>touter.b)`).Sort().Check( | ||
tk.MustQuery(`select * from touter where touter.a > (select sum(tinner.b) from tinner use index(a) where tinner.a>touter.b)`).Sort().Rows()) | ||
|
||
// random queries | ||
ops := []string{"!=", ">", "<", ">=", "<="} | ||
aggFuncs := []string{"sum", "count", "max", "min"} | ||
tbls := []string{"tinner", "thash", "trange"} | ||
for i := 0; i < 50; i++ { | ||
var r [][]interface{} | ||
op := ops[rand.Intn(len(ops))] | ||
agg := aggFuncs[rand.Intn(len(aggFuncs))] | ||
x := rand.Intn(10000) | ||
for _, tbl := range tbls { | ||
q := fmt.Sprintf(`select * from touter where touter.a > (select %v(%v.b) from %v where %v.a%vtouter.b-%v)`, agg, tbl, tbl, tbl, op, x) | ||
if r == nil { | ||
r = tk.MustQuery(q).Sort().Rows() | ||
} else { | ||
tk.MustQuery(q).Sort().Check(r) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func (s *partitionTableSuite) TestDirectReadingWithAgg(c *C) { | ||
if israce.RaceEnabled { | ||
c.Skip("exhaustive types test, skip race test") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tinner is a non-partition table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's expected. It's used to generate the correct result so that we can compare this result with results generated by partition tables.