oceanbase / oceanbase/oceanbase
after changing VARIANCE(DATE value ) to VARIANCE(-DATE value ),the value unexpectedly change
Open
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Self Checks
- I have read the Contributing Guide.
- This is only for bug report, if you would like to ask a question, please head to Discussions.
- I have searched for existing issues search for existing issues, including closed ones.
- I confirm that I am using English to submit this report, otherwise it will be closed.
- 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- Please do not modify this template :) and fill in all the required fields.
OceanBase version
5.7.25 OceanBase_CE 4.3.5.4
Self Hosted
Self Hosted (Docker)
Environment
Linux LAPTOP-2SQAVLB0 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Steps to reproduce
DROP DATABASE IF EXISTS test;
CREATE DATABASE IF NOT EXISTS test;
SET GLOBAL sort_buffer_size = 64 * 1024 * 1024;
SET GLOBAL read_rnd_buffer_size = 8 * 1024 * 1024;
USE test;
CREATE TABLE t3 (
c1 INT NOT NULL AUTO_INCREMENT,
c2 INT NOT NULL,
c3 INT NOT NULL,
c4 YEAR NOT NULL,
c5 DATETIME NULL,
c6 TINYINT NULL,
c7 SMALLINT NULL,
c8 MEDIUMINT NULL,
c9 BIGINT NULL,
c10 LONGTEXT NULL,
c11 GEOMETRY NULL,
c12 TINYTEXT NULL,
c13 TINYBLOB NULL,
c14 SET('x','y','z') NULL,
c15 TINYINT(1) NULL,
PRIMARY KEY (c1)
);
INSERT INTO t3 (c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15) VALUES (9473, 3166, 7923, 2009, '2025-10-28 00:33:04', 64, 33, 23, 5, 'sample_zTTcDyJQiepslGYJ3zx7HK7FrfiC27HYfiM2DyjEqVaxZXyJQZAk243c5b7yltsU3bDVzF2sv1hGOpsKD5u5Vsxz394dHEEgy83H8xb47ex2oB6Sq0o7pOfwoVHbKZu6RgdQZDvfErgKcrI6jjhxlh5vvf4A5bMHspZVCHf6xQTLobsltrxVRPWcVEpcFa5j1I95z3Z4Rjv7rhDXeACav9XF6AozF9GisKKaR6TZV1uqxe9tbHTweWshIEX8yNnrU3IxQZKPJKdvzuZULMFQtInIhk96d8YG30AdQ5pBtYaX65GusSaJXGMp3Ihk3IErQfBpVTu29NJzaMcfVkaVMp2xAwfBSI3cvVabVv8biqnHJEPV5TWpfuyEyNERmQB3uT4QchyRMQMwZvjD7dLdhzAswCYPfR1cgVswYIJ1uRUY5JmnVxXSazO9HaCdk42BhmyWoXGzKbcNQ4D5uw3C9jIuse73AKzFL2LkIeEwgZAsimZuiM7Q4EwQWxy7B09PFzXlmKpILqGuT0hKw5wsTyKNl0wjI2FNH2bPoVq4ujSAQDwJr4jSz38', ST_GeomFromText('POINT(-7.208789 -111.046928)'), 'sample_lo1SDGmMjznqDAbPH7lv1PLIycmmGnug3w9c1EMVaOOvVY0FM7GLWSZHVE6MVSrkzdR1XlrSer0Ae6U0ldCAgDDUG', X'CBBA34E99F8CDA95E4A2AFDF8210', 'z', NULL);
WITH cte_899 AS (SELECT DAY('2023-01-01 12:00:00') AS col_2, MIN(mdx16.c5 - INTERVAL mdx16.c2 DAY) AS col_3 FROM t3 AS mdx16 GROUP BY ST_CENTROID(mdx16.c11), DAY('2023-01-01 12:00:00'), mdx16.c7 % CEIL(mdx16.c9)) SELECT subq.variance_490 AS variance_490 FROM (SELECT VARIANCE(s106.col_3) AS variance_490 FROM cte_899 AS s106 GROUP BY s106.col_2, s106.col_3) AS subq;
WITH cte_899 AS (SELECT DAY('2023-01-01 12:00:00') AS col_2, MIN(mdx16.c5 - INTERVAL mdx16.c2 DAY) AS col_3 FROM t3 AS mdx16 GROUP BY ST_CENTROID(mdx16.c11), DAY('2023-01-01 12:00:00'), mdx16.c7 % CEIL(mdx16.c9)) SELECT subq.variance_490 AS variance_490 FROM (SELECT VARIANCE(-s106.col_3) AS variance_490 FROM cte_899 AS s106 GROUP BY s106.col_2, s106.col_3) AS subq;
✔️ Expected Behavior
In mysql 8.0.20,the value is the same
mysql> WITH cte_899 AS (SELECT DAY('2023-01-01 12:00:00') AS col_2, MIN(mdx16.c5 - INTERVAL mdx16.c2 DAY) AS col_3 FROM t3 AS mdx16 GROUP BY ST_CENTROID(mdx16.c11), DAY('2023-01-01 12:00:00'), mdx16.c7 % CEIL(mdx16.c9)) SELECT subq.variance_490 AS variance_490 FROM (SELECT VARIANCE(s106.col_3) AS variance_490 FROM cte_899 AS s106 GROUP BY s106.col_2, s106.col_3) AS subq;
+--------------+
| variance_490 |
+--------------+
| 0 |
+--------------+
1 row in set (0.00 sec)
mysql> WITH cte_899 AS (SELECT DAY('2023-01-01 12:00:00') AS col_2, MIN(mdx16.c5 - INTERVAL mdx16.c2 DAY) AS col_3 FROM t3 AS mdx16 GROUP BY ST_CENTROID(mdx16.c11), DAY('2023-01-01 12:00:00'), mdx16.c7 % CEIL(mdx16.c9)) SELECT subq.variance_490 AS variance_490 FROM (SELECT VARIANCE(-s106.col_3) AS variance_490 FROM cte_899 AS s106 GROUP BY s106.col_2, s106.col_3) AS subq;
+--------------+
| variance_490 |
+--------------+
| 0 |
+--------------+
1 row in set (0.00 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.20 |
+-----------+
1 row in set (0.00 sec)
❌ Actual Behavior
mysql> WITH cte_899 AS (SELECT DAY('2023-01-01 12:00:00') AS col_2, MIN(mdx16.c5 - INTERVAL mdx16.c2 DAY) AS col_3 FROM t3 AS mdx16 GROUP BY ST_CENTROID(mdx16.c11), DAY('2023-01-01 12:00:00'), mdx16.c7 % CEIL(mdx16.c9)) SELECT subq.variance_490 AS variance_490 FROM (SELECT VARIANCE(s106.col_3) AS variance_490 FROM cte_899 AS s106 GROUP BY s106.col_2, s106.col_3) AS subq;
+--------------+
| variance_490 |
+--------------+
| 0 |
+--------------+
1 row in set (0.02 sec)
mysql> WITH cte_899 AS (SELECT DAY('2023-01-01 12:00:00') AS col_2, MIN(mdx16.c5 - INTERVAL mdx16.c2 DAY) AS col_3 FROM t3 AS mdx16 GROUP BY ST_CENTROID(mdx16.c11), DAY('2023-01-01 12:00:00'), mdx16.c7 % CEIL(mdx16.c9)) SELECT subq.variance_490 AS variance_490 FROM (SELECT VARIANCE(-s106.col_3) AS variance_490 FROM cte_899 AS s106 GROUP BY s106.col_2, s106.col_3) AS subq;
+--------------+
| variance_490 |
+--------------+
| -13418916416 |
+--------------+
1 row in set (0.00 sec)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source files, tests, or entry points are named. First run the two SQL statements from the reproduction against OceanBase 4.3.5.4 and compare VARIANCE(col_3) with VARIANCE(-col_3); done means both expressions return the same result as MySQL 8.0.20, namely 0.
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
- 32/100