Support ON/OFF for SET autocommit #383
Support ON/OFF for SET autocommit #383ajnavarro merged 1 commit intosrc-d:masterfrom kuba--:fix-374/upgrade-vitess
Conversation
|
Finally it compiles after upgrading vitess. |
sql/parse/parse.go
Outdated
| default: | ||
| return nil, ErrUnsupportedFeature.New("qualifiers in set variable names other than @@session") | ||
| name := strings.TrimSpace(e.Name.Lowered()) | ||
| if strings.Contains(name, "autocommit") { |
There was a problem hiding this comment.
Is ON/OFF only for autocommit on MySQL?
There was a problem hiding this comment.
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.
|
@erizocosmico - I've made ON/OFF more generic (no autocommit checks). I just added extra if in transformation and looks that it works. |
ajnavarro
left a comment
There was a problem hiding this comment.
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`. | |||
There was a problem hiding this comment.
I would prefer to have this script separated in another PR as you did: #384
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
#384 is already merged. This file shouldn't be here now.
engine_test.go
Outdated
| 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')`) |
There was a problem hiding this comment.
autocommit=1 should work too, so I would prefer to do not change this test.
There was a problem hiding this comment.
ok, I'll add another test.
| @@ -1,65 +1,19 @@ | |||
| module gopkg.in/src-d/go-mysql-server.v0 | |||
|
|
|||
| require ( | |||
There was a problem hiding this comment.
Is it normal that all that dependencies disappear?
There was a problem hiding this comment.
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.
| `SET @@session.autocommit=1, foo="bar"`: plan.NewSet( | ||
| plan.SetVariable{ | ||
| Name: "autocommit", | ||
| Name: "@@session.autocommit", |
There was a problem hiding this comment.
this means that we are adding session variables as global variables (but with a name @@session.blah) now?
There was a problem hiding this comment.
Why the change adding @@session.? It should work without it too
There was a problem hiding this comment.
Because right now for SetExpr we don't have Qualifiers so in convertSet we return what was passed.
There was a problem hiding this comment.
But we should trim that part as it was before. Only session variables should be saved with Set
sql/session.go
Outdated
| s.mu.Lock() | ||
| defer s.mu.Unlock() | ||
|
|
||
| key = strings.TrimLeft(key, "@") |
There was a problem hiding this comment.
so, all variables are set as session level? what happens when the user disconnects? per example autocommit=1 will disappear?
There was a problem hiding this comment.
autocommit is a session variable, isn't it?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
that's why the session. should be removed in the select
There was a problem hiding this comment.
ok, makes sense. I've moved that logic from session.Get/Set to
analyzer.resolveColumns and to plan.(*Set)RowIter
There was a problem hiding this comment.
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 "@".
|
@kuba-- could you rebase please? |
|
@ajnavarro - done. |
|
@ajnavarro - hmm I've rebased again and I don't see Makefile in changes. |
sql/session.go
Outdated
| func (s *BaseSession) Set(key string, typ Type, value interface{}) { | ||
| s.mu.Lock() | ||
| defer s.mu.Unlock() | ||
|
|
There was a problem hiding this comment.
that file shouldn't be modified on that PR.
ajnavarro
left a comment
There was a problem hiding this comment.
just session.go minor change and LGTM
|
hmm, we are testing with session columns, and that line appears that never is true: https://codecov.io/gh/src-d/go-mysql-server/compare/7f8e182c469e77663f886baa8170a5662733d185...645a95d0855995f7b623c4d4b862e835478d57e4/src/sql/analyzer/resolve_columns.go#L71 |
Signed-off-by: kuba-- <kuba@sourced.tech> Add more parser tests. Handle also true/false. Signed-off-by: kuba-- <kuba@sourced.tech>
|
@ajnavarro - I've added many tests (even to test this particular line), but I'm not sure why this cover tool still complains. |
|
@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. |
|
@jfontan - I think it's not the case. I extended |
Signed-off-by: kuba-- kuba@sourced.tech
It closes #374