Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Two phase topn batch plan generation is incorrect when input is singleton. #14900

Closed
liurenjie1024 opened this issue Jan 31, 2024 · 1 comment · Fixed by #15045
Closed
Assignees
Labels
type/bug Something isn't working
Milestone

Comments

@liurenjie1024
Copy link
Contributor

Describe the bug

When generation 2 phase topn plan for batch query, and the input is singleton, the result is incorrect.

Error message/log

No response

To Reproduce

CREATE TABLE t1 (
    pk int, 
    a int, 
    b int,
    c bigint,
    d int
);

CREATE MATERIALIZED VIEW t1_mv AS
SELECT SUM(a) as sa, SUM(b) as sb, SUM(c) as sc, SUM(d) as sd FROM t1;

EXPLAIN
SELECT sa, count(*) as cnt2 
FROM t1_mv GROUP BY sa ORDER BY cnt2 DESC LIMIT 50 OFFSET 50;

The result is:

dev=> EXPLAIN
SELECT sa, count(*) as cnt2
FROM t1_mv GROUP BY sa ORDER BY cnt2 DESC LIMIT 50 OFFSET 50;
                                QUERY PLAN
--------------------------------------------------------------------------
 BatchExchange { order: [count DESC], dist: Single }
 └─BatchTopN { order: [count DESC], limit: 100, offset: 0 }
   └─BatchSimpleAgg { aggs: [internal_last_seen_value(t1_mv.sa), count] }
     └─BatchScan { table: t1_mv, columns: [sa] }
(4 rows)

Expected behavior

The topn should still be offset 50, limit 50.

How did you deploy RisingWave?

Docker.

The version of RisingWave

dev=> select version() ;
                                      version
------------------------------------------------------------------------------------
 PostgreSQL 9.5.0-RisingWave-1.7.0-alpha (fb42759622c52f682c6b905d887f8c2c3591c80d)
(1 row)

Additional context

No response

@liurenjie1024 liurenjie1024 added the type/bug Something isn't working label Jan 31, 2024
@github-actions github-actions bot added this to the release-1.7 milestone Jan 31, 2024
@liurenjie1024
Copy link
Contributor Author

I think this bug is this line, we should return self rather input.

cc @chenzl25

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants