A system and method that manages and pre-optimizes incoming database
queries by decomposing queries into component parts, and executing
corresponding pre-compiled procedures. A requestor specifies search
arguments and/or query options. Middle tier code cooperates with database
code by decomposing the query operations into stages, one stage for each
specified search argument. To improve performance, the stages are ordered
such that the most selective searches are executed first, and if after
any stage it is recognized that no results are possible, the search
terminates without attempting further stages. As each stage is executed,
a list of matching keys is maintained in the database. After completing
the stages, the list is sorted as specified and returned to the middle
tier, which then retrieves the details for each entity represented in the
key list, and formats and returns the results to the client. Relatively
complex queries may be submitted without executing ad-hoc queries.