Skip to content
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: support COMMENT ON SCHEMA #68606

Merged
merged 1 commit into from
Aug 18, 2021
Merged

Conversation

ekalinin
Copy link
Contributor

@ekalinin ekalinin commented Aug 9, 2021

Fixes #67689

This change adds support for SCHEMA comment.

Release note (sql change): This change adds associating
comment to SQL schema using PostgreSQL's
COMMENT ON SCHEMA syntax.

@ekalinin ekalinin requested a review from a team August 9, 2021 18:29
@ekalinin ekalinin requested a review from a team as a code owner August 9, 2021 18:29
@ekalinin ekalinin requested review from shermanCRL and removed request for a team August 9, 2021 18:29
@blathers-crl
Copy link

blathers-crl bot commented Aug 9, 2021

Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR.

Before a member of our team reviews your PR, I have some potential action items for you:

  • We notice you have more than one commit in your PR. We try break logical changes into separate commits, but commits such as "fix typo" or "address review commits" should be squashed into one commit and pushed with --force
  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

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.

@blathers-crl blathers-crl bot added O-community Originated from the community X-blathers-triaged blathers was able to find an owner labels Aug 9, 2021
@blathers-crl blathers-crl bot requested review from jordanlewis and knz August 9, 2021 18:29
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@blathers-crl
Copy link

blathers-crl bot commented Aug 9, 2021

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@shermanCRL shermanCRL removed their request for review August 9, 2021 18:53
@blathers-crl
Copy link

blathers-crl bot commented Aug 9, 2021

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl
Copy link

blathers-crl bot commented Aug 10, 2021

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl
Copy link

blathers-crl bot commented Aug 10, 2021

Thank you for updating your pull request.

Before a member of our team reviews your PR, I have some potential action items for you:

  • Please ensure your git commit message contains a release note.
  • When CI has completed, please ensure no errors have appeared.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan.

@blathers-crl
Copy link

blathers-crl bot commented Aug 10, 2021

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.

@jordanlewis jordanlewis requested review from a team and removed request for a team, jordanlewis and knz August 10, 2021 20:26
Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

This PR is missing the necessary changes to sql/pg_catalog.go to generate the values in pg_catalog.pg_description. This will also need a test about how to retrieve the schema comment via pg_catalog.obj_description().

You'll probably need input from someone in the SQL schema team about how to populate pg_description properly.

Reviewed 14 of 14 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ekalinin)


pkg/sql/drop_schema.go, line 185 at r1 (raw file):

		}

		if err := p.removeSchemaComment(params.ctx, sc.GetID()); err != nil {

This needs to go to dropSchemaImpl otherwise the comment is not dropped upon DROP DATABASE CASCADE

@ekalinin ekalinin force-pushed the comment-on-database branch 2 times, most recently from fa378dd to c02b849 Compare August 11, 2021 19:10
@ekalinin
Copy link
Contributor Author

This PR is missing the necessary changes to sql/pg_catalog.go to generate the values in pg_catalog.pg_description. This will also need a test about how to retrieve the schema comment via pg_catalog.obj_description().

You'll probably need input from someone in the SQL schema team about how to populate pg_description properly.

Thanks. Added.

This needs to go to dropSchemaImpl otherwise the comment is not dropped upon DROP DATABASE CASCADE

Done.

Copy link
Contributor

@knz knz left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r2, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ekalinin)


pkg/sql/pg_catalog.go, line 1398 at r2 (raw file):

			case keys.SchemaCommentType:
				objID = tree.NewDOid(tree.MustBeDInt(objID))
				classOid = tree.NewDOid(catconstants.PgCatalogSchemaID)

We'll need a review from SQL Schema for this change.
(@ajwerner?)


pkg/sql/logictest/testdata/logic_test/pg_catalog, line 5085 at r2 (raw file):

----
objoid  classoid    objsubid  description
94      4294967022  0         testing schema

I think we need to test this via pg_catalog.obj_description() because I don't think we wish to assert particular object IDs inside unit tests.

Someone from SQL experience would know better.
(@rafiss?)

@@ -1942,6 +1942,8 @@ func getCatalogOidForComments(catalogName string) (id int, ok bool) {
return catconstants.PgCatalogClassTableID, true
case "pg_database":
return catconstants.PgCatalogDatabaseTableID, true
case "pg_schema":
return catconstants.PgCatalogSchemaID, true
Copy link
Contributor

Choose a reason for hiding this comment

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

I checked the postgres documentation and I couldn't find any mention of pg_schema in there. Strictly speaking the table for schemas in the pg catalog is pg_namespace. As far as comments are concerned, it seems they might actually belong in pg_shdescription or pg_description. Perhaps @rafiss can enlighten us?

Copy link
Contributor

Choose a reason for hiding this comment

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

a quick test inside psql tells me that schema comments get stored inside pg_description.

@ekalinin
Copy link
Contributor Author

I think we need to test this via pg_catalog.obj_description() because I don't think we wish to assert particular object IDs inside unit tests.

Fixed.

I checked the postgres documentation and I couldn't find any mention of pg_schema in there. Strictly speaking the table for schemas in the pg catalog is pg_namespace

Fixed.

Copy link
Contributor

@otan otan left a comment

Choose a reason for hiding this comment

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

Reviewed 13 of 14 files at r1, 2 of 6 files at r2, 3 of 4 files at r3, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ekalinin, @knz, and @rafiss)


pkg/sql/logictest/testdata/logic_test/pg_catalog, line 5085 at r2 (raw file):

Previously, knz (kena) wrote…

I think we need to test this via pg_catalog.obj_description() because I don't think we wish to assert particular object IDs inside unit tests.

Someone from SQL experience would know better.
(@rafiss?)

i'd probably omit the oids / subids simply because they are potentially unstable.


pkg/sql/logictest/testdata/logic_test/pg_catalog, line 5082 at r3 (raw file):

SELECT obj_description(objoid)
  FROM pg_catalog.pg_description
 WHERE description = 'testing schema';

nit: drop the trailing ; here and above


pkg/sql/logictest/testdata/logic_test/schema, line 881 at r3 (raw file):


statement ok;
USE comment_db;

nit: drop the trailing ; here


pkg/sql/sem/builtins/pg_builtins.go, line 1946 at r2 (raw file):

Previously, knz (kena) wrote…

a quick test inside psql tells me that schema comments get stored inside pg_description.

pg_description is correct

Copy link
Contributor Author

@ekalinin ekalinin left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ekalinin, @knz, and @rafiss)


pkg/sql/logictest/testdata/logic_test/pg_catalog, line 5085 at r2 (raw file):

Previously, otan (Oliver Tan) wrote…

i'd probably omit the oids / subids simply because they are potentially unstable.

Should I remove test via obj_description?

@otan
Copy link
Contributor

otan commented Aug 17, 2021


pkg/sql/logictest/testdata/logic_test/pg_catalog, line 5085 at r2 (raw file):

Previously, ekalinin (Eugene Kalinin) wrote…

Should I remove test via obj_description?

Is there a test for it? We should keep it for sure if there is and add it if it isn't.

Copy link
Contributor Author

@ekalinin ekalinin left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ekalinin, @knz, @otan, and @rafiss)


pkg/sql/drop_schema.go, line 185 at r1 (raw file):

Previously, knz (kena) wrote…

This needs to go to dropSchemaImpl otherwise the comment is not dropped upon DROP DATABASE CASCADE

Fixed.


pkg/sql/logictest/testdata/logic_test/pg_catalog, line 5085 at r2 (raw file):

Previously, otan (Oliver Tan) wrote…

Is there a test for it? We should keep it for sure if there is and add it if it isn't.

Yes, there's. Please, see the latest version of the PR.

https://github.com/cockroachdb/cockroach/pull/68606/files#diff-44361d449f2d21bb6beb453a14b8475fe98e73a04bf990d251ed99f055001eb8R5080


pkg/sql/logictest/testdata/logic_test/pg_catalog, line 5082 at r3 (raw file):

Previously, otan (Oliver Tan) wrote…

nit: drop the trailing ; here and above

Fixed.


pkg/sql/logictest/testdata/logic_test/schema, line 881 at r3 (raw file):

Previously, otan (Oliver Tan) wrote…

nit: drop the trailing ; here

Fixed.

@ekalinin ekalinin requested a review from a team as a code owner August 17, 2021 17:41
@blathers-crl blathers-crl bot requested a review from otan August 17, 2021 17:41
This change adds support for SCHEMA commenting.

Release note (sql change): This change adds associating
comment to SQL schema using PostgreSQL's COMMENT ON SCHEMA syntax.
Copy link
Contributor Author

@ekalinin ekalinin left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ekalinin, @knz, @otan, and @rafiss)


pkg/sql/sem/builtins/pg_builtins.go, line 1946 at r2 (raw file):

Previously, otan (Oliver Tan) wrote…

pg_description is correct

Fixed

Copy link
Contributor

@otan otan left a comment

Choose a reason for hiding this comment

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

looks good to me! thanks

bors r+

@craig
Copy link
Contributor

craig bot commented Aug 18, 2021

Build succeeded:

@craig craig bot merged commit a60b8bb into cockroachdb:master Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
O-community Originated from the community X-blathers-triaged blathers was able to find an owner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sql: Support 'COMMENT ON SCHEMA'
5 participants