> > Wouldn't doing something like this inside IsMergeableConst
> > """
> > if (!IsA(arg, Const) && !IsA(arg, Param))
> > """
> >
> > instead of
> > """
> > if (!IsA(arg, Const))
> > """
> >
> > be sufficient?
>
> That's exactly what the original rejected implementation was doing. I
> guess to answer this question fully I need to do some more detailed
> investigation, I'm probably not aware about everything at this point.
I am not sure which rejected implementation you are referring to
as this is a log thread :). But I will just add my findings ( as I
really wanted to try this out )
on top of your latest v27 here. Maybe this is all we need. Essentially
check for a PARAM_EXTERN
as we are scanning through the elements and only consider those types of args,
and the constants of course.
"""
--- a/src/backend/nodes/queryjumblefuncs.c
+++ b/src/backend/nodes/queryjumblefuncs.c
@@ -295,6 +295,14 @@ IsMergeableConst(Node *element, List
**known_immutable_funcs)
{
Node *arg = lfirst(temp);
+ if (IsA(arg, Param))
+ {
+ Param *p = (Param *) arg;
+
+ if (p->paramkind == PARAM_EXTERN)
+ return true;
+ }
+
if (!IsA(arg, Const))
return false;
}
@@ -302,6 +310,14 @@ IsMergeableConst(Node *element, List
**known_immutable_funcs)
return true;
}
+ if (IsA(element, Param))
+ {
+ Param *p = (Param *) element;
+
+ if (p->paramkind == PARAM_EXTERN)
+ return true;
+ }
+
if (!IsA(element, Const))
return false;
"""
"""
set query_id_squash_values = on;
select pg_stat_statements_reset();
select where 1 in (1, 2, 3);
select where 1 in (1, 2, 3, 4);
prepare prep(int, int, int) as select where 1 in ($1, $2, $3);
execute prep(1, 2, 3);
deallocate prep;
prepare prep(int, int, int, int) as select where 1 in ($1, $2, $3, $4);
execute prep(1, 2, 3, 4);
deallocate prep;
-- mixed constants and parameters
prepare prep(int, int, int) as select where 1 in ($1, $2, $3, 4);
execute prep(1, 2, 3);
deallocate prep;
prepare prep(int, int, int, int) as select where 1 in ($1, $2, $3, 4, $4);
execute prep(1, 2, 3, 5);
deallocate prep;
select where 1 in ($1, $2, $3) \bind 1 2 3
;
select where 1 in ($1, $2, $3, $4) \bind 1 2 3 4
;
-- mixed constants and parameters
select where 1 in ($1, $2, $3, 4) \bind 1 2 3
;
select where 1 in ($1, $2, $3, 4, $4) \bind 1 2 3 5
;
select query, queryid, calls from pg_stat_statements;
postgres=# select query, queryid, calls from pg_stat_statements;
query | queryid | calls
------------------------------------+----------------------+-------
select pg_stat_statements_reset() | 522241623491678666 | 1
deallocate $1 | -3638851837470664936 | 4
select where $1 in ($2 /*, ... */) | -7657972370536959080 | 10
(3 rows)
"""
---
Sami