Skip to content

[Tech Request]: Optimize query for statement_info by response_at #17367

Closed

Description

@DanielZhangQD

Is there an existing issue for the same tech request?

  • I have checked the existing issues.

Does this tech request not affect user experience?

  • This tech request doesn't affect user experience.

What would you like to be added ?

For cu calculation, the application needs to query `statement_info` by `response_at` to determine the actual CU consumed during a specific duration.
However, querying `statement_info` by `response_at` may be slow, so we need optimization in MO.

Why is this needed ?

No response

Additional information

No response

Activity

  1. added this to the 1.3.0 milestone on Jul 8, 2024
  2. aressu1985 commented on Sep 25, 2024

    @aressu1985
    Contributor

    fixed

  3. DanielZhangQD commented on Sep 26, 2024

    @DanielZhangQD
    ContributorAuthor

    The SQL is as following, no order by limit:

    SELECT `statement_id`,any_value(`stats`) as `stats`,any_value(`duration`) as `duration`,any_value(`sql_source_type`) as `sql_source_type`,any_value(`account`) as `account`,any_value(`response_at`) as `response_at` FROM `system`.`statement_info` WHERE status != 'Running' and account != 'sys' and account != 'mocloud_mo_ob' and response_at >= '2024-09-25 23:58:00' and response_at < '2024-09-25 23:59:00' GROUP BY `statement_id`
    
  4. DanielZhangQD commented on Sep 26, 2024

    @DanielZhangQD
    ContributorAuthor

    For the SQL with order by limit in cloud dev, it takes about 7s:

    {"level":"WARN","time":"2024/09/26 00:04:12.766899 +0000","caller":"worker/controller.go:278","msg":"trace","elapsed":"6.875395539s","rows":1,"sql":"SELECT response_at FROM `system`.`statement_info` WHERE response_at > '2024-09-25 21:04:05.891' and response_at <= '2024-09-26 01:04:05.891' ORDER BY response_at desc LIMIT 1"}
    
  5. badboynt1 commented on Sep 26, 2024

    @badboynt1
    Contributor

    这条query,只需要读很少的数据,算子内耗时很少。
    目前主要瓶颈在于读取元数据,需要依赖shard功能来优化。

  6. 7 remaining items

  7. modified the milestones: 2.1.0, 2506 on Apr 25, 2025
  8. added theissue type on Apr 25, 2025
  9. fengttt commented on Apr 25, 2025

    @fengttt
    Contributor
  10. XuPeng-SH commented on Apr 29, 2025

    @XuPeng-SH
    Contributor

    #21740

    #21740 is required for request_at, which is a part of the composite key. For this issue, it takes about 7 seconds to load all the metadata of the statement_info in one CN pod. The overall metadata size of this table in the dev env is larger than the metadata cache. A 7-second delay when loading statement_info metadata in a CN pod is caused by excessive cache swapping.

  11. modified the milestones: MO-2506, MO-2509 on Jul 23, 2025
  12. modified the milestones: MO-2509, MO-202602 on Feb 3, 2026
  13. aptend commented on Jun 29, 2026

    @aptend
    Contributor

    optimized in 4.0, statement_info is clusterd by (request_at, account)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/tech-requestpriority/p0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions