oceanbase / oceanbase/oceanbase

after changing STD(x) to STD(-x), the value unexpectedly become different

Open
#2,372 1 comment 0 reactions 0 assignees View on GitHub

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 t2 (
    c13 DATETIME NULL
);

INSERT INTO t2 (c13) VALUES ('2026-01-06 13:03:11');
WITH cte_670 AS (SELECT MAX(ADDDATE(bin51.c13, 'DAY')) AS col_2 FROM t2 AS bin51) SELECT cte.col_2 AS col_2, STD(cte.col_2) AS col_1_2 FROM cte_670 AS cte GROUP BY cte.col_2;
WITH cte_670 AS (SELECT MAX(ADDDATE(bin51.c13, 'DAY')) AS col_2 FROM t2 AS bin51) SELECT cte.col_2 AS col_2, STD(-cte.col_2) AS col_1_2 FROM cte_670 AS cte GROUP BY cte.col_2;

✔️ Expected Behavior

col_1_2's value should be 0
Aditionally,In mysql 8.0.20,the value is the same

mysql> WITH cte_670 AS (SELECT MAX(ADDDATE(bin51.c13, 'DAY')) AS col_2 FROM t2 AS bin51) SELECT cte.col_2 AS col_2, STD(cte.col_2) AS col_1_2 FROM cte_670 AS cte GROUP BY cte.col_2;
+---------------------+---------+
| col_2               | col_1_2 |
+---------------------+---------+
| 2026-01-06 13:03:11 |       0 |
+---------------------+---------+
1 row in set, 1 warning (0.00 sec)

mysql> WITH cte_670 AS (SELECT MAX(ADDDATE(bin51.c13, 'DAY')) AS col_2 FROM t2 AS bin51) SELECT cte.col_2 AS col_2, STD(-cte.col_2) AS col_1_2 FROM cte_670 AS cte GROUP BY cte.col_2;
+---------------------+---------+
| col_2               | col_1_2 |
+---------------------+---------+
| 2026-01-06 13:03:11 |       0 |
+---------------------+---------+
1 row in set, 1 warning (0.00 sec)

In oceanbase:

mysql> WITH cte_670 AS (SELECT MAX(ADDDATE(bin51.c13, 'DAY')) AS col_2 FROM t2 AS bin51) SELECT cte.col_2 AS col_2, STD(cte.col_2) AS col_1_2 FROM cte_670 AS cte GROUP BY cte.col_2;
+---------------------+---------+
| col_2               | col_1_2 |
+---------------------+---------+
| 2026-01-06 13:03:11 |       0 |
+---------------------+---------+
1 row in set (0.00 sec)

mysql> WITH cte_670 AS (SELECT MAX(ADDDATE(bin51.c13, 'DAY')) AS col_2 FROM t2 AS bin51) SELECT cte.col_2 AS col_2, STD(-cte.col_2) AS col_1_2 FROM cte_670 AS cte GROUP BY cte.col_2;
+---------------------+--------------------+
| col_2               | col_1_2            |
+---------------------+--------------------+
| 2026-01-06 13:03:11 | 192579.96593363496 |
+---------------------+--------------------+
1 row in set (0.00 sec)
❌ Actual Behavior
mysql> WITH cte_670 AS (SELECT MAX(ADDDATE(bin51.c13, 'DAY')) AS col_2 FROM t2 AS bin51) SELECT cte.col_2 AS col_2, STD(cte.col_2) AS col_1_2 FROM cte_670 AS cte GROUP BY cte.col_2;
+---------------------+---------+
| col_2               | col_1_2 |
+---------------------+---------+
| 2026-01-06 13:03:11 |       0 |
+---------------------+---------+
1 row in set (0.00 sec)

mysql> WITH cte_670 AS (SELECT MAX(ADDDATE(bin51.c13, 'DAY')) AS col_2 FROM t2 AS bin51) SELECT cte.col_2 AS col_2, STD(-cte.col_2) AS col_1_2 FROM cte_670 AS cte GROUP BY cte.col_2;
+---------------------+--------------------+
| col_2               | col_1_2            |
+---------------------+--------------------+
| 2026-01-06 13:03:11 | 192579.96593363496 |
+---------------------+--------------------+
1 row in set (0.00 sec)

Contributor guide

Open the contributing guide

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 provided OceanBase SQL reproduction and trace the STD aggregate with a DATETIME expression after unary negation. Compare the type conversion and aggregate input for STD(cte.col_2) and STD(-cte.col_2); done when both forms return 0, consistent with the expected MySQL behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.