cockroachdb / cockroachdb/cockroach
sql: propagate routine execution metrics to internal executor planners
- 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
Assessment
This issue has not been assessed yet.