Unexpected Result Difference with ANY_VALUE and MAX Aggregation on BOOL Column
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
It seems that the query results differ depending on the presence of the PRIMARY KEY constraint on the c0 column. The behavior of the query should not change based on the presence of the PRIMARY KEY constraint, but there is a difference in how the ANY_VALUE function and the aggregation interact with the MAX of a BOOL column. This discrepancy needs further investigation.
### 1. Minimal reproduce step (Required)
```sql
DROP DATABASE IF EXISTS test;
CREATE DATABASE test;
USE test;
-- Create table with PRIMARY KEY constraint
CREATE TABLE t0(c0 BOOL ZEROFILL , c1 TEXT(232) , PRIMARY KEY(c0));
INSERT HIGH_PRIORITY INTO t0(c1, c0) VALUES ('[]', '0');
-- Query 1:
SELECT ANY_VALUE( !(MAX(X'68656C6C6F'))) FROM t0 AS tom0 GROUP BY tom0.c0;
-- Drop table and recreate without PRIMARY KEY constraint
DROP TABLE t0;
CREATE TABLE t0(c0 BOOL ZEROFILL , c1 TEXT(232));
-- Insert data into t0
INSERT INTO t0(c1, c0) VALUES ('[]', '0');
-- Query 2:
SELECT ANY_VALUE( !(MAX(X'68656C6C6F'))) FROM t0 AS tom0 GROUP BY tom0.c0;
```
### 2. What did you expect to see? (Required)
I expected both queries to return the same result because the only difference between them is the presence of the PRIMARY KEY constraint on the c0 column. The behavior of the ANY_VALUE function in conjunction with the MAX function should not be affected by whether or not the column has a PRIMARY KEY.
### 3. What did you see instead (Required)
```sql
Output for Query 1:
+----------------------------------------+
| ANY_VALUE( !( MAX( X'68656C6C6F' ) ) ) |
+----------------------------------------+
| 0 |
+----------------------------------------+
1 row in set (0.00 sec)
Output for Query 2:
+----------------------------------------+
| ANY_VALUE( !( MAX( X'68656C6C6F' ) ) ) |
+----------------------------------------+
| 1 |
+----------------------------------------+
1 row in set, 1 warning (0.00 sec)
```
### 4. What is your TiDB version? (Required)
```sql
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.5.5
Edition: Community
Git Commit Hash: 1fa258b833ff113883beeba40bc130be7ce66610
Git Branch: HEAD
UTC Build Time: 2026-03-12 08:34:59
GoVersion: go1.25.5
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
```
Contributor guide
Assessment
This issue has not been assessed yet.