[Bug]: COUNT(*) overcounts updated rows in filtered scans

Aperta
#33,248 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@XuPeng-SH ci sta già lavorando.

Dal 26/11/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

severity/s0

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.

Lingua principale
Go
Stelle
1.9k
Fork
312
Merge medio
22h 59m
PR unite (30g)
736

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di matrixorigin/matrixone

Tutte le issue di matrixorigin/matrixone

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.