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

plan: add hint to force to choose hash join. #5315

Merged
merged 9 commits into from
Dec 8, 2017

Conversation

winoros
Copy link
Member

@winoros winoros commented Dec 5, 2017

for #5282
PTAL @hanfei1991 @coocood @lamxTyler

parser/parser.y Outdated
@@ -421,6 +421,7 @@ import (
statsHistograms "STATS_HISTOGRAMS"
statsBuckets "STATS_BUCKETS"
tidb "TIDB"
tidbHASHJOIN "TIDB_HASHJOIN"
Copy link
Member

Choose a reason for hiding this comment

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

As convention, we should use TIDB_HJ

Copy link
Member

Choose a reason for hiding this comment

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

s/tidbHASHJOIN/tidbHashJoin/

@shenli
Copy link
Member

shenli commented Dec 5, 2017

/run-all-tests

@shenli
Copy link
Member

shenli commented Dec 5, 2017

/run-all-tests

@@ -29,7 +30,7 @@ func tryToGetJoinGroup(j *LogicalJoin) ([]LogicalPlan, bool) {
// 2. not inner join
// 3. forced merge join
// 4. forced index nested loop join
if j.reordered || !j.cartesianJoin || j.preferMergeJoin || j.preferINLJ > 0 {
if j.reordered || !j.cartesianJoin || bits.OnesCount(j.preferJoinType) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update the comment?

@@ -147,6 +147,8 @@ func (s *testSuite) TestJoin(c *C) {

// Test that two conflict hints will return error.
_, err = tk.Exec("select /*+ TIDB_INLJ(t) TIDB_SMJ(t) */ * from t join t1 on t.a=t1.a")
_, err = tk.Exec("select /*+ TIDB_INLJ(t) TIDB_HASHJOIN(t) */ from t join t1 on t.a=t1.a")
_, err = tk.Exec("select /*+ TIDB_SMJ(t) TIDB_HASHJOIN(t) */ from t join t1 on t.a=t1.a")
Copy link
Contributor

Choose a reason for hiding this comment

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

The err will be overwritten, so check just once is not enough.

}
// If there're multiple join hints, they're conflict.
if bits.OnesCount(joinPlan.preferJoinType) > 1 {
b.err = errors.New("Optimizer Hints is conflict")
Copy link
Member

Choose a reason for hiding this comment

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

make error message more specific ? like: Optimizer Hints conflict, at most one of {TIDB_INLJ, TIDB_SMJ, TIDB_HASHJOIN} join hints should be specified.

@coocood
Copy link
Member

coocood commented Dec 6, 2017

/run-all-tests

@shenli
Copy link
Member

shenli commented Dec 6, 2017

/run-all-tests

// Which it joins on with depend on sequence of traverse
// and without reorder, user might adjust themselves.
// This is similar to MySQL hints.
for _, tableName := range tableNames {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not extract the common code,
and put the hint type as an input parameter.

@@ -1800,10 +1812,20 @@ func (b *planBuilder) buildSemiJoin(outerPlan, innerPlan LogicalPlan, onConditio
if b.TableHints() != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this branch be extracted as a function.

Copy link
Contributor

Choose a reason for hiding this comment

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

@winoros this branch can be extracted as a function?

Copy link
Member Author

Choose a reason for hiding this comment

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

i think it's not too much need to do this.

@XuHuaiyu
Copy link
Contributor

XuHuaiyu commented Dec 8, 2017

LGTM

@winoros winoros added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 8, 2017
@shenli
Copy link
Member

shenli commented Dec 8, 2017

/run-all-tests

@coocood
Copy link
Member

coocood commented Dec 8, 2017

LGTM

@iamxy
Copy link
Member

iamxy commented Dec 8, 2017

/run-integration-common-test

@iamxy
Copy link
Member

iamxy commented Dec 8, 2017

/run-integration-compatibility-test

@coocood coocood merged commit c9245f5 into pingcap:master Dec 8, 2017
@shenli
Copy link
Member

shenli commented Dec 8, 2017

@winoros Remind to update the document.

@winoros winoros deleted the hashjoin-hint branch December 8, 2017 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/LGT1 Indicates that a PR has LGTM 1.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants