54.6. Managed Functions #
Managed functions can be used in distributed queries or with other objects managed by Postgres Pro Shardman. These functions are registered in the shardman.global_functions dictionary.
A managed function can be marked as a shippable one. Use of shippable and always-shippable functions may help to reduce the load on the local node when executing distributed queries that involve remote nodes.
An unmanaged function can be converted to the managed one using CREATE OR REPLACE FUNCTION ... WITH (global). The backward conversion is not possible.
For converting an unmanaged function to the managed one, the following prerequisites must be met:
The unmanaged function must be declared only on the node of a cluster where the conversion is made.
If an unmanaged function with the same signature already exists on the other nodes of the cluster, the conversion fails.
A managed role must already exist in a cluster.
Only managed roles can own a managed function.
When multiple functions are to be dropped using a single DROP FUNCTION ... command, make sure that managed and unmanaged functions are not mixed in the command.
Use a separate DROP command for each function class.
54.6.1. Shippable Managed Functions #
During the planning of a distributed SQL query execution, a WHERE clause is evaluated if present. An individual condition in the clause is classified as either a local or remote filter.
While local filters are applied on the coordinator node after fetching rows from the remote node, the remote ones are shipped to the remote node and can be applied remotely.
In general, functions that are present in the query are executed on the coordinator node. However, there is an exception from this rule: if a shippable function is present in the query and the query is eligible for fast path, then this function is executed on the remote nodes, not the coordinator node.
When using EXPLAIN to view a plan of a distributed SQL query, any non-shippable functions are highlighted in the command output like that:
EXPLAIN SELECT * FROM sharded_table WHERE id = f(...);
...
Non-shippable:
Functions:
public.f(...)
A managed function can be marked as shippable using ALTER FUNCTION ... SET shippable = true. To remove the mark, use the same command with false.
To mark a managed function as shippable, the following prerequisites must be met:
The managed function must not use
voidas the return type.The managed function must have the
IMMUTABLEvolatility category.The volatility category of the shippable managed function cannot be changed.