sql: populate pg_class.relhastriggers#170891
Merged
Merged
Conversation
Contributor
|
😎 Merged successfully - details. |
Member
spilchen
approved these changes
May 25, 2026
Contributor
spilchen
left a comment
There was a problem hiding this comment.
@spilchen made 2 comments.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on rafiss).
pkg/sql/pg_catalog.go line 4174 at r1 (raw file):
tree.MakeDBool(tree.DBool(table.IsPhysicalTable())), // hasindexes tree.DBoolFalse, // hasrules tree.DBoolFalse, // hastriggers
is this the same bug?
pg_dump uses relhastriggers as a fast-path filter when collecting triggers — if it's false, the trigger query is skipped for that table. Hard-coding it to false caused pg_dump to silently omit all triggers. Also fix pg_tables; the view-style summary of pg_class. Both columns were hard-coded to false in CockroachDB even when the table had triggers or row-level security enabled. The pg_class equivalents are already populated correctly from the table descriptor, so derive these from the same source. Resolves: cockroachdb#170842 Epic: none Release note (bug fix): Fixed a bug where pg_class.relhastriggers always reported false, even for tables that had triggers defined. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
PostgreSQL initializes tgenabled to 'O' (TRIGGER_FIRES_ON_ORIGIN) when
a trigger is created, and only sets 'A' (ALWAYS) when the user runs
ALTER TABLE ... ENABLE ALWAYS TRIGGER. CockroachDB has no
session_replication_role equivalent and no ENABLE ALWAYS / ENABLE
REPLICA syntax, so a trigger is either enabled (the PostgreSQL default,
'O') or disabled ('D').
The previous default of 'A' caused pg_dump to emit a spurious
"ALTER TABLE ... ENABLE ALWAYS TRIGGER" statement after every trigger
because pg_dump treats tgenabled != 'O' as a non-default state worth
restoring.
Epic: none
Release note: None
Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
4e7e125 to
a06a851
Compare
rafiss
commented
May 25, 2026
Collaborator
Author
rafiss
left a comment
There was a problem hiding this comment.
TFTR!
/trunk merge
@rafiss made 2 comments.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on spilchen).
pkg/sql/pg_catalog.go line 4174 at r1 (raw file):
Previously, spilchen wrote…
is this the same bug?
done; nice catch!
PostgreSQL's pg_get_triggerdef returns schema-qualified but not catalog-qualified names for the target table (and unqualified or search-path-resolved names for the trigger function). CockroachDB's renderCreateTriggerStatement was emitting the full database.schema.relation form for both, which made the output unusable under pg_dump_compatibility=postgres: pg_dump treats the dumped string as a CREATE TRIGGER body and replays it against the target database, where CockroachDB rejects three-part names as cross-database references. Drop the catalog component from both the table and the function name in the rendered statement, matching pg_get_triggerdef and aligning with how pg_get_indexdef already behaves. Epic: none Release note: None Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
a06a851 to
42294b9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pg_dump uses relhastriggers as a fast-path filter when collecting triggers — if it's false, the trigger query is skipped for that table. Hard-coding it to false caused pg_dump to silently omit all triggers.
Resolves: #170842
Epic: none
Release note (bug fix): Fixed a bug where pg_class.relhastriggers always reported false, even for tables that had triggers defined.