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

Tiflash return inconsistent result in multiple times (single node) #9667

Open
Dylan0222 opened this issue Nov 24, 2024 · 3 comments
Open

Tiflash return inconsistent result in multiple times (single node) #9667

Dylan0222 opened this issue Nov 24, 2024 · 3 comments
Labels
affects-8.4 affects-8.5 This bug affects the 8.5.x(LTS) versions. component/compute type/bug The issue is confirmed as a bug.

Comments

@Dylan0222
Copy link

Dylan0222 commented Nov 24, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

DROP TABLE IF EXISTS t0;

CREATE TABLE t0 (
    grade DOUBLE
);

INSERT INTO t0 (grade) 
VALUES 
    (1), 
    (129), 
    (2), 
    (130), 
    (3), 
    (131), 
    (25), 
    (153), 
    (1), 
    (129), 
    (2), 
    (130), 
    (3), 
    (131), 
    (25), 
    (153);
    
ALTER TABLE t0 SET TIFLASH REPLICA 1;

SELECT 
    grade,
    score
FROM (
    SELECT /*+ READ_FROM_STORAGE(tikv[t0]) */
        grade,
        ((grade * 3 + 5) % 128) ^ 40 AS score,
        ROW_NUMBER() OVER (ORDER BY ((grade * 3 + 5) % 128) ^ 40) AS rn
    FROM t0
) AS sub
WHERE rn <= 4;

SELECT 
    grade,
    score
FROM (
    SELECT /*+ READ_FROM_STORAGE(tiflash[t0]) */
        grade,
        ((grade * 3 + 5) % 128) ^ 40 AS score,
        ROW_NUMBER() OVER (ORDER BY ((grade * 3 + 5) % 128) ^ 40) AS rn
    FROM t0
) AS sub
WHERE rn <= 4;

INSERT INTO t0 (grade) 
VALUES 
    (1), 
    (129), 
    (2), 
    (130), 
    (3), 
    (131), 
    (25), 
    (153), 
    (1), 
    (129), 
    (2), 
    (130), 
    (3), 
    (131), 
    (25), 
    (153);

SELECT 
    grade,
    score
FROM (
    SELECT /*+ READ_FROM_STORAGE(tikv[t0]) */
        grade,
        ((grade * 3 + 5) % 128) ^ 40 AS score,
        ROW_NUMBER() OVER (ORDER BY ((grade * 3 + 5) % 128) ^ 40) AS rn
    FROM t0
) AS sub
WHERE rn <= 4;

SELECT 
    grade,
    score
FROM (
    SELECT /*+ READ_FROM_STORAGE(tiflash[t0]) */
        grade,
        ((grade * 3 + 5) % 128) ^ 40 AS score,
        ROW_NUMBER() OVER (ORDER BY ((grade * 3 + 5) % 128) ^ 40) AS rn
    FROM t0
) AS sub
WHERE rn <= 4;

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

I have also found that this inconsistency is a probabilistic event. Repeatedly executing the TiFlash query produces different results, while TiKV consistently guarantees fixed results. Moreover, this bug must be triggered strictly by inputting the cases one by one; skipping any SQL query does not necessarily reproduce the issue. I think the issue may lie in the sorting operation inside TiFlash.

3. What did you see instead (Required)

mysql> SELECT
    ->     grade,
    ->     score
    -> FROM (
    ->     SELECT /*+ READ_FROM_STORAGE(tiflash[t0]) */
    ->         grade,
    ->         ((grade * 3 + 5) % 128) ^ 40 AS score,
    ->         ROW_NUMBER() OVER (ORDER BY ((grade * 3 + 5) % 128) ^ 40) AS rn
    ->     FROM t0
    -> ) AS sub
    -> WHERE rn <= 4;
+-------+-------+
| grade | score |
+-------+-------+
|     1 |    32 |
|     1 |    32 |
|   129 |    32 |
|   129 |    32 |
+-------+-------+
4 rows in set (0.04 sec)

mysql> SELECT
    ->     grade,
    ->     score
    -> FROM (
    ->     SELECT /*+ READ_FROM_STORAGE(tiflash[t0]) */
    ->         grade,
    ->         ((grade * 3 + 5) % 128) ^ 40 AS score,
    ->         ROW_NUMBER() OVER (ORDER BY ((grade * 3 + 5) % 128) ^ 40) AS rn
    ->     FROM t0
    -> ) AS sub
    -> WHERE rn <= 4;
+-------+-------+
| grade | score |
+-------+-------+
|     1 |    32 |
|     1 |    32 |
|     1 |    32 |
|   129 |    32 |
+-------+-------+
4 rows in set (0.05 sec)
mysql> SELECT
    ->     grade,
    ->     score
    -> FROM (
    ->     SELECT /*+ READ_FROM_STORAGE(tikv[t0]) */
    ->         grade,
    ->         ((grade * 3 + 5) % 128) ^ 40 AS score,
    ->         ROW_NUMBER() OVER (ORDER BY ((grade * 3 + 5) % 128) ^ 40) AS rn
    ->     FROM t0
    -> ) AS sub
    -> WHERE rn <= 4;
+-------+-------+
| grade | score |
+-------+-------+
|     1 |    32 |
|     1 |    32 |
|   129 |    32 |
|     1 |    32 |
+-------+-------+
4 rows in set (0.04 sec)

4. What is your TiDB version? (Required)

TiDB v8.4.0

@Dylan0222 Dylan0222 added the type/bug The issue is confirmed as a bug. label Nov 24, 2024
@Dylan0222
Copy link
Author

/label affects-8.4
/label affects-8.5

@ti-chi-bot ti-chi-bot bot added affects-8.4 affects-8.5 This bug affects the 8.5.x(LTS) versions. labels Nov 24, 2024
@yibin87
Copy link
Contributor

yibin87 commented Nov 27, 2024

Maybe related to pingcap/tidb#57655

@Dylan0222
Copy link
Author

Maybe related to pingcap/tidb#57655

It seems like a different problem since this issue shows that tiflash has an unstable behaviour, rather than tikv.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-8.4 affects-8.5 This bug affects the 8.5.x(LTS) versions. component/compute type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

3 participants