@@ -252,6 +252,7 @@ compute_function_hashkey(FunctionCallInfo fcinfo,
252252 CachedFunctionHashKey * hashkey ,
253253 Size cacheEntrySize ,
254254 bool includeResultType ,
255+ bool includeInputCollation ,
255256 bool forValidator )
256257{
257258 /* Make sure pad bytes within fixed part of the struct are zero */
@@ -286,8 +287,9 @@ compute_function_hashkey(FunctionCallInfo fcinfo,
286287 hashkey -> trigOid = trigdata -> tg_trigger -> tgoid ;
287288 }
288289
289- /* get input collation, if known */
290- hashkey -> inputCollation = fcinfo -> fncollation ;
290+ /* get input collation, if known and wanted */
291+ if (includeInputCollation )
292+ hashkey -> inputCollation = fcinfo -> fncollation ;
291293
292294 /*
293295 * We include only input arguments in the hash key, since output argument
@@ -487,6 +489,10 @@ delete_function(CachedFunction *func)
487489 * If includeResultType is true and the function returns composite,
488490 * include the actual result descriptor in the cache lookup key.
489491 *
492+ * If includeInputCollation is true, include the call's input collation in
493+ * the cache lookup key. Languages whose compiled form doesn't depend on the
494+ * collation should pass false, to avoid building redundant cache entries.
495+ *
490496 * If forValidator is true, we're only compiling for validation purposes,
491497 * and so some checks are skipped. In this case the passed fcinfo need
492498 * only provide the function OID and indications of whether the function
@@ -507,6 +513,7 @@ cached_function_compile(FunctionCallInfo fcinfo,
507513 CachedFunctionDeleteCallback dcallback ,
508514 Size cacheEntrySize ,
509515 bool includeResultType ,
516+ bool includeInputCollation ,
510517 bool forValidator )
511518{
512519 Oid funcOid = fcinfo -> flinfo -> fn_oid ;
@@ -535,7 +542,7 @@ cached_function_compile(FunctionCallInfo fcinfo,
535542 /* Compute hashkey using function signature and actual arg types */
536543 compute_function_hashkey (fcinfo , procStruct , & hashkey ,
537544 cacheEntrySize , includeResultType ,
538- forValidator );
545+ includeInputCollation , forValidator );
539546 hashkey_valid = true;
540547
541548 /* And do the lookup */
@@ -591,7 +598,7 @@ cached_function_compile(FunctionCallInfo fcinfo,
591598 if (!hashkey_valid )
592599 compute_function_hashkey (fcinfo , procStruct , & hashkey ,
593600 cacheEntrySize , includeResultType ,
594- forValidator );
601+ includeInputCollation , forValidator );
595602
596603 /*
597604 * Create the new function struct, if not done already. The function
0 commit comments