use plan cost to spot expensive query
Feature Request
Is your feature request related to a problem? Please describe:
Currently, isPhysicalPlanExpensive uses row count of each plan node to determine whether this plan is expensive. For cases like index look up join, if inner table is huge, but the join condition is equal expression on handle, this index join should not be as that expensive as the row count of inner table indicates.
Describe the feature you'd like:
Should we record cost in each plan node and use this cost to decide whether the plan is expensive or not?
Teachability, Documentation, Adoption, Migration Strategy:
A concern for this proposal is that the cost threshold can be something hard to understand and decide for DBA.
In release 3.0, TiDB prints an expensive query log based on the runtime performance:
- if the query runs longer than
@@tidb_expensive_query_time_threshold(1 minutes by default), it prints an expensive log - if the query uses more than memory quota for a query, it also prints an expensive log.
It's more accurate than the method proposed in this issue. I think we can close this issue for now. Feel free to reopen it if you have other concerns.