Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: postgresql-cfbot/postgresql
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: cf/4564~1
Choose a base ref
...
head repository: postgresql-cfbot/postgresql
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: cf/4564
Choose a head ref
  • 3 commits
  • 7 files changed
  • 2 contributors

Commits on Apr 3, 2025

  1. Add assertion to verify derived clause has constant RHS

    find_derived_clause_for_ec_member() searches for a previously-derived
    clause that equates a non-constant EquivalenceMember to a constant.
    It is only called for EquivalenceClasses with ec_has_const set, and
    with a non-constant member the EquivalenceMember to search for.
    
    The matched clause is expected to have the non-constant member on the
    left-hand side and the constant EquivalenceMember on the right.
    
    Assert that the RHS is indeed a constant, to catch violations of this
    structure and enforce assumptions made by
    generate_base_implied_equalities_const().
    
    Author: Ashutosh Bapat <[email protected]>
    Discussion: https://postgr.es/m/CAExHW5scMxyFRqOFE6ODmBiW2rnVBEmeEcA-p4W_CyuEikURdA@mail.gmail.com
    amitlan authored and Commitfest Bot committed Apr 3, 2025
    Configuration menu
    Copy the full SHA
    89cbe72 View commit details
    Browse the repository at this point in the history
  2. Make derived clause lookup in EquivalenceClass more efficient

    Derived clauses are stored in ec_derives, a List of RestrictInfos.
    These clauses are later looked up by matching the left and right
    EquivalenceMembers along with the clause's parent EC.
    
    This linear search becomes expensive in queries with many joins or
    partitions, where ec_derives may contain thousands of entries. In
    particular, create_join_clause() can spend significant time scanning
    this list.
    
    To improve performance, introduce a hash table (ec_derives_hash) that
    is built when the list reaches 32 entries -- the same threshold used
    for join_rel_hash. The original list is retained alongside the hash
    table to support EC merging and serialization
    (_outEquivalenceClass()).
    
    Each clause is stored in the hash table using a canonicalized key: the
    EquivalenceMember with the lower memory address is placed in the key
    before the one with the higher memory address. This avoids storing or
    searching for both permutations of the same clause. For clauses
    involving a constant EM, the key places NULL in the first slot and the
    non-constant EM in the second.
    
    The hash table is initialized using list_length(ec_derives_list) as
    the size hint. simplehash internally adjusts this to the next power of
    two after dividing by the fillfactor, so this typically results in at
    least 64 buckets near the threshold -- avoiding immediate resizing
    while adapting to the actual number of entries.
    
    The lookup logic for derived clauses is now centralized in
    ec_search_derived_clause_for_ems(), which consults the hash table when
    available and falls back to the list otherwise.
    
    The new ec_clear_derived_clauses() always frees ec_derives_list, even
    though some of the original code paths that cleared the old
    ec_derives field did not. This ensures consistent cleanup and avoids
    leaking memory when large lists are discarded.
    
    An assertion originally placed in find_derived_clause_for_ec_member()
    is moved into ec_search_derived_clause_for_ems() so that it is
    enforced consistently, regardless of whether the hash table or list is
    used for lookup.
    
    This design incorporates suggestions by David Rowley, who proposed
    both the key canonicalization and the initial sizing approach to
    balance memory usage and CPU efficiency.
    
    Author: Ashutosh Bapat <[email protected]>
    Reviewed-by: Amit Langote <[email protected]>
    Reviewed-by: David Rowley <[email protected]>
    Tested-by: Dmitry Dolgov <[email protected]>
    Tested-by: Alvaro Herrera <[email protected]>
    Tested-by: Amit Langote <[email protected]>
    Tested-by: David Rowley <[email protected]>
    Discussion: https://postgr.es/m/CAExHW5vZiQtWU6moszLP5iZ8gLX_ZAUbgEX0DxGLx9PGWCtqUg@mail.gmail.com
    amitlan authored and Commitfest Bot committed Apr 3, 2025
    Configuration menu
    Copy the full SHA
    bbbe3d4 View commit details
    Browse the repository at this point in the history
  3. [CF 4564] v9 - Reducing memory consumed by RestrictInfo list translat…

    …ions in partitionwise join planning
    
    This branch was automatically generated by a robot using patches from an
    email thread registered at:
    
    https://commitfest.postgresql.org/patch/4564
    
    The branch will be overwritten each time a new patch version is posted to
    the thread, and also periodically to check for bitrot caused by changes
    on the master branch.
    
    Patch(es): https://www.postgresql.org/message-id/CA+HiwqH8OaVD8LOpON=h3UyzXBwj=hHzTF_46DGvoeXzRrkx9A@mail.gmail.com
    Author(s): Ashutosh Bapat
    Commitfest Bot committed Apr 3, 2025
    Configuration menu
    Copy the full SHA
    d7a6f46 View commit details
    Browse the repository at this point in the history
Loading