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: create implicit array types for UDTs #49678

Merged
merged 1 commit into from
May 30, 2020
Merged

Conversation

rohany
Copy link
Contributor

@rohany rohany commented May 29, 2020

Fixes #49197.

This PR adds the Postgres behavior of creating an implicit array type
for a user defined type when it is created. The implicit array type will
track the user defined type.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@rohany rohany requested review from jordanlewis and otan May 29, 2020 02:50
@rohany rohany marked this pull request as ready for review May 29, 2020 02:50
@rohany rohany requested a review from a team as a code owner May 29, 2020 02:50
@rohany
Copy link
Contributor Author

rohany commented May 29, 2020

cc @ajwerner, @lucy-zhang if you guys want to take a look.

pkg/sql/pg_catalog.go Outdated Show resolved Hide resolved
pkg/sql/create_type.go Show resolved Hide resolved
@@ -513,4 +513,10 @@ message InternalType {
// StableTypeID is set only for User Defined Types.
optional uint32 stable_type_id = 15
Copy link
Contributor

Choose a reason for hiding this comment

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

wondering if it's worth keeping this in a struct, e.g. optional UserDefinedTypeMetadata udt_metadata... and make this field and the one below non nullable. then it's easy to tell whether it's a UDT or not (udt_metadata != nil)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, that might be a good idea! IDK if we are worried about extra allocations when reading types protos though (maybe thats nothing to worry about).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll wait until more fields pop up -- i think 3 is a good tipping point for its own struct.

Copy link
Contributor

@otan otan May 30, 2020

Choose a reason for hiding this comment

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

i think 2 is :3 (it's especially good forward planning for protobufs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, PTAL!

pkg/sql/create_type.go Show resolved Hide resolved
pkg/sql/create_type.go Outdated Show resolved Hide resolved
pkg/sql/logictest/testdata/logic_test/enums Show resolved Hide resolved
pkg/sql/types/types.proto Outdated Show resolved Hide resolved
@blathers-crl blathers-crl bot requested a review from otan May 29, 2020 19:12
@rohany rohany force-pushed the array-types branch 3 times, most recently from ffb96b6 to 1a83c1d Compare May 30, 2020 01:56
Copy link
Member

@jordanlewis jordanlewis left a comment

Choose a reason for hiding this comment

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

Just a last few comments but LGTM otherwise, this is cool stuff

pkg/sql/sqlbase/structured.go Outdated Show resolved Hide resolved
INSERT INTO enum_array VALUES (ARRAY['hello'], ARRAY['hello']), (ARRAY['howdy'], ARRAY['howdy'])

query TT rowsort
SELECT * FROM enum_array
Copy link
Member

Choose a reason for hiding this comment

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

Can you check that the elements of this column are properly enum-typed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

what do you mean by this?

Copy link
Member

Choose a reason for hiding this comment

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

Like - select pg_typeof(x[0]) from enum_array should return greeting, and x[0] should be a greeting and not a string. Not sure how you can test that. I'm sure the type system mostly guarantees this already. I think it'd be good to have a smoke test though that you can roundtrip enums through arrays, through disk, and back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, dang you caught a sneaky bug with names not getting set up in the right spots.

pkg/sql/logictest/testdata/logic_test/enums Show resolved Hide resolved
pkg/sql/logictest/testdata/logic_test/enums Outdated Show resolved Hide resolved
@rohany rohany force-pushed the array-types branch 3 times, most recently from 17f6a35 to 5a9241a Compare May 30, 2020 02:49
optional uint32 stable_type_id = 15
[(gogoproto.nullable) = false, (gogoproto.customname) = "StableTypeID"];
// UDTMetadata is populated for user defined types.
optional SerializedUserDefinedTypeMetadata udt_metadata = 15 [(gogoproto.customname) = "UDTMetadata"];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is safe to change only because stable_type_id was added in in this release.

// SerializedUserDefinedTypeMetadata contains user defined type metadata
// that will be serialized to disk, unlike other user defined type metadata
// that is only stored in memory once a type is resolved.
message SerializedUserDefinedTypeMetadata {
Copy link
Contributor

@otan otan May 30, 2020

Choose a reason for hiding this comment

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

minor nit: doesn't need Serialized as a prefix, as protobufs imply serialization.
(ok if you decide to keep it, in case there's another UDT struct somewhere, but on first glance looks unnecessary)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already have a UserDefinedTypeMetadata for the in memory metadata, so I need some way to differentiate -- do you have a different suggestion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok i renamed to PersistentUserDefinedTypeMetadata -- thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah fair enough. works for me.

Fixes cockroachdb#49197.

This PR adds the Postgres behavior of creating an implicit array type
for a user defined type when it is created. The implicit array type will
track the user defined type.

Release note: None
@rohany
Copy link
Contributor Author

rohany commented May 30, 2020

TFTRs!

bors r=otan,jordanlewis

@craig
Copy link
Contributor

craig bot commented May 30, 2020

Build succeeded

@craig craig bot merged commit 021d876 into cockroachdb:master May 30, 2020
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: create array types for new user defined types
4 participants