Skip to content

schemachanger: fix flaky DML injection test for drop column with NOT NULL#164535

Open
bghal wants to merge 2 commits intocockroachdb:masterfrom
bghal:fix-dml-injection-null-constraint
Open

schemachanger: fix flaky DML injection test for drop column with NOT NULL#164535
bghal wants to merge 2 commits intocockroachdb:masterfrom
bghal:fix-dml-injection-null-constraint

Conversation

@bghal
Copy link
Contributor

@bghal bghal commented Feb 27, 2026

Summary

  • Fix flaky TestExecuteWithDMLInjection_drop_column_with_null_constraint by accepting both NOT NULL error message variants in the expected error regex.
  • When metamorphic locked leasing is enabled (~90% of test runs), the DML injection may see a stale descriptor where the native NOT NULL constraint hasn't yet been converted to a synthetic CHECK constraint, producing a different but semantically equivalent error message.
  • Fix typos in pkg/sql/catalog/lease/lease.go: diabledisable in variable name, descrptordescriptors in comment.

Fixes: #160985

Release note: None

…NULL

When dropping a NOT NULL column, the schema changer converts the native
NOT NULL constraint into a synthetic CHECK constraint (`j IS NOT NULL`)
during PreCommitPhase. With metamorphic locked leasing enabled (~90% of
test runs), the DML injection's implicit transaction may acquire a lease
on the pre-PreCommitPhase descriptor where the column still has
`nullable=false` and no CHECK constraint. This produces the error
"null value in column \"j\" violates not-null constraint" instead of the
expected "failed to satisfy CHECK constraint (j IS NOT NULL)".

Both error messages correctly enforce the NOT NULL semantics — the
difference is only which code path catches the violation (native NOT NULL
check vs. synthetic CHECK constraint). Update the expected error regex to
accept either variant.

Fixes: cockroachdb#160985

Release note: None

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
@bghal bghal requested a review from a team as a code owner February 27, 2026 19:12
@trunk-io
Copy link
Contributor

trunk-io bot commented Feb 27, 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.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Fix "diable" → "disable" in `disableLeasedDescriptorsByDefaultThreshold`
and "descrptor" → "descriptors" in the `UseLeasedDescriptorsForCatalogDefault`
comment.

Release note: None

Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

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

@fqazi made 1 comment.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on bghal).


pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_null_constraint/drop_column_with_null_constraint.definition line 11 at r1 (raw file):

INSERT INTO t (i) VALUES($stageKey);
----
pq: (failed to satisfy CHECK constraint \(j IS NOT NULL\)|null value in column "j" violates not-null constraint)

We are supposed to have a WaitForOneVersion operation, so this is surprising. Is it easy to reproduce?

Copy link
Collaborator

@fqazi fqazi left a comment

Choose a reason for hiding this comment

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

@fqazi made 1 comment.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on bghal).


pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_null_constraint/drop_column_with_null_constraint.definition line 11 at r1 (raw file):

Previously, fqazi (Faizan Qazi) wrote…

We are supposed to have a WaitForOneVersion operation, so this is surprising. Is it easy to reproduce?

If you can reproduce it can you try with the session variable: catalog_digest_staleness_check_enabled set to false.

Copy link
Contributor Author

@bghal bghal left a comment

Choose a reason for hiding this comment

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

@bghal made 1 comment.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on fqazi).


pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_null_constraint/drop_column_with_null_constraint.definition line 11 at r1 (raw file):

Previously, fqazi (Faizan Qazi) wrote…

If you can reproduce it can you try with the session variable: catalog_digest_staleness_check_enabled set to false.

Yeah can repro with enough runs.

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.

pkg/sql/schemachanger/schemachanger_test: TestExecuteWithDMLInjection_drop_column_with_null_constraint failed

3 participants