diff --git a/pkg/sql/logictest/testdata/logic_test/udf b/pkg/sql/logictest/testdata/logic_test/udf index b971f6cf27ad..980c18f6a2b3 100644 --- a/pkg/sql/logictest/testdata/logic_test/udf +++ b/pkg/sql/logictest/testdata/logic_test/udf @@ -174,6 +174,13 @@ FROM pg_catalog.pg_proc WHERE proname IN ('proc_f', 'proc_f_2'); 100119 proc_f 105 1546506610 14 true true false i 2 25 25 20 {i,i} {"",b} SELECT 'hello'; 100121 proc_f_2 120 1546506610 14 false false false v 1 25 25 {i} NULL SELECT 'hello'; +# Ensure that the pg_proc virtual index works properly. + +query TT +SELECT oid, proname FROM pg_proc WHERE oid = 'sc.proc_f_2'::regproc +---- +100121 proc_f_2 + statement ok USE defaultdb; diff --git a/pkg/sql/pg_catalog.go b/pkg/sql/pg_catalog.go index 24654ea3ced4..243f0b69692a 100644 --- a/pkg/sql/pg_catalog.go +++ b/pkg/sql/pg_catalog.go @@ -2568,21 +2568,16 @@ https://www.postgresql.org/docs/9.5/catalog-pg-proc.html`, coid := tree.MustBeDOid(unwrappedConstraint) ooid := coid.Oid - name, overload, err := p.ResolveFunctionByOID(ctx, ooid) - if err != nil { - if errors.Is(err, tree.ErrFunctionUndefined) { - return false, nil //nolint:returnerrcheck - } - return false, err - } - if funcdesc.IsOIDUserDefinedFunc(ooid) { - fnDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Get().Function(ctx, descpb.ID(overload.Oid)) + fnDesc, err := p.Descriptors().ByID(p.Txn()).WithoutNonPublic().Get().Function(ctx, funcdesc.UserDefinedFunctionOIDToID(ooid)) if err != nil { + if errors.Is(err, tree.ErrFunctionUndefined) { + return false, nil //nolint:returnerrcheck + } return false, err } - scDesc, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Schema(ctx, descpb.ID(ooid)) + scDesc, err := p.Descriptors().ByIDWithLeased(p.Txn()).WithoutNonPublic().Get().Schema(ctx, fnDesc.GetParentSchemaID()) if err != nil { return false, err } @@ -2597,7 +2592,15 @@ https://www.postgresql.org/docs/9.5/catalog-pg-proc.html`, return true, nil } else { - err := addPgProcBuiltinRow(tree.NewDOid(catconstants.PgCatalogID), name, addRow) + name, _, err := p.ResolveFunctionByOID(ctx, ooid) + if err != nil { + if errors.Is(err, tree.ErrFunctionUndefined) { + return false, nil //nolint:returnerrcheck + } + return false, err + } + + err = addPgProcBuiltinRow(tree.NewDOid(catconstants.PgCatalogID), name, addRow) if err != nil { return false, err }