The same SQL fingerprint generated different execution plan IDs, but the plan content is the same! Why?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 同一个sql指纹, 产生了不同的执行计划id,但计划内容又一样!为什么?

| username: 帅的掉渣

[TiDB Usage Environment] Production Environment
[TiDB Version]
[Reproduction Path] TiDB Dashboard → SQL Statement Analysis, sorted by execution plan count
[Issue] Found multiple different execution plans under the same SQL fingerprint. Upon checking the detailed plan information, the execution plans appear identical (using the same index and operator). So why are different execution plans still being generated?



| username: 有猫万事足 | Original post link

Even for Prepare statements, the execution plan cache must be enabled to skip the generation of the execution plan. There are also a bunch of situations that will cause the execution plan cache to become invalid. You can read it yourself.

The LRU list is designed as a session-level cache because Prepare /Execute cannot be executed across sessions.

Moreover, the current execution plan cache of TiDB is session-level, so even if two sessions execute the same SQL using Prepare statements with the cache enabled, there will still be two plans.

As for the execution plan cache of non-Prepare statements,

it is disabled by default. So if you are not even executing through Prepare statements, by default, there will be different execution plans.

| username: 帅的掉渣 | Original post link

“Even for Prepare statements, the execution plan cache must be enabled to skip the generation of the execution plan.”
Does generating an execution plan always result in a new execution plan ID?

| username: 有猫万事足 | Original post link

The ID should uniquely identify an instance. Even if the content is the same, the IDs should be different if they are generated repeatedly. After all, no matter how small the execution plan is, it still occupies memory.

| username: Carpwei | Original post link

100 points

| username: Kongdom | Original post link

:yum: :+1: :+1: :+1:

| username: zhang_2023 | Original post link

What is the reason? Waiting for the result.

| username: Hacker_QGgM2nks | Original post link

Isn’t this somewhat similar to Oracle? I’m not quite sure, let’s wait for an expert to answer.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.