sql: support indexes in regclass cast and pg_table_is_visible#90649
sql: support indexes in regclass cast and pg_table_is_visible#90649craig[bot] merged 4 commits intocockroachdb:masterfrom
Conversation
b46116e to
601932b
Compare
ajwerner
left a comment
There was a problem hiding this comment.
This change may have surprising performance implications. When this cast is executed, it's now no longer going to be able to leverage leases. Before we'd be doing mostly point-lookups in the happy path from in-memory data structures. Now we're going to be fetching a bunch of descriptors from the key-value store and then materializing a virtual table.
I get the motivation, but it just generally scares me a lot.
The answer I keep coming to in my head is that we need a toolkit to cache and version whole hierarchies of descriptors and we need to build data structures over them to make this sort of thing cheap. We're totally not there and I don't know when we'll get the time to be there.
How do we validate that this change is not going to trash performance of some workload?
pkg/sql/sem/eval/parse_doid.go
Outdated
| } | ||
| id, err := evalCtx.Planner.ResolveTableName(ctx, &tn) | ||
|
|
||
| if tn.ExplicitCatalog { |
There was a problem hiding this comment.
Can you encapsulate this new logic? It's not very simple and we'll want to comment it.
601932b to
a07c766
Compare
rafiss
left a comment
There was a problem hiding this comment.
Before we'd be doing mostly point-lookups in the happy path from in-memory data structures. Now we're going to be fetching a bunch of descriptors from the key-value store and then materializing a virtual table.
I've modified this so the old happy path remains. The more expensive cast logic should only happen for indexes now. I feel like the index cast is useful for debugging, but isn't something that would be as commonly used in a hot path of a workload. Also, with the new internal executor work, it's sharing more of the descriptor leases.
How do we validate that this change is not going to trash performance of some workload?
I was hoping to see some results in the RTT benchmarks.
pkg/sql/sem/eval/parse_doid.go
Outdated
| } | ||
| id, err := evalCtx.Planner.ResolveTableName(ctx, &tn) | ||
|
|
||
| if tn.ExplicitCatalog { |
a07c766 to
335361c
Compare
This is a problem with the rttanalysis benchmark. It can show decreases in round-trips if your change leads to scanning all descriptors because we do that in one round-trip. It's often very expensive. |
|
oh no |
ajwerner
left a comment
There was a problem hiding this comment.
This is cool. Thanks for adding it!
pkg/sql/sem/eval/parse_doid.go
Outdated
| JOIN %[1]spg_catalog.pg_namespace AS n ON c.relnamespace = n.oid | ||
| JOIN current_schemas AS cs ON cs.scname = n.nspname | ||
| WHERE c.relname = $1 | ||
| AND $2 IS NOT NULL |
There was a problem hiding this comment.
when is $2 NULL here? I think this is tn.Schema() but I think that always returns a string value. What's the intention here?
There was a problem hiding this comment.
it's never null and it should get constant-folded away
there's a comment up above:
// There is an unused $2 placeholder in the query so that the call to QueryRow can
// be consolidated.
There was a problem hiding this comment.
i can make it less confusing by making an args... slice that is different in the conditional branches, and passing it through
|
|
335361c to
24b3395
Compare
ce8d714 to
e709a03
Compare
|
This PR is currently blocked on #91012 |
e709a03 to
fe34fe4
Compare
45efe60 to
73c9dd7
Compare
|
thanks @yuzefovich - your fix has unblocked this |
73c9dd7 to
4b743aa
Compare
4b743aa to
904f867
Compare
The ParseQualifiedTableName function was deprecated and unused. Release note: None
Release note (sql change): Casts from index name to regclass are now supported. Previously, only table names could be cast to regclass.
904f867 to
3b66cdb
Compare
ajwerner
left a comment
There was a problem hiding this comment.
but see how you feel about my suggestion regarding temp schemas
Reviewed 1 of 16 files at r14, 1 of 16 files at r20, 3 of 3 files at r21, 4 of 6 files at r22, 8 of 8 files at r23, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @msbutler and @rafiss)
pkg/sql/pg_catalog.go line 2083 at r23 (raw file):
indexes: []virtualIndex{ { // incomplete is true because this index does not contain temporary schemas.
Does this matter? I think, if we can, it'd be better to say this is complete and just say our temp table implementation is somewhat broken. Given nobody ought to use it, that seems like a better tradeoff to me. Also, this will find the local session's temp namespace, right? WDYT?
pkg/sql/pg_catalog.go line 2107 at r23 (raw file):
// No schema found, so no rows. //nolint:returnerrcheck return false, nil
nit: assign err to nil here and you can avoid having to defeat the linter
Code quote:
// No schema found, so no rows.
//nolint:returnerrcheck
return false, nilpkg/sql/pg_catalog.go line 2120 at r23 (raw file):
} else if sc.SchemaKind() == catalog.SchemaPublic { // admin is the owner of the public schema. ownerOID = h.UserOid(username.MakeSQLUsernameFromPreNormalizedString("admin"))
nit: can we pull this out to a var rather than re-hashing every time?
rafiss
left a comment
There was a problem hiding this comment.
tftr! added the changes
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @ajwerner and @msbutler)
pkg/sql/pg_catalog.go line 2083 at r23 (raw file):
i'm fine with that tradeoff.
Also, this will find the local session's temp namespace, right?
you're right, i didn't realize. that makes me feel better about marking it as complete. added a test.
pkg/sql/pg_catalog.go line 2107 at r23 (raw file):
Previously, ajwerner wrote…
nit: assign err to nil here and you can avoid having to defeat the linter
done
pkg/sql/pg_catalog.go line 2120 at r23 (raw file):
Previously, ajwerner wrote…
nit: can we pull this out to a var rather than re-hashing every time?
done
3b66cdb to
e3c687e
Compare
rafiss
left a comment
There was a problem hiding this comment.
bors r=ajwerner
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @ajwerner and @msbutler)
|
whoops missed a test ... bors r- |
|
Canceled. |
This will allow us to efficiently join to this table. Release note: None
This uses the internal executor now to do the introspection using pg_class where everything can be looked up all at once. There's an increase in number of round trips, but it's a constant factor. Release note (bug fix): Fixed the pg_table_is_visible builtin function so it correctly reports visibility of indexes based on the current search_path.
e3c687e to
062845b
Compare
|
turns out our implementation of the bors r=ajwerner |
|
Build succeeded: |
Epic: CRDB-23454
fixes #88097
sql: remove deprecated function from DatabaseCatalog
The ParseQualifiedTableName function was deprecated and unused.
sql: support casts from index name to regclass
Release note (sql change): Casts from index name to regclass are now
supported. Previously, only table names could be cast to regclass.
sql: add index on pg_namespace(oid)
This will allow us to efficiently join to this table.
sql: fix pg_table_is_visible to handle indexes
This uses the internal executor now to do the introspection using
pg_class where everything can be looked up all at once.
There's an increase in number of round trips, but it's a constant
factor.
Release note (bug fix): Fixed the pg_table_is_visible builtin function
so it correctly reports visibility of indexes based on the current
search_path.