Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

sql/analyzer: refactor and fix bugs in qualify_columns rule #706

Merged
merged 1 commit into from
May 13, 2019

Commits on May 10, 2019

  1. sql/analyzer: refactor and fix bugs in qualify_columns rule

    qualify_columns rule has been a source of bugs for quite a long time
    due to the way we used to look for columns. Before, we looked for
    all available schemas in all the tree of a query (excluding subqueries).
    This required a lot of exceptions and treatments for special cases
    that have been added over time in order to patch the bugs that kept
    appearing.
    It had special cases for aliases, for GroupBy, etc that kept complicating
    the code and making the rule harder to follow and confusing.
    
    This refactor simplifies the logic of the rule and treats all nodes
    in the exact same way so it's simpler, more obvious and easier to
    reason about.
    Now, a node only has knowledge of the columns (aliases or not) defined
    until it reaches the first Project, GroupBy, ResolvedTable or subquery
    in each branch of the tree. This way, we can gather all the available
    columns and infer the schema (which we cannot just call using the Schema
    method because the tree is not resolved yet). Then, qualifying columns
    becomes a trivial job once you have the schema.
    
    All the tests of go-mysql-server and gitbase pass with this new
    implementation of the rule.
    
    Signed-off-by: Miguel Molina <miguel@erizocosmi.co>
    erizocosmico committed May 10, 2019
    Configuration menu
    Copy the full SHA
    c059a12 View commit details
    Browse the repository at this point in the history