Key features v2
These are the key features of the MySQL Foreign Data Wrapper.
Writable foreign data wrapper
MySQL Foreign Data Wrapper provides the write capability. You can insert, update, and delete data in the remote MySQL tables by inserting, updating, and deleting the data locally in the foreign tables. MySQL foreign data wrapper uses the Postgres type casting mechanism to provide opposite type casting between MySQL and Postgres data types.
Note
The first column of MySQL table must have unique/primary key for DML to work.
See also:
Connection pooling
MySQL Foreign Data Wrapper establishes a connection to a foreign server during the first query that uses a foreign table associated with the foreign server. This connection is kept and reused for subsequent queries in the same session.
WHERE clause pushdown
MySQL Foreign Data Wrapper allows the pushdown of a WHERE
clause to the foreign server for execution. This feature optimizes remote queries to reduce the number of rows transferred from foreign servers.
Column pushdown
MySQL Foreign Data Wrapper supports column pushdown. As a result, the query brings back only those columns that are a part of the select target list.
Join pushdown
MySQL Foreign Data Wrapper supports join pushdown. It pushes the joins between the foreign tables of the same remote MySQL server to that remote MySQL server, enhancing the performance.
Note
- Currently, joins involving only relational and arithmetic operators in join clauses are pushed down to avoid any potential join failure.
- Only the INNER and LEFT/RIGHT OUTER joins are supported.
See also:
- Example: Join pushdown
- Blog: Join Pushdown - covers performance improvements and partition-wise join pushdowns
Aggregate pushdown
MySQL Foreign Data Wrapper supports aggregate pushdown for min, max, sum, avg, and count aggregate functions, allowing you to push aggregates to the remote MySQL server instead of fetching all of the rows and aggregating them locally. Aggregate filters and aggregate orders aren't pushed down as MySQL doesn't support them.
See also:
For more information, see Example: Aggregate pushdown Also, see Blog: Aggregate Pushdown - covers performance improvements, using join and aggregate pushdowns together, and pushing down aggregates to the partition table
ORDER BY pushdown
MySQL Foreign Data Wrapper supports ORDER BY pushdown. If possible, push ORDER BY clause to the remote server so that we get the ordered result set from the foreign server itself. It might help us to have an efficient merge join. NULLs behavior is opposite on the MySQL server. Thus to get an equivalent result, we add the "expression IS NULL" clause at the beginning of each of the ORDER BY expressions.
For more information, see Example: ORDER BY pushdown
LIMIT OFFSET pushdown
MySQL Foreign Data Wrapper supports limit offset push-down. Wherever possible, perform LIMIT
and OFFSET
operations on the remote server. This reduces network traffic between local PostgreSQL and remote MySQL servers. ALL/NULL
options are not supported on the MySQL server, and thus they are not pushed down. Also, OFFSET
without LIMIT
is not supported on the MySQL server hence queries having that construct are not pushed.
For more information, see Example: LIMIT OFFSET pushdown
Configuration file to restrict pushdowns
MySQL 2.9.0 and later provides the mysql_fdw_pushdown.config
configuration file to restrict the pushdowns. You can define the list of functions and operators in this file that can pushdown to the remote server. You can easily add or modify the list as per the requirements.
This file lists the objects as aggregates, functions, and operators allowed to push down to the remote server. Each entry should be on a single line. Each entry must have two columns:
- Object type that can be ROUTINE (functions, aggregates, and procedures) or OPERATOR
- The second column is the schema-qualified object names with their arguments
The exact form of the second column can be formatted using the following query:
For ROUTINE:
For OPERATOR: