Skip to content

sql/schemachanger: allow ALTER COLUMN TYPE with dependent routines#170003

Draft
michae2 wants to merge 1 commit into
cockroachdb:masterfrom
michae2:allow-alter-column-type-with-routines
Draft

sql/schemachanger: allow ALTER COLUMN TYPE with dependent routines#170003
michae2 wants to merge 1 commit into
cockroachdb:masterfrom
michae2:allow-alter-column-type-with-routines

Conversation

@michae2
Copy link
Copy Markdown
Collaborator

@michae2 michae2 commented May 8, 2026

Previously, ALTER TABLE ... ALTER COLUMN TYPE unconditionally failed when UDFs or stored procedures referenced the column, even for compatible type changes like INT4→INT8 or VARCHAR(30)→VARCHAR(60). This was a significant limitation for users with many routines who needed to widen column types without downtime.

This change makes the schema changer re-validate dependent routine bodies against the new column type before rejecting the ALTER. A synthetic table descriptor with the new type is injected into the catalog, and each dependent function/procedure body is type-checked via BuildReferenceProvider. If validation passes, the ALTER proceeds and FunctionBody elements are updated with refreshed dependency references. If any routine body would become invalid with the new type, a descriptive error is returned.

Fixes: #160622

Release note (sql change): ALTER TABLE ... ALTER COLUMN TYPE now succeeds when dependent functions or stored procedures reference the column, as long as the type change is compatible with the routine bodies. Previously, any dependent routine would unconditionally block the type change. Incompatible changes still produce a clear error identifying which routine would become invalid.

@trunk-io
Copy link
Copy Markdown
Contributor

trunk-io Bot commented May 8, 2026

Merging to master in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@michae2 michae2 force-pushed the allow-alter-column-type-with-routines branch from 3690f5e to ea68989 Compare May 8, 2026 22:36
@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 8, 2026

Detected infrastructure failure (matched: self-hosted runner lost communication with the server). Automatically rerunning failed jobs. (run link)


subtest dep_function

# Compatible type change (INT4 → INT8) should succeed with dependent function.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see widening tests but is there coverage that unsafe narrowing is blocked?

Previously, ALTER TABLE ... ALTER COLUMN TYPE unconditionally failed
when UDFs or stored procedures referenced the column, even for
compatible type changes like INT4→INT8 or VARCHAR(30)→VARCHAR(60).
This was a significant limitation for users with many routines who
needed to widen column types without downtime.

This change makes the schema changer re-validate dependent routine
bodies against the new column type before rejecting the ALTER. A
synthetic table descriptor with the new type is injected into the
catalog, and each dependent function/procedure body is type-checked
via BuildReferenceProvider. If validation passes, the ALTER proceeds
and FunctionBody elements are updated with refreshed dependency
references. If any routine body would become invalid with the new
type, a descriptive error is returned.

Fixes: cockroachdb#160622

Release note (sql change): ALTER TABLE ... ALTER COLUMN TYPE now
succeeds when dependent functions or stored procedures reference the
column, as long as the type change is compatible with the routine
bodies. Previously, any dependent routine would unconditionally block
the type change. Incompatible changes still produce a clear error
identifying which routine would become invalid.

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@michae2 michae2 force-pushed the allow-alter-column-type-with-routines branch from 7232852 to 2cfec33 Compare May 15, 2026 19:48
@blathers-crl
Copy link
Copy Markdown

blathers-crl Bot commented May 15, 2026

Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sql: allow altering type of columns referenced in UDFs and SPs

3 participants