In order to maximize efficiency of the compound statement, sub-statements should be prepared before the BEGIN COMPOUND statement, and then executed within the compound statement.
This also simplifies error handling since prepare errors can be handled outside of the compound statement.