Closed rossj-cargotel closed 7 years ago
As a workaround I found that I can cast char() columns to text and avoid the error.
Yeah, looks like the FDW is not careful enough when deparsing pushdown predicates. Will look if i can prepare a patch for this.
Btw., your debugging output leaks sensitive user information! I've removed the responsible part from the code to be safe in the future. Sorry for that, it was tempting to have the associated options in the log for debugging, but it seems it's too dangerous if it gets listed in public bug reports easily.
For everyone else trying to use this fdw and wants to understand what is happening:
SELECT * FROM load_flags WHERE type = 'R'
basically means that 'R' which is text needs a cast via ::bpchar
to match char(1)
(see http://www.postgresql.org/docs/9.5/static/typeconv-query.html for details).
This cast is also pushed down to the target server, which does not support bpchar, as a quick fix two options are possible:
SELECT * FROM load_flags WHERE type::text = 'R'
which eliminates the WHERE
push down and results in all rows being transferred and filtered in postgres, or:
SELECT * FROM load_flags WHERE type = 'R'::char(1)
which results in a properly pushed down query
SELECT *, rowid FROM load_flags WHERE type = 'R'::character(1)
Oh, another option:
ALTER FOREIGN TABLE load_flags ALTER "type" TYPE varchar(1)
which will interestingly enough result in for :
SELECT *, rowid FROM load_flags WHERE type = 'R'::character varying(255)
not sure why 255 all of a sudden ;)
Cannot wait to see the actual fix -- I tried fixing it myself, but I am lost in the fdw code for now :(
The current caveat in the pushdown code is, that the machinery currently doesn't have any clue about the typmods used in the foreign table and in your specific example gets a TEXT expression for deparsing. Responsible for this is ifxConvertNodeConst(), which has a special case for TEXT only, which silently assumes IFX_MAX_VARCHAR_LEN for a varchar column in Informix. The reason why that even counts for varchar is, that the PostgreSQL parser adds a RelabelType Node into the query tree expression, which results in type TEXT.
I'm currently working on the deparsing code to make it more smarter for CHAR, VARCHAR and TEXT, which need certainly more special care.
So some news here, sorry for the long delay.
I finally came up with this patch https://github.com/credativ/informix_fdw/commit/8a49038064d144024f7dbb62ce1a8b84e61f1a92. Its pushed in its own testing branch, so beware to use it in production. However, the fixes there aim to address all the issues Florian and rossj-cargotel brought up here. Opinions?
Thanks, I'll see that I can test it. Regarding your commit message: I did not mean to gripe, I merely wanted to provide more background and help in debugging since I have/had no idea about fdws at all. Thank you for your work on it!
The changes seem to work nicely for me, all of my examples are pushed down properly. During testing I noted that IN-clauses are not pushed down, but that also happens for integers, so that would be another problem…
@apollo13 : "gripe" is PostgreSQL jargon for basically any kind of bug report, if you grep the PostgreSQL git log, you'll see it used a lot there.
Tells you how much I am involved with PG development :D
Please note the other commit in the branch. I've just pushed https://github.com/credativ/informix_fdw/commit/bd384d77425b375581572592b1cc9f114ae34513, which adds the ability to pushdown IN() expressions to the remote Informix instance.
I'm going to prepare the FDW also for 9.6 and make a release if everything is in shape.
Related patches merged with master, so i'm closing this, too.
Hi again!
I've been trying to convert a working function to use the informix foreign tables instead of the local postgres tables and I'm running into this issue:
load_flags on informix:
The foreign table is the same:
Any ideas?
Thanks! Jeff