From 70996addd2522cf522fed582a96604bf0f962143 Mon Sep 17 00:00:00 2001 From: Andres Taylor Date: Tue, 10 Dec 2024 12:43:59 +0100 Subject: [PATCH] feat: fail if last_insert_id is used in other contexts that SELECT Signed-off-by: Andres Taylor --- go/vt/vtgate/planbuilder/operators/query_planning.go | 4 +++- go/vt/vtgate/planbuilder/testdata/unsupported_cases.json | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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" } ]