Skip to content

Fix 2307 alter column type assert - #2318

Closed
tuhaihe wants to merge 3 commits into
apache:mainfrom
tuhaihe:fix-2307-alter-column-type-assert
Closed

tuhaihe wants to merge 3 commits into
apache:mainfrom
tuhaihe:fix-2307-alter-column-type-assert

Conversation

@tuhaihe

@tuhaihe tuhaihe commented Nov 13, 2026

Copy link
Copy Markdown
Member

Fixes #2307

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


@tuhaihe
tuhaihe marked this pull request as draft November 13, 2026 09:25
@reshke

reshke commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Ohh yes issue looks real, will take a look

@reshke

reshke commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Shoul be fixed once #2284 merge

@reshke

reshke commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Shoul be fixed once #2284 merge

No. Recheck-separate issue. 2284 does not fix that as-is

@andr-sokolov

Copy link
Copy Markdown
Collaborator

to fix the alter_column_type test it is necessary to cherry-pick d36980b7159a343ec56baca40bfe6c67765095b7 too

tglsfdc and others added 3 commits November 13, 2026 20:16
Sometimes a table's constraint may depend on a column of another
table, so that we have to update the constraint when changing the
referenced column's type.  We need to have lock on the constraint's
table to do that.  ATPostAlterTypeCleanup believed that this case
was only possible for FOREIGN KEY constraints, but it's wrong at
least for CHECK and EXCLUDE constraints; and in general, we'd
probably need exclusive lock to alter any sort of constraint.
So just remove the contype check and acquire lock for any other
table.  This prevents a "you don't have lock" assertion failure,
though no ill effect is observed in production builds.

We'll error out later anyway because we don't presently support
physically altering column types within stored composite columns.
But the catalog-munging is basically all there, so we may as well
make that part work.

Bug: #18970
Reported-by: Alexander Lakhin <exclusion@gmail.com>
Diagnosed-by: jian he <jian.universality@gmail.com>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/18970-a7d1cfe1f8d5d8d9@postgresql.org
Backpatch-through: 13
(cherry picked from commit c15798cf94c452f057c6b8dd38c904bb30a8864d)
The upstream fix removed the contype local variable since upstream no
longer needs it after dropping the FOREIGN KEY-only lock condition.
Cloudberry keeps an extra GPDB-specific rejection of ALTER TYPE on
primary key / unique constraint columns (see gpdb#10561), which still
references contype.  Restore the declaration and assignment so the
function keeps compiling and behaves identically to upstream plus the
GPDB-only check.
Commits 8319e5cb5 et al missed the fact that ATPostAlterTypeCleanup
contains three calls to ATPostAlterTypeParse, and the other two
also need protection against passing a relid that we don't yet
have lock on.  Add similar logic to those code paths, and add
some test cases demonstrating the need for it.

In v18 and master, the test cases demonstrate that there's a
behavioral discrepancy between stored generated columns and virtual
generated columns: we disallow changing the expression of a stored
column if it's used in any composite-type columns, but not that of
a virtual column.  Since the expression isn't actually relevant to
either sort of composite-type usage, this prohibition seems
unnecessary; but changing it is a matter for separate discussion.
For now we are just documenting the existing behavior.

Reported-by: jian he <jian.universality@gmail.com>
Author: jian he <jian.universality@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: CACJufxGKJtGNRRSXfwMW9SqVOPEMdP17BJ7DsBf=tNsv9pWU9g@mail.gmail.com
Backpatch-through: 13
(cherry picked from commit d36980b7159a343ec56baca40bfe6c67765095b7)

Cloudberry Debug CI also reaches the missing statistics-table lock:

    relation_open -> transformStatsStmt -> ATPostAlterTypeParse -> ATController

The existing alter_column_type test exercises this path.  Keep the
Cloudberry-specific ATPostAlterTypeParse context and PK/UNIQUE checks.
@reshke
reshke force-pushed the fix-2307-alter-column-type-assert branch from d5fa714 to b5a17b4 Compare November 13, 2026 15:16
@tuhaihe

tuhaihe commented Nov 13, 2026

Copy link
Copy Markdown
Member Author

hi @reshke @andr-sokolov is there a need to keep this PR? If not, let's close it.

@andr-sokolov

andr-sokolov commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

there is no need to keep this PR because #2319 has been merged

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.

Assertion failure in relation_open() on ALTER COLUMN TYPE with cross-table CHECK constraint

4 participants