Skip to content

Commit

Permalink
sql: rework some internal executor logic related to synthetic descrip…
Browse files Browse the repository at this point in the history
…otrs

The pre-existing logic would reset the synthetic descriptors whenever anything
was run on behalf of the internal planner. That's never what we want. We
prevent that by attaching the logic to reset the synthetic descriptors to
whether the internal executor has attached synthetic descriptors, which
it never has when using the planner's state.

Release justification: part of bug fix

Release note: None
  • Loading branch information
ajwerner authored and Xiang-Gu committed Aug 31, 2022
1 parent 5ac8e5b commit c6ec1ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
10 changes: 8 additions & 2 deletions pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,10 @@ type connExecutor struct {
// delete schema change job records. Instead, we leave the caller of the
// internal executor to release them.
fromOuterTxn bool
// shouldResetSyntheticDescriptors should be set to true only if
// fromOuterTxn is set to true, and, upon finishing the statement, the
// synthetic descriptors should be reset.
shouldResetSyntheticDescriptors bool

// descCollection collects descriptors used by the current transaction.
descCollection *descs.Collection
Expand Down Expand Up @@ -1662,7 +1666,9 @@ func (ex *connExecutor) resetExtraTxnState(ctx context.Context, ev txnEvent) {
ex.extraTxnState.hasAdminRoleCache = HasAdminRoleCache{}

if ex.extraTxnState.fromOuterTxn {
ex.extraTxnState.descCollection.ResetSyntheticDescriptors()
if ex.extraTxnState.shouldResetSyntheticDescriptors {
ex.extraTxnState.descCollection.ResetSyntheticDescriptors()
}
} else {
ex.extraTxnState.descCollection.ReleaseAll(ctx)
for k := range ex.extraTxnState.schemaChangeJobRecords {
Expand Down Expand Up @@ -3267,7 +3273,7 @@ func (ex *connExecutor) runPreCommitStages(ctx context.Context) error {
scs.jobID,
scs.stmts,
)

ex.extraTxnState.descCollection.ResetSyntheticDescriptors()
after, jobID, err := scrun.RunPreCommitPhase(
ctx, ex.server.cfg.DeclarativeSchemaChangerTestingKnobs, deps, scs.state,
)
Expand Down
20 changes: 11 additions & 9 deletions pkg/sql/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,14 +331,14 @@ func (ie *InternalExecutor) newConnExecutorWithTxn(
// let it inherit the descriptor collection, schema change job records
// and job collections from the caller.
postSetupFn := func(ex *connExecutor) {
if ie.extraTxnState != nil {
if ie.extraTxnState.descCollection != nil {
ex.extraTxnState.descCollection = ie.extraTxnState.descCollection
ex.extraTxnState.fromOuterTxn = true
ex.extraTxnState.schemaChangeJobRecords = ie.extraTxnState.schemaChangeJobRecords
ex.extraTxnState.jobs = ie.extraTxnState.jobs
ex.extraTxnState.schemaChangerState = ie.extraTxnState.schemaChangerState
}
if ie.extraTxnState != nil && ie.extraTxnState.descCollection != nil {
ex.extraTxnState.descCollection = ie.extraTxnState.descCollection
ex.extraTxnState.fromOuterTxn = true
ex.extraTxnState.shouldResetSyntheticDescriptors = len(ie.syntheticDescriptors) > 0
ex.extraTxnState.schemaChangeJobRecords = ie.extraTxnState.schemaChangeJobRecords
ex.extraTxnState.jobs = ie.extraTxnState.jobs
ex.extraTxnState.schemaChangerState = ie.extraTxnState.schemaChangerState
ex.initPlanner(ctx, &ex.planner)
}
}

Expand Down Expand Up @@ -393,7 +393,9 @@ func (ie *InternalExecutor) newConnExecutorWithTxn(
// Modify the Collection to match the parent executor's Collection.
// This allows the InternalExecutor to see schema changes made by the
// parent executor.
ex.extraTxnState.descCollection.SetSyntheticDescriptors(ie.syntheticDescriptors)
if len(ie.syntheticDescriptors) > 0 {
ex.extraTxnState.descCollection.SetSyntheticDescriptors(ie.syntheticDescriptors)
}
return ex, err
}

Expand Down

0 comments on commit c6ec1ca

Please sign in to comment.