Distinct aggregations over TABLESAMPLE see different rows in Memory connector
Author: jiwen624Created Sep 17, 2026Updated Sep 17, 2026
Trino version
483
Please describe the bug
MultipleDistinctAggregationsToSubqueries reads the source once per distinct aggregation. The Memory connector samples each page independently, so each copy of a sampled scan reads different rows.
With a = b in every row (10,000 rows, inserted in 20 batches of 500):
SELECT count(DISTINCT a), count(DISTINCT b) FROM t TABLESAMPLE SYSTEM (50)Expected: two equal counts. Actual (default settings): the counts usually differ and change between runs, e.g. 7500, 2500. Memory is the only connector affected: it is the only one that both pushes down sampling and allows split reads.
Related: #31151
Source: trinodb/trino