Re: ORDER BY pushdowns seem broken in postgres_fdw
Ronan Dunklau <ronan.dunklau@aiven.io>
From: Ronan Dunklau <ronan.dunklau@aiven.io>
To: Robert Haas <robertmhaas@gmail.com>,
Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>,
David Rowley <dgrowleyml@gmail.com>
Cc: Ranier Vilela <ranier.vf@gmail.com>,
PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2021-07-27T05:20:17Z
Lists: pgsql-hackers
Le mardi 27 juillet 2021, 03:19:18 CEST David Rowley a écrit : > On Thu, 22 Jul 2021 at 20:49, Ronan Dunklau <ronan.dunklau@aiven.io> wrote: > > Le jeudi 22 juillet 2021, 09:44:54 CEST David Rowley a écrit : > > > Can you also use explain (verbose, costs off) the same as the other > > > tests in that area. Having the costs there would never survive a run > > > of the buildfarm. Different hardware will produce different costs, e.g > > > 32-bit hardware might cost cheaper due to narrower widths. > > > > Sorry about that. Here it is. > > I had a look over the v5 patch and noticed a few issues and a few > things that could be improved. Thank you. > > This is not ok: > > + tuple = SearchSysCache4(AMOPSTRATEGY, > + ObjectIdGetDatum(pathkey->pk_opfamily), > + em->em_datatype, > + em->em_datatype, > + pathkey->pk_strategy); > > SearchSysCache* expects Datum inputs, so you must use the *GetDatum() > macro for each input that isn't already a Datum. Noted. > > I also: > 1. Changed the error message for when that lookup fails so that it's > the same as the others that perform a lookup with AMOPSTRATEGY. > 2. Put back the comment in equivclass.c for find_em_expr_for_rel. I > saw no reason that comment should be changed when the function does > exactly what it did before. > 3. Renamed appendOrderbyUsingClause to appendOrderBySuffix. I wasn't > happy that the name indicated it was only handling USING clauses when > it also handled ASC/DESC. I also moved in the NULLS FIRST/LAST stuff > in there I agree that name is better. > 4. Adjusted is_foreign_pathkey() to make it easier to read and do > is_shippable() before calling find_em_expr_for_rel(). I didn't see > the need to call find_em_expr_for_rel() when is_shippable() returned > false. > 5. Adjusted find_em_expr_for_rel() to remove the ternary operator. > > I've attached what I ended up with. Looks good to me. > > It seems that it was the following commit that introduced the ability > for sorts to be pushed down to the foreign server, so it would be good > if the authors of that patch could look over this. One thing in particular I was not sure about was how to fetch the operator associated with the path key ordering. I chose to go through the opfamily recorded on the member, but maybe locating the original SortGroupClause by its ref and getting the operator number here woud have worked. It seems more straightforward like this though. -- Ronan Dunklau
Commits
-
Fix postgres_fdw to check shippability of sort clauses properly.
- f3dd9fe1dd92 15.0 landed
- b9eb0412ffb8 11.16 landed
- 9f9489aa2eef 14.3 landed
- 989d3e4a2957 12.11 landed
- 79df1d20c59c 13.7 landed
- 728fc0f9a2dd 10.21 landed
-
postgres_fdw: Add ORDER BY to some remote SQL queries.
- f18c944b6137 9.6.0 cited