Abstract:
A procedure for detecting a reordering requirement in a directed record stream during query execution in a relational database processing system. The query compiler component of a relational database processing system includes procedures for building query execution plans (QEPs) for evaluation preparatory to selecting an optimal plan for execution. These plans are constructed from the bottom up using an internal graphical representation for the user query that has a number of relation nodes interconnected by directed record streams (data flows). A relational operation within each node imposes an &#34;order requirement&#34; on the outflow stream represented by an order requirement vector O R . The records within each directed record stream have an &#34;order property&#34; represented by an order property vector O P . Order detection occurs when these two vectors are compared to determine whether the order property satisfies the order requirement. Order detection by normalization (ODN) according to this invention first normalizes the two order specification vectors to remove all attributes made redundant by the effects of predicates and functional dependencies. Query execution plans constructed using ODN are found to execute an order of magnitude faster than those constructed using order detection without normalization.

Description:
BACKGROUND OF THE INVENTION 
     1. Field of the Invention 
     This invention relates generally to computer-implemented systems for optimal query execution in relational database processing systems and particularly to a system for optimizing query ordering requirements by normalization of relational order specifications to accommodate predicates and functional dependencies before order detection in a query compiler system. 
     2. Description of the Related Art 
     A relational database management system (RDBMS) is a computer-implemented database processing system that uses relational techniques for storing and retrieving data. Relational database management systems are computerized information storage and retrieval systems in which data in the form of tables (formally denominated &#34;relations&#34;) are typically stored for use on disk drives or similar mass data stores. A &#34;relation&#34; includes a set of rows (formally denominated &#34;tuples&#34; or &#34;records&#34;) spanning several columns (formally denominated &#34;attributes&#34;). Each &#34;attribute&#34; in a relation includes &#34;restrictions&#34; on the data contents thereof, which may include designation as a primary or foreign key. A &#34;tuple&#34; expresses a mathematical relation between its &#34;attributes&#34; (column elements), while a &#34;record&#34; does not. Reference is made to C. J. Date, An Introduction to Database Systems, 6th Edition, Addison-Wesley Publishing Company, Reading, Mass. (1994) for a general treatment of the relational database art. 
     A relational database processing system is structured to accept commands to store, retrieve and delete data using high-level query languages such as the Structured Query Language (SQL). As used herein, a &#34;query&#34; refers to a set of user commands for retrieving data from a stored database. The query language requires the return of a particular data set (relation) in response to a particular query but the method of query execution employed by the database management system is not specified by the query. The method of query execution is herein denominated the &#34;Query Execution Plan (QEP)&#34; and there are typically many different useful QEPs for any particular user query, each of which returns the required data set. For large databases, the execution plan selected to execute a query must provide the required data return at a reasonable cost in time and hardware resources. Most RDBPSs include a query compiler to translate queries into a QEP, which includes a query optimizer to select an efficiently executable QEP. 
     Among many well-known SQL commands, a SQL query may include the ORDER BY clause. For instance, the following SQL query example returns a list of movie titles, in alphabetical order, from a relation keyed to movie stars: 
     SELECT DISTINCT MOVIE --  TITLE 
     FROM MOVIE --  STARS 
     ORDER BY MOVIE --  TITLE ASC; 
     In this example, only one attribute or column is used for ordering. ASC requires an ascending order, as opposed to DESC for descending order. This query imposes an &#34;order requirement&#34; that must be satisfied by the query compiler when it generates a QEP. Moreover, the query compiler itself may generate internal order requirements arising from combinations of other SQL operations. For example, the internal procedures used to satisfy GROUP BY and DISTINCT clauses generally require an input record stream with an &#34;order property&#34;. The sort-merge join operation is known in the art to require an &#34;order property&#34; in each of its record stream inputs. Also, where VIEW specifications are used, an order requirement may arise for the intermediate results of a query as well as for the final query data return. As used herein, the terms &#34;order property&#34; and &#34;order requirement&#34; refer to two order specifications imposed on a group of records in a relation. Such order specifications list one or more &#34;attributes&#34; (columns) within each record on which the records are ordered. 
     A typical RDBPS puts records in order by either sorting the records on their &#34;order requirement&#34; attributes or, when possible, by scanning an existing index that already provides the required ordering. Sorting is a costly operation that is avoided when possible, so the typical query compiler first searches for an existing index that satisfies the order requirement. As used herein, an &#34;index&#34; is a user-defined relation that maintains a certain order of records. Each relation may be associated with any number of indexes or with no index. When no index can be found, sorting is unavoidable and the query compiler then attempts to minimize the number of sort &#34;attributes&#34; to optimize execution plan efficiency. Thus, as it generates an execution plan, a query compiler must detect whether a sort can be avoided and, if unavoidable, how many attributes in the &#34;sort requirement&#34; may be eliminated during actual sorting. This process is herein denominated &#34;order detection&#34;. The following example illustrates the &#34;order detection&#34; problem known in the art: 
     SELECT SALARY, NAME 
     FROM EMP 
     WHERE SALARY=50,000 
     AND DEPTNO=:HV 
     ORDER BY 1,2; 
     In this SQL example, each execution plan must produce a stream of records in the order specified by the ORDER BY clause. Consequently, the query compiler must satisfy the order requirement (SALARY, NAME), with SALARY being the major ordering attribute. If an ascending index exists on attributes (SALARY, NAME), then an index scan produces the required &#34;order property&#34; without sorting. Alternatively, an unordered table scan followed by a sorting process may be employed to produce the required &#34;order property&#34; in the final relation. Typically, a query compiler considers both plans and chooses the less expensive to execute. 
     In the above example, if an ascending index also exists on the NAME attribute, then such index could also be used to produce the requisite order property without sorting. No sorting is actually then required because the SALARY attribute is bound to a constant by the predicate SALARY=50,000. Accordingly, the SALARY attribute does not affect the order property because all qualifying records have the same SALARY attribute (the same value in the SALARY column). Similarly, where an unordered table scan and sort are used, the sort need only be on the NAME attribute. Finally, if an index is found for (DEPTNO, NAME), it also satisfies the order requirement without sorting because, like the SALARY attribute, the DEPTNO attribute is bound to a constant (in this case to a host variable value). 
     The above-described example shows how the order detection process could improve execution efficiency if it could be aware of which relation attributes are &#34;bound&#34; to constants by way of predicates during execution plan generation. Order detection could also improve efficiency if it could be aware of keys and any functional dependencies arising therefrom, as illustrated by the following example: 
     SELECT E.EMPNO, E.NAME, D.DEPTNO 
     FROM EMP E, DEPT D 
     WHERE E.DEPTNO=D.DEPTNO 
     ORDER BY 1,2,3; 
     In this SQL query example, the query compiler must satisfy the order requirement vector (E.EMPNO, E.NAME, D.DEPTNO), which includes the first, second and third attributes in each record. If the EMPNO attribute is a key of the EMP relation, then sorting on EMPNO alone is sufficient to meet this order requirement. Alternatively, using an index ordered on EMPNO is sufficient without sorting. The skilled database practitioner can appreciate the reason for this sufficiency, which arises because the primary key EMPNO creates a &#34;functional dependency&#34; between the EMPNO attribute and all other attributes within the relation. This functional dependency combined with the predicate E.DEPTNO=D. DEPTNO means that E.EMPNO &#34;functionally determines&#34; both E.NAME and D.DEPTNO, which in turn implies that sorting on E.EMPNO is sufficient to create the three-attribute order property specified by the above example. Until now, the sort detection processes in the art have not been aware of these relationships. 
     Succinctly, a &#34;functional dependency&#34; herein denotes a relationship between two attributes where &#34;A functionally determines B&#34; when every record in a relation that has a particular value for attribute A has an unchanging value for attribute B. In the art, this functional dependency is denoted by the standard notation A→B. An attribute B is &#34;functionally dependent&#34; on a set of attributes or columns C={C 1 , C 2 , . . . , C n  } if, for any two records with the same values for the columns C, the value of column B is the same. Equivalently, it is said B is functionally determined by C, which is denoted as C→B. As is known in the art, key attributes are actually a special case of functional dependency referred to as a &#34;key dependency&#34;. A key dependency functionally determines all columns of the record stream for which it is a key. Any remaining dependencies are denoted &#34;non-key dependencies&#34;. Functional dependencies usually arise from keys, whether primary or foreign. Joins and other relational operations can transform a key dependency into a non-key dependency. Relational operations such as DISTINCT and GROUP BY can add key dependencies to derived relations. For the purposes of this disclosure, it is assumed that means are available to determine whether C→B is true. 
     Reference is made to Hugh Darwen et al. (RELATIONAL DATABASE WRITINGS 1989-1991, C. J. Date with Hugh Darwen, Chapter 10: The Role of Functional Dependencies in Query Decomposition for a description of the semantic concept of functional dependencies. Darwen et al. suggest algorithms for deriving functional dependencies from base relations and for propagating functional dependencies across derived relations. Darwen et al. also consider a variety of uses for functional dependencies by a RDBMS query compiler, but they neither consider nor suggest how to accommodate functional dependencies during order detection. 
     As is known in the art, a query compiler for a relational database processing system translates a high-level query into a query execution plan (QEP), which is then interpreted by a database engine at run time. Conceptually, a QEP is viewed in the art as a data flow graph of operators, whese each node in the graph corresponds to a set of output records arising from a relational operation such as &#34;join&#34; or a lower-level operation such as &#34;sort&#34;. FIG. 2 shows a query execution plan (QEP) for the following exemplary SQL qudry. 
     SELECT NAME, ADDRESS 
     FROM EMP E, DEPT D 
     WHERE E.DNO=D.DNO AND MGR=`Haas` 
     Note that the QEP in FIG. 2 is a directed graph of LOw LEvel Plan OPerators (LOLEPOPs), herein formally denominated &#34;relation nodes&#34;. Note that the data-flow arcs exemplified by arc 12 point toward the source of the record stream and not in the direction of data-flow. For instance, the SORT node 14, representing a relational SORT operation, receives a record stream from the ACCESS node 16 along the directed data-flow arc 18 and produces a directed record stream along arc 12 to the JOIN node 20. For the purposes of this disclosure, notice that each relation node in FIG. 2 is coupled to one or more other relation nodes by data-flow arcs (herein formally denominated &#34;directed record streams&#34;) exemplified by directed record streams 12 and 18. With the notation used herein, each relation node N i  consumes one or more incoming record streams {R ji  } and produces at least one output record stream R ik  that is directed to one or more other nodes (k and j may each assume more than one value). In the example shown in FIG. 2, each relation node produces only one output record stream routed as an input record stream to one other relation node. 
     Reference is made to Guy M. Lohman (&#34;Grammar-like Functional Rules for Representing Query Optimization Alternatives&#34;, A CM SIGMOD International Conference on Management of Data, 1988, pp. 18-27) for a detailed discussion of the &#34;properties&#34; associated with relation nodes or operators in a QEP. Every relation node is associated with a set of properties that summarizes the work accomplished in the relation thus far in the dataflow path from bottom (base-tables) to top (TOP node). Lohman et al. discuss these properties in terms of the query execution cost model and notes that all properties are handled uniformly as elements of a &#34;property vector&#34;, which is easily extended to include more properties. The &#34;property vector&#34; includes the &#34;attributes property&#34;, herein denominating the columns of a record stream, which may include columns from base-relations and those derived from expressions. The &#34;attributes property&#34; is used to track the record stream columns. 
     Examples of properties include the set of attributes that make up each record or tuple in the stream, represented by the head of each node. Other examples include the set of predicates that are applied to the incoming records within the node body, the specification of which attributes form unique keys and/or functional dependencies (if any), the order specification for the record stream, and the like. Each relational operator node in a QEP determines the properties of its output record stream. 
     The properties of an output record stream from a node are a function of the node input streams and the internal operations applied within the node. For example, a sort operation passes on all of the properties of its input stream unchanged except for the order property. A query compiler typically constructs a QEP from the bottom up, operator by operator, computing and updating properties as it proceeds. Depending on the implementation, some properties may be stored in QEP operators (within &#34;nodes&#34;) while others may be recomputed when needed to save space. 
     Each node in a QEP receives one or more directed record streams each having an &#34;order property&#34;. By virtue of operations within the node, each node produces an output record stream according to an &#34;order requirement&#34;. As discussed above, the ORDER BY, GROUP BY, and DISTINCT specifications create order requirements. Moreover, the query compiler may generate order requirements, depending on the alternative execution plan characteristics. An example of an execution strategy is the &#34;sort merge join&#34; operation, which requires certain order properties in the incoming record streams. There may be multiple order requirements imposed within any given SQL query. Both order properties and order requirements are represented by an order specification and are herein referred to generally as order specifications. As a simple example, ORDER BY C 1 , C 2 , C 3  gives rise to the order requirement vector (C 1 , C 2 , C 3 ). In the case of the GROUP BY and DISTINCT clauses, any permutation of the order specification suffices. For example, GROUP BY C 1 , C 2  is represented by either of the order requirements (C 1 , C 2 ) and (C 2 , C 1 ). The order requirement of the GROUP BY operation is satisfied if either order requirement is satisfied. In some query compilers, these two order requirement vectors can be represented as a single order requirement specification. For the purposes of this disclosure and without loss of generality, it is assumed that each record stream must satisfy only a single order requirement. In the general case, many order requirements may be imposed on a single record stream, which might benefit from additional procedures to &#34;compact&#34; multiple order requirements into a single order specification. 
     As a QEP is constructed, order requirements must be satisfied. That is, for instance, when an ORDER BY operator is added to the QEP, the &#34;order detection&#34; procedure examines the &#34;order property&#34; of the vector associated with the input stream to determine whether it satisfies the &#34;order requirement&#34; imposed by relational operations in the local relation node. If the &#34;order property&#34; of the incoming record stream does not satisfy the &#34;order requirement&#34; imposed by the receiving relation node, then the query compiler adds a sort operator to the QEP, representing an additional operation internal to the receiving relation node. This sort operator adds substantial cost to the resulting QEP and it is a desired function of the &#34;order detection&#34; procedure to avoid adding sort operators wherever possible. 
     Initially, the properties of stored base tables and access methods are determined from the system catalogs. At first, no predicates are applied and no cost has been incurred in the query. The &#34;order property&#34; is unknown unless the base relation is known to store records in some order or if an index is used to access the relation in which case the order is defined by the set of attributes on which the records are ordered. 
     During compilation, the predicates in a SQL query are usually broken down into conjunctive normal form. This permits each conjunct to be applied as an independent predicate. When a predicate or conjunct is applied to an input record stream, each record in the resulting output record stream is imprinted with the &#34;property&#34; that it satisfies the predicate. Herein, the term &#34;predicate property&#34; denominates the property used to track all predicates that have been applied to a record stream. 
     The &#34;order property&#34; for a record stream represents the physical ordering of the stream&#39;s records. An order property is denoted by listing the attributes or columns of the order in major to minor sequence. Such representation is herein denominated an &#34;order specification vector&#34;. For example, (C 1 , C 2 , C 3 ) is an &#34;order specification vector&#34; with C 1  as the most major ordering column and C 3  is the most minor ordering column. Column C 2  is in a &#34;more major&#34; position relative to C 3  and in a &#34;more minor&#34; position relative to C 1 . Two records are ordered with respect to an &#34;order requirement&#34; vector by comparing attribute values in most major to most minor sequence until order is determined (ISO-ANSI, &#34;ISO-ANSI Working Draft: Database Language SQL2 and SQL3; X3H2; ISO/IEC/JTC1/SC21/WG3, 1993&#34;). A record stream can acquire an &#34;order property&#34; because of an index access or a sort operation while other operations may preserve the order of an input record stream. For example, a nested-loop join operation preserves the order of the outer relation. 
     The &#34;functional dependency&#34; property specifies a collection of functional dependencies that hold for the attributes of the record stream. For base relations, these are typically the key dependencies of the base relations. Operations that remove duplicates can add key dependencies as described above. Key dependencies survive joins as non-key functional dependencies. The above-cited Darwen et al. reference describes the functional dependency derivation and propagation for relational operations. For the order detection process, the &#34;functional dependency&#34; property permits enumeration of all functional dependencies holding for the record stream. 
     There is an untilled need in the art for a sort detection process that permits the query compiler to understand and exploit the effects of both predicates and functional dependencies during order detection. The failure in the art to account for these effects causes the query compiler to inject unnecessary sorts or to sort on more attributes than necessary. This in turn causes the compiler to generate suboptimal query execution plans. The desire to reduce QEP cost in large database systems motivates the need for any useful method that avoids unnecessary sort operations during execution plan generation. 
     Practitioners in the relational database art generally appreciate the absence of a solution to this problem. For instance, Boykin et al. (&#34;Order Class Detection&#34;, IBM Technical Disclosure Bulletin, Vol. 32, no. 52, pp. 283-285, October, 1989) discuss the continuing need to improve order detection during query optimization. Boykin et al. propose a process for recognizing when special combined order classes can be constructed to satisfy the order requirements arising from more than one order specification in a query. An order class is a list of attributes or columns, each having the attribute &#34;ascending&#34;, &#34;descending&#34;, or &#34;either&#34;. The combined order classes are used to locate indexes or to specify the sorting operation necessary to satisfy the order requirements. As used herein, the &#34;order class&#34; is denominated an &#34;order specification vector&#34;, which may be an &#34;order property vector O Pi  &#34; or an &#34;order requirement vector O Ri  &#34;. By combining the &#34;order specification vectors&#34; within a query, Boykin et al. permit the query compiler to insert a single sort to satisfy two separate ordering requirements, but do not consider the effects of functional dependencies or predicates on sort specifications. 
     L. W. Yongren (&#34;Dynamic Ordering of Joined Rows using Fields from Multiple Tables&#34;, IBM Technical Disclosure Bulletin, Vol. 36, no. 11, pp. 363-366, November 1993) disclose a method for ordering joined &#34;live&#34; data (dynamic views) without producing a temporary result table. Yongren proposes maintaining indexes that can be updated responsive to updates to the underlying base-relations. By providing for a &#34;composite index&#34;, Yongren is able to avoid resorting operations during the maintenance of dynamic VIEW tables, but he neither considers nor suggests methods for eliminating sort operations or index scans by exploiting functional dependencies. 
     Similarly, in U.S. Pat. No. 5,241,648, Cheng et al. propose a hybrid method for joining tables that relies on maintaining indexes to speed the nested join procedure. In U.S. Pat. No. 5,369,761, Conley et al. speed the table join operation by selectively &#34;denormalizing&#34; the base-relations to avoid joining unnecessary attributes. Neither Conley et al. nor Cheng et al. consider or suggest methods for eliminating sort operations by detecting redundancy arising from functional dependencies. 
     There is a need in the art for an order detection process that fully assimilates and exploits the effects of both predicates and functional dependencies to avoid sorting whenever possible. The absence in the art of any process for exploiting predicate and functional dependency effects during query order detection reduces query execution plan efficiencies. These unresolved problems and deficiencies are clearly felt in the art and are solved by this invention in the manner described below. 
     SUMMARY OF THE INVENTION 
     The process of this invention improves order detection by first reducing both the order requirement vector O Ri  and the order property vector O Pi  to a normalized form before comparing them during order detection. The order specification normalization process of this invention uses both predicate relationships and functional dependencies to reduce each vector to a normalized canonical form. The normalized order specifications are then compared according to a naive order detection procedure to achieve order detection. QEP cost can be reduced by orders of magnitude through the order detection by normalization (ODN) process of this invention. 
     It is an object of the ODN process of this invention to improve query execution plan efficiency. It is an advantage of the process of this invention that all sort procedures made redundant by predicates and functional dependencies are removed automatically from the query execution plan by the query compiler. It is a feature of the process of this invention that the ODN process can be performed at each directed record stream during the &#34;bottom-up&#34; construction of the query execution plans (QEPs) for the user query. 
    
    
     The foregoing, together with other objects, features and advantages of this invention, can be better appreciated with reference to the following specification, claims and the accompanying drawing. 
     BRIEF DESCRIPTION OF THE DRAWING 
     For a more complete understanding of this invention, reference is now made to the following detailed description of the embodiments as illustrated in the accompany drawing, wherein: 
     FIG. 1 is a functional block diagram of a relational database processing system suitable for application of the order detection by normalization (ODN) process of this invention; 
     FIG. 2 shows a Query Execution Plan (QEP) diagram from the prior art for an exemplary SQL query; 
     FIG. 3 is a functional block diagram of a flow chart embodying the naive order detection process from the prior art; 
     FIG. 4 is a functional block diagram of a flow chart showing the preferred embodiment of the order specification normalization process of this invention; and 
     FIG. 5 is a functional block diagram of a flow chart showing a preferred embodiment of the order detection by normalization (ODN) process of this invention. 
    
    
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT 
     The System of the Invention 
     FIG. 1 shows a functional block diagram of a computer-implemented database processing system 46 suitable for practicing the procedure of this invention. This exemplary configuration is described for illustrative purposes only and it can be appreciated that the process and system of this invention may be embodied within system 46 in many different useful fashions, including the arrangement depicted in FIG. 1. System 46 includes a central processing unit (CPU) 48, which is coupled to a parallel bus 50. The query input terminal 52 allows the user to enter queries into system 46, either from a remote terminal or through any other useful method known in the art. The data output terminal 54 displays the query results to the user and may be physically co-located with query input terminal 52. 
     System 46 includes the address space 56, which is shown schematically as containing program objects and data objects. The base table 58 is an example of a data object pulled into address space 56 from the external mass store 60 by way of bus 50. The view definition 52 is another data object representing a &#34;virtual table&#34; made up of elements from one or more base tables in accordance with a VIEW definition statement. External mass store 60 includes a generally large plurality of base tables (also denominated base relations), exemplified by base tables 64 and 66. These base tables are moved partially or entirely between memory space 56 and external mass store 60 in a manner well-known in the art for database management systems. 
     Address space 56 also includes the control program object 68, which manages the other components of system 46. These components include a query parser 70 for accepting the query input from terminal 52 and constructing an internal representation of the query. A query optimizer 74 receives the internal representation of the user query and generates, in a bottom-up fashion, all feasible query execution plans (QEPs). Query optimizer 74 then determines a &#34;cost&#34; (which is an estimate of the CPU and I/O resources that are consumed during execution of a plan) for each plan based on data statistics, configuration parameters and the query itself. Optimizer 74 then chooses the plan having minimal cost as the &#34;optimal&#34; query execution plan. The order detection by normalization (ODN) process of this invention is embedded in query optimizer 74 to avoid unnecessary sorting operations during the construction of QEPs and, when sorting is unavoidable, to specify a minimal sorting criteria. 
     After identifying an &#34;optimal&#34; query execution plan, query optimizer 74 produces this plan as a program object, depicted as QEP 76 in address space 56. QEP 76 is finally executed with the assistance of control program 68 and the resulting relation is forwarded to data output display 54. Practitioners skilled in the art can appreciate that the description of system 46 in FIG. 1 is exemplary and the system and process of this invention, represented by query optimizer 74, may be incorporated in any RDBMS that uses a query optimization process. 
     Naive Order Detection Process 
     FIG. 3 provides a flow chart illustrating the naive order detection process known in the art. This process is straight-forward because it simply checks whether the elements of the order requirement vector O R  are a &#34;prefix&#34; of the order property vector O P . If so, the process returns &#34;true&#34; to indicate that the order requirement is satisfied by the order property without any sorting operations. 
     In FIG. 3, the order requirement vector O R  is introduced at step 78 as an ordered vector of attributes or columns (R 1 , . . . , R r ) where r≧1. If the order requirement vector O R  is empty (r=0) then there is no order requirement and order detection is unnecessary. As mentioned above, the SQL92 standard provides that the vector O R  requires the associated directed record stream to be first ordered according to the first attribute R 1 , and, within that attribute, again ordered according to the second attribute R 2 , and, within that attribute, again ordered according to the next-minor attribute, and so forth. Similarly, step 80 introduces the order property vector O P  for the same directed record stream. Vector O P  also includes a list of attributes or columns (P 1 , . . . , P p ) where p≧0. The order property vector O P  may be empty (p=0) to signify no known ordering property within the directed record stream. 
     The exemplary naive order detection process embodiment in FIG. 3 first examines the two order specification vectors to ensure that O R  is no larger than O P  at step 82. That is, step 82 tests the length of O R  against the length of O P  and immediately proceeds to step 84 to return a &#34;false&#34; indication if the order requirement vector is too long to be a &#34;prefix&#34; of the order property vector. If O R  is short enough to fit within O P , then the procedure initiates an i-loop at step 86 to compare each attribute in sequence at step 88. Upon any finding that R i  ≠P i , step 88 immediately exits to step 84 to return a &#34;false&#34; indication, demonstrating the detection of a sort requirement. So long as each element R i  of the order requirement vector matches the corresponding element of P i  of the order property vector, the loop recycles at steps 90 and 92. When all elements of O R  have been tested, step 90 proceeds to step 94 to return a &#34;true&#34; indication, showing that no sorting requirement exists for the particular directed record stream under test. Importantly, the naive order detection process of FIG. 3 looks only at the order requirement and order property of the record stream and does not consider the effects of other properties. Consequently, the procedure cannot correctly anticipate the effects of predicates and functional dependencies when detecting sorting requirements. This deficiency in the art introduces many unnecessary &#34;false&#34; returns to step 84. 
     Order Detection by Normalization 
     The concept of &#34;column equivalence&#34; or attribute equivalence is important for implementing the order detection by normalization (ODN) process of this invention. When a predicate equates two columns (e.g., EMPNO=DEPTNO), for instance, it creates an &#34;equivalence class&#34;. An equivalence class herein denominates a set of columns made equivalent through the application of equality predicates. Two columns or attributes can be made equivalent by a single predicate equating the two columns or by transitivity among two or more equality predicates. For a given equivalence class, one attribute may be arbitrarily chosen as an &#34;equivalence class head&#34;. For the purposes of this disclosure, every attribute belongs to an &#34;equivalence class&#34; and some equivalence classes have only a single member, which is of course the &#34;head&#34; of its single-member equivalence class. This recognizes that each attribute is equivalent to itself. In equivalence classes having more than one member, the &#34;equivalence class head&#34; member is arbitrarily designated such that no equivalence class has more than one &#34;head&#34; attribute member. It is assumed for the purposes of this disclosure that, given a set of applied predicates, means exist to determine whether some column C i  belongs to the same equivalence class as some other column C j  and means are assumed to exist for determining the equivalence class head for an arbitrary column C. 
     As discussed above, the order detection process also must know when a column or attribute has a constant value. A column C is herein said to be &#34;bound&#34; in a record stream if C has the same value for every record in the stream. A column C can be bound in several ways. For instance, C may be derived from a constant expression. As an example, the derived column VC1 defined by the view CREATE VIEW V1 (VC1, VC2) AS SELECT `name`, lastname FROM EMPLOYEE, is derived from a constant expression. A column may also be bound through application of a predicate. As an example, rows qualifying after application of the predicate C=1,000*0.001 have column C bound. A column in the equivalence class to which C belongs may become bound through the operation of some predicate or by some other action. 
     A column C may also become bound in a context-dependent manner. For example, if C i  =C j  where C j  is a &#34;correlated&#34; column, then C i  is &#34;bound&#34; in the context where C j  is correlated. Finally, column C may be functionally dependent on a set of other columns which themselves become bound through some referential mechanism. For the purposes of this disclosure, it is assumed that, given a set of applied predicates, means exist to determine whether a column C in a directed record stream is bound. 
     FIG. 4 provides a flow chart illustrating the preferred embodiment of the ODN process of this invention. The fundamental purpose of the ODN process is to reduce both the order requirement vector and the order property vector to a canonical form before comparison. That is, both order specifications are &#34;normalized&#34; by removing all attributes that are redundant to the order detection process. Each attribute in both order specification vectors is somehow examined to determine whether it is affected by known predicate relationships and functional dependencies. Once the specifications are normalized, the naive order detection procedure discussed above in connection with FIG. 3 is then used to compare the normalized order specifications. 
     In FIG. 4, the order specification vector O (either property or requirement) is introduced at step 94. The vector O is assumed to include K attributes, where K≧1. The ODN process includes the four steps shown in FIG. 4 as steps 96, 98, 100 and 102. The normalized specification resulting from each step is equivalent to the original specification vector O in the sense that records ordered with respect to the resulting order specification are also ordered with respect to O. Although the steps 96, 98, 100 and 102 can be applied in the order shown in FIG. 4, these steps may also be applied in any order and may be applied repeatedly until no progress is made. Thus, while shown in a sequence in FIG. 4, the four normalization steps should be considered as axiomatic rather than algorithmic in nature. 
     Referring to FIG. 4, in step 96, each attribute C i  contained in specification vector O is replaced with the head attribute C Hi  for the equivalence class that includes the attribute C i . This step 96 can be expressed simply as &#34;substitute each column with its arbitrarily-selected equivalence class head&#34;. Of course, where a column has no equivalences, it is merely replaced by itself in this step. The resulting normalized vector (C H1 , C H2 , . . . , C HK ) also has K elements. Records ordered with respect to this normalized vector are also ordered with respect to the original vector O because all columns in the same equivalence class are equivalent by definition. 
     In step 98, all minor duplicate attributes or columns are eliminated (&#34;squeezed&#34;) from the specification vector. Only the most major duplicate column element is retained. This step 98 in combination with step 96 serves to eliminate equivalent columns from the specification vector. The normalized vector resulting from step 98 includes the columns (C 1 , . . . , C L ) where 1≦L≦K. The vector cannot include less than one column because the original specification vector O had at least one column. However, the remaining L attributes in the normalized vector may be less in number than the original K attributes in specification vector O. 
     In step 100, all &#34;functionally-dependent&#34; columns are squeezed or eliminated from the specification vector wherever the functionally-dependent column is in a more minor position than the one or more columns by which it is determined. That is, if C={C 1 , C 2 , . . . C m  } and if there exists a functional dependency C→C n , where n≦m, and the columns in C are a subset of the columns in the specification vector, then column C n  is eliminated from the specification vector. In determining whether C→C n , some examination of predicates and functional dependencies is required. For example, if {C 1 , C 2 , C 4  }→C 7  and the predicates C 2  =2, C 3  =C 4  and C 5  =C 7  have been applied to the record stream, then it is necessary to conclude that {C 1 , C 3  }→C 5 . Thus, the concept of normalization may require an analysis of functional dependencies but a detailed discussion of this concept is unnecessary for the purposes of this disclosure. 
     The equivalence in the order specification vectors before and after eliminating minor columns that are functionally determined by a major column can be appreciated by considering that when two records t 1  and t 2  are compared, the value of attribute C n  affects their order only when t 1  and t 2  have the same values in columns C 1 , C 2 , . . . , C m , C n-1 . But t 1 .C n  and t 2 .C n  must also have the same value in that case because C→C n . Consequently, squeezing C n  from the order specification does not change the resulting order of the records, thereby demonstrating that records ordered with respect to the normalized order specification vector are also ordered with respect to the original order specification vector. 
     Returning to FIG. 4, step 102 eliminates (squeezes) all bound columns from the specification vector. A column B may become bound indirectly through functional dependencies. For example, if {C 1 , C 2  }→B and both C 1 , C 2  are bound, then B is bound as well. For the purposes of this disclosure, it is assumed that means exist for determining which order specification attributes are bound. Because a bound column has the same value for every record, squeezing bound columns from the order specification has no effect on the ordering in the record stream. 
     After completing the four normalizing steps, the normalized order specification vector O N  is produced at the step 104 in FIG. 4. The normalized specification vector O N  may be reintroduced at step 94 if desired and the normalizing steps repeated iteratively until no further changes are noted. 
     The four steps 96, 98, 100, and 102 (FIG. 4) are now illustrated by the following example: 
     SELECT E.EMPNO, E.NAME, D.DEPTNO, D.SIZE 
     FROM EMP E, DEPT D 
     WHERE E.DEPTNO=D.DEPTNO 
     AND D.SIZE=100 
     ORDER BY 1,2,3,4; 
     Assume that EMPNO is the key for the EMP relation. In this case, the query compiler must satisfy the order requirement (E.EMPNO, E.NAME, D.DEPTNO, D.SIZE). By step 96, D.DEPTNO can be replaced by E.DEPTNO to provide the normalized specification vector (E.EMPNO, E.NAME, E.DEPTNO, D.SIZE). Because E.EMPNO is a key, it functionally determines both E.NAME and E.DEPTNO. That is, E.EMPNO→E.NAME and E.EMPNO→E.DEPTNO. Thus, using step 100 (FIG. 4), the order specification vector can be further normalized to produce (E.EMPNO, D.SIZE). Finally, using step 102, the order specification vector is reduced yet again to yield (E.EMPNO) because the value of D.SIZE is bound by the predicate D.SIZE=100. Accordingly, if an index on EMPNO is used at the outer access for either a nested-loop or sort-merge join operation, for instance, then no additional sort is necessary to satisfy the ORDER BY clause because the &#34;order property&#34; of the index (E.EMPNO) satisfies the normalized &#34;order requirement&#34; of (E.EMPNO). 
     Note that, in this example, D.DEPTNO may not be replaced by E.DEPTNO in the order requirement vector until the predicate E.DEPTNO=D.DEPTNO has been applied. This illustrates that, in general, each normalization step in the ODN process of this invention is context-sensitive, depending on the &#34;property vector&#34; associated with the particular directed record stream undergoing order detection. 
     The complete ODN process of this invention is now described in connection with the flow chart shown in FIG. 5 and the pseudocode embodiment provided in Table 1 below. 
     
                       TABLE 1______________________________________normalize OP to form NOPnormalize OR to form NORif (there are no columns in NOR)  all columns with respect to OR are bound and OR is  trivially satisfied}else if (there are no columns in NOP){  OP does not satisfy OR}else{  apply the naive order detection algorithm to NOR and NOP}______________________________________ 
    
     In FIG. 5, the order requirement vector O R  is produced at step 104 and the order property vector O P  is produced at step 106. At step 108, the order requirement vector O R  is normalized by the process shown in FIG. 4 to produce the normalized order requirement vector O RN . Similarly, at step 110, the order property vector O P  is normalized to produce the normalized order property vector O PN . At step 112, the normalized order requirement vector O RN  is tested to determine whether any attributes remain in the vector. If step 112 finds the normalized order requirement vector to be empty, then step 114 immediately returns a &#34;true&#34; indicating no sorting requirement. If step 112 finds attributes in the normalized order requirement vector, then step 116 tests the normalized order property vector O PN  for emptiness. If O PN  has no attributes, then step 118 immediately returns a &#34;false&#34; indication showing detection of an unavoidable sorting operation because the empty normalized property vector cannot possibly satisfy the non-empty normalized order requirement vector. 
     If both normalized order specification vectors are non-empty, then step 120 initiates the naive order detection loop that compares the two specification vectors, column by column, as discussed above in connection with FIG. 3. 
     The order specification normalization procedure of this invention may also be used to determine an optimal sort order when a sorting operation is unavoidable. When performing a sort, it is important to minimize the number of sorting columns to reduce the &#34;cost&#34; of the sorting operation. If OR denotes the order requirement vector and NOR denotes the normalized order requirement vector, then Table 2 below provides a pseudocode embodiment of a useful procedure for determining an optimal sort order. 
     
                       TABLE 2______________________________________normalize OR to form NORif (there are no columns in NOR)  all columns with respect to OR are bound and there is no  need to sort}else{  sort on NOR}______________________________________ 
    
     Compared to the order detection procedures known in the art, the ODN process of this invention is more cognizant of properties such as functional dependencies and applied predicates. Because of this, the ODN process more often detects situations where sorting operations can be avoided. The normalization process described above in connection with FIG. 4 may also be used to determine the minimum number of sorting columns when a sorting operation is unavoidable. In practice, the inventors have found that query execution plans produced using the ODN process of this invention can execute orders of magnitude faster than those produced without it. 
     Clearly, other embodiments and modifications of this invention may occur readily to those of ordinary skill in the art in view of these teachings. Therefore, this invention is to be limited only by the following claims, which include all such embodiments and modifications when viewed in conjunction with the above specification and accompanying drawing.