Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong query result of Apply operator when late materialization is enable #51204

Closed
Lloyd-Pottiger opened this issue Feb 20, 2024 · 5 comments · Fixed by #51205 or pingcap/tiflash#8782
Closed
Labels
affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. component/tiflash report/customer Customers have encountered this bug. severity/major type/bug The issue is confirmed as a bug.

Comments

@Lloyd-Pottiger
Copy link
Contributor

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `invoice_info` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `client_type` tinyint(3) DEFAULT NULL,
  `client_no` char(18) DEFAULT NULL,
  `taxpayer_no` varchar(50) DEFAULT NULL,
  `status` tinyint(3) DEFAULT '0',
  `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

CREATE TABLE `company` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `company_no` char(18) NOT NULL,
  `name` varchar(200) DEFAULT NULL,
  `tax_registry_no` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,
  UNIQUE KEY `uk_company_no` (`company_no`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

ALTER TABLE invoice_info SET TIFLASH REPLICA 1;

INSERT INTO test.invoice_info(id, taxpayer_no, client_no, client_type, status, update_time)
VALUES
    (1, 'TAX001', 'Z9005', 1, 1, '2024-02-18 10:00:00'),
    (2, 'TAX002', 'Z9005', 1, 0, '2024-02-18 09:00:00'),
    (3, 'TAX003', 'Z9005', 2, 1, '2024-02-18 08:00:00'),
    (4, 'TAX004', 'Z9006', 1, 1, '2024-02-18 12:00:00');


INSERT INTO test.company(company_no,name,tax_registry_no) 
VALUES
    ('Z9005','AA','aaa'),
    ('Z9006','BB','bbb'),
    ('Z9007','CC','ccc');

SELECT  company_no,  IFNULL(   (    SELECT  /*+ READ_FROM_STORAGE(TIFLASH[test.invoice_info]) */   taxpayer_no    FROM     test.invoice_info    WHERE     client_no = c.company_no    AND client_type = 1    AND STATUS = 1    ORDER BY     update_time DESC    LIMIT 1   ),   tax_registry_no  ) AS tax_registry_no FROM  test.company c WHERE  company_no = 'Z9005' LIMIT 1;
+------------+-----------------+
| company_no | tax_registry_no |
+------------+-----------------+
| Z9005      | aaa             |
+------------+-----------------+

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

SELECT  company_no,  IFNULL(   (    SELECT  /*+ READ_FROM_STORAGE(TIFLASH[test.invoice_info]) */   taxpayer_no    FROM     test.invoice_info    WHERE     client_no = c.company_no    AND client_type = 1    AND STATUS = 1    ORDER BY     update_time DESC    LIMIT 1   ),   tax_registry_no  ) AS tax_registry_no FROM  test.company c WHERE  company_no = 'Z9005' LIMIT 1;
+------------+-----------------+
| company_no | tax_registry_no |
+------------+-----------------+
| Z9005      | TAX001          |
+------------+-----------------+

3. What did you see instead (Required)

SELECT  company_no,  IFNULL(   (    SELECT  /*+ READ_FROM_STORAGE(TIFLASH[test.invoice_info]) */   taxpayer_no    FROM     test.invoice_info    WHERE     client_no = c.company_no    AND client_type = 1    AND STATUS = 1    ORDER BY     update_time DESC    LIMIT 1   ),   tax_registry_no  ) AS tax_registry_no FROM  test.company c WHERE  company_no = 'Z9005' LIMIT 1;
+------------+-----------------+
| company_no | tax_registry_no |
+------------+-----------------+
| Z9005      | aaa             |
+------------+-----------------+

4. What is your TiDB version? (Required)

@JaySon-Huang
Copy link
Contributor

/label affects-7.5

@ti-chi-bot ti-chi-bot bot added the affects-7.5 This bug affects the 7.5.x(LTS) versions. label Feb 20, 2024
@JaySon-Huang
Copy link
Contributor

/label affects-7.1

@ti-chi-bot ti-chi-bot bot added the affects-7.1 This bug affects the 7.1.x(LTS) versions. label Feb 20, 2024
@ti-chi-bot ti-chi-bot bot added may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 labels Feb 21, 2024
@windtalker windtalker removed may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 labels Feb 21, 2024
@JaySon-Huang
Copy link
Contributor

JaySon-Huang commented Feb 21, 2024

Another similar fixed case #49241

@JaySon-Huang
Copy link
Contributor

JaySon-Huang commented Feb 21, 2024

The execution plan of this query. There is an "Apply_24" operator in the execution plan that satisfies parallel apply and triggers this bug.

explain SELECT company_no,
       Ifnull((SELECT /*+ READ_FROM_STORAGE(TIFLASH[test.invoice_info]) */
              taxpayer_no
               FROM   test.invoice_info
               WHERE  client_no = c.company_no
                      AND client_type = 1
                      AND status = 1
               ORDER  BY update_time DESC
               LIMIT  1), tax_registry_no) AS tax_registry_no
FROM   test.company c
WHERE  company_no = 'Z9005'
LIMIT  1; 

+----------------------------------+---------+--------------+------------------------------------------------+-------------------------------------------------------------------------------------------------------------+
| id                               | estRows | task         | access object                                  | operator info                                                                                               |
+----------------------------------+---------+--------------+------------------------------------------------+-------------------------------------------------------------------------------------------------------------+
| Projection_19                    | 1.00    | root         |                                                | test.company.company_no, ifnull(test.invoice_info.taxpayer_no, test.company.tax_registry_no)->Column#18     |
| └─Limit_22                       | 1.00    | root         |                                                | offset:0, count:1                                                                                           |
|   └─Apply_24                     | 1.00    | root         |                                                | CARTESIAN left outer join                                                                                   |
|     ├─Limit_26(Build)            | 1.00    | root         |                                                | offset:0, count:1                                                                                           |
|     │ └─Point_Get_27             | 1.00    | root         | table:company, index:uk_company_no(company_no) |                                                                                                             |
|     └─TopN_30(Probe)             | 0.00    | root         |                                                | test.invoice_info.update_time:desc, offset:0, count:1                                                       |
|       └─TableReader_38           | 0.00    | root         |                                                | MppVersion: 2, data:ExchangeSender_37                                                                       |
|         └─ExchangeSender_37      | 0.00    | mpp[tiflash] |                                                | ExchangeType: PassThrough                                                                                   |
|           └─TopN_36              | 0.00    | mpp[tiflash] |                                                | test.invoice_info.update_time:desc, offset:0, count:1                                                       |
|             └─Selection_35       | 0.00    | mpp[tiflash] |                                                | eq(test.invoice_info.client_type, 1), eq(test.invoice_info.status, 1)                                       |
|               └─TableFullScan_34 | 10.00   | mpp[tiflash] | table:invoice_info                             | pushed down filter:eq(test.invoice_info.client_no, test.company.company_no), keep order:false, stats:pseudo |
+----------------------------------+---------+--------------+------------------------------------------------+-------------------------------------------------------------------------------------------------------------+

ti-chi-bot bot pushed a commit to pingcap/tiflash that referenced this issue Feb 23, 2024
@windtalker windtalker mentioned this issue Feb 23, 2024
18 tasks
wuhuizuo pushed a commit to PingCAP-QE/artifacts that referenced this issue May 20, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [pingcap/tiflash](https://github.com/pingcap/tiflash) | major |
`v7.6.0` -> `v8.0.0` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>pingcap/tiflash (pingcap/tiflash)</summary>

###
[`v8.0.0`](https://github.com/pingcap/tiflash/releases/tag/v8.0.0):
TiFlash v8.0.0

[Compare
Source](https://github.com/pingcap/tiflash/compare/v7.6.0...v8.0.0)

For new features, improvements, and bug fixes released in 8.0.0 for
tiflash, see [TiDB 8.0.0 release
notes](https://docs.pingcap.com/tidb/v8.0/release-8.0.0/).
See the difference from the issue perspective: <details>

    - pingcap/tiflash#8510

-   [#&#8203;8382](https://github.com/pingcap/tiflash/issues/8382)
-   [#&#8203;8697](https://github.com/pingcap/tiflash/issues/8697)
-   [#&#8203;8685](https://github.com/pingcap/tiflash/issues/8685)
-   [#&#8203;8703](https://github.com/pingcap/tiflash/issues/8703)
-   [#&#8203;8712](https://github.com/pingcap/tiflash/issues/8712)
-   [#&#8203;8715](https://github.com/pingcap/tiflash/issues/8715)
-   [#&#8203;8710](https://github.com/pingcap/tiflash/issues/8710)
-   [#&#8203;8419](https://github.com/pingcap/tiflash/issues/8419)
-   [#&#8203;8695](https://github.com/pingcap/tiflash/issues/8695)
-   [#&#8203;8688](https://github.com/pingcap/tiflash/issues/8688)
-   [#&#8203;8351](https://github.com/pingcap/tiflash/issues/8351)
- [#&#8203;8323](https://github.com/pingcap/tiflash/issues/8323),
close [#&#8203;8504](https://github.com/pingcap/tiflash/issues/8504)
-   [#&#8203;8351](https://github.com/pingcap/tiflash/issues/8351)
-   [#&#8203;8711](https://github.com/pingcap/tiflash/issues/8711)
-   [#&#8203;8351](https://github.com/pingcap/tiflash/issues/8351)
-   [#&#8203;8751](https://github.com/pingcap/tiflash/issues/8751)
-   [#&#8203;8674](https://github.com/pingcap/tiflash/issues/8674)
-   [#&#8203;8765](https://github.com/pingcap/tiflash/issues/8765)
-   [#&#8203;8768](https://github.com/pingcap/tiflash/issues/8768)
-   [pingcap/tidb#51204](https://github.com/pingcap/tidb/issues/51204)
-   [#&#8203;8777](https://github.com/pingcap/tiflash/issues/8777)
-   [#&#8203;8691](https://github.com/pingcap/tiflash/issues/8691)
-   [#&#8203;8796](https://github.com/pingcap/tiflash/issues/8796)
-   [#&#8203;8799](https://github.com/pingcap/tiflash/issues/8799)
-   [#&#8203;8806](https://github.com/pingcap/tiflash/issues/8806)
-   [#&#8203;8824](https://github.com/pingcap/tiflash/issues/8824)
-   [#&#8203;8826](https://github.com/pingcap/tiflash/issues/8826)
-   [#&#8203;8843](https://github.com/pingcap/tiflash/issues/8843)
-   [#&#8203;8837](https://github.com/pingcap/tiflash/issues/8837)
-   [#&#8203;8589](https://github.com/pingcap/tiflash/issues/8589)

      </details>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/PingCAP-QE/artifacts).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@seiya-annie
Copy link

/found customer

@ti-chi-bot ti-chi-bot bot added the report/customer Customers have encountered this bug. label Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. component/tiflash report/customer Customers have encountered this bug. severity/major type/bug The issue is confirmed as a bug.
Projects
None yet
5 participants