* Compute the hashkey for a given function invocation * * The hashkey is returned into the caller-provided storage at *hashkey. */
| 2469 | * The hashkey is returned into the caller-provided storage at *hashkey. |
| 2470 | */ |
| 2471 | static void |
| 2472 | compute_function_hashkey(FunctionCallInfo fcinfo, |
| 2473 | Form_pg_proc procStruct, |
| 2474 | PLpgSQL_func_hashkey *hashkey, |
| 2475 | bool forValidator) |
| 2476 | { |
| 2477 | /* Make sure any unused bytes of the struct are zero */ |
| 2478 | MemSet(hashkey, 0, sizeof(PLpgSQL_func_hashkey)); |
| 2479 | |
| 2480 | /* get function OID */ |
| 2481 | hashkey->funcOid = fcinfo->flinfo->fn_oid; |
| 2482 | |
| 2483 | /* get call context */ |
| 2484 | hashkey->isTrigger = CALLED_AS_TRIGGER(fcinfo); |
| 2485 | hashkey->isEventTrigger = CALLED_AS_EVENT_TRIGGER(fcinfo); |
| 2486 | |
| 2487 | /* |
| 2488 | * If DML trigger, include trigger's OID in the hash, so that each trigger |
| 2489 | * usage gets a different hash entry, allowing for e.g. different relation |
| 2490 | * rowtypes or transition table names. In validation mode we do not know |
| 2491 | * what relation or transition table names are intended to be used, so we |
| 2492 | * leave trigOid zero; the hash entry built in this case will never be |
| 2493 | * used for any actual calls. |
| 2494 | * |
| 2495 | * We don't currently need to distinguish different event trigger usages |
| 2496 | * in the same way, since the special parameter variables don't vary in |
| 2497 | * type in that case. |
| 2498 | */ |
| 2499 | if (hashkey->isTrigger && !forValidator) |
| 2500 | { |
| 2501 | TriggerData *trigdata = (TriggerData *) fcinfo->context; |
| 2502 | |
| 2503 | hashkey->trigOid = trigdata->tg_trigger->tgoid; |
| 2504 | } |
| 2505 | |
| 2506 | /* get input collation, if known */ |
| 2507 | hashkey->inputCollation = fcinfo->fncollation; |
| 2508 | |
| 2509 | if (procStruct->pronargs > 0) |
| 2510 | { |
| 2511 | /* get the argument types */ |
| 2512 | memcpy(hashkey->argtypes, procStruct->proargtypes.values, |
| 2513 | procStruct->pronargs * sizeof(Oid)); |
| 2514 | |
| 2515 | /* resolve any polymorphic argument types */ |
| 2516 | plpgsql_resolve_polymorphic_argtypes(procStruct->pronargs, |
| 2517 | hashkey->argtypes, |
| 2518 | NULL, |
| 2519 | fcinfo->flinfo->fn_expr, |
| 2520 | forValidator, |
| 2521 | NameStr(procStruct->proname)); |
| 2522 | } |
| 2523 | } |
| 2524 | |
| 2525 | /* |
| 2526 | * This is the same as the standard resolve_polymorphic_argtypes() function, |
no test coverage detected