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

executor: add several sql hint related to session variables #11809

Merged
merged 15 commits into from
Sep 17, 2019

Conversation

foreyes
Copy link
Contributor

@foreyes foreyes commented Aug 21, 2019

What problem does this PR solve?

Add SQL hints: MEMORY_QUOTA, USE_TOJA, NO_INDEX_MERGE, READ_CONSISTENT_REPLICA

What is changed and how it works?

Extract sql hints before executing each query, and store hints in StmtCtx.

When we need access or set related session variables, we have to use interfaces instead.

For example, if there is ReplicaRead hint in StmtCtx, GetReplicaRead() will return the value in StmtCtx, otherwise return SessionVars.replicaRead.

Check List

Tests

  • Unit Test

Code Changes

  • Has exported fields change.

Release Notes

Support several SQL hints related to session variables: MEMORY_QUOTA, USE_TOJA, NO_INDEX_MERGE, READ_CONSISTENT_REPLICA.

@foreyes foreyes self-assigned this Aug 21, 2019
@foreyes foreyes requested review from lzmhhh123 and qw4990 and removed request for qw4990 and lzmhhh123 August 21, 2019 09:47
@codecov
Copy link

codecov bot commented Aug 21, 2019

Codecov Report

Merging #11809 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #11809   +/-   ##
===========================================
  Coverage   81.6107%   81.6107%           
===========================================
  Files           455        455           
  Lines        101380     101380           
===========================================
  Hits          82737      82737           
  Misses        12852      12852           
  Partials       5791       5791

@foreyes
Copy link
Contributor Author

foreyes commented Aug 21, 2019

PTAL. @qw4990 @lzmhhh123

session/session.go Outdated Show resolved Hide resolved
session/session.go Outdated Show resolved Hide resolved
@foreyes
Copy link
Contributor Author

foreyes commented Sep 9, 2019

PTAL. @qw4990

@foreyes foreyes requested a review from qw4990 September 9, 2019 11:11
@qw4990
Copy link
Contributor

qw4990 commented Sep 10, 2019

Almost LGTM, and please address comments and resolve CI problems @foreyes .

@foreyes
Copy link
Contributor Author

foreyes commented Sep 11, 2019

/run-all-tests

@foreyes foreyes requested a review from qw4990 September 11, 2019 03:29
@foreyes
Copy link
Contributor Author

foreyes commented Sep 11, 2019

Address comments and add some tests. PTAL again. @qw4990

Copy link
Contributor

@qw4990 qw4990 left a comment

Choose a reason for hiding this comment

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

LGTM

@foreyes foreyes added status/all tests passed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 11, 2019
@foreyes foreyes requested review from lzmhhh123 and XuHuaiyu and removed request for lzmhhh123 September 11, 2019 03:50
@foreyes
Copy link
Contributor Author

foreyes commented Sep 11, 2019

PTAL. @XuHuaiyu

@foreyes
Copy link
Contributor Author

foreyes commented Sep 11, 2019

/run-unit-test

executor/executor.go Show resolved Hide resolved
executor/executor.go Show resolved Hide resolved
executor/executor.go Outdated Show resolved Hide resolved
c.Assert(tk.Se.GetSessionVars().StmtCtx.MemTracker.CheckBytesLimit(val), IsTrue)
tk.MustExec("select /*+ MEMORY_QUOTA(1 GB), MEMORY_QUOTA(1 MB) */ 1;")
val = int64(1) * 1024 * 1024
c.Assert(tk.Se.GetSessionVars().StmtCtx.GetWarnings(), HasLen, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

May we check the warning msg?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Warning messages need to be dealt with specially later, and there is no need to care too much about them at this stage.

c.Assert(tk.Se.GetSessionVars().GetReplicaRead(), Equals, kv.ReplicaReadLeader)
}

func (s *testSessionSuite) TestStmtHints(c *C) {
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 add some test case with hints in subqueries?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's unlikely to support use these hints in subqueries.
These hints need to handle before sql execute and set statement variables, handle them in subquries is too expensive.
Maybe discuss with PM team later.

util/memory/tracker.go Show resolved Hide resolved
@foreyes
Copy link
Contributor Author

foreyes commented Sep 17, 2019

address comment, add test and change a few codes.
PTAL again. @XuHuaiyu

Copy link
Contributor

@XuHuaiyu XuHuaiyu left a comment

Choose a reason for hiding this comment

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

LGTM

@XuHuaiyu XuHuaiyu added status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2. labels Sep 17, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Sep 17, 2019

/run-all-tests

@sre-bot sre-bot merged commit e173c7f into pingcap:master Sep 17, 2019
@foreyes foreyes deleted the dev/add_sql_hints branch September 17, 2019 05:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution status/can-merge Indicates a PR has been approved by a committer. status/LGT1 Indicates that a PR has LGTM 1. status/LGT2 Indicates that a PR has LGTM 2. type/new-feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants