sql: add a virtual index on the pg_catalog.pg_type.OID#51374
sql: add a virtual index on the pg_catalog.pg_type.OID#51374craig[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
|
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
c316fd0 to
c332751
Compare
|
Thank you for updating your pull request. My owl senses detect your PR is good for review. Please keep an eye out for any test failures in CI. 🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
|
Hey @ekalinin, thanks for your contribution! However, this doesn't do what we want. Right now, your virtual index is ignoring the input constraint value and generating all rows of the table instead. You should be using the input |
Thanks for response, @rohany ! I'm trying to use the input constraint value like this: indexes: []virtualIndex{
{
partial: false,
populate: func(ctx context.Context, constraint tree.Datum, p *planner, db *sqlbase.ImmutableDatabaseDescriptor,
addRow func(...tree.Datum) error) (bool, error) {
oid := tree.MustBeDOid(constraint)
fmt.Printf("--> populate index: oid: %+v\n", oid)
tbl, err := p.LookupTableByID(ctx, sqlbase.ID(oid.DInt))
if err != nil {
fmt.Printf("--> populate index: lookup err=%+v\n", err)
if sqlbase.IsUndefinedRelationError(err) {
fmt.Printf("--> populate index: IsUndefinedRelationError\n")
return false, nil
}
return false, err
}
// ...and getting an error: ➜ ./cockroach demo
root@127.0.0.1:34233/movr> select * from pg_type where oid = 1000;
--> populate index: oid: 1000
--> populate index: lookup err=relation "[1000]" does not exist |
|
You're on the right track! You'll first want to check if the input oid is one of the predefined type oids. If not, then you'll want to look up the oid's TypeDescriptor. Note that the oid of a type doesn't directly correspond to its descriptor ID. You have to use |
|
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is otan. |
542f2a8 to
17a4103
Compare
Hey @rohany! Thanks for the hints! I hope i understood them correctly. |
ef7f435 to
971e343
Compare
rohany
left a comment
There was a problem hiding this comment.
Looking good! Just 2 more small requests.
971e343 to
e222791
Compare
Release note (performance improvement): scans over virtual table pg_type by OID column have improved performance in common cases.
e222791 to
d85f407
Compare
|
Thanks for the contribution! This is ready to go. bors r=rohany |
Build succeeded |
Fixes #49208
Release note (performance improvement): scans over virtual
table pg_type by OID column have improved performance in common cases.