Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit211e157

Browse files
committed
Change postgres_fdw to show casts as casts, not underlying function calls.
On reflection this method seems to be exposing an unreasonable amount ofimplementation detail. It wouldn't matter when talking to a remote serverof the identical Postgres version, but it seems likely to make things worsenot better if the remote is a different version with different castinginfrastructure. Instead adopt ruleutils.c's policy of regurgitating thecast as it was originally specified; including not showing it at all, ifit was implicit to start with. (We must do that because for some datatypesexplicit and implicit casts have different semantics.)
1 parent5fd386b commit211e157

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

‎contrib/postgres_fdw/deparse.c

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -855,10 +855,6 @@ deparseArrayRef(StringInfo buf, ArrayRef *node, PlannerInfo *root)
855855

856856
/*
857857
* Deparse given node which represents a function call into buf.
858-
*
859-
* Here not only explicit function calls and explicit casts but also implicit
860-
* casts are deparsed to avoid problems caused by different cast settings
861-
* between local and remote.
862858
*/
863859
staticvoid
864860
deparseFuncExpr(StringInfobuf,FuncExpr*node,PlannerInfo*root)
@@ -870,6 +866,37 @@ deparseFuncExpr(StringInfo buf, FuncExpr *node, PlannerInfo *root)
870866
boolfirst;
871867
ListCell*arg;
872868

869+
/*
870+
* If the function call came from an implicit coercion, then just show the
871+
* first argument.
872+
*/
873+
if (node->funcformat==COERCE_IMPLICIT_CAST)
874+
{
875+
deparseExpr(buf, (Expr*)linitial(node->args),root);
876+
return;
877+
}
878+
879+
/*
880+
* If the function call came from a cast, then show the first argument
881+
* plus an explicit cast operation.
882+
*/
883+
if (node->funcformat==COERCE_EXPLICIT_CAST)
884+
{
885+
Oidrettype=node->funcresulttype;
886+
int32coercedTypmod;
887+
888+
/* Get the typmod if this is a length-coercion function */
889+
(void)exprIsLengthCoercion((Node*)node,&coercedTypmod);
890+
891+
deparseExpr(buf, (Expr*)linitial(node->args),root);
892+
appendStringInfo(buf,"::%s",
893+
format_type_with_typemod(rettype,coercedTypmod));
894+
return;
895+
}
896+
897+
/*
898+
* Normal function: display as proname(args).
899+
*/
873900
proctup=SearchSysCache1(PROCOID,ObjectIdGetDatum(node->funcid));
874901
if (!HeapTupleIsValid(proctup))
875902
elog(ERROR,"cache lookup failed for function %u",node->funcid);
@@ -1062,9 +1089,10 @@ static void
10621089
deparseRelabelType(StringInfobuf,RelabelType*node,PlannerInfo*root)
10631090
{
10641091
deparseExpr(buf,node->arg,root);
1065-
appendStringInfo(buf,"::%s",
1066-
format_type_with_typemod(node->resulttype,
1067-
node->resulttypmod));
1092+
if (node->relabelformat!=COERCE_IMPLICIT_CAST)
1093+
appendStringInfo(buf,"::%s",
1094+
format_type_with_typemod(node->resulttype,
1095+
node->resulttypmod));
10681096
}
10691097

10701098
/*

‎contrib/postgres_fdw/expected/postgres_fdw.out

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,11 @@ SELECT * FROM ft1 WHERE false;
188188

189189
-- with WHERE clause
190190
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE t1.c1 = 101 AND t1.c6 = '1' AND t1.c7 >= '1';
191-
QUERY PLAN
192-
------------------------------------------------------------------------------------------------------------------------------------------------------
191+
QUERY PLAN
192+
------------------------------------------------------------------------------------------------------------------------------------------------
193193
Foreign Scan on public.ft1 t1
194194
Output: c1, c2, c3, c4, c5, c6, c7, c8
195-
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE ((c7 >= '1'::bpchar)) AND (("C 1" = 101)) AND ((c6::text = '1'::text))
195+
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE ((c7 >= '1'::bpchar)) AND (("C 1" = 101)) AND ((c6 = '1'::text))
196196
(3 rows)
197197

198198
SELECT * FROM ft1 t1 WHERE t1.c1 = 101 AND t1.c6 = '1' AND t1.c7 >= '1';
@@ -353,11 +353,11 @@ EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c1 IS NOT NULL; --
353353
(3 rows)
354354

355355
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE round(abs(c1), 0) = 1; -- FuncExpr
356-
QUERY PLAN
357-
--------------------------------------------------------------------------------------------------------------------------------
356+
QUERY PLAN
357+
---------------------------------------------------------------------------------------------------------------------
358358
Foreign Scan on public.ft1 t1
359359
Output: c1, c2, c3, c4, c5, c6, c7, c8
360-
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE ((round("numeric"(abs("C 1")), 0) = 1::numeric))
360+
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE ((round(abs("C 1"), 0) = 1::numeric))
361361
(3 rows)
362362

363363
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c1 = -c1; -- OpExpr(l)
@@ -369,11 +369,11 @@ EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c1 = -c1; --
369369
(3 rows)
370370

371371
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE 1 = c1!; -- OpExpr(r)
372-
QUERY PLAN
373-
----------------------------------------------------------------------------------------------------------------
372+
QUERY PLAN
373+
----------------------------------------------------------------------------------------------------------
374374
Foreign Scan on public.ft1 t1
375375
Output: c1, c2, c3, c4, c5, c6, c7, c8
376-
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE ((1::numeric = (int8("C 1") !)))
376+
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE ((1::numeric = ("C 1" !)))
377377
(3 rows)
378378

379379
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE (c1 IS NOT NULL) IS DISTINCT FROM (c1 IS NOT NULL); -- DistinctExpr
@@ -401,11 +401,11 @@ EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c1 = (ARRAY[c1,c2,3])[
401401
(3 rows)
402402

403403
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c6 = E'foo''s\\bar'; -- check special chars
404-
QUERY PLAN
405-
-------------------------------------------------------------------------------------------------------------------
404+
QUERY PLAN
405+
-------------------------------------------------------------------------------------------------------------
406406
Foreign Scan on public.ft1 t1
407407
Output: c1, c2, c3, c4, c5, c6, c7, c8
408-
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE ((c6::text = E'foo''s\\bar'::text))
408+
Remote SQL: SELECT "C 1", c2, c3, c4, c5, c6, c7, c8 FROM "S 1"."T 1" WHERE ((c6 = E'foo''s\\bar'::text))
409409
(3 rows)
410410

411411
EXPLAIN (VERBOSE, COSTS false) SELECT * FROM ft1 t1 WHERE c8 = 'foo'; -- can't be sent to remote

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp