1. One or more computer-readable storage media storing computer-executable instructions for causing a computer system when programmed thereby to perform: receiving, at a query engine, a request comprising a first version of a database query including first query code in a declarative language, the database query specifying a plurality of database operations, the plurality of database operations comprising at least one linear operation and at least one non-linear operation; with the query engine, based on the first query code, generating second query code for the at least one non-linear operation in an imperative language; with the query engine, embedding the second query code in a second version of the database query, the second version of the database query comprising the at least one linear operation specified in the declarative language and the at least one non-linear operation in the imperative language code; with an execution engine of a database management system, generating an intermediate representation of the at least one linear operation specified in a declarative language, the intermediate representation specifying one or more operations for retrieving information from one or more database records; with the execution engine, executing the intermediate representation and directly executing the imperative language code for the at least one non-linear operation, wherein the execution engine retrieves information from one or more database records as specified by the intermediate representation and performs one or more calculations on the retrieved data as specified by the at least one non-linear operation; and with the execution engine, returning execution results in response to the request.