Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: allow UDFs in EXECUTE arguments #108215

Open
mgartner opened this issue Aug 4, 2023 · 0 comments
Open

sql: allow UDFs in EXECUTE arguments #108215

mgartner opened this issue Aug 4, 2023 · 0 comments
Labels
A-sql-routine UDFs and Stored Procedures C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-queries SQL Queries Team

Comments

@mgartner
Copy link
Collaborator

mgartner commented Aug 4, 2023

We currently disallow UDFs from being used in EXECUTE arguments (see #99008, #108213). UDF calls cannot be simply evaluated like placeholder expressions are currently:

d, err := eval.Expr(f.ctx, f.evalCtx, e.(*memo.PlaceholderExpr).Value)

UDFs must be built by the optimizer and executed as routines. #107767 attempted to address this by replacing placeholders with expressions instead of constants. There were some major issues with this approach though:

  1. If the UDF references any database objects, like tables, indexes, columns, or views, then the catalog must be initialized to build the expression. During placeholder assignment, the catalog is not initialized.
  2. Inlining the UDF will result in the UDF being effectively evaluated each time the argument is referenced in the prepared statement. For example, if the prepared statement looks like PREPARE p AS SELECT $1::INT + $1::INT, then f will be evaluated twice when running EXECUTE p(f()). This is fine for stable, immutable, and leakproof functions, but causes unexpected behavior for volatile functions. See the related issue sql: EXECUTE arguments should be evaluated only once #108027.

Jira issue: CRDB-30365

@mgartner mgartner added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Aug 4, 2023
@github-project-automation github-project-automation bot moved this to Triage in SQL Queries Aug 4, 2023
@mgartner mgartner moved this from Triage to 24.1 Release in SQL Queries Aug 4, 2023
@exalate-issue-sync exalate-issue-sync bot added the T-sql-queries SQL Queries Team label Aug 8, 2023
@exalate-issue-sync exalate-issue-sync bot removed the T-sql-queries SQL Queries Team label Aug 9, 2023
@rafiss rafiss added the T-sql-queries SQL Queries Team label Nov 2, 2023
@mgartner mgartner added the A-sql-routine UDFs and Stored Procedures label Nov 28, 2023
@mgartner mgartner moved this from 24.1 Release to 24.2 Release in SQL Queries Nov 28, 2023
@mgartner mgartner moved this from 24.2 Release to Backlog in SQL Queries Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-routine UDFs and Stored Procedures C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-sql-queries SQL Queries Team
Projects
Status: Backlog
Development

No branches or pull requests

2 participants