Skip to content

Commit 2e835a4

Browse files
committed
Fix the code that adds regclass constants to a plan's list of relation OIDs
that it depends on for replan-forcing purposes. We need to consider plain OID constants too, because eval_const_expressions folds a RelabelType atop a Const to just a Const. This change could result in OID values that aren't really for tables getting added to the dependency list, but the worst-case consequence would be occasional useless replans. Per report from Gabriele Messineo.
1 parent 19a6bac commit 2e835a4

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/backend/optimizer/plan/setrefs.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.141 2008/01/01 19:45:50 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.142 2008/06/17 14:51:32 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -63,6 +63,17 @@ typedef struct
6363
int rtoffset;
6464
} fix_upper_expr_context;
6565

66+
/*
67+
* Check if a Const node is a regclass value. We accept plain OID too,
68+
* since a regclass Const will get folded to that type if it's an argument
69+
* to oideq or similar operators. (This might result in some extraneous
70+
* values in a plan's list of relation dependencies, but the worst result
71+
* would be occasional useless replans.)
72+
*/
73+
#define ISREGCLASSCONST(con) \
74+
(((con)->consttype == REGCLASSOID || (con)->consttype == OIDOID) && \
75+
!(con)->constisnull)
76+
6677
#define fix_scan_list(glob, lst, rtoffset) \
6778
((List *) fix_scan_expr(glob, (Node *) (lst), rtoffset))
6879

@@ -694,7 +705,7 @@ fix_scan_expr_mutator(Node *node, fix_scan_expr_context *context)
694705
Const *con = (Const *) node;
695706

696707
/* Check for regclass reference */
697-
if (con->consttype == REGCLASSOID && !con->constisnull)
708+
if (ISREGCLASSCONST(con))
698709
context->glob->relationOids =
699710
lappend_oid(context->glob->relationOids,
700711
DatumGetObjectId(con->constvalue));
@@ -722,7 +733,7 @@ fix_scan_expr_walker(Node *node, fix_scan_expr_context *context)
722733
Const *con = (Const *) node;
723734

724735
/* Check for regclass reference */
725-
if (con->consttype == REGCLASSOID && !con->constisnull)
736+
if (ISREGCLASSCONST(con))
726737
context->glob->relationOids =
727738
lappend_oid(context->glob->relationOids,
728739
DatumGetObjectId(con->constvalue));
@@ -1391,7 +1402,7 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context)
13911402
Const *con = (Const *) node;
13921403

13931404
/* Check for regclass reference */
1394-
if (con->consttype == REGCLASSOID && !con->constisnull)
1405+
if (ISREGCLASSCONST(con))
13951406
context->glob->relationOids =
13961407
lappend_oid(context->glob->relationOids,
13971408
DatumGetObjectId(con->constvalue));
@@ -1489,7 +1500,7 @@ fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context)
14891500
Const *con = (Const *) node;
14901501

14911502
/* Check for regclass reference */
1492-
if (con->consttype == REGCLASSOID && !con->constisnull)
1503+
if (ISREGCLASSCONST(con))
14931504
context->glob->relationOids =
14941505
lappend_oid(context->glob->relationOids,
14951506
DatumGetObjectId(con->constvalue));

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy