Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Support ON/OFF for SET autocommit #383

Merged
merged 1 commit into from
Sep 28, 2018
Merged

Support ON/OFF for SET autocommit #383

merged 1 commit into from
Sep 28, 2018

Conversation

kuba--
Copy link
Contributor

@kuba-- kuba-- commented Sep 26, 2018

Signed-off-by: kuba-- kuba@sourced.tech
It closes #374

@kuba-- kuba-- added enhancement New feature or request proposal proposal for new additions or changes wip work in progress and removed wip work in progress labels Sep 26, 2018
@kuba-- kuba-- changed the title [WIP] Support ON/OFF for SET autocommit Support ON/OFF for SET autocommit Sep 27, 2018
@kuba-- kuba-- requested review from erizocosmico and a team September 27, 2018 15:35
@kuba--
Copy link
Contributor Author

kuba-- commented Sep 27, 2018

Finally it compiles after upgrading vitess.

@kuba-- kuba-- requested a review from ajnavarro September 27, 2018 15:36
default:
return nil, ErrUnsupportedFeature.New("qualifiers in set variable names other than @@session")
name := strings.TrimSpace(e.Name.Lowered())
if strings.Contains(name, "autocommit") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is ON/OFF only for autocommit on MySQL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe there are different cases (I didn't investigate any other cases, just focused on this particular case), but the main issue here can be transformation. For some expressions Type() panics.
I'm totally open to have the most generic solution transformation here.

@kuba--
Copy link
Contributor Author

kuba-- commented Sep 27, 2018

@erizocosmico - I've made ON/OFF more generic (no autocommit checks). I just added extra if

if !e.Resolved() || e.Type() != sql.Text

in transformation and looks that it works.

Copy link
Contributor

@ajnavarro ajnavarro left a comment

Choose a reason for hiding this comment

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

Good!

Some minor changes related with the makefile script that is already on another PR and questions about variables.

@@ -1,56 +1,41 @@
# Tooling to create the package `gopkg.in/src-d/go-vitess.v0`.
# Tooling to create the package `gopkg.in/src-d/go-vitess.v1`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would prefer to have this script separated in another PR as you did: #384

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it's already there
#384. I just didn't revert changes on this branch (so doesn't matter in what order we'll merge it, hopefully there will not be conflicts).

Copy link
Contributor

Choose a reason for hiding this comment

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

#384 is already merged. This file shouldn't be here now.

engine_test.go Outdated
@@ -1081,7 +1081,7 @@ func TestSessionVariables(t *testing.T) {
session := sql.NewBaseSession()
ctx := sql.NewContext(context.Background(), sql.WithSession(session), sql.WithPid(1))

_, _, err := e.Query(ctx, `set autocommit=1, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')`)
_, _, err := e.Query(ctx, `set autocommit=ON, sql_mode = concat(@@sql_mode,',STRICT_TRANS_TABLES')`)
Copy link
Contributor

Choose a reason for hiding this comment

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

autocommit=1 should work too, so I would prefer to do not change this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I'll add another test.

@@ -1,65 +1,19 @@
module gopkg.in/src-d/go-mysql-server.v0

require (
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it normal that all that dependencies disappear?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure how vgo builds this dependency graph, but as you see everything what disappeared are indirect deps. The good thing is that it still builds.

@@ -654,14 +654,70 @@ var fixtures = map[string]sql.Node{
),
`SET @@session.autocommit=1, foo="bar"`: plan.NewSet(
plan.SetVariable{
Name: "autocommit",
Name: "@@session.autocommit",
Copy link
Contributor

Choose a reason for hiding this comment

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

this means that we are adding session variables as global variables (but with a name @@session.blah) now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why the change adding @@session.? It should work without it too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because right now for SetExpr we don't have Qualifiers so in convertSet we return what was passed.

Copy link
Contributor

Choose a reason for hiding this comment

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

But we should trim that part as it was before. Only session variables should be saved with Set

sql/session.go Outdated
@@ -51,13 +53,25 @@ func (s *BaseSession) Address() string { return s.addr }
func (s *BaseSession) Set(key string, typ Type, value interface{}) {
s.mu.Lock()
defer s.mu.Unlock()

key = strings.TrimLeft(key, "@")
Copy link
Contributor

Choose a reason for hiding this comment

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

so, all variables are set as session level? what happens when the user disconnects? per example autocommit=1 will disappear?

Copy link
Contributor

Choose a reason for hiding this comment

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

autocommit is a session variable, isn't it?

Copy link
Contributor Author

@kuba-- kuba-- Sep 28, 2018

Choose a reason for hiding this comment

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

Here what I only changed is checking if we have session prefix and remove them before set. Because right now we don't have Qualifiers in SetExpr, so if you try sth, like:

SET @autocommit = 1
SELECT @@session.autocommit

we'll set in s.config["autocommit"]=1 but for select we'll try to get s.config["session.autocommit"] what is not there.

Copy link
Contributor

Choose a reason for hiding this comment

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

that's why the session. should be removed in the select

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, makes sense. I've moved that logic from session.Get/Set to
analyzer.resolveColumns and to plan.(*Set)RowIter

Copy link
Contributor Author

@kuba-- kuba-- Sep 28, 2018

Choose a reason for hiding this comment

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

I had to fix TestResolveColumnsSession. I think right now it wasn't right (correct me if I'm wrong):
it looked like:

node := plan.NewProject(
		[]sql.Expression{
			expression.NewUnresolvedColumn("@@foo_bar"),
			expression.NewUnresolvedColumn("@@bar_baz"),
		},
		plan.NewResolvedTable(dualTable),
	)

	result, err := resolveColumns(ctx, NewDefault(nil), node)
	require.NoError(err)

	expected := plan.NewProject(
		[]sql.Expression{
			expression.NewGetSessionField("@@foo_bar", sql.Int64, int64(42)), // <-- @@-
			expression.NewGetSessionField("@@bar_baz", sql.Null, nil), // <-- @@
		},
		plan.NewResolvedTable(dualTable),
	)

I assumed that in session we don't keep fields prefixed by @, because:

  • if you take a look into session config:
func defaultSessionConfig() map[string]typedValue {
	return map[string]typedValue{
		"auto_increment_increment": typedValue{Int64, int64(1)},
		"time_zone":                typedValue{Text, time.Local.String()},
		"system_time_zone":         typedValue{Text, time.Local.String()},
		"max_allowed_packet":       typedValue{Int32, math.MaxInt32},
		"sql_mode":                 typedValue{Text, ""},
	}
}
  • and also func (f *GetSessionField) String() string { return "@@" + f.name } already prefixes with "@".

@ajnavarro
Copy link
Contributor

@kuba-- could you rebase please?

@kuba--
Copy link
Contributor Author

kuba-- commented Sep 28, 2018

@ajnavarro - done.

@kuba--
Copy link
Contributor Author

kuba-- commented Sep 28, 2018

@ajnavarro - hmm I've rebased again and I don't see Makefile in changes.

sql/session.go Outdated
@@ -51,13 +51,15 @@ func (s *BaseSession) Address() string { return s.addr }
func (s *BaseSession) Set(key string, typ Type, value interface{}) {
s.mu.Lock()
defer s.mu.Unlock()

Copy link
Contributor

Choose a reason for hiding this comment

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

that file shouldn't be modified on that PR.

Copy link
Contributor

@ajnavarro ajnavarro left a comment

Choose a reason for hiding this comment

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

just session.go minor change and LGTM

@ajnavarro
Copy link
Contributor

Signed-off-by: kuba-- <kuba@sourced.tech>

Add more parser tests.
Handle also true/false.

Signed-off-by: kuba-- <kuba@sourced.tech>
@kuba--
Copy link
Contributor Author

kuba-- commented Sep 28, 2018

@ajnavarro - I've added many tests (even to test this particular line), but I'm not sure why this cover tool still complains.

@jfontan
Copy link
Contributor

jfontan commented Sep 28, 2018

@kuba-- I don't know if this is the case but coverage by default only counts coverage in files from the same package as the test. If that code path is used with a test from another package it's not counted.

@kuba--
Copy link
Contributor Author

kuba-- commented Sep 28, 2018

@jfontan - I think it's not the case. I extended TestQualifyColumns to test qualifyColumns and it still complain on the same line, and everything is in the same package.

@ajnavarro ajnavarro merged commit a086daa into src-d:master Sep 28, 2018
@kuba-- kuba-- deleted the fix-374/upgrade-vitess branch September 28, 2018 11:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request proposal proposal for new additions or changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support ON/OFF as synonyms of 1/0
4 participants