Skip to content

sql: implement alter sequence/view owner#59049

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
RichardJCai:alter_table_owner_01142021
Jan 19, 2021
Merged

sql: implement alter sequence/view owner#59049
craig[bot] merged 1 commit intocockroachdb:masterfrom
RichardJCai:alter_table_owner_01142021

Conversation

@RichardJCai
Copy link
Copy Markdown
Contributor

Resolves #57965

Release note (sql change): Add support for ALTER VIEW/SEQUENCE OWNER TO commands.

@RichardJCai RichardJCai requested review from a team and pbardea and removed request for a team January 15, 2021 16:56
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

Some minor comments, but otherwise looks good

Reviewed 2 of 14 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @pbardea, @RichardJCai, and @solongordon)


pkg/ccl/importccl/read_import_pgdump.go, line 543 at r1 (raw file):

		// the auto stats stuff will pick up the changes and run if needed.
	case *tree.AlterTableOwner:
		// ignore

Why'd this move?


pkg/sql/alter_table_owner.go, line 25 at r1 (raw file):

type alterTableOwnerNode struct {
	owner     security.SQLUsername
	tableDesc *tabledesc.Mutable

nit: s/tableDesc/desc


pkg/sql/alter_table_owner.go, line 40 at r1 (raw file):

	tn := n.Name.ToTableName()
	requiredTableKind := tree.ResolveAnyTableKind

This deserves a comment indicating that an ALTER TABLE OWNER applies to views and sequences as well, and that's why we're resolving any descriptor as opposed to a table desc explicitly.


pkg/sql/alter_table_owner.go, line 94 at r1 (raw file):

// checkCanAlterTableAndSetNewOwner handles privilege checking and setting new owner.
// Called in ALTER TABLE and REASSIGN OWNED BY.

nit: comment over 80 characters. Also, could you remove the "Called in ALTER ..." seems more effort to maintain than its usefulness.


pkg/sql/logictest/testdata/logic_test/alter_view_owner, line 44 at r1 (raw file):


# MATERIALIZED keyword must be present to change the owner of materialized views.
statement error pq: "mvx" is a materialized view

What if you say ALTER TABLE mvx OWNER TO ...? Does that work with Postgres? Either way, it's worth adding a test for that case

Copy link
Copy Markdown
Contributor Author

@RichardJCai RichardJCai 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 @arulajmani, @pbardea, and @solongordon)


pkg/ccl/importccl/read_import_pgdump.go, line 543 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

Why'd this move?

I split this out from being a general AlterTable subcommand to its own statement (so it could also used for VIEWS/SEQUENCES) so it no longer a subcase of *tree.AlterTable.

Not sure if this case ignore is actually needed though.


pkg/sql/alter_table_owner.go, line 40 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

This deserves a comment indicating that an ALTER TABLE OWNER applies to views and sequences as well, and that's why we're resolving any descriptor as opposed to a table desc explicitly.

Done.


pkg/sql/logictest/testdata/logic_test/alter_view_owner, line 44 at r1 (raw file):

Previously, arulajmani (Arul Ajmani) wrote…

What if you say ALTER TABLE mvx OWNER TO ...? Does that work with Postgres? Either way, it's worth adding a test for that case

Good call! That indeed does work with Postgres, adding a case.

@RichardJCai RichardJCai force-pushed the alter_table_owner_01142021 branch from ca27b89 to 507d06a Compare January 18, 2021 22:16
Copy link
Copy Markdown
Collaborator

@arulajmani arulajmani left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @pbardea, @RichardJCai, and @solongordon)


pkg/ccl/importccl/read_import_pgdump.go, line 543 at r1 (raw file):

Previously, RichardJCai (Richard Cai) wrote…

I split this out from being a general AlterTable subcommand to its own statement (so it could also used for VIEWS/SEQUENCES) so it no longer a subcase of *tree.AlterTable.

Not sure if this case ignore is actually needed though.

Ah makes sense, I was just curious.

@pbardea pbardea removed their request for review January 19, 2021 15:30
@RichardJCai RichardJCai force-pushed the alter_table_owner_01142021 branch 2 times, most recently from 041ff8a to cd48947 Compare January 19, 2021 16:59
Release note (sql change): Add support for ALTER VIEW/SEQUENCE OWNER TO commands.
@RichardJCai RichardJCai force-pushed the alter_table_owner_01142021 branch from cd48947 to 3f69983 Compare January 19, 2021 20:08
@RichardJCai
Copy link
Copy Markdown
Contributor Author

bors r=arulajmani

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 19, 2021

Build succeeded:

@craig craig bot merged commit 47eb9f3 into cockroachdb:master Jan 19, 2021
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.

sql: ALTER VIEW/SEQUENCE .. OWNER TO is not implemented

3 participants