Skip to content

SNOW-1734385: Do not create CTE when partitioning WithQueryBlocks#2948

Merged
sfc-gh-aalam merged 4 commits intomainfrom
aalam-SNOW-1734385-do-not-create-cte-at-withqueryblock-partition
Jan 30, 2025
Merged

SNOW-1734385: Do not create CTE when partitioning WithQueryBlocks#2948
sfc-gh-aalam merged 4 commits intomainfrom
aalam-SNOW-1734385-do-not-create-cte-at-withqueryblock-partition

Conversation

@sfc-gh-aalam
Copy link
Contributor

@sfc-gh-aalam sfc-gh-aalam commented Jan 28, 2025

  1. Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-1734385

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
      • If this test skips Local Testing mode, I'm requesting review from @snowflakedb/local-testing
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am adding new credentials
    • I am adding a new dependency
    • If this is a new feature/behavior, I'm adding the Local Testing parity changes.
    • I acknowledge that I have ensured my changes to be thread-safe. Follow the link for more information: Thread-safe Developer Guidelines
  3. Please describe how your code solves the related issue.

    When large query breakdown partitions node such that the child node being partitioned is a WithQueryBlock, do not create a cte. Instead, use the underlying sql to materialize it as a table.

@sfc-gh-aalam sfc-gh-aalam added the NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md label Jan 28, 2025
@sfc-gh-aalam sfc-gh-aalam marked this pull request as ready for review January 28, 2025 21:07
@sfc-gh-aalam sfc-gh-aalam requested review from a team as code owners January 28, 2025 21:07
def _get_partitioned_plan(self, root: TreeNode, child: TreeNode) -> SnowflakePlan:
def _extract_child_from_with_query_block(
self, child: Optional[LogicalPlan]
) -> TreeNode:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this to utils right below is_with_query_block function to group the functionality.



def is_with_query_block(node: Optional[LogicalPlan]) -> bool:
if isinstance(node, WithQueryBlock):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a comment here that this function is check whether a given logical node is a node or resolved SnowflakePlan or Selectable for WithQueryBlock

return session._run_query("SELECT CURRENT_TRANSACTION()")[0][0] is not None


def is_with_query_block(node: Optional[LogicalPlan]) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the node needs to be optional? when it will be none?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be none if node is a snowflakeplan and node.source_plan is None. But it can be handled within the if-else logic so I'll make it non-optional here

Copy link
Contributor

@sfc-gh-helmeleegy sfc-gh-helmeleegy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sfc-gh-aalam sfc-gh-aalam merged commit 6ffbddc into main Jan 30, 2025
37 checks passed
@sfc-gh-aalam sfc-gh-aalam deleted the aalam-SNOW-1734385-do-not-create-cte-at-withqueryblock-partition branch January 30, 2025 01:41
@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

NO-CHANGELOG-UPDATES This pull request does not need to update CHANGELOG.md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants