Skip to content

Conversation

@github-actions
Copy link
Contributor

Cherry-picked from #55194

…ains limit or topN (#55194)

Support limit or topN rewrite when materialized view contains limit or
topN

the doc pr is apache/doris-website#3059

such as mv def is as fllowing
```sql
        CREATE MATERIALIZED VIEW mv_with_limit
        BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL
        DISTRIBUTED BY RANDOM BUCKETS 2
        PROPERTIES ('replication_num' = '1') 
        AS
            select
            o_orderdate,
            o_shippriority,
            o_comment
            from
            orders
            limit 4 offset 2;
```

query is as following which can be rewritten success by mv
`mv_with_limit` above
```sql
            select
            o_orderdate,
            o_shippriority,
            o_comment
            from
            orders
            limit 2 offset 3;
```


another example:
such as mv def is as fllowing
```sql
        CREATE MATERIALIZED VIEW mv_with_topN
        BUILD IMMEDIATE REFRESH COMPLETE ON MANUAL
        DISTRIBUTED BY RANDOM BUCKETS 2
        PROPERTIES ('replication_num' = '1') 
        AS
            select
            o_orderdate,
            o_shippriority,
            o_comment
            from
            orders
            order by o_orderkey
            limit 4 offset 2;
```

query is as following which can be rewritten success by mv
`mv_with_topN` above
```sql
            select
            o_orderdate,
            o_shippriority,
            o_comment
            from
            orders
            order by o_orderkey
            limit 2 offset 5;
```
@github-actions github-actions bot requested a review from yiguolei as a code owner November 18, 2025 07:31
@Thearas
Copy link
Contributor

Thearas commented Nov 18, 2025

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@Thearas
Copy link
Contributor

Thearas commented Nov 18, 2025

run buildall

@hello-stephen
Copy link
Contributor

FE UT Coverage Report

Increment line coverage 41.95% (159/379) 🎉
Increment coverage report
Complete coverage report

@yiguolei yiguolei closed this Nov 25, 2025
@yiguolei yiguolei reopened this Nov 25, 2025
@yiguolei yiguolei merged commit a78fe2e into branch-4.0 Nov 26, 2025
25 of 27 checks passed
@github-actions github-actions bot deleted the auto-pick-55194-branch-4.0 branch November 26, 2025 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants