Skip to content

Conversation

@seawinde
Copy link
Contributor

@seawinde seawinde commented Nov 6, 2025

Versions

  • dev
  • 4.x
  • 3.x
  • 2.1

Languages

  • Chinese
  • English

Docs Checklist

  • Checked by AI
  • Test Cases Built

starocean999 pushed a commit to apache/doris that referenced this pull request Nov 18, 2025
…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 bot pushed a commit to apache/doris that referenced this pull request Nov 18, 2025
…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;
```
@morrySnow morrySnow merged commit f164f26 into apache:master Nov 26, 2025
1 check passed
nagisa-kunhah pushed a commit to nagisa-kunhah/doris that referenced this pull request Dec 14, 2025
…ains limit or topN (apache#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;
```
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.

2 participants