EnterpriseDB / mysql_fdw

PostgreSQL foreign data wrapper for MySQL
Other
521 stars 160 forks source link

[Feature Support] Support push down unique function in WHERE clause only: pi(), rand(),.. #248

Open khieuvm opened 2 years ago

khieuvm commented 2 years ago

Currently, PostgreSQL does not allow pushdown constant functions like (pi(), rand(), ...), so these functions will be calculated in PostgreSQL core and can not be pushed down to the remote database.

But we can push down them to the remote database by creating a stub function:

EXPLAIN VERBOSE
SELECT value1 FROM s3 WHERE mysql_pi() > value1 LIMIT 1;
                                           QUERY PLAN                                            
-------------------------------------------------------------------------------------------------
 Foreign Scan on public.s3  (cost=100.00..100.07 rows=1 width=8)
   Output: value1
   Local server startup cost: 10
   Remote query: SELECT `value1` FROM `mysql_fdw_regress`.`s3` WHERE ((pi() > `value1`)) LIMIT 1
(4 rows)

I would like to contribute them to the repository and community. I will create a pull request to share this feature if you have any interest.