Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions go/vt/vtgate/planbuilder/operators/rewriters.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ type (
VisitRule bool
)

var (
NoRewrite *ApplyResult = nil
)
var NoRewrite *ApplyResult = nil

const (
VisitChildren VisitRule = true
Expand Down
14 changes: 13 additions & 1 deletion go/vt/vtgate/planbuilder/operators/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,19 @@ func findVSchemaTableAndCreateRoute(
tableName sqlparser.TableName,
planAlternates bool,
) *Route {
vschemaTable, _, _, tabletType, target, err := ctx.VSchema.FindTableOrVindex(tableName)
var (
vschemaTable *vindexes.BaseTable
tabletType topodatapb.TabletType
target key.ShardDestination
err error
)

if ctx.IsMirrored() {
vschemaTable, _, tabletType, target, err = ctx.VSchema.FindTable(tableName)
} else {
vschemaTable, _, _, tabletType, target, err = ctx.VSchema.FindTableOrVindex(tableName)
}

if err != nil {
panic(err)
}
Expand Down
1 change: 0 additions & 1 deletion go/vt/vtgate/planbuilder/operators/route_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ func optimizeJoin(ctx *plancontext.PlanningContext, op *Join) (Operator, *ApplyR
}

func optimizeQueryGraph(ctx *plancontext.PlanningContext, op *QueryGraph) (result Operator, changed *ApplyResult) {

switch {
case ctx.PlannerVersion == querypb.ExecuteOptions_Gen4Left2Right:
result = leftToRightSolve(ctx, op)
Expand Down
126 changes: 126 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/mirror_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,132 @@
]
}
},
{
"comment": "select from source of unsharded, unqualified, table mirrored to unsharded table with routing rules",
"query": "select t4.id from t4 where t4.id = 1",
"plan": {
"Type": "Complex",
"QueryType": "SELECT",
"Original": "select t4.id from t4 where t4.id = 1",
"Instructions": {
"OperatorType": "Mirror",
"Variant": "PercentBased",
"Percent": 10,
"Inputs": [
{
"OperatorType": "Route",
"Variant": "Unsharded",
"Keyspace": {
"Name": "unsharded_src1",
"Sharded": false
},
"FieldQuery": "select t4.id from t4 where 1 != 1",
"Query": "select t4.id from t4 where t4.id = 1",
"Table": "t4"
},
{
"OperatorType": "Route",
"Variant": "Unsharded",
"Keyspace": {
"Name": "unsharded_dst1",
"Sharded": false
},
"FieldQuery": "select t4.id from t4 where 1 != 1",
"Query": "select t4.id from t4 where t4.id = 1",
"Table": "t4"
}
]
},
"TablesUsed": [
"unsharded_dst1.t4",
"unsharded_src1.t4"
]
}
},
{
"comment": "select from source of unsharded, qualified, table mirrored to unsharded table with routing rules",
"query": "select t4.id from unsharded_src1.t4 where t4.id = 1",
"plan": {
"Type": "Complex",
"QueryType": "SELECT",
"Original": "select t4.id from unsharded_src1.t4 where t4.id = 1",
"Instructions": {
"OperatorType": "Mirror",
"Variant": "PercentBased",
"Percent": 10,
"Inputs": [
{
"OperatorType": "Route",
"Variant": "Unsharded",
"Keyspace": {
"Name": "unsharded_src1",
"Sharded": false
},
"FieldQuery": "select t4.id from t4 where 1 != 1",
"Query": "select t4.id from t4 where t4.id = 1",
"Table": "t4"
},
{
"OperatorType": "Route",
"Variant": "Unsharded",
"Keyspace": {
"Name": "unsharded_dst1",
"Sharded": false
},
"FieldQuery": "select t4.id from t4 where 1 != 1",
"Query": "select t4.id from t4 where t4.id = 1",
"Table": "t4"
}
]
},
"TablesUsed": [
"unsharded_dst1.t4",
"unsharded_src1.t4"
]
}
},
{
"comment": "select from destination of unsharded, qualified, table mirrored to unsharded table with routing rules",
"query": "select t4.id from unsharded_dst1.t4 where t4.id = 1",
"plan": {
"Type": "Complex",
"QueryType": "SELECT",
"Original": "select t4.id from unsharded_dst1.t4 where t4.id = 1",
"Instructions": {
"OperatorType": "Mirror",
"Variant": "PercentBased",
"Percent": 10,
"Inputs": [
{
"OperatorType": "Route",
"Variant": "Unsharded",
"Keyspace": {
"Name": "unsharded_src1",
"Sharded": false
},
"FieldQuery": "select t4.id from t4 where 1 != 1",
"Query": "select t4.id from t4 where t4.id = 1",
"Table": "t4"
},
{
"OperatorType": "Route",
"Variant": "Unsharded",
"Keyspace": {
"Name": "unsharded_dst1",
"Sharded": false
},
"FieldQuery": "select t4.id from t4 where 1 != 1",
"Query": "select t4.id from t4 where t4.id = 1",
"Table": "t4"
}
]
},
"TablesUsed": [
"unsharded_dst1.t4",
"unsharded_src1.t4"
]
}
},
{
"comment": "select unsharded, qualified, table mirrored to unsharded table with zero percentage",
"query": "select t3.id from unsharded_src1.t3 where t3.id = 1",
Expand Down
63 changes: 63 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/vschemas/mirror_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,69 @@
"from_table": "unsharded_src1.t3",
"to_table": "unsharded_dst1.t2",
"percent": 0
},
{
"from_table": "unsharded_src1.t4",
"to_table": "unsharded_dst1.t4",
"percent": 10
}
]
},
"routing_rules": {
"rules": [
{
"from_table": "t4",
"to_tables": [
"unsharded_src1.t4"
]
},
{
"from_table": "t4@replica",
"to_tables": [
"unsharded_src1.t4"
]
},
{
"from_table": "t4@rdonly",
"to_tables": [
"unsharded_src1.t4"
]
},
{
"from_table": "unsharded_src1.t4",
"to_tables": [
"unsharded_src1.t4"
]
},
{
"from_table": "unsharded_src1.t4@replica",
"to_tables": [
"unsharded_src1.t4"
]
},
{
"from_table": "unsharded_src1.t4@rdonly",
"to_tables": [
"unsharded_src1.t4"
]
},
{
"from_table": "unsharded_dst1.t4",
"to_tables": [
"unsharded_src1.t4"
]
},
{
"from_table": "unsharded_dst1.t4@replica",
"to_tables": [
"unsharded_src1.t4"
]
},
{
"from_table": "unsharded_dst1.t4@rdonly",
"to_tables": [
"unsharded_src1.t4"
]
}
]
},
Expand Down
6 changes: 5 additions & 1 deletion go/vt/vtgate/semantics/table_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,11 @@ func (etc *earlyTableCollector) createTable(
return nil, err
}

mr, err := etc.si.FindMirrorRule(t)
tblName := t
if tbl != nil && tbl.Keyspace != nil {
tblName = tbl.GetTableName()
}
mr, err := etc.si.FindMirrorRule(tblName)
if err != nil {
// Mirroring is best effort. If we get an error while mirroring, keep going
// as if mirroring was disabled. We don't want to interrupt production work
Expand Down