From 0302a9d0269dfda217255d5e7960b44063eae91e Mon Sep 17 00:00:00 2001 From: Jerry Hu Date: Wed, 22 Nov 2023 19:47:09 +0800 Subject: [PATCH] [fix](fe) slots in having clause should be set to need materialized (#27412) --- .../org/apache/doris/analysis/SelectStmt.java | 5 ++ .../test_two_phase_read_with_having.out | 5 ++ .../test_two_phase_read_with_having.groovy | 57 +++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 regression-test/data/query_p0/test_two_phase_read_with_having.out create mode 100644 regression-test/suites/query_p0/test_two_phase_read_with_having.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java index a9811cf4e0..dca02e091e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java @@ -698,6 +698,11 @@ public class SelectStmt extends QueryStmt { if (whereClause != null) { whereClause.collect(SlotRef.class, conjuntSlots); } + + if (havingClauseAfterAnalyzed != null) { + havingClauseAfterAnalyzed.collect(SlotRef.class, conjuntSlots); + } + resultSlots.removeAll(orderingSlots); resultSlots.removeAll(conjuntSlots); // reset slots need to do fetch column diff --git a/regression-test/data/query_p0/test_two_phase_read_with_having.out b/regression-test/data/query_p0/test_two_phase_read_with_having.out new file mode 100644 index 0000000000..39ab3b251b --- /dev/null +++ b/regression-test/data/query_p0/test_two_phase_read_with_having.out @@ -0,0 +1,5 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !test -- +10003 1 +10001 1 + diff --git a/regression-test/suites/query_p0/test_two_phase_read_with_having.groovy b/regression-test/suites/query_p0/test_two_phase_read_with_having.groovy new file mode 100644 index 0000000000..eda2240d4b --- /dev/null +++ b/regression-test/suites/query_p0/test_two_phase_read_with_having.groovy @@ -0,0 +1,57 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +suite("test_two_phase_read_with_having") { + + sql """ set enable_partition_topn = 1; """ + sql """ set topn_opt_limit_threshold = 1024; """ + sql """ set enable_two_phase_read_opt = 1; """ + + sql """ + drop table if exists `test_two_phase_read_with_having_tbl`; + """ + + sql """ + CREATE TABLE `test_two_phase_read_with_having_tbl` ( + `id` bigint(20) NOT null, + `account_id` bigint(20) DEFAULT NULL, + `queue_id` int(11) DEFAULT NULL, + `call_date` datetime DEFAULT NULL, + `loan_id_list` varchar(200) DEFAULT NULL + ) DUPLICATE KEY (`id`,`account_id`) + DISTRIBUTED BY HASH (`id`) BUCKETS 3 + PROPERTIES("replication_num" = "1"); + """ + + sql """ + INSERT INTO `test_two_phase_read_with_having_tbl` (id,`account_id`, `queue_id`, `call_date`, `loan_id_list`) VALUES + (10001, 10001, 23, '2023-08-24 10:00:00', '249073260533940345,249073260533940346'), + (10002, 10002, 23, '2023-08-25 12:00:00', '249073260533940347,249073260533940348'), + (10003, 10003, 23, '2023-08-26 14:00:00', '249073260533940345,249073260533940350'), + (10004, 10004, 23, '2023-08-27 16:00:00', '249073260533940351,249073260533940352'), + (10005, 10005, 23, '2023-08-28 18:00:00', '249073260533940346,249073260533940353'); + """ + + qt_test """ + select + `account_id` + ,FIND_IN_SET(249073260533940345,loan_id_list) as loan_id + from `test_two_phase_read_with_having_tbl` + where + `queue_id` in (23) and `call_date` >= '2023-08-23 20:33:11' and `call_date` <= '2023-11-20 20:33:11' having loan_id >= 1 + order by `id` desc limit 20 offset 0; + """ +} \ No newline at end of file