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: use catalog.TableDescriptor instead of tabledesc.Immutable #59495

Merged
merged 9 commits into from
Feb 2, 2021

Conversation

postamar
Copy link
Contributor

This PR makes the tabledesc.Immutable type private and makes use of the
catalog.TableDescriptor interface instead.

Fixes #59486.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@postamar postamar marked this pull request as ready for review January 27, 2021 23:42
@postamar postamar requested a review from a team January 27, 2021 23:42
@postamar postamar requested review from a team as code owners January 27, 2021 23:42
@postamar postamar requested review from adityamaru and a team and removed request for a team January 27, 2021 23:42
Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

opt_catalog and opt_exec_factory changes LGTM

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru)

@postamar
Copy link
Contributor Author

postamar commented Jan 27, 2021

@ajwerner @lucy-zhang I realize that with this change, Collection's immutable getters return dbdesc.Immutable schemadesc.Immutable typedesc.Immutable but for tables it's now catalog.TableDescriptor. Breaking this pattern is the price to pay for making tabledesc.Immutable private. It doesn't have to be private, but it's kinda neat that it is IMHO. I wonder how you feel about this.

Copy link
Contributor

@thoszhang thoszhang left a comment

Choose a reason for hiding this comment

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

LGTM, just a few minor comments.

Reviewed 1 of 1 files at r1, 117 of 117 files at r3, 2 of 2 files at r4, 2 of 2 files at r5, 6 of 6 files at r6, 3 of 3 files at r7, 5 of 5 files at r8, 119 of 119 files at r9, 10 of 10 files at r10.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru and @postamar)


pkg/sql/drop_sequence.go, line 180 at r5 (raw file):

		affectsNoColumns := true
		canBeSafelyRemoved := false

I think these could benefit from some documentation comments on what they mean. Using the iterator makes the logic less obvious.


pkg/sql/catalog/descriptor.go, line 248 at r8 (raw file):

	HasColumnBackfillMutation() bool
	MakeFirstMutationPublic(includeConstraints bool) (MutableDescriptor, error)

I suspect we should be able to convert all the callers of this function to just use catalog.TableDescriptor. I don't think constraint validation needs to mutate these descriptors. #58906 should also help.

Copy link
Contributor Author

@postamar postamar left a comment

Choose a reason for hiding this comment

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

Thanks for the review!

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @adityamaru and @lucy-zhang)


pkg/sql/drop_sequence.go, line 180 at r5 (raw file):

Previously, lucy-zhang (Lucy Zhang) wrote…
		affectsNoColumns := true
		canBeSafelyRemoved := false

I think these could benefit from some documentation comments on what they mean. Using the iterator makes the logic less obvious.

Done.


pkg/sql/catalog/descriptor.go, line 248 at r8 (raw file):

Previously, lucy-zhang (Lucy Zhang) wrote…

I suspect we should be able to convert all the callers of this function to just use catalog.TableDescriptor. I don't think constraint validation needs to mutate these descriptors. #58906 should also help.

Done.

@postamar
Copy link
Contributor Author

postamar commented Feb 1, 2021

Rebased on master to resolve conflict, and edited the commit message for the MakeFirstMutationPublic commit, which I'd forgotten to do.

Previously these methods were defined only on the concrete types
in the tabledesc package as well as in descpb.TableDescriptor. This
patch  adds these to catalog.TableDescriptor.

These specific methods are called in places where we'd rather be
calling them on the interface type instead of one of these concrete
types. This patch is a prerequisite to that change.

Release note: None
@postamar
Copy link
Contributor Author

postamar commented Feb 1, 2021

Rebased again to fix a few more conflicts.

@postamar
Copy link
Contributor Author

postamar commented Feb 1, 2021

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 1, 2021

Build failed (retrying...):

Marius Posta added 5 commits February 1, 2021 17:04
This patch is a refactor which replaces field accesses on
tabledesc.Immutable types with catalog.TableDescriptor method calls.
This is a prerequisite to using the interface type instead.

Field reads are replaced with corresponding getter method calls and
field writes are done on the TableDesc() method return value.

Release note: None
Previously this method only had one call site. This patch moves its
logic next to that call site and removes the method. There are enough
methods already.

Release note: None
Previously, there was only one call site for the GetDependedOnBy method
on a tabledesc.Immutable receiver. This patch replaces it with an equivalent
call to ForeachDependedOnBy with a suitable closure. This allows us to
avoid declaing the method on the catalog.TableDescriptor interface.

Release note: None
This patch replaces this method with recently-introduced
methods for catalog.Index types. The motivation for this refactor is to
avoid bringing this deprecated method into the catalog.TableDescriptor
interface.

Release note: None
Previously, the test helper functions in the tabledesc package were
defined as methods on Immutable receivers. This refactor transforms them
into functions on catalog.TableDescriptor interfaces. This is
a prerequisite to making the Immutable concrete type private.

Release note: None
Marius Posta added 3 commits February 1, 2021 17:04
Previously, this method returned a tabledesc.Mutable type and this
made it impossible to add it to the catalog.TableDescriptor interface.
This patch does it by changing it to a catalog.TableDescriptor.
This is a prerequisite to using the catalog.TableDescriptor interface
type instead of the tabledesc.Immutable concrete type wherever possible.

Release note: None
Previously we tended to use the concrete tabledesc.Immutable type
rather than the catalog.TableDescriptor type. This was mainly for
historical reasons because the former predates the latter. This patch
builds on my previous commits by switching to the interface type
everywhere outside of the tabledesc package.

This required making the MakeImmutable factory function in tabledesc
private, and changing the signatures of the NewImmutable factory
functions and using them instead of MakeImmutable.

Fixes cockroachdb#59486.

Release note: None
Previously, this concrete type implementing catalog.TableDescriptor was
exported and, until my previous commit, could be found throughout the
codebase. This patch makes it private to ensure that the interface type
continues to be used instead.

Release note: None
@craig
Copy link
Contributor

craig bot commented Feb 1, 2021

Build failed:

@postamar
Copy link
Contributor Author

postamar commented Feb 1, 2021

Sorry for the noise, just silly build failures due to having had to rebase.

@postamar
Copy link
Contributor Author

postamar commented Feb 2, 2021

bors r+

@craig
Copy link
Contributor

craig bot commented Feb 2, 2021

Build succeeded:

@craig craig bot merged commit e854509 into cockroachdb:master Feb 2, 2021
@postamar postamar deleted the 59486 branch February 2, 2021 13:47
craig bot pushed a commit that referenced this pull request Apr 8, 2021
62755: sql: replace dbdesc/schemadesc/typedesc Immutable types with catalog interfaces r=postamar a=postamar

This follows on a similar effort for tables: #59495

Fixes #62750

Co-authored-by: Marius Posta <[email protected]>
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: use catalog.TableDescriptor instead of tabledesc.Immutable
4 participants