cockroachdb / cockroachdb/cockroach

sql: propagate routine execution metrics to internal executor planners

Open
#151,943 1 comment 0 reactions 1 assignee Claimed by @ZhouXing19 View on GitHub
A-sql-routine branch-master C-bug T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

Currently, stmts that leverage internal executor to invoke a udf will lose count the sql stmt within the udf in the routine related metrics. For example:

```
statement ok
CREATE TABLE xy (x INT, y INT);
INSERT INTO xy VALUES (1, 2), (3, 4), (5, 6);

statement ok
CREATE FUNCTION f_scalar() RETURNS INT LANGUAGE SQL AS $$ SELECT count(*) FROM xy $$;

statement ok
CREATE FUNCTION f_setof() RETURNS SETOF xy LANGUAGE SQL AS $$ SELECT * FROM xy $$;

statement ok
CREATE MATERIALIZED VIEW mv AS SELECT x, y, f_scalar() FROM f_setof();
```

We will not see the `sql_routine_select_count` increase after the `mv` is created, which is wrong.

This is the creation of a mv calls `SchemaChanger.backfillQueryIntoTable()`, which leverage internal executor to create a new planner to execute the udf. However, this new planner is not propagated with the routine metrics that is used by the main runtime conn executor.

A possible solution is to implement a `Metrics()` method in the `isql.Txn` interface, and we can use it to propagate the metrics to the newly created planner within the internal executor's usage.

Jira issue: CRDB-53549

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.