Query executor: preparing for SHOW VITESS_MIGRATIONS via ShowBasic#12688
Conversation
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…es a ShowMigrationsPlan based on ShowBasic, in preparation for ShowBasic statement coming up in next releases Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
| if showInternal.Command == sqlparser.Table { | ||
| switch showInternal.Command { | ||
| case sqlparser.VitessMigrations: | ||
| return &Plan{PlanID: PlanShowMigrations, FullStmt: show}, nil |
There was a problem hiding this comment.
i chose to return a PlanShowMigrations rather than returning a PlanSelect and generating SQL here.
There was a problem hiding this comment.
The benefit of doing it at plan time is that it is cached. So, at execution, it does not need to create the select query and parse it.
I will leave this to you as it is not a critical query on execution.
There was a problem hiding this comment.
Caching is a good point. I feel like it's wrong to construct this query in query_executor, though, and that it makes more sense in onlineddl.Executor. We can always change that in the future.
mattlord
left a comment
There was a problem hiding this comment.
We need to handle the variable sidecar database name. Otherwise looks good (two very nitty comments).
go/vt/vttablet/onlineddl/executor.go
Outdated
| // ShowMigrations shows migrations, optionally filtered by a condition | ||
| func (e *Executor) ShowMigrations(ctx context.Context, show *sqlparser.Show) (result *sqltypes.Result, err error) { | ||
| if atomic.LoadInt64(&e.isOpen) == 0 { | ||
| return nil, vterrors.New(vtrpcpb.Code_FAILED_PRECONDITION, "online ddl is disabled") |
There was a problem hiding this comment.
Nit, but IMO OnlineDDL or online DDL is better. I feel like perhaps the former so as to identify that it's really the Vitess OnlineDDL functionality that's disabled (MySQL itself supports online DDL, and this could be confusing for MySQL users).
go/vt/vttablet/onlineddl/executor.go
Outdated
| return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "[BUG] ShowMigrations expects a ShowBasic statement. Got: %s", sqlparser.String(show)) | ||
| } | ||
| if showBasic.Command != sqlparser.VitessMigrations { | ||
| return nil, vterrors.Errorf(vtrpcpb.Code_INTERNAL, "[BUG] ShowMigrations expects a VitessMigrations command, got %v. Statement: %s", showBasic.Command, sqlparser.String(show)) |
There was a problem hiding this comment.
Might be worth %+v for the struct.
mattlord
left a comment
There was a problem hiding this comment.
I only had two very minor comments. LGTM!
Sorry about the temporary confusion around the sidecardb. That was my fault.
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Description
Today, a
SHOW VITESS_MIGRATIONScommand is parsed invtagteasShowBasic, but converted to aSELECT...before being sent to vttablet:vitess/go/vt/vtgate/planbuilder/show.go
Lines 276 to 290 in 7af519e
We want to send the original
ShowBasic, instead. However, for compatibility reasons we must first ensurevttabletcan interceptSHOW VITESS_MIGRATIONSviaShowBasic.In this PR query executor intercepts a
ShowBasicand identifies if it has aVitessMigrationscommand. It then generates aPlanShowMigrations. With this plan, the executor callsonlineddl.Executor'sShowMigrations()function, which then generates the SQL query, same way that this is done today invtgate.This code path it not being used now. This will be included in
v17. And inv18we will re-implementvtgate's behavior as explained above.@harshit-gangal please note I chose to create a
PlanShowMigrationsas opposed to generate the SQL directly in query executor.Related Issue(s)
Replaces #12676
Checklist
Deployment Notes