Skip to content

sql/backfill: prevent index backfill from evaluating new volatile key columns #81521

@ajwerner

Description

@ajwerner

Is your feature request related to a problem? Please describe.

Follow-up from #81486. The index backfiller can happily evaluate default expressions for new columns which will be part of a new primary index. This is critical to enable #47989. However, if the expressions being evaluated are volatile and are part of the key, then restarts will no longer be idempotent and will cause a corrupt index.

Describe the solution you'd like

We should return an assertion failure error if we ever try to execute such an index backfill. We should know the properties of the expressions at backfill time, so it's not hard to add.

Additional context

Relates both to #81449 and #81448.

When we want to support the following, we'll need to be smarter in how we plan. Namely, we need to first add the column to a primary index but not as a key column, take that all the way to at least validated, then go and build the index with the now materialized k being read from the new source.

CREATE TABLE t (i INT);
ALTER TABLE t ADD COLUMN k UUID DEFAULT (gen_random_uuid()) PRIMARY KEY

Jira issue: CRDB-15105

Epic CRDB-61003

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-schema-changer-implRelated to the implementation of the new schema changerC-cleanupTech debt, refactors, loose ends, etc. Solution not expected to significantly change 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