Postgresql – How compiled are prepared statements

performancepostgresqlprepared-statement

I found this explanation of how prepared statements are compiled, but I'm still unsure.

What exactly is "compiled" in the context of a prepared statement? Is a C compiler executed to create a custom executable?

If so, is that limited by prepareThreshold?

If not, what exactly is it compiled into, and are there any projects for converting prepared statements into executables?

Best Answer

The post you found is from 2007. Rather start with the current manual:

When the PREPARE statement is executed, the specified statement is parsed, analyzed, and rewritten. When an EXECUTE command is subsequently issued, the prepared statement is planned and executed. This division of labor avoids repetitive parse analysis work, while allowing the execution plan to depend on the specific parameter values supplied.

And:

If a prepared statement is executed enough times, the server may eventually decide to save and re-use a generic plan rather than re-planning each time.

Bold emphasis mine. Read more details in the manual.

I wouldn't know of projects trying to convert prepared statements into executables.