Skip to content

A node-initiator unnecessarily prepares the right part of a join, when it is supposed to just send the query to a cluster #3253

Closed

Description

@SaltTan

I run a query against a distributed table and I want the join to be performed by shards:

SELECT toUInt64(dummy) AS number
FROM cluster(segmented, system, one)
ANY LEFT JOIN numbers(50000000) USING (number)

However the initiator runs CreatingSetsBlockInputStream itself BEFORE sending the query to the shards:

[chdw1-1] 2018.09.28 19:17:54.540691 {eeebc7ef-b811-499c-97eb-73277e2aeb67} [ 165 ] <Debug> executeQuery: (from [::1]:40542) select toUInt64(dummy) as number from cluster(segmented, system, one) any left join numbers(50000000) using (number)
[chdw1-1] 2018.09.28 19:17:54.541666 {eeebc7ef-b811-499c-97eb-73277e2aeb67} [ 165 ] <Debug> executeQuery: Query pipeline:
CreatingSets
 Lazy
 Union
  Expression
   Materializing
    CreatingSets
     Lazy
     Expression
      Expression
       One
  Expression
   Remote

↖ Progress: 51.58 million rows, 412.61 MB (15.13 million rows/s., 121.08 MB/s.) 
[chdw1-1] 2018.09.28 19:17:57.862391 {eeebc7ef-b811-499c-97eb-73277e2aeb67} [ 2821963 ] <Debug> CreatingSetsBlockInputStream: Created. Join with 50000000 entries from 50000000 rows. In 3.321 sec.

Now it sends the query:

[chdw1-1] 2018.09.28 19:17:57.864864 {da656ec1-49b5-47d4-8221-45db8c757387} [ 834399 ] <Debug> executeQuery: (from [::ffff:10.253.52.2]:51966, initial_query_id: eeebc7ef-b811-499c-97eb-73277e2aeb67) SELECT toUInt64(dummy) AS number FROM system.one  ANY LEFT JOIN numbers(50000000) USING (number)
[chdw1-1] 2018.09.28 19:17:57.865380 {da656ec1-49b5-47d4-8221-45db8c757387} [ 834399 ] <Debug> executeQuery: Query pipeline:
CreatingSets
 Lazy
 Expression
  Expression
   One

┌─number─┐
│      0 │
└────────┘
[chdw1-1] 2018.09.28 19:18:01.137332 {da656ec1-49b5-47d4-8221-45db8c757387} [ 840459 ] <Debug> CreatingSetsBlockInputStream: Created. Join with 50000000 entries from 50000000 rows. In 3.272 sec.
┌─number─┐
│      0 │
└────────┘
↗ Progress: 150.01 million rows, 1.20 GB (22.52 million rows/s., 180.14 MB/s.) 
[chdw1-1] 2018.09.28 19:18:01.137831 {da656ec1-49b5-47d4-8221-45db8c757387} [ 834399 ] <Information> executeQuery: Read 50003969 rows, 381.50 MiB in 3.273 sec., 15278091 rows/sec., 116.56 MiB/sec.

In my case the initiator is in fact one of the shards, so it runs CreatingSetsBlockInputStream for the second time:

[chdw1-1] 2018.09.28 19:18:01.201398 {eeebc7ef-b811-499c-97eb-73277e2aeb67} [ 2821965 ] <Debug> CreatingSetsBlockInputStream: Created. Join with 50000000 entries from 50000000 rows. In 3.339 sec.

So ClickHouse read 150 million rows instead of 100 million:

[chdw1-1] 2018.09.28 19:18:01.201922 {eeebc7ef-b811-499c-97eb-73277e2aeb67} [ 165 ] <Information> executeQuery: Read 150011906 rows, 1.12 GiB in 6.661 sec., 22520302 rows/sec., 171.82 MiB/sec.

2 rows in set. Elapsed: 6.663 sec. Processed 150.01 million rows, 1.20 GB (22.52 million rows/s., 180.13 MB/s.)

I guess the initiator should not try to do the join if it's going to send the query to shards.

Activity

  1. CurtizJ commented on Oct 11, 2018

    @CurtizJ
    Member

    Fixed #3340.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions