You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ignite使用GROUP BY与IN查询时出现计数结果异常问题

GridGain Community 8.8.25 GROUP BY + IN子句导致count(*)计数翻倍问题

问题场景

  • 表结构:包含date、id、info三个字段
  • 数据状态:id为'a'的记录在2023-07-03和2023-07-04各有3条;id为'b'的记录完全不存在
  • 执行的SQL语句:
select date, count(*) from table where id in ('a', 'b') and date between '2023-07-03' and '2023-07-04' group by date
  • 预期结果:2023-07-03和2023-07-04的count值均为3
  • 实际结果:每日count值均为6

问题根源

这是GridGain 8.8.25版本的SQL引擎bug:当IN子句中包含无对应数据的取值(比如这里的'b')时,查询引擎会错误地将已有数据与空结果集做笛卡尔积,导致符合条件的记录被重复统计,最终count值翻倍。

解决办法

  • 清理IN子句无效值:直接只保留存在数据的id,将SQL改为id in ('a'),能立刻得到正确的计数结果。
  • 用EXISTS替换IN子句:重构SQL避免笛卡尔积问题,示例如下:
select t.date, count(*) 
from table t 
where exists (
    select 1 from (select 'a' as id union all select 'b' as id) ids 
    where ids.id = t.id
)
and t.date between '2023-07-03' and '2023-07-04'
group by t.date
  • 升级版本:该bug在GridGain后续的8.8.x小版本及更高主版本中已被修复,升级到新版本可以彻底解决这个问题。

内容的提问来源于stack exchange,提问作者Vincent Y

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.17 07:52:07