Skip to content

sql/schemachanger: missing function dep when adding an unvalidated constraint #155400

@spilchen

Description

@spilchen

When altering a table to add a constraint that references a function, we fail to correctly establish the function dependency, resulting in an internal error. This only happens if the constraint is created as 'NOT VALID'. Validated constraints have the proper dependency tracking.

Reproduction

> CREATE TABLE IF NOT EXISTS t
(
    a TEXT
);
CREATE TABLE

> CREATE OR REPLACE FUNCTION func(a text) RETURNS boolean AS $$
BEGIN
  RETURN TRUE;
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION

> ALTER TABLE t
ADD CONSTRAINT IF NOT EXISTS check_a CHECK (func(a)) NOT VALID;
ERROR: internal error: executing declarative schema change StatementPhase stage 1 of 1 with 3 MutationType ops (rollback=false) for ALTER TABLE: error executing StatementPhase stage 1 of 1 with 3 MutationType ops: relation "t" (112): depends-on function "func" (113) has no corresponding depended-on-by back reference
SQLSTATE: XX000

https://github.com/cockroachlabs/support/issues/3458

Jira issue: CRDB-55424

Epic CRDB-55074

Metadata

Metadata

Assignees

Labels

A-schema-changesC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.O-supportWould prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docsP-1Issues/test failures with a fix SLA of 1 monthT-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)branch-release-24.1Used to mark GA and release blockers, technical advisories, and bugs for 24.1branch-release-24.2Used to mark GA and release blockers, technical advisories, and bugs for 24.2branch-release-24.3Used to mark GA and release blockers, technical advisories, and bugs for 24.3branch-release-25.1branch-release-25.2branch-release-25.3Used to mark GA and release blockers and technical advisories for 25.3branch-release-25.4Used to mark GA and release blockers and technical advisories for 25.4target-release-24.1.26target-release-24.3.22target-release-25.2.8target-release-25.3.4target-release-25.4.0target-release-26.1.0

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions