TableDual in the Execution Plan of Select Statements

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

Original topic: select执行计划中的tabledual

| username: chenhanneu

[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]
Under what circumstances does tabledual occur, and there is another execution plan for the same batch of SQL.
The execution plan with tabledual has very low latency.
[Resource Configuration]
[Attachments: Screenshots/Logs/Monitoring]


1691110183150
1691110263381

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

Is there a limit in SQL?
Limit 0 will be directly optimized to table_dual to avoid constructing useless execution plans.

| username: chenhanneu | Original post link

The SQL is like this.

| username: Kongdom | Original post link

Is there caching? The first read is empty, and the second read goes through table_dual.

| username: chenhanneu | Original post link

The two values of customerno>?<? in the condition will change, and the values queried each time will not be the same.

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

Is it possible for a situation like a.customerno >= 2 and a.customerno < 1 to occur? In this case, the query result would be limit 0, and the SQL execution plan would be directly optimized to table_dual to avoid constructing a useless execution plan.

| username: Kongdom | Original post link

Then it should be the situation mentioned by the previous poster. TiDB is still very smart~ :wink:

| username: WalterWj | Original post link

It feels like this. Change to a condition that cannot possibly have data and check the execution plan to confirm.

| username: chenhanneu | Original post link

Manually gave a false condition, it indeed resulted in a tabledual.

| username: system | Original post link

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