Skip to content

sql: fix pg_type_is_visible and ::regtype cast to handle UDTs#62181

Merged
craig[bot] merged 3 commits intocockroachdb:masterfrom
rafiss:fix-udt-bugs
Mar 18, 2021
Merged

sql: fix pg_type_is_visible and ::regtype cast to handle UDTs#62181
craig[bot] merged 3 commits intocockroachdb:masterfrom
rafiss:fix-udt-bugs

Conversation

@rafiss
Copy link
Copy Markdown
Collaborator

@rafiss rafiss commented Mar 17, 2021

fixes #61216
fixes #60008

The 1st commit is a simple refactor.

Release note (bug fix): Previously, casting an OID to a regtype did not
work for user-defined types. This is now fixed.

Release note (bug fix): Previously, the pg_type_is_visible builtin
function did not correctly handle user-defined types. This is fixed now.

@rafiss rafiss requested review from a team and pbardea and removed request for a team March 17, 2021 23:33
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

query B
SELECT pg_type_is_visible(t.oid)
FROM pg_type t
WHERE t.typname = 'int8'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe:

query B
SELECT t.typname pg_type_is_visible(t.oid)
FROM pg_type t
WHERE t.typname IN ( 'int8', '_date', ...)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixd

if _, ok := types.OidToType[typeID]; ok {
return true, true, nil
}
// TODO(ajwerner): look at this error and only no-op if it is
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

any reason we can't do this now

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

doesn't seem there's a reason we can't do it now -- i meant to ask @ajwerner about this comment (which was just added recently). it does look like there's a few more errors than just ErrDescriptorNotFound that we need to check for

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i guess my concern is if it fails due to some transient error it will return False instead of error. arguably this is bad...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right, also, if it is a transaction restart I think it could expose some other anomalies.

FWIW cleaning up the errors here and probably making these methods return clear booleans and deal with flags properly to declare desired behavior is a major roadmap item for schema this release.

This code is actually a nightmare right now. I'm trying to untangle all of the errors you can get and it's making my angry. I'm 75% sure that the condition at the moment here is:

errors.Is(err, catalog.ErrDescriptorNotFound) || errors.Is(err, catalog.ErrDescriptorDropped) || pgcode.GetPGCode(err) == pgcode.UndefinedObject

Sorry 😓

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

thank you for that list and the roadmap item!

Copy link
Copy Markdown
Contributor

@ajwerner ajwerner 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 @otan, @pbardea, and @rafiss)


pkg/sql/resolver.go, line 262 at r2 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

thank you for that list and the roadmap item!

Gah


pkg/sql/resolver.go, line 220 at r5 (raw file):

		if errors.Is(err, catalog.ErrDescriptorNotFound) ||
			errors.Is(err, catalog.ErrDescriptorDropped) ||
			pgerror.GetPGCode(err) == pgcode.UndefinedObject {

This one needs pgcode.UndefinedTable 🎉

rafiss added 2 commits March 18, 2021 15:48
Release note (bug fix): Previously, the pg_type_is_visible builtin
function did not correctly handle user-defined types. This is fixed now.
Release note (bug fix): Previously, casting an OID to a regtype did not
work for user-defined types. This is now fixed.
@rafiss
Copy link
Copy Markdown
Collaborator Author

rafiss commented Mar 18, 2021

ty for the tip!

bors r=otan,ajwerner

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Mar 18, 2021

Build succeeded:

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: ::regtype casts don't work for user defined types sql: pg_type_is_visible does not handle user-defined types

4 participants