From 2e35451769ae4f00d9aeb0f08278a3e63ed16648 Mon Sep 17 00:00:00 2001 From: Harshit Gangal Date: Sat, 1 May 2021 12:23:18 +0530 Subject: [PATCH 1/2] ddl bypass planner Signed-off-by: Harshit Gangal Signed-off-by: Rafael Chacon --- go/vt/vtgate/planbuilder/ddl.go | 15 +++++++++++++++ .../planbuilder/testdata/bypass_cases.txt | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/go/vt/vtgate/planbuilder/ddl.go b/go/vt/vtgate/planbuilder/ddl.go index 77873b3abbe..d61a8997ced 100644 --- a/go/vt/vtgate/planbuilder/ddl.go +++ b/go/vt/vtgate/planbuilder/ddl.go @@ -25,6 +25,9 @@ const ( // and which chooses which of the two to invoke at runtime. func buildGeneralDDLPlan(sql string, ddlStatement sqlparser.DDLStatement, vschema ContextVSchema) (engine.Primitive, error) { normalDDLPlan, onlineDDLPlan, err := buildDDLPlans(sql, ddlStatement, vschema) + if vschema.Destination() != nil { + return buildByPassDDLPlan(sql, vschema) + } if err != nil { return nil, err } @@ -38,6 +41,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 diff --git a/go/vt/vtgate/planbuilder/testdata/bypass_cases.txt b/go/vt/vtgate/planbuilder/testdata/bypass_cases.txt index daafda9d360..7bb0fc36af5 100644 --- a/go/vt/vtgate/planbuilder/testdata/bypass_cases.txt +++ b/go/vt/vtgate/planbuilder/testdata/bypass_cases.txt @@ -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 + } +} From 5501139822e1a166a889765f89ae5cfa9cf261d2 Mon Sep 17 00:00:00 2001 From: Rafael Chacon Date: Tue, 4 May 2021 22:40:26 -0700 Subject: [PATCH 2/2] Fixes bad conflict resolution Signed-off-by: Rafael Chacon --- go/vt/vtgate/planbuilder/ddl.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/go/vt/vtgate/planbuilder/ddl.go b/go/vt/vtgate/planbuilder/ddl.go index d61a8997ced..f0627c8723c 100644 --- a/go/vt/vtgate/planbuilder/ddl.go +++ b/go/vt/vtgate/planbuilder/ddl.go @@ -24,10 +24,11 @@ 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) { - normalDDLPlan, onlineDDLPlan, err := buildDDLPlans(sql, ddlStatement, vschema) if vschema.Destination() != nil { return buildByPassDDLPlan(sql, vschema) } + + normalDDLPlan, onlineDDLPlan, err := buildDDLPlans(sql, ddlStatement, vschema) if err != nil { return nil, err }