-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
we should add extra info to inform that a query plan is from plan cache #16127
Comments
It's a little tricky to add Through this method, users can tell whether the executed statement benefits from the plan cache via It's something like this: mysql> execute stmt;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> SHOW WARNINGS;
+-------+------+------------------------------------+
| Level | Code | Message |
+-------+------+------------------------------------+
| Note | 1051 | Hit plan cache: True |
+-------+------+------------------------------------+
1 row in set (0.00 sec) |
I think that this will lead to applications ignoring warnings because 1051 is a generic error. i.e. they can not check by error code safely, and it is usually unwise to check by the If it can't be shown in EXPLAIN, could it be added to optimizer trace? #9243 |
How about using another unused error code reserved for the Typically, when the application meets the performance issue, they may need to check the plan cache hit ratio. For now, we can do this via the grafana monitor. Or we can record whether a SQL used the plan from the cache in the slow log. For a single query executed by a user, he/she may be curious about whether this statement hits the cache. I prefer a "Note" level warning comparted with modifying the execution plan returned by Another advantage of this way is it's easy for the test framework. We can simply check the warning message, no need to parse the execution plan returned by
Yes, I think we should consider plan cache in optimizer trace. cc @winoros |
I think it's an improvement, but could still break compatibility for applications that are not expecting this. This is a MySQL protocol problem. There are warnings and errors, but there is not really an elegant way to send purely debug 'notices' to applications. I have a couple of other suggestions:
Yeah, I agree! Please also include a counter in |
I'm sorry, I can not understand the detailed behavior of this method. What does hide it behind a "tidb_enable_*" flag mean?
This way is better than the warning message 👍. Do you have any suggestions about the variable name? How about
Sure, it's indeed necessary to record the hit counter or ratio in
Do you mean to show whether the prepared statement is put into the plan cache? |
SQL Plan Binding may also have the same issue: how to intuitively observe whether a SQL used the session or global level binding? For now, users have to check whether the execution plan is matched with the hints in the binding. But this method requires the user to be very similar with the optimizer and SQL hint behaviors. Considered that the binding creator and the binding user maybe is not the same person. For example, binding creator may be the database administrator while the user may be the application developer. Like plan cache, it's better to display this information in:
|
I meant add another one of these:
May I suggest I like the wording "last_statement". It is similar to "last_insert_id", but also "last_statement" is the name that MySQL sys schema uses in views like sys.session.
I will comment in #16217 |
This method and the variable name LGTM. @eurekaka PTAL |
Shall we raise a warning when users try to execute |
added many automation ticases about last_plan_from_cache |
Feature Request
Is your feature request related to a problem? Please describe:
prepared-plan-cache.enabled=true;
I don't know whether the last sql's plan is from plan cache.
Describe the feature you'd like:
mysql> explain for connection 1;
+-----------------------+---------+-----------+---------------+--------------------------------+
| id | estRows | task | access object | operator info |
+-----------------------+---------+-----------+---------------+--------------------------------+
| TableReader_5 | 3.00 | root | | data:TableFullScan_4, plan cache: true |
| └─TableFullScan_4 | 3.00 | cop[tikv] | table:t | keep order:false, stats:pseudo |
+-----------------------+---------+-----------+---------------+--------------------------------+
2 rows in set (0.01 sec)
The text was updated successfully, but these errors were encountered: