Skip to content

[Bug] 在明细模型上建立物化视图后,聚合查询结果不正确 #27277

Closed

Description

@eleven-f

Search before asking

  • I had searched in the issues and found no similar issues.

Version

2.0.2

What's Wrong?

按照官方文档,创建明细基表:
create table sales_records(record_id int, seller_id int, store_id int, sale_date date, sale_amt bigint) distributed by hash(record_id) properties("replication_num" = "1");

建立物化视图:
create materialized view store_amt as select store_id, sum(sale_amt) from sales_records group by store_id;

插入数据:
insert into sales_records values(1,1,1,"2020-02-02",1),(1,2,2,"2020-02-02",1);
注意:这里store_id 不同。

查询聚合数据:
SELECT store_id, sum(sale_amt) FROM sales_records GROUP BY store_id;
结果:
image
期望结果:
应该有两条结果,分别表示 store_id=1和store_id=2的汇聚结果。

explain确认走了物化视图:
EXPLAIN SELECT store_id, sum(sale_amt) FROM sales_records GROUP BY store_id;
image

另外:当我先建立明细表,然后插入多条明细数据,再建立物化视图后,查询结果是正确的,但当再次插入数据后,结果就不正确了。

What You Expected?

分组聚合结果正确

How to Reproduce?

按照问题里步骤操作

Anything Else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. eleven-f commented on Nov 20, 2023

    @eleven-f
    Author

    进一步测试发现,在insert into values跟一条数据的情况下,统计是正确的,但同时插入多条数据时,结果是错误的。

  2. BiteTheDDDDt commented on Nov 20, 2023

    @BiteTheDDDDt
    Contributor

    very thanks for your report,I fix it on #27297.

  3. eleven-f commented on Nov 22, 2023

    @eleven-f
    Author

    请问什么时候能发布啊,2.0.2版本太多问题了,迫切需要发布新版解决。
    master编译报错,跑不通···

  4. BiteTheDDDDt commented on Nov 22, 2023

    @BiteTheDDDDt
    Contributor

    we will release 2.0.3 on next week.

  5. BiteTheDDDDt commented on Dec 14, 2023

    @BiteTheDDDDt
    Contributor

    @BiteTheDDDDt 物化视图仍然存在问题。

    在2.0.3 使用聚合模型,然后建立物化视图后,查询走物化视图得结果和不走物化视图得结果不一致。 走物化视图: image 不走物化视图: image

    Can you provide a reproduction method?

  6. eleven-f commented on Dec 14, 2023

    @eleven-f
    Author

    抱歉,这个可能是个乌龙,我们得BE节点没有正确升级。

  7. eleven-f commented on Dec 14, 2023

    @eleven-f
    Author

    测试2.0.3上正常,可以关闭。
    给你带来麻烦十分抱歉。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions