Skip to content

tabledesc: GetReferencedDescIDs is incorrect #77140

@postamar

Description

@postamar

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 desctestutils function
  • checks that there are back-references to the table descriptor in both type descriptors
  • checks that GetAllReferencedTypeIDs returns both type descriptor IDs (this is correct)
  • checks that GetReferencedDescIDs only returns one type descriptor ID (this is incorrect, and is the bug that needs to be fixed)

Jira issue: CRDB-13429

Epic CRDB-30352

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-schema-descriptorsRelating to SQL table/db descriptor handling.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions