Skip to content

Commit 20c8867

Browse files
tanjinxClaude
andauthored
restore v19 behavior: push LIMIT to each shard for non-scatter multi-shard DML (#838)
* feat: add scatter-update-limit-passthru vtgate flag When enabled, multi-shard UPDATE/DELETE with LIMIT on non-scatter routes (e.g. WHERE id IN (...) on a vindex column) pushes the LIMIT to each shard directly instead of converting to DMLWithInput which requires schema tracking. Scatter routes are unaffected. This restores v19 behavior for targeted multi-shard DML with LIMIT behind an opt-in flag. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> Signed-off-by: Tanjin Xu <tanjin.xu@slack-corp.com> * fix: return false instead of panic for test mock IsScatterUpdateLimitPassthruEnabled Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> Signed-off-by: Tanjin Xu <tanjin.xu@slack-corp.com> * feat: add scatter-update-limit-passthru to help text files Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> Signed-off-by: Tanjin Xu <tanjin.xu@slack-corp.com> * fix: remove scatter-update-limit-passthru from vttestserver help text The flag is only registered for vtgate and vtcombo, not vttestserver. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> Signed-off-by: Tanjin Xu <tanjin.xu@slack-corp.com> * fix: correct spacing in scatter-update-limit-passthru help text Add one extra space to align the description column consistently with other flags in vtgate.txt and vtcombo.txt. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> Signed-off-by: Tanjin Xu <tanjin.xu@slack-corp.com> * remove scatter-update-limit-passthru flag, enable by default The behavior is now always-on: non-scatter multi-shard DML with LIMIT pushes the LIMIT to each shard directly. Scatter DML with LIMIT still uses DMLWithInput as before. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> Signed-off-by: Tanjin Xu <tanjin.xu@slack-corp.com> * remove scatter-update-limit-passthru from help text files Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> Signed-off-by: Tanjin Xu <tanjin.xu@slack-corp.com> * fix e2e test: use col instead of val for user_extra The user_extra table does not have a val column in the e2e schema. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> Signed-off-by: Tanjin Xu <tanjin.xu@slack-corp.com> --------- Signed-off-by: Tanjin Xu <tanjin.xu@slack-corp.com> Co-authored-by: Claude <svc-devxp-claude@slack-corp.com>
1 parent fabb599 commit 20c8867

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

go/vt/vtgate/planbuilder/operators/query_planning.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,9 @@ func tryPushingDownLimitInRoute(ctx *plancontext.PlanningContext, in *Limit, src
525525
}
526526

527527
if sqlparser.IsDMLStatement(ctx.Statement) {
528+
if src.Routing.OpCode() != engine.Scatter {
529+
return Swap(in, src, "push limit under route")
530+
}
528531
return setUpperLimit(in)
529532
}
530533

go/vt/vtgate/planbuilder/testdata/dml_cases.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7430,5 +7430,57 @@
74307430
]
74317431
},
74327432
"skip_e2e": true
7433+
},
7434+
{
7435+
"comment": "update with IN clause on vindex and limit pushes limit to each shard",
7436+
"query": "update user_extra set col = 1 where user_id in (1, 2) limit 5",
7437+
"plan": {
7438+
"Type": "MultiShard",
7439+
"QueryType": "UPDATE",
7440+
"Original": "update user_extra set col = 1 where user_id in (1, 2) limit 5",
7441+
"Instructions": {
7442+
"OperatorType": "Update",
7443+
"Variant": "IN",
7444+
"Keyspace": {
7445+
"Name": "user",
7446+
"Sharded": true
7447+
},
7448+
"Query": "update user_extra set col = 1 where user_id in ::__vals limit 5",
7449+
"Table": "user_extra",
7450+
"Values": [
7451+
"(1, 2)"
7452+
],
7453+
"Vindex": "user_index"
7454+
},
7455+
"TablesUsed": [
7456+
"user.user_extra"
7457+
]
7458+
}
7459+
},
7460+
{
7461+
"comment": "delete with IN clause on vindex and limit pushes limit to each shard",
7462+
"query": "delete from user_extra where user_id in (1, 2) limit 5",
7463+
"plan": {
7464+
"Type": "MultiShard",
7465+
"QueryType": "DELETE",
7466+
"Original": "delete from user_extra where user_id in (1, 2) limit 5",
7467+
"Instructions": {
7468+
"OperatorType": "Delete",
7469+
"Variant": "IN",
7470+
"Keyspace": {
7471+
"Name": "user",
7472+
"Sharded": true
7473+
},
7474+
"Query": "delete from user_extra where user_id in ::__vals limit 5",
7475+
"Table": "user_extra",
7476+
"Values": [
7477+
"(1, 2)"
7478+
],
7479+
"Vindex": "user_index"
7480+
},
7481+
"TablesUsed": [
7482+
"user.user_extra"
7483+
]
7484+
}
74337485
}
74347486
]

0 commit comments

Comments
 (0)