This is an automated email from the ASF dual-hosted git repository.
dataroaring pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 90af1b0113 [fix](subquery) fix bug of using constexpr and some agg
func(like count,max) as subquery's output (#16579)
90af1b0113 is described below
commit 90af1b01132010c70659453663ffb57ff522470c
Author: xueweizhang <[email protected]>
AuthorDate: Tue Feb 14 00:11:56 2023 +0800
[fix](subquery) fix bug of using constexpr and some agg func(like
count,max) as subquery's output (#16579)
Signed-off-by: nextdreamblue <[email protected]>
---
.../java/org/apache/doris/analysis/SelectStmt.java | 7 +-
.../test_outer_join_with_subquery.out | 74 +++++++
.../test_outer_join_with_subquery.groovy | 229 +++++++++++++++++++++
3 files changed, 308 insertions(+), 2 deletions(-)
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 4b84dd0a86..540e1b25e4 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
@@ -898,10 +898,13 @@ public class SelectStmt extends QueryStmt {
}
boolean hasConstant = resultExprs.stream().anyMatch(e ->
e.isConstant() || e.refToCountStar());
// In such case, agg output must be materialized whether outer
query block required or not.
- if (tableRef instanceof InlineViewRef && hasConstant) {
+ if (tableRef instanceof InlineViewRef) {
InlineViewRef inlineViewRef = (InlineViewRef) tableRef;
QueryStmt queryStmt = inlineViewRef.getQueryStmt();
- queryStmt.resultExprs.forEach(Expr::materializeSrcExpr);
+ boolean inlineViewHasConstant =
queryStmt.resultExprs.stream().anyMatch(Expr::isConstant);
+ if (hasConstant || inlineViewHasConstant) {
+ queryStmt.resultExprs.forEach(Expr::materializeSrcExpr);
+ }
}
}
}
diff --git
a/regression-test/data/correctness_p0/test_outer_join_with_subquery.out
b/regression-test/data/correctness_p0/test_outer_join_with_subquery.out
index 875d88ccc5..e7f2cb8a09 100644
--- a/regression-test/data/correctness_p0/test_outer_join_with_subquery.out
+++ b/regression-test/data/correctness_p0/test_outer_join_with_subquery.out
@@ -5,3 +5,77 @@
-- !select --
1
+-- !select --
+1
+
+-- !select --
+
+-- !select --
+aaa
+
+-- !select --
+1
+
+-- !select --
+1 aaa
+
+-- !select --
+0
+
+-- !select --
+1 aaa
+
+-- !select --
+0 aaa
+
+-- !select --
+1 aaa
+
+-- !select --
+0 aaa
+
+-- !select --
+1
+
+-- !select --
+0
+
+-- !select --
+1
+
+-- !select --
+0 \N
+
+-- !select --
+0 \N
+
+-- !select --
+1 100
+
+-- !select --
+1 100
+
+-- !select --
+1 0
+
+-- !select --
+1 100
+
+-- !select --
+\N
+
+-- !select --
+\N
+
+-- !select --
+100
+
+-- !select --
+100
+
+-- !select --
+0
+
+-- !select --
+100
+
diff --git
a/regression-test/suites/correctness_p0/test_outer_join_with_subquery.groovy
b/regression-test/suites/correctness_p0/test_outer_join_with_subquery.groovy
index 97de116ca1..c8ccb9d220 100644
--- a/regression-test/suites/correctness_p0/test_outer_join_with_subquery.groovy
+++ b/regression-test/suites/correctness_p0/test_outer_join_with_subquery.groovy
@@ -110,4 +110,233 @@ suite("test_outer_join_with_subquery") {
sql """
drop table if exists test_outer_join_with_subquery_outerjoin_B;
"""
+
+ ////////////////////////////////////
+
+ sql """
+ drop table if exists test_outer_join_with_subquery_outerjoin_A_1;
+ """
+
+ sql """
+ drop table if exists test_outer_join_with_subquery_outerjoin_B_1;
+ """
+
+ sql """
+ drop table if exists test_outer_join_with_subquery_outerjoin_C_1;
+ """
+
+ sql """
+ drop table if exists test_outer_join_with_subquery_outerjoin_D_1;
+ """
+
+ sql """
+ CREATE TABLE test_outer_join_with_subquery_outerjoin_A_1(user_id int
NULL)
+ ENGINE = OLAP DUPLICATE KEY(user_id) DISTRIBUTED BY HASH(user_id)
BUCKETS 1 PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1",
+ "in_memory" = "false",
+ "storage_format" = "V2"
+ );
+ """
+
+ sql """
+ CREATE TABLE test_outer_join_with_subquery_outerjoin_B_1(user_id int
NULL)
+ ENGINE = OLAP DUPLICATE KEY(user_id) DISTRIBUTED BY HASH(user_id)
BUCKETS 1 PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1",
+ "in_memory" = "false",
+ "storage_format" = "V2"
+ );
+ """
+
+ sql """
+ CREATE TABLE test_outer_join_with_subquery_outerjoin_C_1(user_id int
NULL)
+ ENGINE = OLAP DUPLICATE KEY(user_id) DISTRIBUTED BY HASH(user_id)
BUCKETS 1 PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1",
+ "in_memory" = "false",
+ "storage_format" = "V2"
+ );
+ """
+
+ sql """
+ CREATE TABLE test_outer_join_with_subquery_outerjoin_D_1(user_id int
NULL)
+ ENGINE = OLAP DUPLICATE KEY(user_id) DISTRIBUTED BY HASH(user_id)
BUCKETS 1 PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1",
+ "in_memory" = "false",
+ "storage_format" = "V2"
+ );
+ """
+
+ qt_select """
+ WITH W1 AS (
+ SELECT
+ t.user_id
+ FROM
+ test_outer_join_with_subquery_outerjoin_A_1 t
+ JOIN test_outer_join_with_subquery_outerjoin_B_1 u ON
u.user_id = t.user_id
+ ),
+ W2 AS (
+ SELECT
+ t.user_id
+ FROM
+ test_outer_join_with_subquery_outerjoin_C_1 t
+ JOIN test_outer_join_with_subquery_outerjoin_B_1 u ON
u.user_id = t.user_id
+ GROUP BY
+ t.user_id
+ ),
+ W3 AS (
+ SELECT
+ t.user_id
+ FROM
+ test_outer_join_with_subquery_outerjoin_D_1 t
+ JOIN test_outer_join_with_subquery_outerjoin_B_1 u ON
u.user_id = t.user_id
+ GROUP BY
+ t.user_id
+ )
+ SELECT
+ COUNT(dataset_30.reg_user_cnt) AS u_18efaea722a8747c_2
+ FROM
+ (
+ SELECT
+ t1.reg_user_cnt,
+ t2.commit_case_user_cnt,
+ t3.watch_live_course_and_commit_case_user_cnt
+ FROM
+ (
+ SELECT
+ COUNT(user_id) AS reg_user_cnt,
+ '1' AS flag
+ FROM
+ W1
+ ) t1
+ JOIN (
+ SELECT
+ COUNT(user_id) AS commit_case_user_cnt,
+ '1' AS flag
+ FROM
+ W2
+ ) t2 ON t2.flag = t1.flag
+ JOIN (
+ SELECT
+ COUNT(t1.user_id) AS
watch_live_course_and_commit_case_user_cnt,
+ '1' AS flag
+ FROM
+ W2 t1
+ JOIN W3 t2 ON t2.user_id = t1.user_id
+ ) t3 ON t3.flag = t1.flag
+ ) dataset_30
+ LIMIT
+ 1000;
+ """
+
+ qt_select """
+ select 'aaa' from( select 'bbb' FROM
test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+ qt_select """
+ select 'aaa' from( select 'bbb' ,count(1) FROM
test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+ qt_select """
+ select count(1) from( select 'bbb' ,count(1) FROM
test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+ qt_select """
+ select count(1), 'aaa' from( select 'bbb' ,count(1) FROM
test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+ qt_select """
+ select count(1) from( select 'bbb' FROM
test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+ qt_select """
+ select count(1), 'aaa' from( select count(1) FROM
test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+ qt_select """
+ select count(1), 'aaa' from( select 'bbb' FROM
test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+ qt_select """
+ select count(1), 'aaa' from( select count(1) FROM ( select count(1)
FROM test_outer_join_with_subquery_outerjoin_A_1 )s )t;
+ """
+
+ qt_select """
+ select count(1), 'aaa' from( select 'bbb' FROM ( select 'bbb' FROM
test_outer_join_with_subquery_outerjoin_A_1 )s )t;
+ """
+
+ qt_select """
+ select count(1) from( select count(1) FROM ( select count(1) FROM
test_outer_join_with_subquery_outerjoin_A_1 )s )t;
+ """
+
+ qt_select """
+ select count(1) from( select 'bbb' FROM ( select 'bbb' FROM
test_outer_join_with_subquery_outerjoin_A_1 )s )t;
+ """
+
+ qt_select """
+ select count(1) from( select 'bbb',count(1) FROM ( select
'bbb',count(1) FROM test_outer_join_with_subquery_outerjoin_A_1 )s )t;
+ """
+
+ qt_select """
+ select count(1), max(user_id) from( select user_id FROM
test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+ qt_select """
+ select count(1), max(user_id) from( select user_id FROM ( select
user_id FROM test_outer_join_with_subquery_outerjoin_A_1 )s )t;
+ """
+
+ qt_select """
+ select count(1), max(user_id) from( select count(1), 100 as user_id
FROM test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+ qt_select """
+ select count(1), max(user_id) from( select 100 as user_id FROM (
select max(user_id) FROM test_outer_join_with_subquery_outerjoin_A_1 )s )t;
+ """
+
+ qt_select """
+ select count(1), max(user_id) from( select user_id FROM ( select
count(1) as user_id, 'abc' FROM test_outer_join_with_subquery_outerjoin_A_1 )s
)t;
+ """
+
+ qt_select """
+ select count(1), max(user_id) from( select max(user_id), 100 as
user_id FROM test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+qt_select """
+ select max(user_id) from( select user_id FROM
test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+ qt_select """
+ select max(user_id) from( select user_id FROM ( select user_id FROM
test_outer_join_with_subquery_outerjoin_A_1 )s )t;
+ """
+
+ qt_select """
+ select max(user_id) from( select count(1), 100 as user_id FROM
test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+ qt_select """
+ select max(user_id) from( select 100 as user_id FROM ( select
max(user_id) FROM test_outer_join_with_subquery_outerjoin_A_1 )s )t;
+ """
+
+ qt_select """
+ select max(user_id) from( select user_id FROM ( select count(1) as
user_id, 'abc' FROM test_outer_join_with_subquery_outerjoin_A_1 )s )t;
+ """
+
+ qt_select """
+ select max(user_id) from( select max(user_id), 100 as user_id FROM
test_outer_join_with_subquery_outerjoin_A_1 )t;
+ """
+
+ sql """
+ drop table if exists test_outer_join_with_subquery_outerjoin_A_1;
+ """
+
+ sql """
+ drop table if exists test_outer_join_with_subquery_outerjoin_B_1;
+ """
+
+ sql """
+ drop table if exists test_outer_join_with_subquery_outerjoin_C_1;
+ """
+
+ sql """
+ drop table if exists test_outer_join_with_subquery_outerjoin_D_1;
+ """
}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]