Skip to content

WITH clause RECURSIVE subquery Unknown column exception when shorhand projection are used. #35164

@Yash-cor

Description

@Yash-cor

Bug Report

For English only, other languages will not accept.

Before report a bug, make sure you have:

Please pay attention on issues you submitted, because we maybe need more details.
If no response anymore and we cannot reproduce it on current information, we will close it.

Please answer these questions before submitting your issue. Thanks!

Which version of ShardingSphere did you use?

5.5.3-SNAPSHOT

Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?

ShardingSphere-JDBC and ShardingSphere-Proxy

Expected behavior

WITH RECURSIVE cte AS ( SELECT * from t_user UNION ALL SELECT user_id+1, name FROM cte WHERE user_id < 5 ) SELECT * FROM cte

Above query runs successfully without showing any Error

Actual behavior

Image

Reason analyze (If you can)

  if (recursive && segment.getAliasName().isPresent()) {
              binderContext.getExternalTableBinderContexts().put(
  new CaseInsensitiveString(segment.getAliasName().get()), new SimpleTableSegmentBinderContext(segment.getColumns().stream().map(ColumnProjectionSegment::new).collect(Collectors.toList()), TableSourceType.TEMPORARY_TABLE));
}

In CommonTableExpressionSegmentBinder when getExternalTableBinderContexts is created Shorthand Projections are not caught correctly as Subquery is not binded first but for subquery to be binded we need getExternalTableBinderContexts

Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.

Example codes for reproduce this issue (such as a github link).

Metadata

Metadata

Assignees

No one assigned

    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