Skip to content

Commit

Permalink
sql: require txn-related metadata if running DDLs with internal execu…
Browse files Browse the repository at this point in the history
…tor 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
  • Loading branch information
ZhouXing19 committed Aug 24, 2022
1 parent b004a63 commit 7e91991
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/sql/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 7e91991

Please sign in to comment.