-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: support scalar user-defined functions #58356
Copy link
Copy link
Closed
Labels
A-sql-pgcompatSemantic compatibility with PostgreSQLSemantic compatibility with PostgreSQLA-tools-datadogA-tools-hasuraA-tools-postgrestC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Metadata
Metadata
Assignees
Labels
A-sql-pgcompatSemantic compatibility with PostgreSQLSemantic compatibility with PostgreSQLA-tools-datadogA-tools-hasuraA-tools-postgrestC-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Type
Projects
Status
Done
This issue tracks adding basic user-defined scalar SQL function support. A scalar user-defined function is a user-defined function that only uses scalar projections in a
SELECT.For example,
There are quite a few modifiers that can be specified on
CREATE FUNCTIONaccording to the PostgreSQL documentation: https://www.postgresql.org/docs/13/sql-createfunction.htmlChecklist for things that we'll want to make sure of by the time this is finished:
Additionally, it turns out that to properly do name resolution for user-defined functions with overloads, there is significant extra complexity. We can't simply store each overload in the namespace table with its type parameters as part of the name, because that would require an uncachable range scan on every resolution to a given user-defined function.
So, what we need to do is to implement a 2-level descriptor tree for user-defined functions: the parent contains the name of the UDF, and the children contain the overload types and definition (and privileges, dependencies, etc). This is fairly irritating because leasing a user-defined function now requires pulling in all of the children overloads, and leasing them as well.
We'd like to follow the pattern that was used for leasing tables that contain user-defined types, which have a similar problem. The problem is solved with a special cache of user-defined types that is implemented in the
pkg/sql/catalog/hydratedtablespackage.Vague todo list:
CREATE FUNCTIONhydratedtablespackage to also work for func overload descriptorsJira issue: CRDB-11401