Skip to content

DOCS-6275 Document dynamic SQL in stored functions (MDEV-39518) - #1064

Merged
mariadb-stefan-hinz merged 2 commits into
mainfrom
DOCS-6275-ps-in-stored-functions
Sep 15, 2026
Merged

mariadb-stefan-hinz merged 2 commits into
mainfrom
DOCS-6275-ps-in-stored-functions

Conversation

@mariadb-stefan-hinz

@mariadb-stefan-hinz mariadb-stefan-hinz commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

DOCS-6275 · MDEV-39518

MDEV-39518 allows PREPARE, EXECUTE, DEALLOCATE PREPARE and EXECUTE IMMEDIATE inside a stored function, but only when the function call is the entire right-hand side of an assignment to a stored routine variable. The restriction moved from the parser to call time, so CREATE FUNCTION now succeeds where it used to fail.

Changes

  • prepare-statement.md — new ### Dynamic SQL in Stored Functions section: the three permitted assignment forms, the rejected contexts, and the consequences (no prelocking, per-statement binary logging, session-scoped statement handles, no MDL on the routine). The blanket "not in a stored function or trigger" sentence and the PREPARE LOCAL equivalent are version-qualified.
  • execute-immediate.md — the existing example showed the error being raised at CREATE FUNCTION time. That is wrong from 13.2.1, so it is split into the before and after forms.
  • stored-function-limitations.md — the prepared-statement bullet is qualified, and EXECUTE IMMEDIATE added to the list of statements it names.

Verification

Every claim is checked against MariaDB/server @ 6f18dc2d117a (the feature is commit bfabe0e53042, on main only). The examples and the lists of rejected contexts are taken from the mysql-test/main/ps_in_func*.result files rather than from prose, so they are the server's own recorded output.

One thing worth a reviewer's eye

The ticket says Release Series 13.1 and sits under the 13.1 epic, but MDEV-39518 is Closed/Fixed with fixVersion 13.2.1, and the commit is on main (13.2.0 alpha) with no 13.1 branch carrying it. The pages are annotated 13.2.1. One test file still carries a stale # End of 13.1 tests marker, which is probably where the ticket's 13.1 came from. If the series is actually 13.1, three annotations need flipping.

🤖 Generated with Claude Code

MDEV-39518 lets a stored function contain PREPARE, EXECUTE,
DEALLOCATE PREPARE and EXECUTE IMMEDIATE, but only when the function
is called as the whole right-hand side of an assignment to a stored
routine variable. The rejection moved from the parser to call time,
so CREATE FUNCTION now succeeds where it used to fail.

- prepare-statement.md: new "Dynamic SQL in Stored Functions" section
  covering the permitted contexts, the rejected ones, and the
  prelocking, binary-logging and session-scope consequences. Qualify
  the blanket "not in a stored function or trigger" sentence and the
  PREPARE LOCAL equivalent.
- execute-immediate.md: the existing example showed the error at
  CREATE FUNCTION time, which is wrong from 13.2.1. Split it into the
  before and after forms.
- stored-function-limitations.md: qualify the prepared-statement
  bullet and add EXECUTE IMMEDIATE to it.

Verified against MariaDB server @ 6f18dc2d117a (commit bfabe0e53042),
using the mysql-test/main/ps_in_func* result files as the oracle.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mariadb-stefan-hinz mariadb-stefan-hinz added the documentation Improvements or additions to documentation label Sep 11, 2026
@mariadb-stefan-hinz
mariadb-stefan-hinz merged commit 7816b38 into main Sep 15, 2026
13 checks passed
@mariadb-stefan-hinz
mariadb-stefan-hinz deleted the DOCS-6275-ps-in-stored-functions branch September 15, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant