From 098c5b876f84aa5bf6a0d5e6143e674fc62e3ef3 Mon Sep 17 00:00:00 2001 From: arulajmani Date: Sun, 7 Feb 2021 22:40:26 -0500 Subject: [PATCH] sql: fail type descriptor validation if referenced descriptor is dropped Previously, when a type descriptor was validated for cross references, we weren't checking if the referenced table descriptor was dropped. This seems erroneous, as before a table descriptor is dropped, it should unlink itself from type descriptors that hold a backreference to it. This patch validates as such. Release note: None --- pkg/sql/catalog/typedesc/type_desc.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/sql/catalog/typedesc/type_desc.go b/pkg/sql/catalog/typedesc/type_desc.go index e1e16928832b..90540d9c33d5 100644 --- a/pkg/sql/catalog/typedesc/type_desc.go +++ b/pkg/sql/catalog/typedesc/type_desc.go @@ -636,9 +636,14 @@ func (desc *Immutable) Validate(ctx context.Context, dg catalog.DescGetter) erro // Validate that all of the referencing descriptors exist. tableExists := func(id descpb.ID) func(got catalog.Descriptor) error { return func(got catalog.Descriptor) error { - if _, isTable := got.(catalog.TableDescriptor); !isTable { + tableDesc, isTable := got.(catalog.TableDescriptor) + if !isTable { return errors.AssertionFailedf("referencing descriptor %d does not exist", id) } + if tableDesc.Dropped() { + return errors.AssertionFailedf( + "referencing descriptor %d was dropped without dependency unlinking", id) + } return nil } }