Mahesha Subrahamanya
06/12/2026, 5:20 AMcatalog1.db1.table1
WHERE
datetime__v >= *DATE_SUB*(*CURRENT_DATE*(), INTERVAL 5 DAY)
AND datetime__v < *CURRENT_DATE*()
)
AS act
JOIN catalog1.db1.table2 AS sent ON
act.col1 = sent.col2
AND sent.col4 = '1-b23673fe-cbff-462d-b3af-b2e7832a452c'
and act.datetime__v BETWEEN '2026-06-08' AND '2026-06-10')t
group by 1,2,3
we have to make this way to work in 4.1 same as 3.5 like below mentioned -
select
_act_date_,
col5,
col3,
*count*(*)
from
(
select
*DATE*( *convert_tz*(act.datetime__v, 'UTC', 'America/Detroit')) AS _act_date_ ,
sent.col5,
act.col6
FROM
(
SELECT
col1,
col2,
col3,
col4
FROM
catalog1.db1.table1
WHERE
datetime__v >= *DATE_SUB*(*CURRENT_DATE*(), INTERVAL 5 DAY)
AND datetime__v < *CURRENT_DATE*()
)
AS act
JOIN catalog1.db1.table2 AS sent ON
act.col1 = sent.col2
AND sent.col4 = '1-b23673fe-cbff-462d-b3af-b2e7832a452c'
and act.datetime__v BETWEEN '2026-06-08' AND '2026-06-10')t
group by 1,2,3Rocky
06/12/2026, 5:21 AMGROUP BY on expressions with `JOIN`s:
1. Iceberg Metadata and Data Cache Staleness (Bug #70522 / #65827)
Version 4.1 introduced more aggressive caching for Iceberg metadata and data files. A known issue (found in Issue #70522) reported that the iceberg_table_cache could occasionally serve stale or partial data, leading to "silent wrong results."
* Why the subquery works: By wrapping the logic in a subquery, you often force the optimizer to materialize a temporary result set or change the way it interacts with the cache, which can bypass certain "stale" plan paths.
* Action: Try disabling the Iceberg table cache temporarily to see if results match 3.5:
sql
SET enable_iceberg_table_cache = false;
2. Aggregate-Join Pushdown Optimization
StarRocks 4.1 features an enhanced optimizer that attempts to push aggregations (like your COUNT(*)) through joins to improve performance on data lakes. However, bugs were identified (e.g., #71856) where this rewrite produced incorrect results specifically for Iceberg base tables when complex expressions or timezones were involved.
* Why the subquery works: The subquery structure creates a "barrier" for the optimizer. In Query 1, the optimizer sees a flat JOIN + GROUP BY and tries to push the count into the scan. In Query 2, the aggregation happens on top of the subquery result, preventing the buggy pushdown.
* Action: Test by disabling aggregation pushdown:
sql
SET enable_materialized_view_agg_pushdown_rewrite = false;
3. Low Cardinality Optimization (#66768)
If your columns col5 or col6 have low cardinality (few unique values), StarRocks 4.1 may apply an optimization to speed up the GROUP BY. A bug was fixed in the 4.1 cycle where local-shuffle aggregations produced wrong results under this optimization.
* Action: You can test if this is the cause by disabling it:
sql
SET enable_low_cardinality_optimize = false;
4. Timezone/Date Evaluation in Pruning
In 4.1, there were changes to how convert_tz and DATE expressions are evaluated during partition pruning for external catalogs. If datetime__v is a partition column in Iceberg, 4.1 might be pruning partitions differently than 3.5 due to timezone interpretation.
* Note: Since your subquery works, it's more likely a grouping/aggregation logic issue (like point 2) than a data access/pruning issue.
Recommended Steps
To confirm which optimization is causing the discrepancy without rolling back, run your original query after setting these session variables:
1. SET enable_iceberg_table_cache = false; (Check for cache staleness)
2. SET enable_materialized_view_agg_pushdown_rewrite = false; (Check for buggy aggregate pushdown)
3. SET enable_low_cardinality_optimize = false; (Check for grouping optimization issues)
If any of these resolve the issue, it is a confirmed bug in the 4.1 optimizer. It is recommended to stay on the version where your results are verified (3.5) or upgrade to the latest patch release (e.g., 4.1.1 or 4.1.2) where many of these Iceberg-specific result issues were addressed.
References
• using_starrocks/async_mv/use_cases/query_rewrite_with_materialized_views.md
• release_notes/release-4.0.md
• release_notes/release-3.4.mdk sen
06/12/2026, 5:20 PM