-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: populated pg_depend with table and view dependencies #57240
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1170,6 +1170,36 @@ https://www.postgresql.org/docs/9.5/catalog-pg-depend.html`, | |
depTypeAuto, // deptype | ||
) | ||
} | ||
|
||
// In the case of table/view relationship, In PostgreSQL pg_depend.objid refers to | ||
// pg_rewrite.oid, then pg_rewrite ev_class refers to the dependent object, but | ||
// cockroach db does not implements pg_rewrite yet | ||
// | ||
// Issue #57417: https://github.com/cockroachdb/cockroach/issues/57417 | ||
reportViewDependency := func(dep *descpb.TableDescriptor_Reference) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how does this code handle views that depend on other views? can you add a test for that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The loop already pick views and descriptor already have dependencies at other views, but this is a nice catch, I tried it and it works, I am going to add a test case for this as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
for _, colID := range dep.ColumnIDs { | ||
if err := addRow( | ||
pgClassTableOid, //classid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you also add a comment here that described how we don't use pg_rewrite (and link to issue #57417) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
tableOid(dep.ID), //objid | ||
zeroVal, //objsubid | ||
pgClassTableOid, //refclassid | ||
tableOid(table.GetID()), //refobjid | ||
tree.NewDInt(tree.DInt(colID)), //refobjsubid | ||
depTypeNormal, //deptype | ||
); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
if table.IsTable() || table.IsView() { | ||
if err := table.ForeachDependedOnBy(reportViewDependency); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
conInfo, err := table.GetConstraintInfoWithLookup(tableLookup.getTableByID) | ||
if err != nil { | ||
return err | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also check for source_class.relname?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done