pingcap / pingcap/tiflash

TiFlash treat -0 and +0 as different value in all hash related operators

Open
#10,144 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

affects-6.1 affects-6.5 affects-7.1 affects-7.5 affects-8.1 affects-8.5 affects-9.0 component/compute severity/major type/bug
Dominant language
C++
Stars
1k
Forks
423
Avg merge
1d 15h
Merged PRs (30d)
24

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)
mysql> drop table test;
Query OK, 0 rows affected (0.05 sec)

mysql> create table test(c1 varchar(10) not null, c2 varchar(10) not null);
Query OK, 0 rows affected (0.02 sec)

mysql> insert into test values('0.0','0.0'),('-0.0','0.0');
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> alter table test set tiflash replica 1;
Query OK, 0 rows affected (0.02 sec)

mysql>  select count(*), cast(c1 as double) from test group by cast(c1 as double);
+----------+--------------------+
| count(*) | cast(c1 as double) |
+----------+--------------------+
|        1 |                  0 |
|        1 |                 -0 |
+----------+--------------------+
2 rows in set (0.03 sec)

mysql> select * from test a join test b on cast(a.c1 as double) = cast(b.c2 as double);
+-----+-----+------+-----+
| c1  | c2  | c1   | c2  |
+-----+-----+------+-----+
| 0.0 | 0.0 | 0.0  | 0.0 |
| 0.0 | 0.0 | -0.0 | 0.0 |
+-----+-----+------+-----+
2 rows in set (0.02 sec)

mysql>  select * from test where cast(c1 as double) in (0,1);
+-----+-----+
| c1  | c2  |
+-----+-----+
| 0.0 | 0.0 |
+-----+-----+
1 row in set (0.00 sec)

mysql>  select * from test where cast(c1 as double) = 0;
+------+-----+
| c1   | c2  |
+------+-----+
| 0.0  | 0.0 |
| -0.0 | 0.0 |
+------+-----+
2 rows in set (0.01 sec)

As you can see, in all hash related operators(hash join, hash agg, in), -0 and +0 is treated as different value, while in compare(=) operator, -0 and +0 is treated as the same value

2. What did you expect to see? (Required)
3. What did you see instead (Required)
4. What is your TiFlash version? (Required)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the SQL reproduction in the issue and compare GROUP BY, hash join, IN, and equality results for -0 and +0. Trace the TiFlash implementations of these hash-related operators and their numeric comparison or hashing behavior. Done means hash-based operations treat the two zero values consistently with equality, with regression coverage for the reported queries.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.