Skip to content

Adding hook to enable index matching through type casts#762

Open
RuchaSK1 wants to merge 2 commits into
babelfish-for-postgresql:BABEL_6_X_DEV__PG_18_Xfrom
amazon-aurora:jira-babel-ssms-perf
Open

Adding hook to enable index matching through type casts#762
RuchaSK1 wants to merge 2 commits into
babelfish-for-postgresql:BABEL_6_X_DEV__PG_18_Xfrom
amazon-aurora:jira-babel-ssms-perf

Conversation

@RuchaSK1

@RuchaSK1 RuchaSK1 commented May 20, 2026

Copy link
Copy Markdown
Contributor

Description

Adding a hook in match_opclause_to_indexcol() that allows babelfish to provide index clauses when the built-in logic cannot match an OpExpr to an index column. This enables extensions to handle type-cast patterns that prevent index usage due to operator family mismatches.

Issues Resolved

Task: BABEL-6814

Authored-by: Rucha Kulkarni ruchask@amazon.com
Signed-off-by: Rucha Kulkarni ruchask@amazon.com

Extension PR: babelfish-for-postgresql/babelfish_extensions#4829

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the PostgreSQL license, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Rucha Kulkarni <ruchask@amazon.com>
@RuchaSK1 RuchaSK1 marked this pull request as ready for review May 22, 2026 02:46
Signed-off-by: Rucha Kulkarni <ruchask@amazon.com>
*/
set_opfuncid(clause); /* make sure we have opfuncid */
return get_index_clause_from_support(root,
iclause = get_index_clause_from_support(root,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you repro the index scan not being chosen in PG?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

dev-dsk-ruchask-1c-a99d43f3 % psql -h localhost -d postgres 
psql (18.3)
Type "help" for help.

postgres=# CREATE TABLE test_oid (id oid PRIMARY KEY, data text);
CREATE TABLE
postgres=#  INSERT INTO test_oid SELECT g, 'row ' || g FROM generate_series(1, 100000) g;
INSERT 0 100000
postgres=# EXPLAIN SELECT * FROM test_oid WHERE id = 12345;
                                  QUERY PLAN                                   
-------------------------------------------------------------------------------
 Index Scan using test_oid_pkey on test_oid  (cost=0.29..8.31 rows=1 width=36)
   Index Cond: (id = '12345'::oid)
(2 rows)

postgres=# EXPLAIN SELECT * FROM test_oid WHERE (id)::int = 12345;
                         QUERY PLAN                         
------------------------------------------------------------
 Seq Scan on test_oid  (cost=0.00..1399.84 rows=1 width=36)
   Filter: ((id)::integer = 12345)
(2 rows)

postgres=#  EXPLAIN SELECT * FROM test_oid WHERE (id)::int4 = 12345;
                         QUERY PLAN                         
------------------------------------------------------------
 Seq Scan on test_oid  (cost=0.00..1791.00 rows=1 width=13)
   Filter: ((id)::integer = 12345)
(2 rows)

postgres=# 

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With catalog table:

postgres=# EXPLAIN SELECT * FROM pg_class WHERE oid = 12345;
                                       QUERY PLAN                                      
  -------------------------------------------------------------------------------------
   Index Scan using pg_class_oid_index on pg_class  (cost=0.27..8.29 rows=1 width=277)
     Index Cond: (oid = '12345'::oid)
  (2 rows)
  
  postgres=#  EXPLAIN SELECT * FROM pg_class WHERE (oid)::int4 = 12345;
                          QUERY PLAN                         
  -----------------------------------------------------------
   Seq Scan on pg_class  (cost=0.00..19.19 rows=1 width=277)
     Filter: ((oid)::integer = 12345)
  (2 rows)
  

@RuchaSK1

Copy link
Copy Markdown
Contributor Author

/code-review

1 similar comment
@RuchaSK1

Copy link
Copy Markdown
Contributor Author

/code-review

@RuchaSK1

Copy link
Copy Markdown
Contributor Author

/code-review

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.

3 participants