Skip to content

TiDB doesn't apply short-circuit evaluation when there is nested sub-query in where condition #58171

@lawrence1223freenew

Description

@lawrence1223freenew

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

SELECT
  tab.id AS id
FROM
  t1 AS tab
WHERE 1 = 1 OR
  (EXISTS(SELECT 1 FROM t2 WHERE table_id = tab.id))


+---------------------------------+------------+---------------+-----------+----------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------+
| id                              | estRows    | estCost       | task      | access object                                                                                      | operator info                                                                                              |
+---------------------------------+------------+---------------+-----------+----------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------+
| Projection_8                    | 6071792.00 | 868583556.41  | root      |                                                                                                    | test.t1.id                                                                                |
| └─Selection_9                   | 6071792.00 | 867977591.57  | root      |                                                                                                    | or(1, Column#68)                                                                                           |
|   └─HashJoin_10                 | 7589740.00 | 489249565.57  | root      |                                                                                                    | left outer semi join, equal:[eq(test.t1.id, test.t2.tableid)] |
|     ├─IndexReader_26(Build)     | 1385922.00 | 33841325.91   | root      |                                                                                                    | index:IndexFullScan_25                                                                                     |
|     │ └─IndexFullScan_25        | 1385922.00 | 392860557.71  | cop[tikv] | table:t2, index:PRIMARY(accountid, metastoreid, tableid, principal, privilege) | keep order:false                                                                                           |
|     └─IndexReader_16(Probe)     | 7589740.00 | 159804590.85  | root      |                                                                                                    | index:IndexFullScan_15                                                                                     |
|       └─IndexFullScan_15        | 7589740.00 | 1768611067.74 | cop[tikv] | table:tab, index:securable_id_deleted_at_index(purgestate, deletedat, id)                        | keep order:false                                                                                           |
+---------------------------------+------------+---------------+-----------+----------------------------------------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------+

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

short-circuit should be applied, table t2 no need to show up

3. What did you see instead (Required)

short-circuit was not applied, table t2 showed up

4. What is your TiDB version? (Required)

current master.

Metadata

Metadata

Assignees

No one assigned

    Labels

    sig/plannerSIG: Plannertype/enhancementThe issue or PR belongs to an enhancement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions