Skip to content

UNION ALL + INNER JOIN = Block structure mismatch #12602

Closed

Description

@wendelb

Describe the unexpected behaviour

Union All in combination with joins breaks when upgrading to Clickhouse 20.5.2.7

How to reproduce

  • Which ClickHouse server version to use: 20.5.2.7
  • Which interface to use, if matters: HTTP (but should not matter)
  • Non-default settings, if any (none that I am aware of)

Please see the following queries:

CREATE TABLE tableCommon (
	`key` FixedString(15),
	`value` Nullable(Int8)
) ENGINE = Log();

CREATE TABLE tableTrees (
	`key` FixedString(15),
	`name` Nullable(Int8),
	`name2` Nullable(Int8)
) ENGINE = Log();

CREATE TABLE tableFlowers (
	`key` FixedString(15),
	`name` Nullable(Int8)
) ENGINE = Log()
;

SELECT * FROM (
	SELECT common.key, common.value, trees.name, trees.name2
	FROM (
		SELECT *
		FROM tableCommon
	) as common
	INNER JOIN (
		SELECT *
		FROM tableTrees
	) trees ON (common.key = trees.key)
)
UNION ALL
(
	SELECT common.key, common.value, 
	-- Variant 1
	null as name, null as name2 
	
	-- OR Variant 2
	-- flowers.name, null as name2
	FROM (
		SELECT *
		FROM tableCommon
	) as common
	INNER JOIN (
		SELECT *
		FROM tableFlowers
	) flowers ON (common.key = flowers.key)
)

Expected behavior
The query should run without an error.

Error message and/or stacktrace
The query returns the following error:

ClickHouse exception, code: 171, host: my.clickhouse.host, port: 8080; Code: 171, e.displayText() = DB::Exception: Block structure mismatch in  function connect between Converting and Concat stream: different number of columns:

key FixedString(15) FixedString(size = 0), value Nullable(Int8) Nullable(size = 0, Int8(size = 0), UInt8(size = 0)), name Nullable(Int8) Nullable(size = 0, Int8(size = 0), UInt8(size = 0)), name2 Nullable(Int8) Nullable(size = 0, Int8(size = 0), UInt8(size = 0)) (version 20.5.2.7 (official build))

Additional context
As you can see, there is no data in play at all. The error message is generated just from the raw structure. The first and the second part of the UNION ALL work when running them on their own.

Commenting out the last INNER JOIN (the one with the alias flowers) makes the issue disappear. This would also mean that the null as name, null as name2 is not the culprit here.

Activity

  1. added
    unexpected behaviour
    on Jul 20, 2020
  2. added
    bug
    and removed
    unexpected behaviour
    on Jul 20, 2020
  3. millin commented on Jul 24, 2020

    @millin
    Contributor

    I have the same error
    ver 20.5.3.27

  4. 4ertus2 commented on Jul 27, 2020

    @4ertus2
    Contributor

    Smaller sample

    SELECT * FROM (
        SELECT value
        FROM (SELECT 0 as key, 1 as value) as common
        INNER JOIN (SELECT 0 as key, 2 as name) trees
        ON (common.key = trees.key)
    )
    UNION ALL
    (
        SELECT value
        FROM (SELECT 1 as key, 3 as value) as common
        INNER JOIN (SELECT 1 as key) flowers
        ON (common.key = flowers.key)
    );
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions