Re: BUG #16583: merge join on tables with different DB collation behind postgres_fdw fails
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Etsuro Fujita <etsuro.fujita@gmail.com>
Cc: Ibrar Ahmed <ibrar.ahmad@gmail.com>,
PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>,
Neil Chen <carpenter.nail.cz@gmail.com>
Date: 2021-09-24T19:11:33Z
Lists: pgsql-bugs, pgsql-hackers
Attachments
- postgres_fdw-collation-doc-warnings.patch (text/x-diff) patch
Etsuro Fujita <etsuro.fujita@gmail.com> writes: > One thing I noticed is that collatable operators/functions sent to the > remote might also cause an unexpected result when the default > collations are not compatible. Consider this example (even with your > patch): > ... > where ft1 is a foreign table with an integer column c1. As shown > above, the sort using the collatable function chr() is performed > remotely, so the select query might produce the result in an > unexpected sort order when the default collations are not compatible. I don't think there's anything really new there --- it's still assuming that COLLATE "default" means the same locally and remotely. As a short-term answer, I propose that we apply (and back-patch) the attached documentation changes. Longer-term, it seems like we really have to be able to represent the notion of a remote column that has an "unknown" collation (that is, one that doesn't match any local collation, or at least is not known to do so). My previous patch essentially makes "default" act that way, but conflating "unknown" with "default" has too many downsides. A rough sketch for making this happen is: 1. Create a built-in "unknown" entry in pg_collation. Insert some hack or other to prevent this from being applied to any real, local column; but allow foreign-table columns to have it. 2. Apply mods, probably fairly similar to my patch, that prevent postgres_fdw from believing that "unknown" matches any local collation. (Hm, actually maybe no special code change will be needed here, once "unknown" has its own OID?) 3. Change postgresImportForeignSchema so that it can substitute the "unknown" collation at need. The exact rules for this could be debated depending on whether you'd rather prioritize safety or ease-of-use, but I think at least we should use "unknown" whenever import_collate is turned off. Perhaps there should be an option to substitute it for remote "default" as well. (Further down the road, perhaps that could be generalized to allow a user-controlled mapping from remote to local collations.) Anyway, I think I should withdraw the upthread patch; we don't want to go that way. regards, tom lane
Commits
-
Doc: extend warnings about collation-mismatch hazards in postgres_fdw.
- 2aa255588756 9.6.24 landed
- 1d7e8e772453 10.19 landed
- b274c982db67 11.14 landed
- 97c5651cea0f 12.9 landed
- 7b0be9fb2ddd 15.0 landed
- 739b872f6c98 13.5 landed
- 02c4e3533926 14.0 landed
-
Add support for asynchronous execution.
- 27e1f14563cf 14.0 cited
-
Suppress unnecessary RelabelType nodes in yet more cases.
- 814a57065ec9 12.5 landed
- 69ffc2f83899 13.0 landed
- 207293240780 14.0 landed