diff --git a/dbms/src/Interpreters/ExpressionActions.h b/dbms/src/Interpreters/ExpressionActions.h index dd12a39b760..3588aceffe6 100644 --- a/dbms/src/Interpreters/ExpressionActions.h +++ b/dbms/src/Interpreters/ExpressionActions.h @@ -51,7 +51,6 @@ public: */ ARRAY_JOIN, - /// INNER|LEFT JOIN. JOIN, /// Reorder and rename the columns, delete the extra ones. The same column names are allowed in the result. diff --git a/dbms/src/Interpreters/ExpressionAnalyzer.cpp b/dbms/src/Interpreters/ExpressionAnalyzer.cpp index af50f485568..9e117e7b7f3 100644 --- a/dbms/src/Interpreters/ExpressionAnalyzer.cpp +++ b/dbms/src/Interpreters/ExpressionAnalyzer.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -2838,7 +2839,9 @@ void ExpressionAnalyzer::collectJoinedColumns(NameSet & joined_columns, NamesAnd && !joined_columns.count(col.name)) /// Duplicate columns in the subquery for JOIN do not make sense. { joined_columns.insert(col.name); - joined_columns_name_type.emplace_back(col.name, col.type); + + bool make_nullable = settings.join_use_nulls && (table_join.kind == ASTTableJoin::Kind::Left || table_join.kind == ASTTableJoin::Kind::Full); + joined_columns_name_type.emplace_back(col.name, make_nullable ? makeNullable(col.type) : col.type); } } } diff --git a/dbms/tests/queries/0_stateless/00549_join_use_nulls.reference b/dbms/tests/queries/0_stateless/00549_join_use_nulls.reference new file mode 100644 index 00000000000..204bf7ebef7 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00549_join_use_nulls.reference @@ -0,0 +1,2 @@ +0 0 \N +1 1 1 diff --git a/dbms/tests/queries/0_stateless/00549_join_use_nulls.sql b/dbms/tests/queries/0_stateless/00549_join_use_nulls.sql new file mode 100644 index 00000000000..d1b2c5060f9 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00549_join_use_nulls.sql @@ -0,0 +1,30 @@ +SET join_use_nulls = 1; + +DROP TABLE IF EXISTS test.null; +CREATE TABLE test.null (k UInt64, a String, b Nullable(String)) ENGINE = Log; + +INSERT INTO test.null SELECT + k, + a, + b +FROM +( + SELECT + number AS k, + toString(number) AS a + FROM system.numbers + LIMIT 2 +) +ANY LEFT JOIN +( + SELECT + number AS k, + toString(number) AS b + FROM system.numbers + LIMIT 1, 2 +) USING (k) +ORDER BY k ASC; + +SELECT * FROM test.null ORDER BY k, a, b; + +DROP TABLE test.null;