Fix LOGICAL_ERROR for join_use_nulls=1 when JOIN contains const from SELECT

This commit is contained in:
Azat Khuzhin 2021-02-12 23:04:45 +03:00
parent f80137626a
commit cbeda6c60e
2 changed files with 15 additions and 1 deletions

View File

@ -230,8 +230,16 @@ void TableJoin::addJoinedColumn(const NameAndTypePair & joined_column)
void TableJoin::addJoinedColumnsAndCorrectNullability(ColumnsWithTypeAndName & columns) const
{
for (auto & col : columns)
{
if (leftBecomeNullable(col.type))
col.type = makeNullable(col.type);
{
/// No need to nullify constants
if (!(col.column && isColumnConst(*col.column)))
{
col.type = makeNullable(col.type);
}
}
}
for (const auto & col : columns_added_by_join)
{

View File

@ -11,5 +11,11 @@ FROM X
RIGHT JOIN Y ON (X.id + 1) = Y.id
SETTINGS join_use_nulls=1; -- { serverError 53 }
-- Logical error: 'Arguments of 'plus' have incorrect data types: '2' of type 'UInt8', '1' of type 'UInt8''.
-- Because 1 became toNullable(1), i.e.:
-- 2 UInt8 Const(size = 1, UInt8(size = 1))
-- 1 UInt8 Const(size = 1, Nullable(size = 1, UInt8(size = 1), UInt8(size = 1)))
SELECT 2+1 FROM system.one X RIGHT JOIN system.one Y ON X.dummy+1 = Y.dummy SETTINGS join_use_nulls = 1; -- { serverError 53 }
DROP TABLE X;
DROP TABLE Y;