Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/route_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func pushDerived(ctx *plancontext.PlanningContext, op *Horizon) (Operator, *Appl
return op, NoRewrite
}

if (innerRoute.Routing.OpCode() != engine.EqualUnique) && !op.IsMergeable(ctx) {
if !innerRoute.Routing.OpCode().IsSingleShard() && !op.IsMergeable(ctx) {
// no need to check anything if we are sure that we will only hit a single shard
return op, NoRewrite
}
Expand Down
24 changes: 23 additions & 1 deletion go/vt/vtgate/planbuilder/testdata/reference_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -893,5 +893,27 @@
"user.music"
]
}
},
{
"comment": "Derived table pushdown optimization",
"query": "SELECT * FROM (SELECT DISTINCT id, col FROM user.ref WHERE id = 1 LIMIT 10) as sub",
"plan": {
"Type": "Passthrough",
"QueryType": "SELECT",
"Original": "SELECT * FROM (SELECT DISTINCT id, col FROM user.ref WHERE id = 1 LIMIT 10) as sub",
"Instructions": {
"OperatorType": "Route",
"Variant": "Reference",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select id, col from (select id, col from ref where 1 != 1) as sub where 1 != 1",
"Query": "select id, col from (select distinct id, col from ref where id = 1 limit 10) as sub"
},
"TablesUsed": [
"user.ref"
]
}
}
]
]
Loading