EnterpriseDB / mysql_fdw

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

Push down of WHERE clause not happening on AWS RDS Postgres 15 with `character(n)` data type #274

Open cseickel opened 1 year ago

cseickel commented 1 year ago

Hi there. I've come across this odd problem where some table just won't push down anything to the foreign server. This issue only happens on AWS RDS Postgres 15, it does not happen on 14.7.

It turns out the issue is that if I use character(6) as the datatype for the column used in the WHERE clause, it just pulls all the row from the foreign server. If I change the datatype to character varying then it will push down the where clause as expected.

On v14.7, it works correctly with either data type.

Is there a reason for this, or some configuration I can change to affect this result?

Thank you for any insights you can offer.


EDIT: Here are some more details:

select * from mysql_fdw_version()

--> 20900

Server Version: PostgreSQL 14.7 on aarch64-unknown-linux-gnu, compiled by gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-6), 64-bit

Table definition

CREATE FOREIGN TABLE IF NOT EXISTS orats.tblearningsdatesarchive(
    "ticker" character(6) NULL COLLATE pg_catalog."default",
    "nextEarn" date NULL,
    "lastEarn" text NOT NULL COLLATE pg_catalog."default",
    "earnTime" character(1) NOT NULL COLLATE pg_catalog."default",
    status character(1) NOT NULL COLLATE pg_catalog."default",
    modified date NOT NULL
)
    SERVER orats
    OPTIONS (dbname 'orats', table_name 'tblearningsdatesarchive');

EXPLAIN output: image

surajkharage19 commented 1 year ago

Hi @cseickel,

Can you please add the required entries in mysql_fdw_pushdown.config file and check? e.g. OPERATOR pg_catalog.=(character,character)

Once that is added you can reload the config file using select mysql_fdw_display_pushdown_list(true); command or start a new session so that new entries can take effect. Users can add/modify/delete the entries as per their requirements from mysql_fdw_pushdown.config file.

After adding this entry in mysql_fdw_pushdown.config file, I can see where clause is getting pushdown to remote server.

edb@106209=#explain (analyze, verbose) select * from chartest where b = 'suraj';
                                                     QUERY PLAN                                                      
---------------------------------------------------------------------------------------------------------------------
 Foreign Scan on public.chartest  (cost=10.00..1010.00 rows=1000 width=32) (actual time=0.855..0.872 rows=1 loops=1)
   Output: a, b
   Local server startup cost: 10
   Remote query: SELECT `a`, `b` FROM `suraj`.`chartest` WHERE ((`b` = 'suraj'))
 Planning Time: 17.829 ms
 Execution Time: 2.223 ms
(6 rows)

Please let us know if the above suggestion works.

cseickel commented 1 year ago

Hi @surajkharage19, thanks for the response!

Can you please add the required entries in mysql_fdw_pushdown.config file and check?

This may be a question for AWS Support, but do you know how I would change those values in AWS RDS? I don't have direct access to the config files. Can these values be applied with a SET command or as options on the foreign table/server?

surajkharage19 commented 1 year ago

Hi @cseickel,

This may be a question for AWS Support, but do you know how I would change those values in AWS RDS?

Apologies, I'm not much familiar with AWS RDS so could not able to help with this.

I don't have direct access to the config files. Can these values be applied with a SET command or as options on the foreign table/server?

No, we don't have such an option. You need to add the entry in config file by accessing the file as suggested above.

cseickel commented 1 year ago

I contacted AWS and they confirmed that I cannot access this file. It seems like I will need to stick with version 14 for the time being until they either come up with a way of allowing me to edit these settings, or this project enables an alternate means of configuring this.

What are the odds that you can add another way of configuring this setting?

surajkharage19 commented 1 year ago

Hi @cseickel,

Currently, we do not have any option other than manually adding that entry in config file. We will think of giving an option without accessing the file directly but Im not sure whether that is going to be worked upon immediately.

AlexFriedmanAWS commented 1 year ago

Jumping in here to try to help. According to the docs, the mysql_fdw_pushdown.config configuration file was added in 2.9.0 to restrict the pushdowns. RDS Postgres 15.2 uses mysql_fdw 2.9.0, while 14.7 uses 2.7.0, which is why the issue didn't happen on 14.7.

By default, the config file includes the following settings for text:

ROUTINE pg_catalog.length(text)
ROUTINE pg_catalog.lower(text)
ROUTINE pg_catalog.upper(text)
OPERATOR pg_catalog.=(text,text)
OPERATOR pg_catalog.>(text,text)
OPERATOR pg_catalog.<(text,text)
OPERATOR pg_catalog.>=(text,text)
OPERATOR pg_catalog.<=(text,text)
OPERATOR pg_catalog.<>(text,text)
OPERATOR pg_catalog.~~(text,text)
OPERATOR pg_catalog.~~(character,text)

And the following settings for character:

ROUTINE pg_catalog.length(character)
OPERATOR pg_catalog.<(character,character)
OPERATOR pg_catalog.~~(character,text)

@surajkharage19 , is there a reason character is now more limited in pushdowns by default? Would it be possible to add to the default config file all the configurations that were available by default in previous versions (for all the data types)?

@cseickel , since the needed operators for text are already included in the config file by default, could you try to use that as a workaround in the meantime?

cseickel commented 1 year ago

Thanks for jumping in @AlexFriedmanAWS. I could certainly alter the types of my foreign tables to use text and that would fix this specific problem. I prefer to not make all these substitutions and I especially don't want to go through all of my foreign tables and test everything looking for other instances of bad pushdown config. At this point, it's easier just to hold back the version of this instance.

The way we are setup now, I have an instance whose only job is house fdw and serve as the connection between all of our other instances and externals dbs, so it doesn't affect any other workload I have to hold the version back on this one fdw instance.

If we get to far behind in versions without either side providing an option to control these settings, then I will go through and make these manual adjustments, but for now I'm content to wait.

surajkharage19 commented 1 year ago

Hi @cseickel, @AlexFriedmanAWS,

We have now added more default entires in the configuration file which includes the entries suggested by you. Can you please check if that is useful at your end by pulling latest sources?