Why the Same SQL Execution Plan is Different

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

Original topic: 相同的SQL执行计划不一样是什么原因

| username: navaca

【TiDB Usage Environment】Production Environment / Testing / PoC
【TiDB Version】
【Reproduction Path】What operations were performed when the issue occurred
【Encountered Issue: Problem Phenomenon and Impact】
【Resource Configuration】Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
【Attachments: Screenshots / Logs / Monitoring】
The same SQL has different execution plans. The sn_type field has an index, but sometimes it still performs a full table scan.


The following execution plan does not use the index.

| username: zhanggame1 | Original post link

It is possible for TiDB to execute the same SQL execution plan differently on different TiDB servers. You can try analyzing the tables on each node or restarting the TiDB server.

| username: andone | Original post link

Statistics

| username: Fly-bird | Original post link

Code execution and manual execution are also different.

| username: WalterWj | Original post link

Under the same conditions but with different data, the data distribution would be different, such as data skew. It is quite normal for the execution plan to take a different path.

| username: tidb菜鸟一只 | Original post link

I saw the pseudo keyword. Seeing this, let’s collect the table’s statistics first…

| username: swino | Original post link

Learned.