• Tom Lane's avatar
    Rearrange the querytree representation of ORDER BY/GROUP BY/DISTINCT items · 95113047
    Tom Lane authored
    as per my recent proposal:
    
    1. Fold SortClause and GroupClause into a single node type SortGroupClause.
    We were already relying on them to be struct-equivalent, so using two node
    tags wasn't accomplishing much except to get in the way of comparing items
    with equal().
    
    2. Add an "eqop" field to SortGroupClause to carry the associated equality
    operator.  This is cheap for the parser to get at the same time it's looking
    up the sort operator, and storing it eliminates the need for repeated
    not-so-cheap lookups during planning.  In future this will also let us
    represent GROUP/DISTINCT operations on datatypes that have hash opclasses
    but no btree opclasses (ie, they have equality but no natural sort order).
    The previous representation simply didn't work for that, since its only
    indicator of comparison semantics was a sort operator.
    
    3. Add a hasDistinctOn boolean to struct Query to explicitly record whether
    the distinctClause came from DISTINCT or DISTINCT ON.  This allows removing
    some complicated and not 100% bulletproof code that attempted to figure
    that out from the distinctClause alone.
    
    This patch doesn't in itself create any new capability, but it's necessary
    infrastructure for future attempts to use hash-based grouping for DISTINCT
    and UNION/INTERSECT/EXCEPT.
    95113047
equalfuncs.c 52.2 KB