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

queries with the same plan have different plan_digest in information_schema.statement_summary #33559

Closed
qw4990 opened this issue Mar 29, 2022 · 2 comments · Fixed by #47216
Closed
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. sig/sql-infra SIG: SQL Infra type/enhancement The issue or PR belongs to an enhancement.

Comments

@qw4990
Copy link
Contributor

qw4990 commented Mar 29, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t (a int);
select * from t where a in (1, 2);
select * from t where a in (1, 2, 3);
use information_schema;

mysql> select plan_digest, digest_text, QUERY_SAMPLE_TEXT from STATEMENTS_SUMMARY where digest_text="select * from `t` where `a` in ( ... )";
+------------------------------------------------------------------+----------------------------------------+--------------------------------------+
| plan_digest                                                      | digest_text                            | QUERY_SAMPLE_TEXT                    |
+------------------------------------------------------------------+----------------------------------------+--------------------------------------+
| ddbf412c92228a757994b14210801d86f61eb9b510e6bc36dca75d5d4151ad02 | select * from `t` where `a` in ( ... ) | select * from t where a in (1, 2, 3) |
| 01308613e49648a4431351439f0596ce1236bc671f9ced66c04bc19b2b8b2c38 | select * from `t` where `a` in ( ... ) | select * from t where a in (1, 2)    |
+------------------------------------------------------------------+----------------------------------------+--------------------------------------+
2 rows in set (0.00 sec)

2. What did you expect to see? (Required)

These two queries above actually have the same plan, so they should have the same plan_digest as well.

3. What did you see instead (Required)

They have different plan_digests.

4. What is your TiDB version? (Required)

mysql> select version();
+-----------------------------------------------+
| version()                                     |
+-----------------------------------------------+
| 5.7.25-TiDB-v6.1.0-alpha-78-g8f8dfafc10-dirty |
+-----------------------------------------------+
1 row in set (0.00 sec)

5. Root Cause Analysis

It is caused by selection operators with different in-list lengths are normalized to different strings.

// ExplainNormalizedInfo implements Plan interface.
func (p *PhysicalSelection) ExplainNormalizedInfo() string {
	return string(expression.SortedExplainNormalizedExpressionList(p.Conditions))
}
@qw4990 qw4990 added type/enhancement The issue or PR belongs to an enhancement. sig/sql-infra SIG: SQL Infra labels Mar 29, 2022
@qw4990
Copy link
Contributor Author

qw4990 commented Mar 29, 2022

PTAL @djshow832

@djshow832 djshow832 added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label Apr 13, 2022
@djshow832 djshow832 removed their assignment Apr 13, 2022
@likzn
Copy link
Contributor

likzn commented Apr 16, 2022

Is the case meet expection? I found these two sql have different plan.So the plan_digest is different?

select * from t where a in (1, 2);
select * from t where a in (1, 2, 3);

image
plan->plan_digest
digest_text->digest.
I found digest of the case sqls is the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. sig/sql-infra SIG: SQL Infra type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants