Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: fix zero-column groups in joins colliding #34667

Merged
merged 1 commit into from
Feb 6, 2019

Commits on Feb 6, 2019

  1. opt: fix zero-column groups in joins colliding

    It's fundamental to the optimizer that any two unrelated (i.e., one is
    not the parent of the other) expressions in the tree have disjoint
    column sets. Usually, this prevents the same relational expression from
    occurring in the tree more than once, but in the case of a group with
    zero columns, this is not true.
    
    This allows the following group collision to occur:
    
    Let A be the 0-column values node with two rows `VALUES (), ()`,
    and B be the 0-column values node with three rows `VALUES (), (), ()`.
    
    Then consider the following query:
    ```
    (A JOIN B) UNION (B JOIN A)
    ```
    
    During build, we add A JOIN B and B JOIN A to *separate memo groups*.
    Then, during exploration, we apply the `CommuteJoin` rule to transform
    `A JOIN B` to `B JOIN A`. This attempts to get interned into the same
    group, but the interner finds that `B JOIN A` already exists in a
    different group, and panics.
    
    As a side note, a values node with no columns is not valid SQL, but it
    can be constructed via the `MergeProjectWithValues` rule:
    ```
    SELECT 1 FROM (VALUES (1))
    => MergeProjectWithValues
    SELECT 1 FROM (VALUES ())
    ```
    
    This commit fixes the problem by simply disabling these types of
    explorations on groups with zero columns. This isn't a perfect fix,
    since the subtle problem is still lurking, and people going forward need
    to understand its implications, but it will fix the problem for the time
    being.
    
    Release note (bug fix): fixed several related panics in the optimizer
    related to plan exploration.
    Justin Jaffray committed Feb 6, 2019
    Configuration menu
    Copy the full SHA
    62a08f7 View commit details
    Browse the repository at this point in the history