Subquery Execution Plan

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

Original topic: 子查询执行计划

| username: 胡杨树旁

Execution plan for the subquery:

explain SELECT
    * 
FROM
    PLC_CAR plccareo0_   
WHERE
    (
        plccareo0_.topId IN (
        SELECT
            plcmaineo1_.topId 
        FROM
            PLC_MAIN plcmaineo1_ 
        WHERE
            1 = 1 
            AND plcmaineo1_.lstVerFlag = '1' 
            AND plcmaineo1_.lstEffVerFlag = '1' 
            AND (
            plcmaineo1_.businessType IN ( '66', '68' )) 
            AND plcmaineo1_.coinsLinkCode <> '4' 
            AND (
            plcmaineo1_.productCode IN ( '0507' )) 
            AND topid <> '20482241691808' 
        )) 
    AND plccareo0_.licensePlateNo = '续A8B30C' 
    AND plccareo0_.licenseType = '02' 
ORDER BY
    plccareo0_.startTime DESC;

The plccareo0_ table uses the index on licenseplateno, and the subquery returns 0 results. Why doesn’t the plccareo0_ table use the topId index? This way, the execution returns 0 rows, but the plccareo0_ table uses the licenseplateno index, matching 1003 rows for plccareo0_.licensePlateNo = '续A8B30C'. When a hint is added to force plccareo0_ to use the topId index, the execution plan shows a full table scan on the index.

| username: buddyyuan | Original post link

Check if the data types are consistent?

| username: 胡杨树旁 | Original post link

The data type of the topid in both tables has always been decimal.

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

Take a look at the execution plan with EXPLAIN ANALYZE.

| username: 胡杨树旁 | Original post link

The image is not visible. Please provide the text you need translated.

| username: 人如其名 | Original post link

This is because currently IndexJoin only supports the inner side being a DataSource, and does not support the inner side being Agg->DataSource, whereas plccareo0_ is in the form of Agg->DataSource.
Refer to my question here: 指定INL_JOIN,但执行计划并不走 - #13,来自 xuyifangreeneyes - TiDB 的问答社区

| username: 胡杨树旁 | Original post link

Currently, IndexJoin only supports the inner side being a DataSource and does not support the inner side being Agg->DataSource. However, plccareo0_ is in the form of Agg->DataSource. I would like to ask where you saw this form, as I couldn’t find it in the execution plan.

| username: 人如其名 | Original post link

I misread it, please ignore my previous answer.