Skip to content

CTE intermittent failure with two JOINs (?) #29748

Closed

Description

@hazzadous

Describe the unexpected behaviour

I'm trying to run a query:

WITH cte1 as (
    SELECT '1234' as x
 ), cte2 as (
    SELECT '1234' as x
   )
SELECT *
FROM events AS events
JOIN cte2 ON cte2.x = events.distinct_id
JOIN cte1 ON cte1.x = cte2.x
limit 1

The events table is created with ON CLUSTER i.e. distributed.

For this query I get:

ClickHouse exception, code: 60, host: <ip>, port: 8443; Code: 60, e.displayText() = DB::Exception: Received from <host>:9000. DB::Exception: Table <cluster>.cte2 doesn't exist. (version 21.6.5.37 (official build))

If I run:

WITH cte1 as (
    SELECT '1234' as x
 ), cte2 as (
    SELECT '1234' as x
   )
SELECT events.distinct_id
FROM events AS events
JOIN cte2 ON cte2.x = events.distinct_id
-- JOIN cte1 ON cte1.x = cte2.x
limit 1

it always works.

If I run:

WITH cte1 as (
    SELECT '1234' as x
 ), cte2 as (
    SELECT '1234' as x
   )
SELECT events.distinct_id
FROM events AS events
JOIN cte2 ON cte2.x = events.distinct_id
JOIN cte1 ON cte1.x = cte2.x
limit 1

it intermittently works.

If I query with the same pattern with another table I do not get errors.

Expected behavior

CTE evaluation shouldn't be dependent on specific select fields (?)

Error message and/or stacktrace

As specified above.

Additional context

None except mainly I'm looking for debug pointers. i.e. sql to run on a specific shard may be appropriate for debugging?

Activity

  1. added
    unexpected behaviour
    on Oct 4, 2021
  2. changed the title [-]CTE intermittent failure[/-] [+]CTE intermittent failure with two JOINs (?)[/+] on Oct 4, 2021
  3. hazzadous commented on Jan 6, 2022

    @hazzadous
    Author

    Looks like this might be relevant in our case, it looks like the events table is Distributed which changes things a little, hopefully I'll get around to reproducing this locally.

  4. added a commit that references this issue on Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    unexpected behaviour

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions