From 7e91991339283e73cdf1de429531c2a9114e44fa Mon Sep 17 00:00:00 2001 From: Jane Xing Date: Wed, 24 Aug 2022 10:37:42 -0500 Subject: [PATCH] sql: require txn-related metadata if running DDLs with internal executor with txn When using internal executor to run DDL statements under a not-nil outer txn, we require txn-related metadata (such as descriptor collections) to be passed to the internal executor from the outer caller too. This commit is to add a gate for this use case. Release justification: bug fix Release note: none --- pkg/sql/internal.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/sql/internal.go b/pkg/sql/internal.go index 4091ea6f0980..738ad99f038c 100644 --- a/pkg/sql/internal.go +++ b/pkg/sql/internal.go @@ -817,6 +817,11 @@ func (ie *InternalExecutor) execInternal( stmt string, qargs ...interface{}, ) (r *rowsIterator, retErr error) { + if ie.extraTxnState != nil { + if txn != ie.extraTxnState.txn { + return nil, errors.New("inconsistent txn with the one when constructing the internal executor") + } + } ctx = logtags.AddTag(ctx, "intExec", opName) var sd *sessiondata.SessionData @@ -879,6 +884,11 @@ func (ie *InternalExecutor) execInternal( timeReceived := timeutil.Now() parseStart := timeReceived parsed, err := parser.ParseOne(stmt) + if tree.CanModifySchema(parsed.AST) && txn != nil { + if ie.extraTxnState == nil || ie.extraTxnState.descCollection == nil { + return nil, errors.New("DDL statement is disallowed if internal executor is not bound with txn metadata") + } + } if err != nil { return nil, err }