-
Notifications
You must be signed in to change notification settings - Fork 4.1k
tabledesc: GetReferencedDescIDs is incorrect #77140
Description
The contract for the GetReferencedDescIDs method in catalog.Descriptor is to return the set of all descriptor IDs referenced by a descriptor: itself, its parents, forward references, backward references, etc. This method is used for cross-descriptor validation to retrieve all the descriptors which might have forward or back-references to the validated descriptor.
Currently, it appears that there are some edge cases for which GetReferencedDescIDs does not behave correctly. These involve user-defined types. Notice that GetAllReferencedTypeIDs and by extension getAllReferencedTypesInTableColumns return the ID closure of any referenced type descriptor. This is a fancy word for transitive dependencies. Practically speaking:
CREATE TYPE greeting AS ENUM ('hello', 'hi');
will create an enum type greeting and also an alias type _greeting which represents the array type greeting[]. It so happens that
CREATE TABLE foo (x greeting);
will create a table descriptor for foo which contains a forward reference to greeting via its column x. However, counterintuitively, back-references to foo will be added in both greeting as well as _greeting.
All this can be quite easily verified in a unit test which:
- spins ups a test cluster,
- executes statements similar to these above,
- retrieves the table descriptor and the two type descriptors via a
desctestutilsfunction - checks that there are back-references to the table descriptor in both type descriptors
- checks that
GetAllReferencedTypeIDsreturns both type descriptor IDs (this is correct) - checks that
GetReferencedDescIDsonly returns one type descriptor ID (this is incorrect, and is the bug that needs to be fixed)
Jira issue: CRDB-13429
Epic CRDB-30352