Skip to content

Conversation

@yjhjstz
Copy link
Member

@yjhjstz yjhjstz commented Dec 31, 2025

postgres=#  set optimizer_enable_groupagg=off;
SET
postgres=# explain select * from atable group by a,k;
ERROR:  could not find hash function for hash operator 78765 (execGrouping.c:118) 

Fix execution-time error when operators have oprcanhash=true but lack actual hash functions. Previously, ORCA would generate HashAgg plans that failed at runtime with "could not find hash function for hash operator" errors.

This occurred when operators were marked with the 'hashes' option but only registered in btree operator families, not hash operator families. The fix adds validation using get_op_hash_functions() to ensure hash functions exist before allowing HashAgg plans, moving error detection from execution to planning time.

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


Fix execution-time error when operators have oprcanhash=true but lack actual
hash functions. Previously, ORCA would generate HashAgg plans that failed at
runtime with "could not find hash function for hash operator" errors.

This occurred when operators were marked with the 'hashes' option but only
registered in btree operator families, not hash operator families. The fix
adds validation using get_op_hash_functions() to ensure hash functions exist
before allowing HashAgg plans, moving error detection from execution to
planning time.
Copilot AI review requested due to automatic review settings December 31, 2025 16:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical bug in ORCA where operators marked with oprcanhash=true but lacking actual hash support functions would cause runtime errors during query execution. The fix moves error detection from execution time to planning time by adding validation in IsOpHashJoinable().

Key Changes:

  • Added hash function existence validation using get_op_hash_functions() in IsOpHashJoinable()
  • Comprehensive regression test demonstrating the fix
  • Test creates operators with the hashes flag but without valid hash operator families

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/backend/gpopt/gpdbwrappers.cpp Enhanced IsOpHashJoinable() to validate hash function existence before allowing hash-based operations
src/test/regress/sql/gp_hashagg.sql Added regression test creating custom type with operators marked hashable but lacking hash functions
src/test/regress/expected/gp_hashagg.out Expected output showing queries succeed with the fix instead of failing at execution time

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant