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

builtins: implement pg_table_is_visible as UDF #94339

Merged
merged 3 commits into from
Jan 5, 2023

Conversation

jordanlewis
Copy link
Member

@jordanlewis jordanlewis commented Dec 27, 2022

Now that we support UDFs, we can implement builtin functions as "virtual
UDFs", that are defined in the builtins map.

The builtin appears to be about twice as fast with this method, which is
nice because it gets used a lot in ORM introspection queries.

Release note (performance improvement): improve the performance of
pg_table_is_visible

Epic: None

Co-authored-by: rafiss [email protected]

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jordanlewis jordanlewis force-pushed the sql-pg-table-is-vibisl branch from dab9289 to cb153a4 Compare December 27, 2022 20:36
@jordanlewis
Copy link
Member Author

UDF team - is this a valid thing to do? Do you understand why the performance would be improved? @mgartner @chengxiong-ruan

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

Seems valid to me. Perhaps inefficiencies in the internal executor explain the speed up from this change?

@jordanlewis jordanlewis force-pushed the sql-pg-table-is-vibisl branch from cb153a4 to d29ac16 Compare December 28, 2022 02:13
@jordanlewis jordanlewis marked this pull request as ready for review December 28, 2022 03:05
@jordanlewis jordanlewis requested a review from a team December 28, 2022 03:05
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

want to get pg_type_is_visible and pg_function_is_visible while you're here?

@jordanlewis jordanlewis force-pushed the sql-pg-table-is-vibisl branch from d29ac16 to 3028f15 Compare December 28, 2022 21:24
@jordanlewis
Copy link
Member Author

Done

@jordanlewis jordanlewis force-pushed the sql-pg-table-is-vibisl branch 3 times, most recently from d8d7c32 to 4a472d5 Compare December 29, 2022 19:09
@jordanlewis jordanlewis requested a review from a team December 29, 2022 19:09
Copy link
Collaborator

@rafiss rafiss 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 @jordanlewis)


pkg/sql/pg_catalog.go line 3335 at r1 (raw file):

				// table. We have special logic for this case.
				if typDesc.GetKind() == descpb.TypeDescriptor_TABLE_IMPLICIT_RECORD_TYPE {
					table, err := p.Descriptors().GetImmutableTableByID(ctx, p.txn, id, tree.ObjectLookupFlags{})

does this part also need to check for dropped tables?

@jordanlewis jordanlewis force-pushed the sql-pg-table-is-vibisl branch from 4a472d5 to 86ed161 Compare December 29, 2022 19:33
@jordanlewis jordanlewis requested a review from rafiss December 29, 2022 19:33
Copy link
Member Author

@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.

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


pkg/sql/pg_catalog.go line 3335 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

does this part also need to check for dropped tables?

Good point, fixed

Copy link
Collaborator

@rafiss rafiss 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! 0 of 0 LGTMs obtained

@@ -175,7 +175,6 @@ func (v TableImplicitRecordType) Adding() bool {

// Dropped implements the Descriptor interface.
func (v TableImplicitRecordType) Dropped() bool {
v.panicNotSupported("Dropped")
return false
Copy link

Choose a reason for hiding this comment

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

Shouldn't this instead delegate to the wrapped table descriptor?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, done

Copy link
Collaborator

@mgartner mgartner left a comment

Choose a reason for hiding this comment

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

LGTM

@jordanlewis jordanlewis force-pushed the sql-pg-table-is-vibisl branch from 86ed161 to 2404b3f Compare January 4, 2023 16:25
jordanlewis and others added 3 commits January 4, 2023 21:25
Previously, the pg_proc and pg_type virtual indexes would show cross-db
objects, which is not supposed to happen. This is now corrected.

Release note (bug fix): the pg_proc and pg_type virtual oid indexes no
longer incorrectly show cross-db objects. This is unlikely to affect
real-world use cases.
Now that we support UDFs, we can implement builtin functions as "virtual
UDFs", that are defined in the builtins map.

The builtin appears to be about twice as fast with this method, which is
nice because it gets used a lot in ORM introspection queries.

Epic: None

Release note (performance improvement): improve the performance of
pg_{function,table,type}_is_visible

Co-authored-by: rafiss <[email protected]>
@jordanlewis jordanlewis force-pushed the sql-pg-table-is-vibisl branch from 2404b3f to d363b40 Compare January 5, 2023 02:25
@jordanlewis
Copy link
Member Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jan 5, 2023

Build succeeded:

@craig craig bot merged commit d123302 into cockroachdb:master Jan 5, 2023
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.

5 participants