2

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?

2

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.

  • Are there definitions for these terms, or can you link me to the source code that handles prepared statements? Thank you in advance. – Jim Bob Feb 27 '15 at 23:26
  • @JimBob: The source code for this is in postgres.c, the "main" module of the postgres backend: github.com/postgres/postgres/blob/… – Erwin Brandstetter Feb 27 '15 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.