Skip to content

Commit

Permalink
Merge pull request vitessio#8035 from tinyspeck/backports-8013-to-9.0
Browse files Browse the repository at this point in the history
[9.0] ddl bypass planner
  • Loading branch information
harshit-gangal authored May 5, 2021
2 parents 48480d8 + 5501139 commit 3bce5f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
16 changes: 16 additions & 0 deletions go/vt/vtgate/planbuilder/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const (
// This is why we return a compound primitive (DDL) which contains fully populated primitives (Send & OnlineDDL),
// and which chooses which of the two to invoke at runtime.
func buildGeneralDDLPlan(sql string, ddlStatement sqlparser.DDLStatement, vschema ContextVSchema) (engine.Primitive, error) {
if vschema.Destination() != nil {
return buildByPassDDLPlan(sql, vschema)
}

normalDDLPlan, onlineDDLPlan, err := buildDDLPlans(sql, ddlStatement, vschema)
if err != nil {
return nil, err
Expand All @@ -38,6 +42,18 @@ func buildGeneralDDLPlan(sql string, ddlStatement sqlparser.DDLStatement, vschem
}, nil
}

func buildByPassDDLPlan(sql string, vschema ContextVSchema) (engine.Primitive, error) {
keyspace, err := vschema.DefaultKeyspace()
if err != nil {
return nil, err
}
return &engine.Send{
Keyspace: keyspace,
TargetDestination: vschema.Destination(),
Query: sql,
}, nil
}

func buildDDLPlans(sql string, ddlStatement sqlparser.DDLStatement, vschema ContextVSchema) (*engine.Send, *engine.OnlineDDL, error) {
var destination key.Destination
var keyspace *vindexes.Keyspace
Expand Down
18 changes: 18 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/bypass_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,21 @@
"SingleShardOnly": true
}
}

# create table
"create /* test */ table t1(id bigint, primary key(id)) /* comments */"
{
"QueryType": "DDL",
"Original": "create /* test */ table t1(id bigint, primary key(id)) /* comments */",
"Instructions": {
"OperatorType": "Send",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"TargetDestination": "Shard(-80)",
"IsDML": false,
"Query": "create /* test */ table t1(id bigint, primary key(id)) /* comments */",
"SingleShardOnly": false
}
}

0 comments on commit 3bce5f8

Please sign in to comment.