Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 98b559b

Browse files
committed
Fix support function to work with operators
Previously a support function only optimized function calls on consts but the operator logic inserts a CoerceToDomain node before the const as well. This PR allows this case to also be handled by relaxing the constrainst on args from having to be constants to having to be merely const-like. That is the expression cannot reference any vars or use volatile functions.
1 parent 6305969 commit 98b559b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

extension/src/support.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <nodes/pathnodes.h>
1010
#include <nodes/supportnodes.h>
11+
#include <nodes/bitmapset.h>
12+
#include <optimizer/optimizer.h>
1113

1214
#ifdef PG_MODULE_MAGIC
1315
PG_MODULE_MAGIC;
@@ -52,8 +54,13 @@ const_support(PG_FUNCTION_ARGS)
5254
}
5355
foreach(lc, expr->args)
5456
{
57+
/* Check that these are expressions that don't reference
58+
any vars, i.e. they are constants or expressions of constants */
5559
Node *arg = lfirst(lc);
56-
if(!IsA(arg, Const))
60+
Relids relids = pull_varnos(arg);
61+
62+
if(bms_membership(relids) != BMS_EMPTY_SET ||
63+
contain_volatile_functions(arg))
5764
{
5865
PG_RETURN_POINTER(NULL);
5966
}

0 commit comments

Comments
 (0)