starocean999 opened a new pull request, #17913:
URL: https://github.com/apache/doris/pull/17913
# Proposed changes
Issue Number: close #xxx
## Problem summary
if the order by keys are not simple slot in sort node, the order by exprs
have to been added to sort node's output tuple. In that case, we need add a
project node above sort node to eliminate the unused order by exprs. for
example:
WITH t0 AS
(SELECT DATE_FORMAT(date,
'%Y%m%d') AS date
FROM cir_1756_t1 ), t3 AS
(SELECT date_format(date,
'%Y%m%d') AS `date`
FROM `cir_1756_t2`
GROUP BY date_format(date, '%Y%m%d')
**ORDER BY date_format(date, '%Y%m%d')** )
SELECT t0.date
FROM t0
LEFT JOIN t3
ON t0.date = t3.date;
before:
```
+--------------------------------------------------------------------------------------------------------------------------------------------------+
| Explain String
|
+--------------------------------------------------------------------------------------------------------------------------------------------------+
| LogicalProject[159] ( distinct=false, projects=[date#1], excepts=[],
canEliminate=true ) |
| +--LogicalJoin[158] ( type=LEFT_OUTER_JOIN,
markJoinSlotReference=Optional.empty, hashJoinConjuncts=[(date#1 = date#3)],
otherJoinConjuncts=[] ) |
| |--LogicalProject[151] ( distinct=false, projects=[date_format(date#0,
'%Y%m%d') AS `date`#1], excepts=[], canEliminate=true ) |
| | +--LogicalOlapScan ( qualified=default_cluster:bugfix.cir_1756_t1,
indexName=cir_1756_t1, selectedIndexId=412339, preAgg=ON ) |
| +--LogicalSort[157] ( orderKeys=[date_format(cast(date#3 as DATETIME),
'%Y%m%d') asc null first] ) |
| +--LogicalAggregate[156] ( groupByExpr=[date#3],
outputExpr=[date#3], hasRepeat=false )
|
| +--LogicalProject[155] ( distinct=false,
projects=[date_format(date#2, '%Y%m%d') AS `date`#3], excepts=[],
canEliminate=true ) |
| +--LogicalOlapScan (
qualified=default_cluster:bugfix.cir_1756_t2, indexName=cir_1756_t2,
selectedIndexId=412352, preAgg=ON ) |
+--------------------------------------------------------------------------------------------------------------------------------------------------+
```
after:
```
+--------------------------------------------------------------------------------------------------------------------------------------------------+
| Explain String
|
+--------------------------------------------------------------------------------------------------------------------------------------------------+
| LogicalProject[171] ( distinct=false, projects=[date#2], excepts=[],
canEliminate=true ) |
| +--LogicalJoin[170] ( type=LEFT_OUTER_JOIN,
markJoinSlotReference=Optional.empty, hashJoinConjuncts=[(date#2 = date#4)],
otherJoinConjuncts=[] ) |
| |--LogicalProject[162] ( distinct=false, projects=[date_format(date#0,
'%Y%m%d') AS `date`#2], excepts=[], canEliminate=true ) |
| | +--LogicalOlapScan ( qualified=default_cluster:bugfix.cir_1756_t1,
indexName=cir_1756_t1, selectedIndexId=1049812, preAgg=ON ) |
| +--LogicalProject[169] ( distinct=false, projects=[date#4], excepts=[],
canEliminate=false ) |
| +--LogicalSort[168] ( orderKeys=[date_format(cast(date#4 as
DATETIME), '%Y%m%d') asc null first] ) |
| +--LogicalAggregate[167] ( groupByExpr=[date#4],
outputExpr=[date#4], hasRepeat=false )
|
| +--LogicalProject[166] ( distinct=false,
projects=[date_format(date#3, '%Y%m%d') AS `date`#4], excepts=[],
canEliminate=true ) |
| +--LogicalOlapScan (
qualified=default_cluster:bugfix.cir_1756_t2, indexName=cir_1756_t2,
selectedIndexId=1049825, preAgg=ON ) |
+--------------------------------------------------------------------------------------------------------------------------------------------------+
```
## Checklist(Required)
* [ ] Does it affect the original behavior
* [ ] Has unit tests been added
* [ ] Has document been added or modified
* [ ] Does it need to update dependencies
* [ ] Is this PR support rollback (If NO, please explain WHY)
## Further comments
If this is a relatively large or complex change, kick off the discussion at
[[email protected]](mailto:[email protected]) by explaining why you
chose the solution you did and what alternatives you considered, etc...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]