The default behaviour of GetImmutableTableByID and similar methods is to lookup leased descriptors when available and we have to set an AvoidLeased flag explicitly to avoid that. The problem is that when it comes to schema changes, we always want to avoid leased descriptors. We have a CommonLookupFlags() method on resolver.SchemaResolver which does the right thing but it's not enough.
Case in point: in 21.2, the canRemoveEnumValue is buggy because it happily looks up a leased table descriptor. This has since been fixed by #79697. But this class of bug can easily happen again.
Perhaps the solution is to flip the tables and replace AvoidLeased with IncludeLeased and have the optimizer set that flag. It might be less trouble. Alternatively, wrap the descs.Collection behind an interface that the planner can readily use when operating on schema change PlanNodes.
Jira issue: CRDB-19516
The default behaviour of
GetImmutableTableByIDand similar methods is to lookup leased descriptors when available and we have to set anAvoidLeasedflag explicitly to avoid that. The problem is that when it comes to schema changes, we always want to avoid leased descriptors. We have aCommonLookupFlags()method onresolver.SchemaResolverwhich does the right thing but it's not enough.Case in point: in 21.2, the
canRemoveEnumValueis buggy because it happily looks up a leased table descriptor. This has since been fixed by #79697. But this class of bug can easily happen again.Perhaps the solution is to flip the tables and replace
AvoidLeasedwithIncludeLeasedand have the optimizer set that flag. It might be less trouble. Alternatively, wrap the descs.Collection behind an interface that the planner can readily use when operating on schema changePlanNodes.Jira issue: CRDB-19516