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

"Detect suboptimal and regressed plans" SQL is no longer valid in 23.2 #18372

Closed
michae2 opened this issue Mar 12, 2024 · 1 comment
Closed

Comments

@michae2
Copy link

michae2 commented Mar 12, 2024

Michael Erickson (michae2) commented:

The SQL query used in https://www.cockroachlabs.com/docs/stable/crdb-internal#detect-suboptimal-and-regressed-plans is no longer valid in 23.2. (crdb_internal.decode_plan_gist is a set-returning function which is no longer allowed directly inside string_agg, an aggregate function.)

How about something like this instead?

SELECT
  substring(statement, 1, 60) AS statement_text,
  plan_id,
  string_agg(plan_line, e'\n  ') AS plan,
  max(timestamp_interval),
  max(num_rows_read_mean),
  max(runtime_latency_mean)
FROM (
  SELECT
    metadata->>'query' AS statement,
    statistics->'statistics'->'planGists'->>0 as plan_id,
    max(aggregated_ts) as timestamp_interval,
    max(statistics->'statistics'->'rowsRead'->'mean') AS num_rows_read_mean,
    max(statistics->'statistics'->'runLat'->'mean') AS runtime_latency_mean
  FROM
    crdb_internal.statement_statistics
  WHERE
    metadata->>'query' LIKE 'SELECT %'
  GROUP BY
    metadata->>'query', statistics->'statistics'->'planGists'->>0
  ) AS x,
  LATERAL crdb_internal.decode_plan_gist(plan_id) AS y(plan_line)
GROUP BY
  statement, plan_id;

Jira Issue: DOC-9851

@michae2
Copy link
Author

michae2 commented Mar 12, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant