diff --git a/src/current/_includes/v26.1/known-limitations/routine-limitations.md b/src/current/_includes/v26.1/known-limitations/routine-limitations.md index 4718c6c7abf..331d494c78f 100644 --- a/src/current/_includes/v26.1/known-limitations/routine-limitations.md +++ b/src/current/_includes/v26.1/known-limitations/routine-limitations.md @@ -7,4 +7,5 @@ - Routines cannot be created with an `OUT` parameter of type `RECORD`. [#123448](https://github.com/cockroachdb/cockroach/issues/123448) - DDL statements (e.g., `CREATE TABLE`, `CREATE INDEX`) are not allowed within UDFs or stored procedures. [#110080](https://github.com/cockroachdb/cockroach/issues/110080) - Polymorphic types cannot be cast to other types (e.g., `TEXT`) within routine parameters. [#123536](https://github.com/cockroachdb/cockroach/issues/123536) -- Routine parameters and return types cannot be declared using the `ANYENUM` polymorphic type, which is able to match any [`ENUM`]({% link {{ page.version.version }}/enum.md %}) type. [123048](https://github.com/cockroachdb/cockroach/issues/123048) \ No newline at end of file +- Routine parameters and return types cannot be declared using the `ANYENUM` polymorphic type, which is able to match any [`ENUM`]({% link {{ page.version.version }}/enum.md %}) type. [#123048](https://github.com/cockroachdb/cockroach/issues/123048) +- [Statement diagnostics]({% link {{ page.version.version }}/explain-analyze.md %}#debug-option) cannot be collected for statements executed inside UDFs or stored procedures. You can request statement diagnostics for the top-level invocation of the function or procedure, and the resulting trace includes spans for each statement executed. However, there is no way to target statements executed inside the function or procedure with a statement diagnostics request. [#159526](https://github.com/cockroachdb/cockroach/issues/159526) diff --git a/src/current/_includes/v26.1/ui/statements-views.md b/src/current/_includes/v26.1/ui/statements-views.md index 607e05528f2..6a85e822e99 100644 --- a/src/current/_includes/v26.1/ui/statements-views.md +++ b/src/current/_includes/v26.1/ui/statements-views.md @@ -32,6 +32,10 @@ The **Statements Fingerprints** view helps you: - View SQL statement fingerprint [details](#statement-fingerprint-page). - Download SQL statement [diagnostics](#diagnostics) for troubleshooting. +{{site.data.alerts.callout_info}} +The **Statements** page displays all SQL statements, including those executed within [user-defined functions]({{ link_prefix}}user-defined-functions.html#statement-statistics) and [stored procedures]({{ link_prefix}}stored-procedures.html#statement-statistics). This allows you to monitor the performance of individual statements within your routines. +{{site.data.alerts.end}} + {% if page.cloud != true %} To view this page, click **SQL Activity** in the left-hand navigation of the DB Console. {% else %} diff --git a/src/current/v26.1/stored-procedures.md b/src/current/v26.1/stored-procedures.md index 753a650e783..3f20f23dea7 100644 --- a/src/current/v26.1/stored-procedures.md +++ b/src/current/v26.1/stored-procedures.md @@ -28,6 +28,16 @@ CREATE PROCEDURE procedure_name(parameters) For details, see [`CREATE PROCEDURE`]({% link {{ page.version.version }}/create-procedure.md %}). +## Statement statistics + +SQL statements executed within stored procedures are tracked in the SQL statistics subsystem and will appear in the [**SQL Activity** > **Statements**]({% link {{ page.version.version }}/ui-statements-page.md %}) page and the [**Insights**]({% link {{ page.version.version }}/ui-insights-page.md %}) page in the DB Console. This allows you to monitor the performance and execution statistics of individual statements within your procedures. +f +When the stored procedure is invoked as part of a transaction, the statements executed within the procedure will also appear in the [**Transaction details**]({% link {{ page.version.version }}/ui-transactions-page.md %}#transaction-details-page) in the **Statement Fingerprints** table. + +{{site.data.alerts.callout_info}} +[Statement diagnostics]({% link {{ page.version.version }}/explain-analyze.md %}#debug-option) cannot be collected for statements executed inside stored procedures. You can request statement diagnostics for the top-level invocation of the procedure, and the resulting trace includes spans for each statement executed. However, there is no way to target statements executed inside the procedure with a statement diagnostics request. For details, refer to [Known limitations](#known-limitations). +{{site.data.alerts.end}} + ## Examples {% include {{page.version.version}}/sql/movr-statements.md %} diff --git a/src/current/v26.1/transaction-diagnostics.md b/src/current/v26.1/transaction-diagnostics.md index 0fc6ab9e7fc..e1c42431770 100644 --- a/src/current/v26.1/transaction-diagnostics.md +++ b/src/current/v26.1/transaction-diagnostics.md @@ -10,6 +10,10 @@ Transaction diagnostics allow operators and support engineers to investigate iss Requesting a transaction diagnostics bundle introduces performance overhead. This feature is primarily intended for use under the guidance of [Cockroach Labs Support](https://support.cockroachlabs.com/). {{site.data.alerts.end}} +{{site.data.alerts.callout_info}} +Transaction diagnostics do not contain a [statement diagnostic bundle]({% link {{ page.version.version }}/explain-analyze.md %}#debug-option) for statements executed inside [user-defined functions]({% link {{ page.version.version }}/user-defined-functions.md %}) or [stored procedures]({% link {{ page.version.version }}/stored-procedures.md %}). However, they do contain a statement diagnostic bundle for the top-level invocation, or call, of the user-defined function or stored procedure. +{{site.data.alerts.end}} + ## Required privileges To use this function on a [secure cluster]({% link {{ page.version.version }}/secure-a-cluster.md %}), you must be an [`admin` user]({% link {{ page.version.version }}/security-reference/authorization.md %}#admin-role) or a SQL user with the [`VIEWACTIVITY`]({% link {{ page.version.version }}/security-reference/authorization.md %}#viewactivity) or [`VIEWACTIVITYREDACTED`]({% link {{ page.version.version }}/security-reference/authorization.md %}#viewactivityredacted) [system privilege]({% link {{ page.version.version }}/security-reference/authorization.md %}#supported-privileges). If the user has only `VIEWACTIVITYREDACTED`, they can request only redacted bundles. diff --git a/src/current/v26.1/user-defined-functions.md b/src/current/v26.1/user-defined-functions.md index c525ac6a5ea..7fb53f6412d 100644 --- a/src/current/v26.1/user-defined-functions.md +++ b/src/current/v26.1/user-defined-functions.md @@ -31,6 +31,16 @@ The basic components of a user-defined function are a name, list of arguments, r - Can reference tables. - Can reference only the `SELECT` statement. +## Statement statistics + +SQL statements executed within user-defined functions are tracked in the SQL statistics subsystem and will appear in the [**SQL Activity** > **Statements**]({% link {{ page.version.version }}/ui-statements-page.md %}) page and the [**Insights**]({% link {{ page.version.version }}/ui-insights-page.md %}) page in the DB Console. This allows you to monitor the performance and execution statistics of individual statements within your functions. + +When the UDF is invoked as part of a transaction, the statements executed within the function also appear in the [**Transaction details**]({% link {{ page.version.version }}/ui-transactions-page.md %}#transaction-details-page) in the **Statement Fingerprints** table. + +{{site.data.alerts.callout_info}} +[Statement diagnostics]({% link {{ page.version.version }}/explain-analyze.md %}#debug-option) cannot be collected for statements executed inside user-defined functions. You can request statement diagnostics for the top-level invocation of the function, and the resulting trace includes spans for each statement executed. However, there is no way to target statements executed inside the function with a statement diagnostics request. For details, refer to [Known limitations](#known-limitations). +{{site.data.alerts.end}} + ## Examples ### Create a UDF