Bug #113060 | The result of avg(distinct xx)is different between from primary and secondary | ||
---|---|---|---|
Submitted: | 13 Nov 2023 10:23 | Modified: | 13 Nov 2023 12:07 |
Reporter: | XIAOJING LI | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: DML | Severity: | S3 (Non-critical) |
Version: | 8.0 | OS: | Any |
Assigned to: | Assigned Account | CPU Architecture: | Any |
Tags: | avg distinct, sum |
[13 Nov 2023 10:23]
XIAOJING LI
[13 Nov 2023 12:07]
MySQL Verification Team
Hi Mr. LI, Thank you for your bug report. We have managed to repeat it with 8.0.35: avg(distinct b) 3.5 avg(distinct b) 3.7 sum(distinct b) 14 sum(distinct b) 37 Verified as reported.
[20 Nov 2023 11:40]
huahua xu
Hi XIAOJING LI, For your query statement `select avg(distinct b) from t1`, the optimizer use covering index skip scan for deduplication on t1.idx_b_l, and aggregate them, then average them. For your query statement `select avg(distinct b) from t1 force index(primary)`, the optimizer collects all the data ('0XS2E55maqch', 'G6UHU26b8dkvwpYiM' and '0XS2E55maqch' all have been converted to 0.0) into an unique for removing of duplicates, then aggregate and average them.