-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Conversation
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. I have added a few people who may be able to assist in reviewing: 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
5e023ff
to
4ab0d7d
Compare
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
4ab0d7d
to
d909bea
Compare
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.
looks pretty good! i have a few requests for testing and commenting
@@ -992,6 +1002,35 @@ JOIN pg_constraint ON objid=pg_constraint.oid AND refobjid=pg_constraint.conindi | |||
contype | |||
f | |||
|
|||
# Testing table-view dependencies in pg_depend, This query will not work the same way | |||
# In PostgreSQL as pg_depend.classid points to pg_rewrite then in pg_rewrite |
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.
I think these Postgres docs also say that pg_depend.classid points directly to pg_class.oid
https://www.postgresql.org/docs/current/catalog-pg-depend.html
but it looks like in Postgres, pg_depend.objid points to pg_rewrite.ev_class. can you update this comment?
i looked into this further.. i think soon we should try to populate pg_rewrite. i created #57417 -- can you include this link in the comment?
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
# pg_rewrite yet. | ||
|
||
statement ok | ||
CREATE TABLE source_table(a INT, b INT, c INT); |
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 make this CREATE TABLE source_table(a INT PRIMARY KEY, b INT, c INT);
then i think fewer other tests will be affected
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
@@ -1153,6 +1153,31 @@ https://www.postgresql.org/docs/9.5/catalog-pg-depend.html`, | |||
depTypeAuto, // deptype | |||
) | |||
} | |||
|
|||
reportViewDependency := func(dep *descpb.TableDescriptor_Reference) error { |
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done
CREATE TABLE source_table(a INT, b INT, c INT); | ||
CREATE VIEW depend_view AS SELECT b, c FROM source_table; | ||
|
||
query TTTTT |
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 make this query TTTTT colnames
so that the output includes the column names?
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
SELECT | ||
depend_cat_class.relname depend_catalog, | ||
source_cat_class.relname source_catalog, | ||
depend_class.relname depend, |
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
reportViewDependency := func(dep *descpb.TableDescriptor_Reference) error { | ||
for _, colID := range dep.ColumnIDs { | ||
if err := addRow( | ||
pgClassTableOid, //classid |
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 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Done
I noticed that you merged master into this branch. the recommended way to update the PR is to rebase your branch on top of master, then force push. that way the git history is easier to read. for example:
(in this case you should also remove your merge commit too) |
d909bea
to
9f6faf8
Compare
Thank you for updating your pull request. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
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.
looks good!
bors r+
Reviewed 2 of 2 files at r3.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @rafiss)
Merge conflict. |
bors r- @mnovelodou i just noticed there is a merge conflict. can you please update it when you have a chance? |
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.
marking as requested change
Previously, pg_depend only contained dependencies from foreign keys, but this table in postgres also cointains dependencies from table-views, To address this, this patch populates this dependency information Fixes cockroachdb#56115 Release note (sql change): added table-view dependency information in pg_depend to improve compatibility with postgresql.
9f6faf8
to
c723c40
Compare
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.
looks good!
bors r+
Build succeeded: |
Previously, pg_depend only contained dependencies from foreign keys,
but this table in postgres also cointains dependencies from table-views,
To address this, this patch populates this dependency information
Fixes #56115
Release note (sql change): added table-view dependency information
in pg_depend to improve compatibility with postgresql.