pingcap / pingcap/tidb

VARIANCE returns inconsistent results (0 vs ~1e-17) on identical inputs

Open
#67,648 2 comments 0 reactions 0 assignees View on GitHub
contribution may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-8.5 severity/major sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

### 1. Minimal reproduce step (Required)

create table t2
(
c0 blob not null
);

create table t3
(
c0 blob not null
);

create definer = root@`%` view v1 as
SELECT `t2`.`c0` AS `c0`
FROM (`database1`.`t2`)
JOIN `database1`.`t3`
WHERE TRUE;

INSERT INTO database1.t2 (c0) VALUES (0x313130323336343636);
INSERT INTO database1.t2 (c0) VALUES (0x313130323336343636);
INSERT INTO database1.t2 (c0) VALUES (0x313130323336343636);
INSERT INTO database1.t2 (c0) VALUES (0x313130323336343636);
INSERT INTO database1.t2 (c0) VALUES (0x313130323336343636);
INSERT INTO database1.t2 (c0) VALUES (0x313130323336343636);

INSERT INTO database1.t3 (c0) VALUES (0x31343234343732313935);
INSERT INTO database1.t3 (c0) VALUES (0x2D3165353030);
INSERT INTO database1.t3 (c0) VALUES (0x7E6267525E252866280929);
INSERT INTO database1.t3 (c0) VALUES (0x2D31363934323832373739);
INSERT INTO database1.t3 (c0) VALUES (0x302E39343539373532343435363137353935);
INSERT INTO database1.t3 (c0) VALUES (0x2D3535373436363831);
INSERT INTO database1.t3 (c0) VALUES (0x302E37333138313335313735323335393736);
INSERT INTO database1.t3 (c0) VALUES (0x302E35373032313331323131393433393235);

SELECT VARIANCE(t2.c0)
FROM v1,t2,t3;

### 2. What did you expect to see? (Required)
The query should return a deterministic result.

Since all values of t2.c0 are identical, the variance should always be:

0

### 3. What did you see instead (Required)
The result is non-deterministic across executions:
0
or
9.246045134522703e-18

### 4. What is your TiDB version? (Required)

Release Version: v8.5.5
Edition: Community
Git Commit Hash: 1fa258b833ff113883beeba40bc130be7ce66610
Git Branch: HEAD
UTC Build Time: 2026-01-14 22:19:19
GoVersion: go1.25.5
Race Enabled: false
Check Table Before Drop: false
Store: tikv

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.