Skip to content

Commit

Permalink
feat: copy the order by from the update query
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Oct 19, 2023
1 parent a68c8d6 commit 27a78be
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions go/vt/vtgate/planbuilder/operators/ast_to_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,15 @@ func createSelectionOp(
selectExprs []sqlparser.SelectExpr,
tableExprs sqlparser.TableExprs,
where *sqlparser.Where,
orderBy sqlparser.OrderBy,
limit *sqlparser.Limit,
lock sqlparser.Lock,
) (ops.Operator, error) {
selectionStmt := &sqlparser.Select{
SelectExprs: selectExprs,
From: tableExprs,
Where: where,
OrderBy: orderBy,
Limit: limit,
Lock: lock,
}
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func createFkCascadeOpForDelete(ctx *plancontext.PlanningContext, parentOp ops.O
}
fkChildren = append(fkChildren, fkChild)
}
selectionOp, err := createSelectionOp(ctx, selectExprs, delStmt.TableExprs, delStmt.Where, nil, sqlparser.ForUpdateLock)
selectionOp, err := createSelectionOp(ctx, selectExprs, delStmt.TableExprs, delStmt.Where, nil, nil, sqlparser.ForUpdateLock)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion go/vt/vtgate/planbuilder/operators/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func createFKCascadeOp(ctx *plancontext.PlanningContext, parentOp ops.Operator,
fkChildren = append(fkChildren, fkChild)
}

selectionOp, err := createSelectionOp(ctx, selectExprs, updStmt.TableExprs, updStmt.Where, nil, sqlparser.ForUpdateLock)
selectionOp, err := createSelectionOp(ctx, selectExprs, updStmt.TableExprs, updStmt.Where, updStmt.OrderBy, nil, sqlparser.ForUpdateLock)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -616,6 +616,7 @@ func createFkVerifyOpForParentFKForUpdate(ctx *plancontext.PlanningContext, updS
sqlparser.NewJoinCondition(joinCond, nil)),
},
sqlparser.NewWhere(sqlparser.WhereClause, whereCond),
nil,
sqlparser.NewLimitWithoutOffset(1),
sqlparser.ShareModeLock)
}
Expand Down Expand Up @@ -685,6 +686,7 @@ func createFkVerifyOpForChildFKForUpdate(ctx *plancontext.PlanningContext, updSt
sqlparser.NewJoinCondition(joinCond, nil)),
},
sqlparser.NewWhere(sqlparser.WhereClause, whereCond),
nil,
sqlparser.NewLimitWithoutOffset(1),
sqlparser.ShareModeLock)
}
Expand Down

0 comments on commit 27a78be

Please sign in to comment.