Skip to content

Optimizer adds redundant projections on casts with confusing alias #3786

Open

Description

@andygrove

Describe the bug

#3764 fixed one regression but introduced another.

I do not understand why this additional projection is being added.

Before

Inner Join: store_sales.ss_sold_date_sk = date_dim.d_date_sk

After

Projection: CAST(date_dim.d_moy AS Int64) AS CAST(date_dim.d_moy AS Int64)date_dim.d_moy, store_sales.ss_customer_sk, date_dim.d_year
  Inner Join: store_sales.ss_sold_date_sk = date_dim.d_date_sk

To Reproduce
No repro available yet

Expected behavior

Additional context

Activity

  1. changed the title [-]Optimizer reduntant projections on casts with confusing alias[/-] [+]Optimizer adds reduntant projections on casts with confusing alias[/+] on Oct 10, 2022
  2. changed the title [-]Optimizer adds reduntant projections on casts with confusing alias[/-] [+]Optimizer adds redundant projections on casts with confusing alias[/+] on Oct 10, 2022
  3. alamb commented on Oct 11, 2022

    @alamb
    Contributor

    Note I tried to explain in #3794 why aliases are needed for optimizer rewrite passes in general.

    This may also be related to #3770

  4. alamb commented on Oct 11, 2022

    @alamb
    Contributor

    Using EXPLAIN VERBOSE on the plan should reveal which optimizer pass is making this change. If I had to guess, I would guess CommonSubexprEliminate

  5. liukun4515 commented on Oct 12, 2022

    @liukun4515
    Contributor

    Maybe related to this issue #3635 which will produce redundant projection after run the optimizer

  6. andygrove commented on Oct 17, 2022

    @andygrove
    MemberAuthor

    Another example:

    Projection: household_demographics.hd_vehicle_count > Int32(0) AS household_demographics.hd_vehicle_count > Int32(0)Int32(0)household_demographics.hd_vehicle_count
    

    The alias name should just be:

    household_demographics.hd_vehicle_count > Int32(0)
    

    and not

    household_demographics.hd_vehicle_count > Int32(0)Int32(0)household_demographics.hd_vehicle_count
    
  7. andygrove commented on Oct 25, 2022

    @andygrove
    MemberAuthor

    Another example in #3884 (comment)

  8. self-assigned this
    on Oct 25, 2022
  9. added this to the 14.0.0 milestone on Oct 30, 2022
  10. andygrove commented on Nov 1, 2022

    @andygrove
    MemberAuthor

    I confirmed that this does happen in common_sub_expression_eliminate

  11. removed their assignment
    on Nov 1, 2022
  12. andygrove commented on Nov 1, 2022

    @andygrove
    MemberAuthor

    Fixing this will involve a significant refactor/rewrite of portions of common_sub_expression_eliminate

  13. removed this from the 14.0.0 milestone on Nov 1, 2022
  14. jackwener commented on Dec 11, 2022

    @jackwener
    Member

    related with #4575

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

    bugSomething isn't workingoptimizerOptimizer rules

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions