If we have a prepared statement like:
SELECT my_func($1::text, $2::int)
Is there is any gain in speed if I prepare a statement with this call and do the call via the prepared statement.
If we have a prepared statement like:
SELECT my_func($1::text, $2::int)
Is there is any gain in speed if I prepare a statement with this call and do the call via the prepared statement.
Let me quote the docs here:
Prepared statements have the largest performance advantage when a single session is being used to execute a large number of similar statements. The performance difference will be particularly significant if the statements are complex to plan or rewrite, for example, if the query involves a join of many tables or requires the application of several rules. If the statement is relatively simple to plan and rewrite but relatively expensive to execute, the performance advantage of prepared statements will be less noticeable.
Emphasize is mine. I think it clearly states in which conditions PREPARE
can have benefits.
Still, all languages currently provide a native way to prepare statements (like PHP), so the overall machinery is executed for you behind the scenes.
To make it short:
PREPARE
or platform's functionality) to prepare for performance reasons.