Skip to content

sql: pg_function_is_visible is not correct for UDFs #89546

@rafiss

Description

@rafiss

Describe the problem

This builtin was added in 2019. The assumptions from back then no longer hold. See:

// pg_function_is_visible returns true if the input oid corresponds to a
// builtin function that is part of the databases on the search path.
// CockroachDB doesn't have a concept of namespaced functions, so this is
// always true if the builtin exists at all, and NULL otherwise.
// https://www.postgresql.org/docs/9.6/static/functions-info.html
"pg_function_is_visible": makeBuiltin(defProps(),
tree.Overload{
Types: tree.ArgTypes{{"oid", types.Oid}},
ReturnType: tree.FixedReturnType(types.Bool),
Fn: func(ctx *eval.Context, args tree.Datums) (tree.Datum, error) {
oid := tree.MustBeDOid(args[0])
t, err := ctx.Planner.QueryRowEx(
ctx.Ctx(), "pg_function_is_visible",
sessiondata.NoSessionDataOverride,
"SELECT * from pg_proc WHERE oid=$1 LIMIT 1", oid.Oid)
if err != nil {
return nil, err
}

Expected behavior
Match the Postgres implementation, and take into account the schemas on the search path. Maybe it also takes into account privileges?

Also, the current implementation is needlessly slow. I hope we can improve the speed of it too.

Environment:

  • CockroachDB v22.2.0-beta

cc @chengxiong-ruan @mgartner

Jira issue: CRDB-20297

Epic CRDB-19147

Metadata

Metadata

Assignees

Labels

A-sql-pgcompatSemantic compatibility with PostgreSQLA-sql-routineUDFs and Stored ProceduresC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions