-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
planner: support straight join order hint #34339
Merged
ti-chi-bot
merged 16 commits into
pingcap:master
from
Reminiscent:planner-StraightJoinHint
May 11, 2022
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
001eaf6
parser: support join order hint
Reminiscent 8ad871e
planner: support straight join order hint
Reminiscent d10d932
fix ut
Reminiscent 45aff8e
Merge branch 'parser-joinOrderHint' of github.com:Reminiscent/tidb in…
Reminiscent b2743ec
Merge branch 'master' of github.com:pingcap/tidb into planner-Straigh…
Reminiscent 1eb5e61
add more test cases
Reminiscent f84307c
add more test cases info
Reminiscent cb409d6
Merge branch 'master' of github.com:pingcap/tidb into planner-Straigh…
Reminiscent 5dcdef9
remove useless test cases
Reminiscent 8a6246e
add more test cases
Reminiscent af9d8fc
Merge branch 'master' of github.com:pingcap/tidb into planner-Straigh…
Reminiscent f42f015
fix ut
Reminiscent 56b187a
Merge branch 'master' of github.com:pingcap/tidb into planner-Straigh…
Reminiscent 6f19b4d
fix ut
Reminiscent 4782b87
fix ut
Reminiscent 3be276c
Merge branch 'master' of github.com:pingcap/tidb into planner-Straigh…
Reminiscent 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
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
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
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2022 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. | ||
|
||
package core_test | ||
|
||
import ( | ||
"testing" | ||
|
||
plannercore "github.com/pingcap/tidb/planner/core" | ||
"github.com/pingcap/tidb/testkit" | ||
"github.com/pingcap/tidb/testkit/testdata" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func runJoinReorderTestData(t *testing.T, tk *testkit.TestKit, name string) { | ||
var input []string | ||
var output []struct { | ||
SQL string | ||
Plan []string | ||
} | ||
joinReorderSuiteData := plannercore.GetJoinReorderSuiteData() | ||
joinReorderSuiteData.GetTestCasesByName(name, t, &input, &output) | ||
require.Equal(t, len(input), len(output)) | ||
for i := range input { | ||
testdata.OnRecord(func() { | ||
output[i].SQL = input[i] | ||
output[i].Plan = testdata.ConvertRowsToStrings(tk.MustQuery("explain format = 'brief' " + input[i]).Rows()) | ||
}) | ||
tk.MustQuery("explain format = 'brief' " + input[i]).Check(testkit.Rows(output[i].Plan...)) | ||
} | ||
} | ||
|
||
func TestStraightJoinHint(t *testing.T) { | ||
store, clean := testkit.CreateMockStore(t) | ||
defer clean() | ||
|
||
tk := testkit.NewTestKit(t, store) | ||
tk.MustExec("use test") | ||
tk.MustExec("drop table if exists t, t1, t2, t3;") | ||
tk.MustExec("create table t(a int, b int, key(a));") | ||
tk.MustExec("create table t1(a int, b int, key(a));") | ||
tk.MustExec("create table t2(a int, b int, key(a));") | ||
tk.MustExec("create table t3(a int, b int, key(a));") | ||
tk.MustExec("create table t4(a int, b int, key(a));") | ||
runJoinReorderTestData(t, tk, "TestStraightJoinHint") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[ | ||
{ | ||
"name": "TestStraightJoinHint", | ||
"cases": [ | ||
"select /*+ straight_join() */ * from t, t1, t2, t3 where t.a = t1.a and t1.b=t2.b;", | ||
"select /*+ straight_join() */ * from t2, t1, t3, t where t.a = t1.a and t1.b=t2.b;", | ||
"select /*+ straight_join() */ * from t3, t2, t1, t where t.a = t1.a and t1.b=t2.b;", | ||
"select /*+ straight_join() */ * from t3, t1, t, t2 where t.a = t1.a and t1.b=t2.b;", | ||
"select /*+ straight_join() */ * from t2 join t1 on t2.a=t1.a join t3 on t1.b=t3.b;", | ||
"select /*+ straight_join() */ * from t3 join t1 on t1.b=t3.b join t2 on t2.a=t1.a;", | ||
"select /*+ straight_join() */ * from t3 join t2 on t2.b=t3.b join t1 on t2.a=t1.a;", | ||
"select /*+ straight_join() */ * from t2 join (t1 join t3 on t1.a=t3.a) on t2.a=1;", | ||
"select /*+ straight_join() */ * from t2 join (t1 join t3 on t1.a=t3.a) on t2.a=t3.a;", | ||
"select /*+ straight_join() */ * from t1 join (t2 join t3 on t2.a=t3.a) on t1.a=t3.a;", | ||
"select /*+ straight_join() */ * from t3 join (t1 join t2 on t1.a=t2.a) on t2.a=t3.a;", | ||
"select /*+ straight_join() */ * from t2 join t1 on t1.a=t2.a join t3 on t2.b=t3.b;", | ||
"select /*+ straight_join() */ * from t1 join t2 on t1.a=t2.a join t3 on t2.b=t3.b;", | ||
"select /*+ straight_join() */ * from t2 join t3 on t3.a=t2.a join t1 on t2.a=t1.a;", | ||
"select /*+ straight_join() */ * from (t1 join t2 on t1.a=t2.a) join (t3 join t4 on t3.a=t4.a) on t2.a=t4.a;", | ||
"select /*+ straight_join() */ * from (t1 join t2 on t1.a=t2.a) join (t3 join t4 on t3.a=t4.a) on t2.a=t3.a;", | ||
"select /*+ straight_join() */ * from (t1 join t2 on t1.a=t2.a) join (t3 join t4 on t3.a=t4.a) on t1.a=t4.a;", | ||
"select /*+ straight_join() */ * from (t3 join t4 on t3.a=t4.a) join (t1 join t2 on t1.a=t2.a) on t2.a=t4.a;", | ||
"select /*+ straight_join() */ * from (t3 join t4 on t3.a=t4.a) join (t1 join t2 on t1.a=t2.a) on t2.a=t3.a;", | ||
"select /*+ straight_join() */ * from ((select t3.a, t3.b from t, t1, t2, t3 where t.a = t1.a and t1.b=t2.b) t3 join t4 on t3.a=t4.a) join (t1 join t2 on t1.a=t2.a) on t1.a=t4.a;", | ||
"select /*+ straight_join() */ * from (t1 join t2 on t1.a=t2.a) join ((select t3.a, t3.b from t, t1, t2, t3 where t.a = t1.a and t1.b=t2.b) t3 join t4 on t3.a=t4.a) on t2.a=t4.a;", | ||
"select /*+ straight_join() */ * from (t1 join t2 on t1.a=t2.a) join ((select t3.a, t3.b from t1, t3, t2, t where t.a = t1.a and t1.b=t2.b) t3 join t4 on t3.a=t4.a) on t2.a=t3.a;", | ||
"select /*+ straight_join() */ * from (t1 join t2 on t1.a=t2.a) join ((select t3.a, t3.b from t3, t2, t1, t where t.a = t1.a and t1.b=t2.b) t3 join t4 on t3.a=t4.a) on t1.a=t4.a;", | ||
"select /*+ straight_join() */ * from ((select t3.a, t3.b from t1, t2, t, t3 where t.a = t1.a and t1.b=t2.b) t3 join t4 on t3.a=t4.a) join (t1 join t2 on t1.a=t2.a) on t2.a=t4.a;", | ||
"select /*+ straight_join() */ * from ((select t3.a, t3.b from t2, t1, t, t3 where t.a = t1.a and t1.b=t2.b) t3 join t4 on t3.a=t4.a) join (t1 join t2 on t1.a=t2.a) on t2.a=t3.a;", | ||
"select /*+ straight_join() */ * from ((select t3.a, t3.b from t3, t2, t1, t where t.a = t1.a and t1.b=t2.b) t3 join t4 on t3.a=t4.a) join (t1 join t2 on t1.a=t2.a) on t1.a=t4.a;" | ||
] | ||
} | ||
] |
Oops, something went wrong.
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.
Please add these two cases in this test: