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 produces incorrect result when using LAG and substring #56650

Open
r33s3n6 opened this issue Oct 15, 2024 · 0 comments
Open

TiFlash produces incorrect result when using LAG and substring #56650

r33s3n6 opened this issue Oct 15, 2024 · 0 comments
Labels
type/bug The issue is confirmed as a bug.

Comments

@r33s3n6
Copy link

r33s3n6 commented Oct 15, 2024

1. Minimal reproduce step (Required)

create table t1 (c1 int, c2 int);
alter table t1 set tiflash replica 1;
insert into t1 (c1, c2) values 
  (-82 ,  -4), 
  (  1 ,   4), 
  (-11 , -45), 
  (-20 , 142);

SELECT /*+ read_from_storage(tiflash[t1]) */ 
  c2,
  lag(1) over (partition by c1 order by c2) as a,
  substring('abc', c2) as b,
  hex(substring('abc', c2)) as bh
FROM
  t1
;

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

mysql> SELECT /*+ read_from_storage(tikv[t1]) */ 
    ->   c2,
    ->   lag(1) over (partition by c1 order by c2) as a,
    ->   substring('abc', c2) as b,
    ->   hex(substring('abc', c2)) as bh
    -> FROM
    ->   t1
    -> ;
+------+------+------+------+
| c2   | a    | b    | bh   |
+------+------+------+------+
|  142 | NULL |      |      |
|  -45 | NULL |      |      |
|    4 | NULL |      |      |
|   -4 | NULL |      |      |
+------+------+------+------+
4 rows in set (0.01 sec)

3. What did you see instead (Required)

Note: in the result, there's leading '\0' before 'abc'.

mysql> SELECT /*+ read_from_storage(tiflash[t1]) */ 
    ->   c2,
    ->   lag(1) over (partition by c1 order by c2) as a,
    ->   substring('abc', c2) as b,
    ->   hex(substring('abc', c2)) as bh
    -> FROM
    ->   t1
    -> ;
+------+------+------+----------+
| c2   | a    | b    | bh       |
+------+------+------+----------+
|   -4 | NULL |      |          |
|  -45 | NULL |      |          |
|    4 | NULL |  abc | 00616263 |
|  142 | NULL |      |          |
+------+------+------+----------+
4 rows in set (0.99 sec)

4. What is your TiDB version? (Required)

Release Version: v8.4.0-alpha-370-gf773b6eeb4
Edition: Community
Git Commit Hash: f773b6eeb4593a3e2c998c265f491a016570a426
Git Branch: HEAD
UTC Build Time: 2024-10-11 02:08:09
GoVersion: go1.23.2
Race Enabled: false
Check Table Before Drop: false
Store: tikv

about us

We are the BASS team from the School of Cyber Science and Technology at Beihang University. Our main focus is on system software security, operating systems, and program analysis research, as well as the development of automated program testing frameworks for detecting software defects. Using our self-developed database vulnerability testing tool, we have identified the above-mentioned vulnerabilities in TiDB that may lead to database logic error.

@r33s3n6 r33s3n6 added the type/bug The issue is confirmed as a bug. label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

1 participant