diff --git a/go/vt/vtgate/planbuilder/operators/query_planning.go b/go/vt/vtgate/planbuilder/operators/query_planning.go index 81e3a099ebc..6d6616ad92f 100644 --- a/go/vt/vtgate/planbuilder/operators/query_planning.go +++ b/go/vt/vtgate/planbuilder/operators/query_planning.go @@ -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() only supported in the select list")) + } if topLevel { return &SaveToSession{ unaryOperator: unaryOperator{ diff --git a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.json b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.json index 9241cec595c..b1a858a65b3 100644 --- a/go/vt/vtgate/planbuilder/testdata/unsupported_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/unsupported_cases.json @@ -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() only supported in the select list", + "query": "select id, foo from user where last_insert_id(bar) = 12", + "plan": "VT12001: unsupported: last_insert_id() only supported in the select list" } ]