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

docs/design: add proposal for sql plan management #8651

Merged
merged 5 commits into from Dec 12, 2018

Conversation

Projects
None yet
4 participants
@lamxTyler
Copy link
Member

lamxTyler commented Dec 11, 2018

What problem does this PR solve?

Add proposal for SQL plan management.

What is changed and how it works?

Check List

Tests

  • No code

Code changes

  • None

Side effects

  • None

Related changes

  • None

PTAL @zz-jason @winoros @XuHuaiyu @eurekaka


This change is Reviewable

@zhouqiang-cl

This comment has been minimized.

Copy link
Member

zhouqiang-cl commented Dec 11, 2018

/run-unit-test

@eurekaka
Copy link
Contributor

eurekaka left a comment

LGTM


To manage the SQL bindings, we need to support basic operations like create, show and drop. We can also support SQL bindings that only exist in the current session. The syntax will be like the following:

- CREATE [GLOBAL|SESSION] BINDING_NAME BINDING FOR `SQL` USING `HINTED SQL`

This comment has been minimized.

Copy link
@XuHuaiyu

XuHuaiyu Dec 12, 2018

Contributor

duplicate blanks before USING 😢

- Store the binding SQL and AST of the hinted SQL in a system table. Since there is a unique mapping from SQL text to AST, we can just store the SQL and parse it to AST for later use. A background goroutine will check if there are new bindings and update the local cache.
- When another SQL comes, we first check if there is a matched SQL in the cache. If so, we can traverse the AST to add hints. Since comparing text for every SQL may affect unrelated SQLs a lot, we can calculate a hash value and first check if there is matching hash values.

## Open issues (if applicable)

This comment has been minimized.

Copy link
@XuHuaiyu

XuHuaiyu Dec 12, 2018

Contributor

Do we need an issue to record the process of this?

This comment has been minimized.

Copy link
@lamxTyler

lamxTyler Dec 12, 2018

Author Member

We may have an issue to record the process, but the meaning of open issues is A discussion of issues relating to this proposal for which the author does not know the solution..


## Proposal

The following proposal mainly focused on two parts: how to bind the plan and what is the syntax to manage it.

This comment has been minimized.

Copy link
@XuHuaiyu

XuHuaiyu Dec 12, 2018

Contributor

s/ focused/ focus?


### How to bind the plan

In order to bind the plan, we need to maintain a mapping from normalized SQL text to plan. To normalize the SQL text, we can remove all the blank space, replace the parameters with placement markers, and convert remaining parts to lower cases. The most difficult problem is how we represent and store the plan.

This comment has been minimized.

Copy link
@XuHuaiyu

XuHuaiyu Dec 12, 2018

Contributor

2 blanks before and convert

@XuHuaiyu
Copy link
Contributor

XuHuaiyu left a comment

LGTM

@lamxTyler lamxTyler merged commit 7f7cfbf into pingcap:master Dec 12, 2018

3 of 4 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
ci/circleci Your tests passed on CircleCI!
Details
idc-jenkins-ci-tidb/build Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details

@lamxTyler lamxTyler deleted the lamxTyler:plan-management branch Dec 12, 2018

iamzhoug37 added a commit to iamzhoug37/tidb that referenced this pull request Dec 13, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.