qidaye opened a new issue #6399: URL: https://github.com/apache/incubator-doris/issues/6399
**Describe the bug** Given the analysis process before rewrite, when collect constant exprs in `FoldConstantRule`, there is no necessary reanalyzing the expr. When reanalyzing the expr in the subquery, Doris current only supports to associate the outer query columns in parent level. See https://github.com/apache/incubator-doris/blob/d9fc1bf3ca67b2f0d8925425cf9a4362829f8b62/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java#L630-L640 When a expr is associating the grandparent level, there will be a exception. Because the single expr does not contain the parent information. **To Reproduce** Steps to reproduce the behavior: 1. Create table ```sql CREATE TABLE `test` ( `vehicleId` int(11) NOT NULL COMMENT "", `workDateTime` datetime NOT NULL COMMENT "", `vinCode` varchar(64) NULL COMMENT "", `modelCode` varchar(64) NULL COMMENT "", `saleOrgName` varchar(150) NULL COMMENT "", `serviceOrgName` varchar(150) NULL COMMENT "", `dayWorkHours` decimal(20, 3) NULL COMMENT "", `actualHours` decimal(10, 3) NULL COMMENT "", `idleHours` decimal(10, 3) NULL COMMENT "", `totalWorkHours` decimal(20, 3) NULL COMMENT "", `totalFuel` decimal(20, 3) NULL COMMENT "", `dayFuel` decimal(20, 3) NULL COMMENT "", `adminDivisionCode` varchar(64) NULL COMMENT "", `idleErrorType` int(11) NULL COMMENT "", `oilErrorType` int(11) NULL COMMENT "", `createdOn` datetime NULL COMMENT "" ) ENGINE=OLAP UNIQUE KEY(`vehicleId`, `workDateTime`) DISTRIBUTED BY HASH(`vehicleId`, `workDateTime`) BUCKETS 10 PROPERTIES ( "replication_num" = "1", "in_memory" = "false", "storage_format" = "DEFAULT" ); ``` 2. Enable fold constant by BE ```sql set enable_fold_constant_by_be=true; ``` 3. Submit a query The `workDateTime` field is the grandchild in subquery `bb`. ```sql WITH aa AS (SELECT DATE_FORMAT(workDateTime, '%Y-%m') mon, vincode, sum(dayworkhours) AS workhours FROM test WHERE workDateTime >= concat(year(now())-1, '-01-01 00:00:00') AND workDateTime < now() GROUP BY vincode, DATE_FORMAT(workDateTime, '%Y-%m')), bb AS (SELECT mon, count(DISTINCT vincode) total FROM aa GROUP BY mon), cc AS (SELECT mon, count(DISTINCT vincode) num FROM aa WHERE aa.workhours >= 0 GROUP BY mon) SELECT bb.mon, round(cc.num / bb.total, 4) rate FROM bb LEFT JOIN cc ON cc.mon = bb.mon ORDER BY mon LIMIT 0, 5000; ``` 4. See error ```sql errCode = 2, detailMessage = Unknown column 'workDateTime' in 'table list' ``` # How to fix Since the reanalyzing in `getConstExpr` is redundant, we should remove it. -- 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]
