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

Query executor: preparing for SHOW VITESS_MIGRATIONS via ShowBasic #12688

Merged

Conversation

shlomi-noach
Copy link
Contributor

@shlomi-noach shlomi-noach commented Mar 22, 2023

Description

Today, a SHOW VITESS_MIGRATIONS command is parsed in vtagte as ShowBasic, but converted to a SELECT... before being sent to vttablet:

sql := sqlparser.BuildParsedQuery("SELECT * FROM %s.schema_migrations", sidecarDBID).Query
if show.Filter != nil {
if show.Filter.Filter != nil {
sql += fmt.Sprintf(" where %s", sqlparser.String(show.Filter.Filter))
} else if show.Filter.Like != "" {
lit := sqlparser.String(sqlparser.NewStrLiteral(show.Filter.Like))
sql += fmt.Sprintf(" where migration_uuid LIKE %s OR migration_context LIKE %s OR migration_status LIKE %s", lit, lit, lit)
}
}
return &engine.Send{
Keyspace: ks,
TargetDestination: dest,
Query: sql,
}, nil

We want to send the original ShowBasic, instead. However, for compatibility reasons we must first ensure vttablet can intercept SHOW VITESS_MIGRATIONS via ShowBasic.

In this PR query executor intercepts a ShowBasic and identifies if it has a VitessMigrations command. It then generates a PlanShowMigrations. With this plan, the executor calls onlineddl.Executor's ShowMigrations() function, which then generates the SQL query, same way that this is done today in vtgate.

This code path it not being used now. This will be included in v17. And in v18 we will re-implement vtgate's behavior as explained above.

@harshit-gangal please note I chose to create a PlanShowMigrations as opposed to generate the SQL directly in query executor.

Related Issue(s)

Replaces #12676

Checklist

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on the CI
  • Documentation was added or is not required

Deployment Notes

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
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 chose to return a PlanShowMigrations rather than returning a PlanSelect and generating SQL here.

Copy link
Member

@harshit-gangal harshit-gangal Mar 22, 2023

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach shlomi-noach requested a review from a team March 28, 2023 07:08
Copy link
Contributor

@mattlord mattlord left a comment

Choose a reason for hiding this comment

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

We need to handle the variable sidecar database name. Otherwise looks good (two very nitty comments).

// 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")
Copy link
Contributor

Choose a reason for hiding this comment

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

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).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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))
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth %+v for the struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

go/vt/vttablet/onlineddl/schema.go Show resolved Hide resolved
Copy link
Contributor

@mattlord mattlord left a comment

Choose a reason for hiding this comment

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

I only had two very minor comments. LGTM!

Sorry about the temporary confusion around the sidecardb. That was my fault.

go/vt/vttablet/onlineddl/schema.go Show resolved Hide resolved
go/vt/vttablet/onlineddl/executor.go Show resolved Hide resolved
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@harshit-gangal harshit-gangal merged commit 746c37f into vitessio:main Apr 3, 2023
@harshit-gangal harshit-gangal deleted the show-migrations-prepare-tablet branch April 3, 2023 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants