[Bug]: COUNT(*) overcounts updated rows in filtered scans
Maintainers usually reply within 1 day
@XuPeng-SH is already working on this.
Since Nov 26, 2026.
Assessment
This issue has not been assessed yet.
Description
Summary
On MatrixOne main, a filtered COUNT(*) returns more rows than the distinct primary-key count after updating a column used by the filter. The discrepancy remains after flushing the table and running ANALYZE TABLE.
Reproduction
CREATE DATABASE count_star_repro;
USE count_star_repro;
CREATE TABLE fact (id INT PRIMARY KEY, bucket INT);
INSERT INTO fact
SELECT result, result % 100
FROM generate_series(1, 10000) g;
-- Uniform control: bucket=0 has 100 rows.
SELECT COUNT(*) AS rows, COUNT(DISTINCT id) AS unique_rows
FROM fact WHERE bucket = 0;
-- Expected: 100, 100
-- Keep NDV=100 while making bucket=0 a hot value.
UPDATE fact SET bucket = 0 WHERE id <= 9000;
SELECT COUNT(*) AS rows,
COUNT(DISTINCT id) AS unique_rows,
SUM(bucket = 0) AS predicate_sum
FROM fact WHERE bucket = 0;
-- Expected: 9010, 9010, 9010
-- Observed on main: 9091, 9010, 9010
SELECT mo_ctl('dn', 'flush', 'count_star_repro.fact');
ANALYZE TABLE fact;
SELECT COUNT(*) AS rows, COUNT(DISTINCT id) AS unique_rows
FROM fact WHERE bucket = 0;
-- Still observed: 9091, 9010
The same overcount appears when joining fact to a dimension table with one primary-key row for each bucket. Thus the join does not introduce duplicate matches. The MOTR regression fixture is 10_optimizer/s-4_8.
Environment and plan observations
Reproduced against MatrixOne main at ca5325ce683a60ef6d7f0888b68d709de2ea8389 on a fresh isolated cluster. EXPLAIN VERBOSE uses starcount(1) for COUNT(*); the filtered scan estimates 100 rows before and after ANALYZE, while the exact primary-key count is 9010.
The skew selectivity estimate is tracked separately in #31994. This report is about the SQL result mismatch. It is also distinct from #33168's 4.2-dev single-remote-scan/materialized-summary scenario: this repro is a local filtered scan on main and does not use a remote CN or a summary table.
Expected behavior
COUNT(*), COUNT(DISTINCT id), and SUM(bucket = 0) should agree for this single-table predicate because id is a primary key and every qualifying row has one unique ID. Flushing or analyzing statistics must not change the result.
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 312
- Avg merge
- 22h 59m
- Merged PRs (30d)
- 736
Getting set up
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.
More from matrixorigin/matrixone
-
kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
matrixorigin/matrixone#33363 ·
Maintainers usually reply within 1 day
-
kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
matrixorigin/matrixone#33362 ·
Maintainers usually reply within 1 day
-
SLEEP rejects NULL and negative durations that MySQL acceptsPossibly taken @XuPeng-SH claimed this 7 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
matrixorigin/matrixone#32653 ·
Maintainers usually reply within 1 day
-
[Bug]: TestChangeWatchProxy loses its first tenant connection during PingContext in Ubuntu CIPossibly taken @XuPeng-SH claimed this today. Openkind/bug needs-triage
matrixorigin/matrixone#33371 · 1 assignee ·
Maintainers usually reply within 1 day
-
[Bug]: TestDaemonClaimSQLRoundTrip exhausts its shared deadline during the stale claim update in Ubuntu CIPossibly taken @XuPeng-SH claimed this today. Openkind/bug needs-triage
matrixorigin/matrixone#33370 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in matrixorigin/matrixone
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
zalando/postgres-operator#3257 ·
Maintainers usually reply within 2 days
-
[inputs.internal] README lists go_version tag on internal_gather instead of internal_agentPossibly taken @cvas22 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 90/100
influxdata/telegraf#20264 ·
Maintainers usually reply within 1 day
-
[Bug] Standalone migration breaks existing Ingress routes using the envoy-http Service port nameOpenaccepted bug wg/enterprise-environment
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vllm-project/semantic-router#7483 · 1 comment ·
Maintainers usually reply within 1 day
-
needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
stacklok/toolhive-catalog#2076 ·
Maintainers usually reply within 1 day