Patent ID: 7359922

Claim:
In a database system, a method for optimizing a query requesting data from a database in an ordered form, the method comprising: generating a plurality of partial access plans for obtaining data requested by the query; constructing generalized orders representing requirements of the query for ordering of data, each generalized order including an array having a plurality of entries, wherein each of said plurality of entries includes an expression, a sequence type, and a fixed attribute; creating generalized orders representing order properties of said partial access plans; intersecting the generalized orders representing requirements of the query for ordering of data with the generalized orders representing order properties of said partial access plans to determine partial access plans having matching orderings, wherein said intersecting step includes constructing a new generalized order representing results of intersecting a generalized order representing requirements of the query for ordering of data with a generalized orders representing order properties of a partial access plan; and building a query execution plan for obtaining and ordering the data requested by the query based, at least in part, on selecting partial access plans having matching orderings.