Skip to content

Conversation

@924060929
Copy link
Contributor

cherry pick from #54947

close apache#54577

optimize normalize window, only push down the expression's used slots to
bottom projects, which the expression not contains WindowFunction, so we
can push down more filter through window.

for this sql:
```sql
  select
    SUBSTR(orderdate,1,10) AS dt,
    ROW_NUMBER() OVER(PARTITION BY orderdate ORDER BY orderid DESC) AS rn
  from lineorders
  having dt = '2025-01-01'
```
we not push down the `dt` slot under LogicalWindow, but push down
[orderdate, orderid]
to the bottom projects, because if we push down `dt`, the plan tree will
be:
```
            LogicalFilter(substr(dt#3, 1, 10) = '2025-01-01')
                                    |
     LogicalWindow(rowNumber(partition by orderdate#2, order by orderid#1))
                                    |
  LogicalProject(orderid#1, orderdate#2, substr(orderdate#1, 1, 10) as dt#3)
```

and can not push down filter by `PushDownFilterThroughWindow`, causing
inefficiency,
because dt#3 in LogicalFilter not contains in the partition key in
LogicalWindow: [orderdate#2].

so we only push down orderdate in the LogicalFilter, not push down `dt`:

```
     LogicalFilter(substr(orderdate#2, 1, 10) = '2025-01-01')
                              |
     LogicalWindow(rowNumber(partition by orderdate#2, order by orderid#1))
                              |
            LogicalProject(orderid#1, orderdate#2)
```

and then, `PushDownFilterThroughWindow` found the LogicalFilter's
`orderdate#2` contains
in the LogicalWindow's partition key: [orderdate#2], and can push down
filter to:

```
  LogicalWindow(rowNumber(partition by orderdate#2, order by orderid#1))
                              |
            LogicalProject(orderid#1, orderdate#2)
                             |
    LogicalFilter(substr(orderdate#2, 1, 10) = '2025-01-01')
```

(cherry picked from commit 0e669b9)
@924060929 924060929 requested a review from yiguolei as a code owner August 20, 2025 04:16
@Thearas
Copy link
Contributor

Thearas commented Aug 20, 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?

@924060929
Copy link
Contributor Author

run buildall

@yiguolei yiguolei merged commit fcc4635 into apache:branch-2.1 Aug 22, 2025
22 checks passed
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.

3 participants