Patent ID: 8356027

Claim:
A computer program product comprising a machine-readable medium storing instructions that, when executed by at least one programmable processor, cause the at least one programmable processor to perform operations comprising: receiving a query execution plan describing a query for accessing data and comprising a first procedural construct; matching the first procedural construct to a stored procedural pattern for which an equivalent declarative operator has been pre-defined, the pre-defined equivalent declarative operator comprising a conversion of procedural logic within the first procedural construct, the conversion comprising implicitly unrolling loops within the procedural logic and independently calculating an expression for each tuple within the procedural logic, use of the pre-defined equivalent declarative operator resulting in avoidance of at least one side effect arising from a tuple within the procedural logic being used to transport state between calculations during loop iterations; generating a hybrid execution plan, the generating comprising replacing the first procedural construct with the pre-defined equivalent declarative operator such that the hybrid query execution plan comprises a combination of at least one other procedural construct of the query execution plan and the predefined equivalent declarative operator; assigning a hybrid execution plan processing cost to execution of the hybrid execution plan and a query execution plan processing cost to execution of the query execution plan, the assigning comprising evaluating a cost model for the hybrid execution plan and the query execution plan; and executing the query using the hybrid execution plan after determining that the hybrid execution plan processing cost is less than the query execution plan processing cost or the query execution plan after determining that if the hybrid execution plan processing cost is greater than the query execution plan processing cost.