morrySnow commented on issue #61219:
URL: https://github.com/apache/doris/issues/61219#issuecomment-4115064548
it is not a column prunning bug, it is a bug about topn lazy materialization
```sql
-- create table
create table t1(id int, c1 int, c2 int, c3 int, c4 int, standard_otd_time
datetime, delivered_time datetime);
-- insert some data
insert into t1 values(1, 1, 2, 3, 4, now(), now());
-- create view
CREATE OR REPLACE VIEW view_name AS
SELECT
id,
c1,
c2,
c3,
CASE
WHEN delivered_time IS NOT NULL THEN 'Delivered'
WHEN otd_now < 3 THEN 'Normal'
WHEN otd_now < 5 THEN 'Level1'
WHEN otd_now < 7 THEN 'Level2'
WHEN otd_now >= 7 THEN 'Level3'
ELSE NULL
END AS otd_status,
c4,
CURRENT_TIMESTAMP() AS data_update_time
FROM (
SELECT
*,
FLOOR(
TIMESTAMPDIFF(
HOUR,
DATE_SUB(standard_otd_time, INTERVAL 10 DAY),
COALESCE(delivered_time, CURRENT_TIMESTAMP())
) / 24
) AS otd_now
FROM t1
) t;
-- query it, the result is wrong
explain verbose SELECT *
FROM view_name
WHERE 1
ORDER BY data_update_time ASC, otd_status DESC
LIMIT 100;
```
result is:
```
+--------+--------+--------+--------+------------+--------+---------------------+
| id | c1 | c2 | c3 | otd_status | c4 | data_update_time
|
+--------+--------+--------+--------+------------+--------+---------------------+
| <null> | <null> | <null> | <null> | Delivered | <null> | 2026-03-24
10:58:33 |
+--------+--------+--------+--------+------------+--------+---------------------+
```
```sql
-- turn off topn set topn lazy materialization, then could get correct
result.
set topn_lazy_materialization_threshold = 0;
```
```
+----+----+----+----+------------+----+---------------------+
| id | c1 | c2 | c3 | otd_status | c4 | data_update_time |
+----+----+----+----+------------+----+---------------------+
| 1 | 1 | 2 | 3 | Delivered | 4 | 2026-03-24 10:58:25 |
+----+----+----+----+------------+----+---------------------+
```
--
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]