Skip to content

Commit

Permalink
feat: fail if last_insert_id is used in other contexts that SELECT
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Dec 10, 2024
1 parent 00cca4d commit 70996ad
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion go/vt/vtgate/planbuilder/operators/query_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,9 @@ func handleLastInsertIDColumns(ctx *plancontext.PlanningContext, output Operator
newExpr := sqlparser.CopyAndReplaceExpr(ae.Expr, replaceFn)
ae.Expr = newExpr.(sqlparser.Expr)
}

if offset == -1 {
panic(vterrors.VT12001("last_insert_id(<expr>) only supported in the select list"))
}
if topLevel {
return &SaveToSession{
unaryOperator: unaryOperator{
Expand Down
5 changes: 5 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/unsupported_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,10 @@
"comment": "SOME/ANY/ALL comparison operator not supported for unsharded queries",
"query": "select 1 from user where foo = ALL (select 1 from user_extra where foo = 1)",
"plan": "VT12001: unsupported: ANY/ALL/SOME comparison operator"
},
{
"comment": "last_insert_id(<expr>) only supported in the select list",
"query": "select id, foo from user where last_insert_id(bar) = 12",
"plan": "VT12001: unsupported: last_insert_id(<expr>) only supported in the select list"
}
]

0 comments on commit 70996ad

Please sign in to comment.