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

Fix crash when partializing agg with HAVING #1544

Commits on Jan 7, 2020

  1. Fix crash when partializing agg with HAVING

    This change fixes an assertion-based crash that happened when using
    the `partialize_agg` function together with HAVING clauses. For
    instance,
    
    ```
    SELECT time_bucket('1 day', time), device,
    __timescaledb_internal.partialize_agg(avg(temp))
    GROUP BY 1, 2
    HAVING avg(temp) > 3;
    ```
    
    would crash because the HAVING clause's aggregate didn't have its
    `Aggref` node set to partial aggregate mode.
    
    Regular partial aggregations executed by the planner (i.e., those not
    induced by the `partialize_agg` function) have their HAVING aggs
    transparently moved to the target list during planning so that the
    finalize node can use it when applying the final filter on the
    resulting groups. However, it doesn't make much sense to transparently
    do that when partializing with `partialize_agg` since it would be odd
    to return more columns than requested by the user. Therefore, the
    caller would have to do that manually. This, in fact, is also done
    when materializing continuous aggregates.
    
    For this reason, HAVING clauses with `partialize_agg` are blocked,
    except in cases where the planner transparently reduces the HAVING
    expression to a simple filter (e.g., `HAVING device > 3`).
    
    Apart from fixing this issue, this change also refectors some of the
    related code and adds tests for some error cases.
    erimatnor committed Jan 7, 2020
    Configuration menu
    Copy the full SHA
    989a132 View commit details
    Browse the repository at this point in the history