Simplification of SQL queries using generalized inference propagation and generalized transitive closure

Information

  • Patent Grant
  • 5701454
  • Patent Number
    5,701,454
  • Date Filed
    Tuesday, January 17, 1995
    29 years ago
  • Date Issued
    Tuesday, December 23, 1997
    26 years ago
Abstract
A method and apparatus for query simplification by applying generalization inference propagation and transitive closure in SQL queries having intersection operations combined with inner and outer join operations further combined with selection and/or projection operations. First a strong set of predicates is calculated, typically a selection or join predicate which is null-intolerant. Second the strong set of attributes is used to select and replace a full, left, or right outer join operation found as the operand of an intersection operation in the query. A less expensive outer or inner join replaces the selected join and the process is repeated until no further simplification if possible. Inferences are propagated from one operand to the other of an intersection operation. Selection operators are applied through transitive closure to reduce the size of intermediate results. The transformations are applied to the query to produces a set of operations that perform more efficiently than that of the original query while providing the same results.
Description

BACKGROUND OF THE INVENTION
1. Field of the Invention
This invention relates in general to database management systems performed by computers, and in particular, to a method and apparatus for query simplification using generalized inference propagation and generalized transitive closure in SQL queries having selection, projection, join, outer join, and intersection operations.
2. Description of Related Art
Computer systems incorporating Relational DataBase Management System (RDBMS) software using a Structured Query Language (SQL) interface are well known in the art. The SQL interface has evolved into a standard language for RDBMS software and has been adopted as such by both the American Nationals Standard Organization (ANSI) and the International Standards Organization (ISO).
In RDBMS software, all data is externally structured into tables. The SQL interface allows users to formulate relational operations on the tables either interactively, in batch files, or embedded in host languages such as C, COBOL, etc. Operators are provided in SQL that allow the user to manipulate the data, wherein each operator operates on either one or two tables and produces a new table as a result. The power of SQL lies on its ability to link information from multiple tables or views together to perform complex sets of procedures with a single statement.
The current state-of-the-art in SQL query optimization provides techniques for simplifying queries based on the nature of null-intolerant predicates, as reflected in the following patent application and publication, both of which are incorporated by reference herein:
1. U.S. patent application Ser. No. 08/326,461, filed Oct. 20, 1994, by G. Bhargava, P. Goel, and B. Iyer, entitled "METHOD AND APPARATUS FOR REORDERING COMPLEX SQL QUERIES CONTAINING INNER AND OUTER JOIN OPERATIONS," (hereinafter referred to as �BHAR94!); and
2. Galindo-Legaria, C. A., "Algebraic optimization of outer join queries," Ph.D. dissertation, Dept. of Applied Science, Harvard University, Cambridge, 1992, (hereinafter referred to as �GALI92b!).
However, these prior art techniques do not simplify queries in the presence of intersection operators. Further, these prior art techniques do not include any scheme for inference propagation.
One prior art simplification technique uses selection predicates for "removing arrows". As explained in the following publication: Galindo-Legaria, C., and Rosenthal, A., "How to extend a conventional optimizer to handle one- and two-sided outer join," Proceedings of Data Engineering, pp. 402-409, 1992, (hereinafter referred to as �GALI92a!), selections may cause the replacement of full and one-sided outer joins with one-sided outer joins and joins, respectively. These simplifications are based on the recursive application of the following identities for relations X.sub.1 =(R.sub.1, V.sub.1, E.sub.1) and X.sub.2 =(R.sub.2, V.sub.2, E.sub.2):
.sigma..sub.p (X.sub.1 .fwdarw.X.sub.2)=.sigma..sub.p (X.sub.1 X.sub.2)
wherein R.sub.1 and R.sub.2 are non-empty sets of real attributes, V.sub.1 and V.sub.2 are non-empty sets of virtual attributes, E.sub.1 and E.sub.2 are extensions of the relations, .sigma..sub.p is a selection operator with predicate p, .fwdarw. is a left outer join operator, is a join operator, sch(p).OR right.R.sub.2, and p is null-intolerant in R.sub.2 ; and:
.sigma..sub.p (X.sub.1 .revreaction.X.sub.2)=.sigma..sub.p (X.sub.1 .fwdarw.X.sub.2)
wherein R.sub.1 and R.sub.2 are non-empty sets of real attributes, V.sub.1 and V.sub.2 are non-empty sets of virtual attributes, E.sub.1 and E.sub.2 are extensions of the relations, .sigma..sub.p is a selection operator with predicate p, .revreaction. is a full outer join operator, .fwdarw. is a left outer join operator, sch(p).OR right.R.sub.1, and p is null-intolerant in R.sub.1.
Another prior art simplification technique for "removing arrows" uses predicates for join and outer join operators. The following identities are used recursively to replace full outer join and one-sided outer join operations with one-sided outer join and join operations, respectively. These identities are a formalization and extension of the ideas presented in �GALI92b!. Note, however, that �GALI92b! does not consider outer join predicates that reference more than two relations.
Let X.sub.i =, where 1.ltoreq.i.ltoreq.3, be relational expressions and let p be a null-intolerant predicate. Then, ##EQU1## if sch(p) .andgate. R.sub.3 .noteq..o slashed.; ##EQU2## if sch(p) .andgate. R.sub.2 .noteq..o slashed.; ##EQU3## if sch(p) .andgate. R.sub.2 .noteq..o slashed. and sch(p) .andgate. R.sub.3 .noteq..o slashed.; ##EQU4## if sch(p) .andgate. R.sub.3 .noteq..o slashed.; ##EQU5## if sch(p) .andgate. R.sub.2 .noteq..o slashed.; and ##EQU6## if sch(p) .andgate. R.sub.2 .noteq..o slashed. and sch(p) .andgate. R.sub.3 .noteq..o slashed..
After applying the above identities, the original query is transformed into a form where all "redundant" (full) outer join operations have been removed.
The following publications present techniques that exploit certain properties of intersection distinct operators to transform them to joins:
1. Pirahesh, H., Hellerstein, J. M. and Hasan, W., "Extensible/rule based query rewrite optimization in STARBURST," SIGMOD, pp. 39-48, San Diego, Calif., June 1992, (hereinafter referred to as �PIRA92!); and
2. Paulley, G. N. and Larson, P.-A., "Exploiting uniqueness in query optimization," CASCON, pp. 804-822, 822, Vol. II, October 1993, (hereinafter referred to as �PAUL93!).
However, the techniques discussed by these publications are not the same as disclosed by the present invention, although they are still applicable after the simplifications proposed by the present invention have been applied.
Finally, the prior art on predicate transitive closure consists of identifying equivalence classes of attributes that are equated though equi-join predicates and then applying the given selection conditions on any of them to the whole class, as described in the following publication Alon Levy, Inderpal Mumick, Yehoshua Sagiv, "Query Optimization by Predicate Move-Around," Proceedings of the 20th VLDB Conference, Santiago, Chile, September, 1994, (hereinafter referred to as "�LEVY94!"). This idea can be formally stated in the form of the following identities. The first two of these identities constitute push-up and push-down rules for .sigma.. Let X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) be relational expressions, p be a selection predicate, and J.sub.XY be a null-intolerant equi-join predicate. Then, ##EQU7## where sch(p).OR right.R.sub.X ; ##EQU8## where sch(p).OR right.R.sub.Y ; ##EQU9## where sch(p).OR right.R.sub.X, sch(p').OR right.R.sub.Y, and p' is obtained from p by replacing every clause of the form X.sub.i .theta.c by Y.sub.j .theta.c, where .theta. is a relational operator, X.sub.i =Y.sub.j is a clause in J.sub.XY ; and ##EQU10## where sch(p).OR right.R.sub.Y, sch(p).OR right.R.sub.X, and p' is obtained from p by replacing every clause of the form Y.sub.j .theta.c by X.sub.i .theta.c, where X.sub.i =Y.sub.j is a clause in J.sub.XY. However, these identities work for join-only queries.
Thus, there is a need in the art for query simplification methods that work for queries involving (full) outer joins operators, intersection operators, as well as join operators.
SUMMARY OF THE INVENTION
To overcome the limitations in the prior art described above, and to overcome other limitations that will become apparent upon reading and understanding the present specification, the present invention discloses a method and apparatus for query simplification using generalized inference propagation and generalized transitive closure in SQL queries having selection, projection, join, outer join, and intersection operations.
An object of the present invention is to propagate inferences about one operand of an intersection operation to the other operand, and then to use this information to simplify the query by transforming outer join operations to less expensive joins. Another object of the present invention is to apply selection operators through transitive closure to make intermediate results of SQL queries smaller. Yet another object of the present invention is to apply "null-intolerance" properties of join predicates in the presence of intersection operators to further simplify SQL queries.





BRIEF DESCRIPTION OF THE DRAWINGS
Referring now to the drawings in which like reference numbers represent corresponding parts throughout:
FIG. 1 illustrates the computer hardware environment of the present invention;
FIG. 2 is a flowchart illustrating the steps necessary for the interpretation and execution of SQL statements in an interactive environment according to the present invention;
FIG. 3 is a flowchart illustrating the steps necessary for the interpretation and execution of SQL statements embedded in source code according to the present invention;
FIG. 4 is a flowchart illustrating the method of optimizing SQL queries of the present invention; and
FIGS. 5A-5H together are a flowchart describing the generalized inference propagation method that determines which of the "component" attribute pairs of the "p* intersection-predicate" become join-reduced and then uses the simplification identities to simplify the query.





DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT
In the following description of the preferred embodiment, reference is made to the accompanying drawings which form a part hereof, and in which is shown by way of illustration a specific embodiment in which the invention may be practiced. It is to be understood that other embodiments may be utilized and structural and functional changes may be made without departing from the scope of the present invention.
DEFINITIONS
Following are definitions for a number of terms used in SQL queries. These definitions are required for an understanding of later portions of the present specification. A complete algebra for relations with duplicates is included in �BHAR94!, which is incorporated by reference. Only the more pertinent definitions are included here, suitably modified to make the presentation more readable.
Tuple
A tuple t is a mapping from a finite set of attributes, R.orgate.V, to a set of atomic (possibly null) values, where R is a non-empty set of real attributes and V is a non-empty set of virtual attributes, R.andgate.V=.o slashed., and the mapping t maps at least one virtual attribute v.epsilon.V to a non-null value. For an attribute set X, t�X! represents the values associated with attributes X under the mapping t, where X.OR right.R.orgate.V and X.noteq..o slashed..
The motivation behind the distinction between real and virtual attributes is to emphasize the difference between the real attributes available for manipulation (to the user of the RDBMS) and the virtual attributes used (by the RDBMS) for bookkeeping only. The set of real attributes of a tuple is the same as the schema of the tuple in the traditional relational algebra. These attributes are accessible to users and can be referenced externally, e.g., in user queries, etc. On the other hand, virtual attributes are (at times) used to provide unique conceptional tuple-ids to tuples, and are not accessible to users and cannot be referenced externally.
Relation
A relation r is a triple (R, V, E) where R is a non-empty set of real attributes, V is a non-empty set of virtual attributes, and E, the extension of relation r, is a set of tuples such that:
(.A-inverted.t.sub.1 .epsilon.E)(.A-inverted.t.sub.2 .epsilon.E)(t.sub.1 .noteq.t.sub.2 t.sub.1 �V!.noteq.t.sub.2 �V!)
In this definition, R.orgate.V is called the schema of relation r.
Predicate
A predicate p over a set of real attributes sch(p), called the schema of p, is a total mapping from tuples to the Boolean values {TRUE, FALSE}, where sch(p) is the minimum set of attributes such that for all tuples t.sub.1 and t.sub.2 :
(t.sub.1 �sch(p)!=t.sub.2 �sch(p)!p(t.sub.1)=p(t.sub.2)).
For a tuple t with real schema R.OR left.sch(p), p(t) is TRUE if and only if (.A-inverted.A .epsilon.sch(p)) (i.e., substitution of t�A! for A in p causes it to evaluate to TRUE).
Null-intolerant
A predicate p is null-intolerant if p evaluates to FALSE for tuples undefined on one or more attributes in sch(p). More formally, p is null-intolerant if:
(.A-inverted.t) (.E-backward.A.epsilon.sch(p))(t�A!=NULL p(t)=FALSE)
Algebraic Operators
Following are definitions for algebraic operators used in SQL queries. These definitions are required for an understanding of later portions of the present specification.
Projection
The projection, .pi..sup.a.sub.x (r), of relation r onto attributes X is the relation (X,V, E') where X.OR right.R and:
E'={t.v.vertline.(.E-backward.t'.epsilon.E)(t=t'�X!v=t'�V!)}
The .pi..sup.a operator is a projection operator that does not remove "duplicates" in the real attributes part of the source expression. The superscript a in .pi..sup.a denotes the fact that all the virtual attributes of the source expression are included in the virtual schema of the result expression. For ease of reading, the superscript a is omitted from .pi..sup.a whenever there is no ambiguity, so it can be written simply as .pi..
The projection, .pi..sup.c.sub.X.sbsb.R.sub.X.sbsb.V (r), of relation r on attributes X.sub.R X.sub.V is the relation (X.sub.R, X.sub.V, E'), where X.sub.R .OR right.R, X.sub.V .OR right.V and:
E'={t.v.vertline.(.E-backward.t'.epsilon.E)(t=t'�X.sub.R !v=t'�X.sub.v !)}
In contrast to .pi., .pi..sup.c allows a choice in the selection of the virtual attributes from the source expression.
Delta-Projection
The delta-projection, .delta..sub.X.sbsb.R.sub.X.sbsb.V (r), of relation r on attributes X.sub.R X.sub.V is the relation (X.sub.R X.sub.V, V.sub.new, E'), where X.sub.R .OR right.R, X.sub.V .OR right.V, and:
E'={t.vertline.(.E-backward.t'.epsilon.E)(t�X.sub.R X.sub.V !=t'�X.sub.R X.sub.V !t�V.sub.new !=a new unique value)}
which is a new, unique value. The .delta. operator models the "SELECT DISTINCT . . . " construct of SQL which allows elimination of "duplicates" from a relation. The .delta. operator is called the distinct projection operator and produces a result relation which has distinct values on the attributes X.sub.R X.sub.V and a new virtual attribute.
Selection
The selection, .sigma..sub.p (r), of relation r on predicate p is the relation (R, V, E'), where sch(p).OR right.R, and:
E'={t.vertline.(t.epsilon.E)p(t)}
Union Compatible
A relation r.sub.1 =({A.sub.1, A.sub.2, . . . , A.sub.n }, V, E.sub.1) is said to be union compatible with relation R.sub.2 =({B.sub.1, B.sub.2, . . . , B.sub.n }, V, E.sub.2) if there exists a permutation p of the numbers 1, 2, . . . , n such that domain (A.sub.1)=domain (B.sub.pi), for 1.ltoreq.i.ltoreq.n. That is, the attributes of r.sub.1 and r.sub.2 can be ordered such that the domains of the first attributes of r.sub.1 and r.sub.2 are the same, the domains of the second attributes of r.sub.1 and r.sub.2 are the same, and so on.
Union and Outer Union
The union, r.sub.1 .orgate.r.sub.2, of relations r.sub.1 and r.sub.2 is the relation (R, V, E.sub.1 .orgate.E.sub.2). The outer union, r.sub.1 r.sub.2, is the relation (R.sub.1 .orgate.R.sub.2, v.sub.1 .orgate.v.sub.2, E'), where:
E'={t.vertline.(.E-backward.t'.epsilon.E.sub.1)(t�R.sub.1 V.sub.1 !=t(.A-inverted.a.epsilon.(R.sub.2 -R.sub.1).orgate.(v.sub.2 -v.sub.1))(t�A!=NULL))(.E-backward.t".epsilon.E.sub.2)(t�R.sub.2 V.sub.2 !=t"(.E-backward.A.epsilon.(R.sub.1 -R.sub.2).orgate.(v.sub.1 -v.sub.2))(t�A!=NULL))}
Note that rows in r.sub.1 r.sub.2 are padded with nulls for those attributes that are not present either in relation r.sub.1 or in relation r.sub.2.
Additional Algebraic Operators
In the following definitions, it is assumed that if predicate p is associated with join/outer/full outer join of relations r.sub.1 and r.sub.2 such that sch(p).andgate.R.sub.1 .noteq..o slashed., sch(p).andgate.R.sub.2 .noteq..o slashed., and sch(p).OR right.R.sub.1 .orgate.R.sub.2.
Join
The join, ##EQU11## of relations r.sub.1 and r.sub.2 is the relation (R.sub.1 R.sub.2, V.sub.1 V.sub.2, E'), where:
E'={t.vertline.t.epsilon.(E.sub.1 .times.E.sub.2)p(t)}
Left and Right Outer Joins
The left outer join, ##EQU12## is the relation (R.sub.1 R.sub.2, V.sub.1 V.sub.2, E'), where: ##EQU13## Relation r.sub.1 in the above definition is called the preserved relation and relation r.sub.2 is called the null supplying relation. The right outer join, ##EQU14## can similarly be defined in which r.sub.1 is the null supplying relation and r.sub.2 is the preserved relation.
Full Outer join
The full outer join, ##EQU15## of relations r.sub.1 and r.sub.2 is the relation (R.sub.1 R.sub.2, V.sub.1 V.sub.2, E'), where: ##EQU16## Equivalence
Values v.sub.1 and v.sub.2 are said to be equivalent, which is denoted as v.sub.1 .ident.v.sub.2, if both v.sub.1, v.sub.2 are non-NULL and v.sub.1 =v.sub.2, or if both v.sub.1, v.sub.2 are NULL.
Intersect Distinct
Let r.sub.1 =({A.sub.1, A.sub.2, . . . , A.sub.n }, V, E.sub.1) and r.sub.2 =({B.sub.1, B.sub.2, . . . , B.sub.n }, V, E.sub.2) be two union compatible relations. Then, the intersect distinct, r.sub.1 .andgate..sub.d r.sub.2, of r.sub.1 and r.sub.2 is the relation ({C.sub.1, C.sub.2, . . . , C.sub.n }, V, E), where each C.sub.i is a possibly renamed version of the union compatible attribute pair (A.sub.i, B.sub.i), 1.ltoreq.i.ltoreq.n, and
E={t.vertline.(.E-backward.t.sub.1 .epsilon.E.sub.1)(.E-backward.t.sub.2 .epsilon.E.sub.2)(.A-inverted.i)(t�C.sub.i !.ident.t.sub.1 �A.sub.i !t�C.sub.i !.ident.t.sub.2 �B.sub.i !)t�V! is a new unique value}
The intersect distinct operation retains the common tuples in relations r.sub.1 and r.sub.2. If a tuple t.sub.1 .epsilon.E.sub.1 contains null value in attribute A.sub.i and t.sub.2 .epsilon.E.sub.2 contains null value in attribute B.sub.i, 1.ltoreq.i.ltoreq.n, and identical non-null values in the remaining attributes, then t.sub.1 and t.sub.2 are considered equivalent and only a single copy is retained in the result. In case there are duplicate tuples in either of the operands, only one copy of the common tuple is retained in the result. In contrast, the intersect all operator, denoted as .andgate..sub.a, retains "some" of the duplicate copies of the common tuples, subject to the "minimum rule". More precisely, in two union compatible relations r.sub.1 and r.sub.2, if a tuple t appears i times in r.sub.1 and j times in r.sub.2, then t appears min {i,j} times in the result relation r.sub.1 .andgate..sub.a r.sub.2.
Expressions and expression trees
The following provides a recursive definition of expressions.
1. If r=(R, V, E) is a relation, then r is an expression. Henceforth, the shorthand notation X will be used to represent the expression X=(R.sub.x, V.sub.x, E.sub.x),
2. If X=(R.sub.x, V.sub.x, E.sub.x) is an expression, then .pi..sup.a.sub.x, (e) is an expression, where X'.OR right.R.sub.x.
3. If X=(R.sub.x, V.sub.x, E.sub.x) is an expression, then .delta..sub.X.sbsb.R.sub.X.sbsb.V (e) is an expression, where X.sub.R .OR right.R.sub.x and X.sub.v .OR right.V.sub.x.
4. If X=(R.sub.x, V.sub.x, E.sub.x) is an expression, then .sigma..sub.p (X) is an expression, where sch(p).OR right.R.sub.x.
5. If X=(R.sub.x, V.sub.x, E.sub.x) and Y=(R.sub.y, V.sub.y, E.sub.y) are expressions, then ##EQU17## is an expression, where: ##EQU18## and p is a predicate such that sch(p).andgate.R.sub.x .noteq..o slashed., sch(p).andgate.R.sub.y .noteq..o slashed., and sch(p).OR right.R.sub.X .orgate.R.sub.Y.
6. If X=(R.sub.x, V.sub.x, E.sub.x) is an expression, then so is (X), where (X)=(R.sub.x, V.sub.x, E.sub.x). This is termed parenthesization, and is required due to the fact that some of the binary operations defined above are not fully associative. Parenthesization determines the evaluation order so that expressions can be evaluated unambiguously. However, whenever there is no ambiguity, parentheses will be dropped freely.
An expression can also be represented by a corresponding expression tree in which the inner nodes are the operators occurring in the expression and the leaves are the base relations referenced in the expression. Let ##EQU19## denote one of the binary operators defined in the previous section, then an expression tree T with left sub-tree T.sub.1, right sub-tree T.sub.r and root ##EQU20## is denoted by: ##EQU21## Henceforth, the two equivalent representations are used interchangeably.
OVERVIEW
The present invention discloses a method and apparatus for simplification of SQL queries using generalized inference propagation. The presence of intersection operations in queries permits the present invention to propagate inferences about one operand of the intersection operation to the other operand, in order to simplify the query by transforming outer join operations to less expensive joins. Further, by applying selection operators through transitive closure, the present invention can make intermediate results of SQL queries smaller. Finally, by applying "null-intolerance" properties of join predicates in the presence of intersection operators, the present invention can further simplify SQL queries.
The first major aspect of the present invention is the use of "generalized inference propagation" to simplify SQL queries. An intersection operator in an SQL query produces tuples that belong to both its input operands. Two tuples are deemed to be equal if, for every attribute, they have either the same non-null value or are both null. This property of the intersection operator, along with the "null-intolerant" nature of (outer) join predicates, allows the present invention to simplify queries by replacing expensive outer join operations with cheaper inner joins, etc. Also, since the intersection operator retains tuples that exist in both its operands, the present invention can apply any known assertion about one of the operands to the other. For example, if it is known that one of the operands of the intersection operator has non-null values for an attribute, then all tuples from the other operand that contain nulls in this attribute can be "filtered" away by appropriate selection or by changing an intermediate operator.
The second major aspect of the present invention is the use of "generalized transitive closure" to simplify SQL queries. In the prior art, optimizers use a technique known as "predicate transitive closure" for the purpose of introducing additional, logically correct, selection predicates into the query expression. This helps in reducing the size of the intermediate relations and, consequently, the query evaluation cost. However, for queries that include an outer join operation, the equivalence-class-based transitive closure method does not work. Further, unlike join-only queries, it is not always correct for outer join operations to push the selection predicate down close to the relation on which the selection predicate is specified. For example: ##EQU22## However, the present invention introduces cost-reducing, logically correct selections into query expressions involving (full) outer joins. The present invention uses such generalized transitive closure to simplify SQL queries.
HARDWARE ENVIRONMENT
FIG. 1 illustrates an exemplary computer hardware environment that could be used with the present invention. In the exemplary environment, a computer system 102 is comprised of one or more processors connected to one or more electronic storage devices 104 and 106, such as disk drives, that store one or more relational databases.
Operators of the computer system 102 use a standard operator interface 108, such as IMS/DB/DC, CICS, TSO, OS/2 or other similar interface, to transmit electrical signals to and from the computer system 102 that represent commands for performing various search and retrieval functions, termed queries, against the databases. In the present invention, these queries conform to the Structured Query Language (SQL) standard, and invoke functions performed by Relational DataBase Management System (RDBMS) software. In the preferred embodiment of the present invention, the RDBMS software comprises the DB2 product offered by IBM for the MVS or OS/2 operating systems. Those skilled in the art will recognize, however, that the present invention has application to any RDBMS software that uses SQL.
As illustrated in FIG. 1, the DB2 architecture for the MVS operating system includes three major components: the IMS Resource Lock Manager (IRLM) 110, the Systems Services module 112, and the Database Services module 114. The IRLM 110 handles locking services, because DB2 treats data as a shared resource, thereby allowing any number of users to access the same data simultaneously, and thus concurrency control is required to isolate users and to maintain data integrity. The Systems Services module 112 controls the overall DB2 execution environment, including managing log data sets 106, gathering statistics, handling startup and shutdown, and providing management support.
At the center of the DB2 architecture is the Database Services module 114. The Database Services module 114 contains several submodules, including the Relational Database System (RDS) 116, the Data Manager 118, the Buffer Manager 120 and other components 122 such as an SQL compiler/interpreter. These submodules support the functions of the SQL language, i.e., definition, access control, retrieval, and update of user and system data.
INTERACTIVE SQL EXECUTION
FIG. 2 is a flowchart illustrating the steps necessary for the interpretation and execution of SQL statements in an interactive environment according to the present invention. Block 202 represents the input of SQL statements into the computer system 102 from the user. Block 204 represents the step of compiling or interpreting the SQL statements. An optimization function within block 204 may transform the SQL query in a manner described in more detail later in this specification. Block 206 represents the step of generating a compiled set of runtime structures called an application plan from the compiled SQL statements. Generally, the SQL statements received as input from the user specify only the data that the user wants, but not how to get to it. This step considers both the available access paths (indexes, sequential reads, etc.) and system held statistics on the data to be accessed (the size of the table, the number of distinct values in a particular column, etc.), to choose what it considers to be the most efficient access path for the query. Block 208 represents the execution of the application plan, and block 210 represents the output of the results of the application plan to the user.
EMBEDDED/BATCH SQL EXECUTION
FIG. 3 is a flowchart illustrating the steps necessary for the interpretation and execution of SQL statements embedded in source code according to the present invention. Block 302 represents program source code containing a host language (such as COBOL or C) and embedded SQL statements. The program source code is then input to a pre-compile step 304. There are two outputs from the pre-compile step 304: a modified source module 306 and a Database Request Module (DBRM) 308. The modified source module 306 contains host language calls to DB2, which the pre-compile step 304 inserts in place of SQL statements. The DBRM 308 consists of the SQL statements from the program source code 302. A compile and link-edit step 310 uses the modified source module 306 to produce a load module 312, while an optimize and bind step 314 uses the DBRM 308 to produce a compiled set of runtime structures for the application plan 316. As indicated above in conjunction with FIG. 2, the SQL statements from the program source code 302 specify only the data that the user wants, but not how to get to it. The optimize and bind step 314 may reorder the SQL query in a manner described in more detail later in this specification. Thereafter, the optimize and bind step 314 considers both the available access paths (indexes, sequential reads, etc.) and system held statistics on the data to be accessed (the size of the table, the number of distinct values in a particular column, etc.), to choose what it considers to be the most efficient access path for the query. The load module 312 and application plan 316 are then executed together at step 318.
SQL QUERY OPTIMIZATION
FIG. 4 is a flowchart illustrating the method of optimizing SQL queries in steps 204 of FIG. 2 and 314 of FIG. 3 according to the present invention. Block 402 represents the acceptance of the SQL query. Block 404 represents the translation of the query into an expression tree. Block 406 represents the RDBMS software performing the generalized inference propagation, as described in more detail below in conjunction with FIGS. 5A-5H. Block 408 represents the RDBMS software performing the generalized transitive closure, as described in more detail below. After these query transformation steps are performed, block 410 returns control to block 204 in FIG. 2 or block 314 in FIG. 3 for subsequent processing steps, including the execution of the SQL query against the relational database and the output of the result table to the user.
GENERALIZED INFERENCE PROPAGATION
FIGS. 5A-5H together are a flowchart describing the generalized inference propagation method that determines which of the "component" attribute pairs of the "p* intersection-predicate" become join-reduced and then uses simplification identities to simplify the query.
For example, consider the relations r.sub.1, r.sub.2, r.sub.3, and r.sub.4 having schemas L.sub.1 L.sub.2, L.sub.3 L.sub.4, R.sub.1, and R.sub.2 R.sub.3 R.sub.4, respectively. Then, an application of inference propagation according to the present invention would simplify a query expression like: ##EQU23## The latter expression can then be made to execute even more efficiently by applying generalized transitive closure of selection operators (as described in more detail hereinafter).
Strong Attributes
An attribute A is said to be strong if all tuples defined on schemas containing A have non-null values for attribute A. Typically, attributes are strong if they are referenced through null-intolerant selection or join predicates. For example, attributes A.sub.1 and B.sub.1 in the relational expression ##EQU24## are strong. Strongly Bound Attributes
A real attribute A is said to be strongly bound if all tuples defined on schemas containing A have exactly the same non-null value for attribute A. Typically, an attribute A in the real schema of expression .sigma. gets strongly bound when .sigma..sub.p (e) assigns a constant value to attribute A.epsilon.sch(p).
Notation
With regard to notation, strongSet(r) is used to denote the set of strong/strongly bound attributes in the (sub) expression represented by (sub)tree T. In addition, if .circle-w/dot..sub.r is the root of the (sub)tree corresponding to (sub)expression e, then the shorthand notation sch(.circle-w/dot..sub.r) is used to represent sch(e). Finally, for any attribute A in the schema of one of the operands of .andgate..sub.d, .andgate..sub.a, the notation Compat(A) is used to represent the corresponding union-compatible attribute from the other operand.
Flowchart
Following is a detailed description of the flowchart of FIGS. 5A-5H, which performs query expression simplification via inference propagation in the expression tree for a given query expression.
Referring first to FIG. 5A, block 502 represents the acceptance of input into the routine, i.e., from block 406 in FIG. 4. The input comprises a root of an expression (sub)tree T containing unary operators {.delta.,.pi.,.sigma.} and binary operators {,.fwdarw.,.rarw., .revreaction., .andgate..sub.d,.andgate..sub.a }. In the expression sub(tree), it is assumed that all selections have been pushed down as close to the base relations as possible. Further, it is assumed that the query has undergone query simplification to convert unnecessary outer joins to joins, etc., as described in �BHAR94!, which is incorporated by reference herein.
Let .circle-w/dot..sub.r be the root of T. The inference propagation method does a post-order traversal of the tree as described in the following steps.
Block 504 is a decision block that determines whether .circle-w/dot..sub.r is a leaf (i.e., a base relation) of the expression tree. If so, then control is transferred to block 506, which sets strongSet(T) to an empty set, and then to block 508, which terminates the routine and returns to the calling routine. Otherwise control is transferred to block 510.
Block 510 is a decision block that determines whether .circle-w/dot..sub.r =.sigma..sub.p and its child .circle-w/dot..sub.c is a base relation s=(R,V,E). If so, then control is transferred to block 512, which stores attribute A in strongSet(T) if A is in sch(p) and p strongly binds A, and then to block 508, which terminates the routine and returns to the calling routine. Otherwise, control is transferred to block 514.
Block 514 is a decision block that determines whether .circle-w/dot..sub.r .epsilon.{.delta..sub.X,.pi..sub.X }, wherein .circle-w/dot..sub.c is its child. If so, then control is transferred to block 516, which stores strongSet(.circle-w/dot..sub.c).andgate.X into strongSet(T), and then to block 508, which terminates the routine and returns to the calling routine. Otherwise, control is transferred to FIG. 5B via "A".
Referring now to FIG. 5B, block 518 is a decision block that determines whether ##EQU25## is a binary operator .epsilon.{,.fwdarw., .rarw..fwdarw.}, wherein .circle-w/dot..sub.L and .circle-w/dot..sub.R are its left and right children, respectively. If not then control is transferred to FIG. 5F via "B"; otherwise, control is transferred to block 520.
Block 520 is a decision block that determines whether .circle-w/dot..sub.r =. If not, then control is transferred FIG. 5C via "C". Otherwise, control is transferred to block 522.
Block 522 computes the strongSet(.circle-w/dot..sub.L) by recursively invoking this inference propagation routine for the left child .circle-w/dot..sub.L. Block 524 computes the strongSet(.circle-w/dot..sub.R) by recursively invoking this inference propagation routine for the right child .circle-w/dot..sub.R. Block 526 computes the strongSet(T) by taking the union of the above two strongSets and all attributes in the join predicates, i.e., by storing strongSet(.circle-w/dot..sub.L) .orgate. strongset (.circle-w/dot..sub.R) .orgate. (all attributes mentioned in p.sub.LR) into strongSet(T). Block 528 terminates the routine and returns control to the calling routine.
Referring now to FIG. 5C, block 530 is a decision block that determines whether .circle-w/dot..sub.r =.fwdarw.. If not, then control is transferred to FIG. 5D via "D". Otherwise, control is transferred to block 532.
Block 532 computes the strongSet(.circle-w/dot..sub.L) by recursively invoking this inference propgation routine. Block 534 stores strongSet(.circle-w/dot..sub.L) into strongSet(T). Block 536 terminates the routine and returns control to the calling routine.
Referring now to FIG. 5D, block 538 is a decision block that determines whether .circle-w/dot..sub.r =.rarw.. If not, then control is transferred to FIG. 5E via "E". Otherwise, control is transferred to block 540.
Block 540 computes the strongSet(.circle-w/dot..sub.R) by recursively invoking this inference propgation routine. Block 542 stores strongSet(.circle-w/dot..sub.R) into strongSet(T). Block 544 terminates the routine and returns control to the calling routine.
Referring now to FIG. 5E, block 546 is a decision block that determines whether .circle-w/dot..sub.r =.revreaction.. If not, then control is transferred to FIG. 5F via "B". Otherwise, control is transferred to block 548.
Block 548 sets strongSet(T) to an empty set. Block 550 terminates the routine and returns control to the calling routine.
Referring now to FIG. 5F, block 552 is a decision block that determines whether .circle-w/dot..sub.r .epsilon.{.andgate..sub.d,.andgate..sub.a }, wherein .circle-w/dot..sub.L and .circle-w/dot..sub.R are its left and right children, respectively. If not, then control is transferred to block 554, which terminates the inference propagation and returns to the calling routine. Otherwise, control is transferred to block 556.
Block 556 stores attribute A into simplifySet(T) if A .epsilon. strongSet(.circle-w/dot..sub.L) and Compat(A) .epsilon slash. strongSet(.circle-w/dot..sub.R), or if A .epsilon. strongSet(.circle-w/dot..sub.L) and Compat(A) .epsilon slash. strongSet (.circle-w/dot..sub.R). Thus, simplifySet(T) is a set of those attributes that are strong or strongly bound in exactly one of the two operands of the intersect operator.
Block 558 is a sequential "for" loop that is executed once for every attribute A .epsilon. simplifySet(T). Block 558 transfers control to block 560 as the first step of the loop for each attribute. Otherwise, control transfers to FIG. 5G via "G" after all attributes A .epsilon. simplifySet(T) have been processed in the loop.
Block 560 recursively applies the simplification identities (1)-(9) to the expression (sub)tree with predicate p* join-reduced in attributes A and Compat(A), as described in more detail below. The simplification identities are applied to the tree to transform it into a modified tree, the identities are then re-applied to the modified tree, and the process continues until none of the simplification identities can be applied to the tree. Control is then returned to block 558 to complete the loop.
Referring now to FIG. 5G, block 562 is a decision block that determines whether simplifySet(T).noteq..o slashed.. If not, then control is transferred to FIG. 5H via "H". Otherwise, control is transferred to block 564.
Block 564 recomputes strongSet (.circle-w/dot..sub.L) by recursively invoking this inference propagation routine with (.circle-w/dot..sub.L) as its input. Block 566 recomputes strongSet(.circle-w/dot..sub.R) by recursively invoking this inference propagation routine with (.circle-w/dot..sub.R) as its input.
Referring now to FIG. 5H, block 568 is a decision block that determines whether simplifySet(T)=.o slashed.. If not, then control is transferred to FIG. 5F via "F" to repeat the above steps. Otherwise, control is transferred to block 570.
Block 570 stores the renamed version of strongSet(.circle-w/dot..sub.L) or strongSet(.circle-w/dot..sub.R) into strongSet(T), where the renaming is done to correspond to the attribute names in the result of .andgate..sub.d or .andgate..sub.a. Finally, block 572 terminates the routine and returns control to the calling routine.
Notes On Inference Propagation
The step of the inference propagation method that handles {.andgate..sub.d,.andgate..sub.a } operators, computes, in some sense, a "fixed point" solution of the strong set. The number of iterations in this fixed point solution are bounded by the number of arrows (counting a one sided outer joins as one arrow, and full outer join as two arrows) in the (sub) tree rooted at the intersection operator. Since this is a finite number, it also provides proof that the method steps will eventually terminate.
In one possible embodiment of the present invention, the execution of the inference propagation method could be made more efficient. For example, every time strongSet(.circle-w/dot..sub.L) or strongSet(.circle-w/dot..sub.R) is re-computed, the computation can be restricted to the paths that are affected by the previous simplification, instead of performing a complete traversal of the subtree. This could, for example, be accomplished by keeping a list of paths from the intersection operator to the leaf that contains the outer join operations that are candidates for simplification.
Example of Inference Propagation
Following is an example of inference propagation. Consider the following query involving relations A, B, C, D, E, F, and G having attributes A.sub.1 A.sub.2 A.sub.3 A.sub.4 A.sub.5, B.sub.1, C.sub.1, D.sub.1, E.sub.1, F.sub.1 F.sub.2, and G.sub.1, respectively, where the union-compatible attribute pairings are A.sub.1 C.sub.1, A.sub.2 D.sub.1, A.sub.3 E.sub.1, A.sub.4 F.sub.1, A.sub.5 F.sub.2, B.sub.1 G.sub.1, C.sub.1 F.sub.1, D.sub.1 F.sub.2, and E.sub.1 G.sub.1 : ##EQU26##
Then, an application of inference propagation would determine the following, incrementally.
Since A.sub.3 and B.sub.1 are strong and A.sub.3 E.sub.1 is a union-compatible pair, .andgate..sub.a would cause: ##EQU27## to become: ##EQU28##
Since C.sub.1 is now strong and C.sub.1 F.sub.1 is a union-compatible pair, .andgate..sub.a would cause: ##EQU29## to become: ##EQU30##
Since F.sub.2 is now strong and D.sub.1 F.sub.2 is a union-compatible pair, .andgate..sub.a would cause: ##EQU31## to become: ##EQU32##
As a result, the query simplifies to: ##EQU33##
SIMPLIFICATION IDENTITIES
Following are the simplification identities applied at block 542 for query expressions involving joins, outer joins, full outer joins, and intersection operators.
Let X.sub.i =(R.sub.i, V.sub.i, E.sub.i), where 1.ltoreq.i.ltoreq.4, be relational expressions, p be a null-intolerant predicate, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }. Then, the following simplification identities can be used, if the associated criteria are met.
Simplification Identity (1) ##EQU34## where sch(p) .andgate.R.sub.3 .noteq..o slashed.. Simplification Identity (2) ##EQU35## where sch(p) .andgate.R.sub.2 .noteq..o slashed.. Simplification Identity (3) ##EQU36## where sch(p).andgate.R.sub.2 .noteq..o slashed. and sch(p).andgate.R.sub.3 .noteq..o slashed..
Simplification Identity (4) ##EQU37## where sch(p).andgate.R.sub.3 .noteq..o slashed.. Simplification Identity (5) ##EQU38## where sch(p).andgate.R.sub.3 .noteq..o slashed.. Simplification Identity (6) ##EQU39## where sch(p).andgate.R.sub.2 .noteq..o slashed. and sch(p).andgate.R.sub.3 .noteq..o slashed..
Corresponding Simplification Identities
Corresponding identities which simplify the right operand of the intersection operator are also used. All of these identities are applied recursively.
Additional Simplification Identities
The intersection operator has two union-compatible operands. Without loss of generality, let the schemas of the two operands be L.sub.1 L.sub.2 . . . L.sub.n and R.sub.1 R.sub.2 . . . R.sub.n, where each of the L.sub.i R.sub.i pairs are union compatible, 1.ltoreq.i.ltoreq.n. The definition of intersection distinct can be re-stated as:
r.sub.1 .andgate..sub.d r.sub.2 ={t.sub.1 .epsilon.r.sub.1 .vertline.(.E-backward.t.sub.2 .epsilon.r.sub.2)(.A-inverted.i) (1.ltoreq.i.ltoreq.np*.sub.L.sbsb.i.sub.R.sbsb.i is TRUE)}
where P*.sub.L.sbsb.i.sub.R.sub.i is the predicate:
(t.sub.1 �L.sub.i ! is not NULL t.sub.2 �R.sub.i ! is not NULL t.sub.1 �L.sub.i !=t.sub.2 �R.sub.i !)(t.sub.1 �L.sub.i ! is NULL t.sub.2 �R.sub.i ! is NULL)
Or, equivalently:
r.sub.1 .andgate..sub.d r.sub.2 ={t.sub.2 .epsilon.r.sub.2 .vertline.(.E-backward.t.sub.1 .epsilon.r.sub.1)(.A-inverted.i)(1.ltoreq.i.ltoreq.np*.sub.L.sbsb.i.sub.R.sub.i is TRUE)}
Also, p*.sub.L.sbsb.i.sub.R.sbsb.i =p*.sub.L.sbsb.i.sub.R.sbsb.I for 1.ltoreq.i.ltoreq.n.
In this context, the operator "=" is used for non-NULL values, along with the predicates "is NULL" and "is not NULL".
For .andgate..sub.a, the same predicate condition determines which tuples are included in the output, although duplicate tuples are permitted in the result, subject to the "minimum rule".
In the definition of p*.sub.L.sbsb.i.sub.R.sbsb.i, if it can be determined that either L.sub.i or R.sub.i, or both, are guaranteed to have non-null values, then the predicate reduces to:
t.sub.1 �L.sub.i !=t.sub.2 �R.sub.i !
Such a predicate is termed "join-reduced" in attributes L.sub.i and R.sub.i. For such join-reduced predicates, the following novel simplification identities can be applied.
Let X.sub.i =(R.sub.i, V.sub.i, E.sub.i), where 1.ltoreq.i.ltoreq.3, be relational expressions, .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }, and let p* be a join-reduced predicate. Then, the following simplification identities can be used, if the associated criteria are met.
Simplification Identity (7) ##EQU40## if p* is join-reduced in an attribute in R.sub.3. Simplification Identity (8) ##EQU41## if p* is join-reduced in an attribute in R.sub.3. Simplification Identity (9) ##EQU42## if p* is join-reduced in an attribute in R.sub.2 and R.sub.3. Corresponding Simplification Identities
Corresponding identities which simplify the left operand of the intersection operator are also used. All these identities are applied recursively.
GENERALIZED TRANSITIVE CLOSURE
The following identities are applied at block 408 of FIG. 4 and constitute a pushup and pushdown rules. The first one of these is a known result for equi-join predicates; the present invention applies to predicates in general. A recursive application of these identities at block 408 of FIG. 4 results in generalized transitive closure.
Let X=(R.sub.X, V.sub.X, E.sub.X), Y=(R.sub.Y, V.sub.Y, E.sub.Y), and Z=(R.sub.Z, V.sub.Z, E.sub.Z) be relational expressions, P.sub.X be a selection predicate on X, P.sub.Y be a selection predicate on Y, and J.sub.XY be a null-intolerant join/outer join predicate. Then, the following generalized transitive closure identities can be used, if the associated criteria are met.
Generalized Transitive Closure Identity (1) ##EQU43## if p.sub.X J.sub.XY p.sub.Y. In the above if J.sub.XY is an equi-join predicate, then the implication can be replaced by equivalence.
Generalized Transitive Closure Identity (2) ##EQU44## if p.sub.X J.sub.XY p.sub.Y. In the above, if J.sub.XY is an equi-join predicate, then the implication can be replaced by equivalence.
Generalized Transitive Closure Identity (3) ##EQU45## if p.sub.X J.sub.XY p.sub.Y. In the above, if J.sub.XY is an equi-join predicate, then the implication can be replaced by equivalence.
Generalized Transitive Closure Identity (4) ##EQU46## (from �GALI92b!). Further: ##EQU47## if p.sub.Y J.sub.XY p.sub.X. Generalized Transitive Closure Identity (5)
Let p be a predicate on the output attributes of an intersection operation (.andgate..sub.d,.andgate..sub.a), and let p.sub.X and p.sub.Y be obtained from p by renaming the attributes referenced in p to the corresponding attributes in the operands X and Y, respectively. Then:
.sigma..sub.p (X.andgate.Y)=.sigma..sub.p.sbsb.X (X).andgate..sigma..sub.p.sbsb.Y (Y)
for .andgate..epsilon.{.andgate..sub.d, .andgate..sub.a }, and:
.sigma..sub.p.sbsb.X (X).andgate.Y=.sigma..sub.p (X.andgate.Y)
for .andgate..epsilon.{.andgate..sub.d, .andgate..sub.a }.
Generalized Transitive Closure Identity (6) ##EQU48## where p is obtained by replacing each of the attributes in J.sub.XY by their corresponding union-compatible attributes from Z, and .andgate..epsilon.(.andgate..sub.d, .andgate..sub.a). If any of the attributes in J.sub.XY are not part of the schema of the expression: ##EQU49## (e.g., removed through projection), then there is no corresponding union-compatible attributes from Z, and the transformation does not apply.
Additionally, using the identities for .sigma.-pushdown described herein, the expression .sigma..sub.p (Z) could be simplified further. This transformation would be applied after the inference propagation method has been used to simplify the query.
CONCLUSION
This concludes the description of the preferred embodiment of the invention. The following describes some alternative embodiments for accomplishing the present invention. For example, any type of computer, such as a mainframe, minicomputer, or personal computer, could be used with the present invention. In addition, any software program adhering (either partially or entirely) to the SQL language could benefit from the present invention.
In summary, the present invention discloses a method and apparatus for query simplification using generalized inference propagation and generalized transitive closure in SQL queries having selection, projection, join, outer join, and intersection operations.
The foregoing description of the preferred embodiment of the invention has been presented for the purposes of illustration and description. It is not intended to be exhaustive or to limit the invention to the precise form disclosed. Many modifications and variations are possible in light of the above teaching. It is intended that the scope of the invention be limited not by this detailed description, but rather by the claims appended hereto.
Claims
  • 1. A method of simplifying an SQL query in a computer having a memory, the SQL query being performed by the computer to retrieve data from a relational database stored in a electronic storage device coupled to the computer, the method comprising the steps of:
  • (a) iteratively calculating, in the memory of the computer, a strong set of attributes referenced in the query; and
  • (b) iteratively replacing, in the memory of the computer, full, left, and right outer join operations found in one or more operands of an intersection operation in the query with outer and inner join operations using the strong set of attributes until no more simplification is possible.
  • 2. The method as set forth in claim 1 above, wherein an attribute A is a member of the strong set of attributes when all tuples defined on schemas containing A have non-null values for attribute A.
  • 3. The method as set forth in claim 1 above, wherein an attribute A is a member of the strong set of attributes when the attribute A is referenced through null-intolerant selection and join predicates.
  • 4. The method as set forth in claim 1 above, wherein an attribute A is a member of the strong set of attributes when all tuples defined on schemas containing A have exactly the same non-null value for attribute A.
  • 5. The method as set forth in claim 1 above, wherein an attribute A is a member of the strong set of attributes when a selection operator referencing the attribute A assigns a constant value to the attribute A.
  • 6. The method as set forth in claim 1 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU50## and the second expression comprises: ##EQU51## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.3 .noteq..o slashed., is a join operator, .fwdarw. is a left outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 7. The method as set forth in claim 1 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU52## and the second expression comprises: ##EQU53## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.2 .noteq..o slashed., .fwdarw. is a left outer join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 8. The method as set forth in claim 1 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU54## and the second expression comprises: ##EQU55## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.2 .noteq..o slashed., sch(p).andgate.R.sub.3 .noteq..o slashed., is a join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 9. The method as set forth in claim 1 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU56## and the second expression comprises: ##EQU57## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.3 .noteq..o slashed., is a join operator, .fwdarw. is a left outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 10. The method as set forth in claim 1 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU58## and the second expression comprises: ##EQU59## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.3 .noteq..o slashed., .fwdarw. is a left outer join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 11. The method as set forth in claim 1 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU60## and the second expression comprises: ##EQU61## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.2 .noteq..o slashed., sch(p).andgate.R.sub.3 .noteq..o slashed., is a join operator, .fwdarw. is a left outer join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 12. The method as set forth in claim 1 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU62## and the second expression comprises: ##EQU63## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p* is a join reduced predicate in an attribute in R.sub.3, is a join operator, .fwdarw. is a left outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 13. The method as set forth in claim 1 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU64## and the second expression comprises: ##EQU65## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p* is a join reduced predicate in an attribute in R.sub.2, .fwdarw. is a left outer join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 14. The method as set forth in claim 1 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU66## and the second expression comprises: ##EQU67## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p* is a join reduced predicate in an attribute in R.sub.2 and R.sub.3, is a join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 15. The method as set forth in claim 1 above, further comprising the steps of:
  • (1) iteratively calculating a strong set of attributes referenced in a sub-expression of the query; and
  • (2) iteratively replacing full, left, and right outer join operations in the sub-expression with outer and inner join operations using the strong set of attributes for the sub-expression until no more simplification is possible.
  • 16. A method of simplifying an SQL query in a computer having a memory, the SQL query being performed by the computer to retrieve data from a relational database stored in a electronic storage device coupled to the computer, the method comprising the steps of:
  • (a) generating an expression tree to represent the query in the memory of the computer, the expression tree comprised of a set of leaves corresponding to relations referenced in the query, and a set of inner nodes corresponding to operators occurring in the query;
  • (b) generating a strong set of attributes for the expression tree in the memory of the computer;
  • (c) post-order traversing the expression tree in the memory of the computer until a node representing an intersection operator is encountered;
  • (d) simplifying a subtree of the expression tree below the intersection operator in the memory of the computer;
  • (e) re-generating the strong set of attributes for the subtree in the memory of the computer; and
  • (f) repeating steps (b)-(d) until the strong set of attributes does not change.
  • 17. The method as set forth in claim 16 above, wherein the strong set of attributes is comprised of one or more attributes A, such that all tuples defined on schemas containing A have non-null values for attribute A.
  • 18. The method as set forth in claim 16 above, wherein the strong set of attributes is comprised of one or more attributes A, wherein the attribute A is referenced through null-intolerant selection and join predicates.
  • 19. The method as set forth in claim 16 above, wherein the strong set of attributes is comprised of one or more attributes A, such that all tuples defined on schemas containing A have exactly the same non-null value for attribute A.
  • 20. The method as set forth in claim 16 above, wherein the strong set of attributes is comprised of one or more attributes A, wherein a selection operator referencing the attribute A assigns a constant value to the attribute A.
  • 21. The method as set forth in claim 16 above, wherein the simplifying step comprises replacing an outer join operation with a join operation.
  • 22. The method as set forth in claim 16 above, wherein the simplifying step comprises replacing a full outer join operation with a one-sided outer join operation.
  • 23. A method of simplifying an SQL query in a computer having a memory, the SQL query being performed by the computer to retrieve data from a relational database stored in a electronic storage device coupled to the computer, the method comprising the steps of:
  • (a) examining the query in the memory of the computer to identify instances where a selection operator is applied to a result of a sub-expression, wherein the sub-expression comprises a first operator applied to first and second operands;
  • (b) identifying, in the memory of the computer, classes of attributes for the selection operator and the sub-expression that are equated through the first operator in the sub-expression;
  • (c) generating, in the memory of the computer, selection predicates from the identified classes; and
  • (d) applying, in the memory of the computer, selection operators to the first and second operands using the generated selection predicates before the first operator is performed, thereby making intermediate results from the first operator smaller.
  • 24. The method of claim 23 above, wherein the first operator is selected from a group comprising: (1) a join operator, (2) a full outer join operator, (3) a one-sided outer join operator, and (4) an intersect operator.
  • 25. The method of claim 23 above, wherein the applying step further comprises the step of replacing: ##EQU68## when p.sub.X J.sub.XY P.sub.Y, wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p.sub.X is a selection predicate on X, p.sub.Y is a selection predicate on Y, J.sub.XY is a null-intolerant join/outer join predicate, is a join operator, and .sigma. is a selection operator.
  • 26. The method of claim 23 above, wherein the applying step further comprises the step of replacing: ##EQU69## when p.sub.x J.sub.XY p.sub.Y, wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p.sub.X is a selection predicate on X, p.sub.Y is a selection predicate on Y, J.sub.XY is a null-intolerant join/outer join predicate, .fwdarw. is a left outer join operator, and .sigma. is a selection operator.
  • 27. The method of claim 23 above, wherein the applying step further comprises the step of replacing: ##EQU70## when p.sub.X J.sub.XY p.sub.Y, wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p.sub.X is a selection predicate on X, p.sub.Y is a selection predicate on Y, J.sub.XY is a null-intolerant join/outer join predicate, .fwdarw. is a left outer join operator, and .sigma. is a selection operator.
  • 28. The method of claim 23 above, wherein the applying step further comprises the step of replacing: ##EQU71## when p.sub.Y J.sub.XY p.sub.X, wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p.sub.X is a selection predicate on X, p.sub.Y is a selection predicate on Y, J.sub.XY is a null-intolerant join/outer join predicate, is a join operator, and .sigma. is a selection operator.
  • 29. The method of claim 23 above, wherein the applying step further comprises the step of replacing:
  • .sigma..sub.p (X.andgate.Y)
  • with:
  • .sigma..sub.p.sbsb.X (X).andgate..sigma..sub.p.sbsb.Y (Y)
  • wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p is a predicate on output attributes of an intersection operation .andgate..epsilon.(.andgate..sub.d,.andgate..sub.a), .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, p.sub.X is a selection predicate on operand X, p.sub.y is a selection predicate on operand Y, p.sub.X and p.sub.Y are obtained from p by renaming attributes referenced in p to corresponding attributes in the operands X and Y, respectively, is a join operator, and .sigma. is a selection operator.
  • 30. The method of claim 23 above, wherein the applying step further comprises the step of replacing:
  • .sigma..sub.p.sbsb.X (X).andgate.Y
  • with:
  • .sigma..sub.p (X.andgate.Y)
  • wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p is a predicate on output attributes of an intersection operation .andgate..epsilon.(.andgate..sub.d d,.andgate..sub.a), .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, p.sub.X is a selection predicate on operand X, p.sub.Y is a selection predicate on operand Y, p.sub.X and p.sub.Y are obtained from p by renaming attributes referenced in p to corresponding attributes in the operands X and Y, respectively, and .sigma. is a selection operator.
  • 31. The method of claim 23 above, wherein the applying step further comprises the step of replacing: ##EQU72## wherein X=(R.sub.X, V.sub.X, E.sub.X), Y=(R.sub.Y, V.sub.Y, E.sub.Y), and Z=(R.sub.Z, V.sub.Z, E.sub.Z) are relational expressions, p is a predicate on output attributes of an intersection operation .andgate..epsilon.(.andgate..sub.d,.andgate..sub.a), .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, p is obtained by replacing each attribute in J.sub.XY by their corresponding union-compatible attributes from Z, is a join operator, and .sigma..sub.p is a selection operator.
  • 32. An apparatus for simplifying an SQL query, comprising:
  • (a) a computer having a memory and an electronic storage device coupled thereto, the data storage device storing a relational database;
  • (b) means, performed by the computer, for accepting the SQL query into the memory of the computer, the SQL query being executed by the computer to retrieve data from a relational database stored in the computer;
  • (c) means, performed by the computer, for iteratively calculating a strong set of attributes referenced in the query; and
  • (d) means, performed by the computer, for iteratively replacing full, left, and right outer join operations found in one or more operands of an intersection operation in the query with outer and inner join operations using the strong set of attributes until no more simplification is possible.
  • 33. The apparatus as set forth in claim 32 above, wherein an attribute A is a member of the strong set of attributes when all tuples defined on schemas containing A have non-null values for attribute A.
  • 34. The apparatus as set forth in claim 32 above, wherein an attribute A is a member of the strong set of attributes when the attribute A is referenced through null-intolerant selection and join predicates.
  • 35. The apparatus as set forth in claim 32 above, wherein an attribute A is a member of the strong set of attributes when all tuples defined on schemas containing A have exactly the same non-null value for attribute A.
  • 36. The apparatus as set forth in claim 32 above, wherein an attribute A is a member of the strong set of attributes when a selection operator referencing the attribute A assigns a constant value to the attribute A.
  • 37. The apparatus as set forth in claim 32 above, wherein the means for iteratively replacing comprises means for replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU73## and the second expression comprises: ##EQU74## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate sch(p).andgate.R.sub.3 .noteq..o slashed., is a join operator, .fwdarw. is a left outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 38. The apparatus as set forth in claim 32 above, wherein the means for iteratively replacing comprises means for replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU75## and the second expression comprises: ##EQU76## wherein X.sub.i =R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.2 .noteq..o slashed., .fwdarw. is a left outer join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 39. The apparatus as set forth in claim 32 above, wherein the means for iteratively replacing comprises means for replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU77## and the second expression comprises: ##EQU78## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.2 .noteq..o slashed., sch(p).andgate.R.sub.3 .noteq..o slashed., is a join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 40. The apparatus as set forth in claim 32 above, wherein the means for iteratively replacing comprises means for replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU79## and the second expression comprises: ##EQU80## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.3 .noteq..o slashed., is a join operator, .fwdarw. is a left outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 41. The apparatus as set forth in claim 32 above, wherein the means for iteratively replacing comprises means for replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU81## and the second expression comprises: ##EQU82## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.3 .noteq..o slashed., .fwdarw. is a left outer join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 42. The apparatus as set forth in claim 32 above, wherein the means for iteratively replacing comprises means for replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU83## and the second expression comprises: ##EQU84## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.2 .noteq..o slashed., sch(p).andgate.R.sub.3 .noteq..o slashed., is a join operator, .fwdarw. is a left outer join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a, .andgate..sub.d }.
  • 43. The apparatus as set forth in claim 32 above, wherein the means for iteratively replacing comprises means for replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU85## and the second expression comprises: ##EQU86## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p* is a join reduced predicate in an attribute in R.sub.3, is a join operator, .fwdarw. is a left outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 44. The apparatus as set forth in claim 32 above, wherein the means for iteratively replacing comprises means for replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU87## and the second expression comprises: ##EQU88## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p* is a join reduced predicate in an attribute in R.sub.2, .fwdarw. is a left outer join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 45. The apparatus as set forth in claim 32 above, wherein the means for iteratively replacing comprises means for replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU89## and the second expression comprises: ##EQU90## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p* is a join reduced predicate in an attribute in R.sub.2 and R.sub.3, is a join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 46. An apparatus for simplifying an SQL query, comprising:
  • (a) a computer having a memory and an electronic storage device coupled thereto, the data storage device storing a relational database;
  • (b) means, performed by the computer, for accepting the SQL query into the memory of the computer, the SQL query being performed by the computer to retrieve data from a relational database stored in the computer;
  • (c) means, performed by the computer, for examining the query to identify instances where a selection operator is applied to a result of a sub-expression, wherein the sub-expression comprises a first operator applied to first and second operand tables;
  • (d) means, performed by the computer, for identifying classes of attributes for the selection operator and the sub-expression that are equated through the first operator in the sub-expression;
  • (e) means, performed by the computer, for generating selection predicates from the identified classes; and
  • (f) means, performed by the computer, for applying selection operators to the first and second operand tables using the generated selection predicates before the first operator is performed, thereby making intermediate results from the first operator smaller.
  • 47. The apparatus as set forth in claim 32 above, further comprising:
  • (1) means for iteratively calculating a strong set of attributes referenced in a sub-expression of the query; and
  • (2) means for iteratively replacing full, left, and right outer join operations in the sub-expression with outer and inner join operations using the strong set of attributes for the sub-expression until no more simplification is possible.
  • 48. The apparatus of claim 46 above, wherein the first operator is selected from a group comprising: (1) a join operator, (2) a full outer join operator, (3) a one-sided outer join operator, and (4) an intersect operator.
  • 49. The apparatus of claim 46 above, wherein the means for applying further comprises means for replacing: ##EQU91## when p.sub.X J.sub.XY p.sub.Y, wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p.sub.X is a selection predicate on X, p.sub.Y is a selection predicate on Y, J.sub.XY is a null-intolerant join/outer join predicate, is a join operator, and .sigma. is a selection operator.
  • 50. The apparatus of claim 46 above, wherein the means for applying further comprises means for replacing: ##EQU92## when p.sub.X J.sub.XY p.sub.Y, wherein X=(R.sub.X, X.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p.sub.X is a selection predicate on X, p.sub.Y is a selection predicate on Y, J.sub.XY is a null-intolerant join/outer join predicate, .fwdarw. is a left outer join operator, and .sigma. is a selection operator.
  • 51. The apparatus of claim 46 above, wherein the means for applying further comprises means for replacing: ##EQU93## when p.sub.X J.sub.XY p.sub.Y, wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p.sub.X is a selection predicate on X, p.sub.Y is a selection predicate on Y, J.sub.XY is a null-intolerant join/outer join predicate, .fwdarw. is a left outer join operator, and .sigma. is a selection operator.
  • 52. The apparatus of claim 46 above, wherein the means for applying further comprises means for replacing: ##EQU94## when p.sub.Y J.sub.XY p.sub.X, wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p.sub.X is a selection predicate on X, p.sub.Y is a selection predicate on Y, J.sub.XY is a null-intolerant join/outer join predicate, is a join operator, and .sigma. is a selection operator.
  • 53. The apparatus of claim 46 above, wherein the means for applying further comprises means for replacing:
  • .sigma..sub.p (X.andgate.Y)
  • with:
  • .sigma..sub.p.sbsb.X (X).andgate..sigma..sub.p.sbsb.Y (Y)
  • wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p is a predicate on output attributes of an intersection operation .andgate..epsilon.(.andgate..sub.d,.andgate..sub.a), .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, p.sub.X is a selection predicate on operand X, p.sub.Y is a selection predicate on operand Y, p.sub.X and p.sub.Y are obtained from p by renaming attributes referenced in p to corresponding attributes in the operands X and Y respectively, is a join operator, and .sigma. is a selection operator.
  • 54. The apparatus of claim 46 above, wherein the means for applying further comprises means for replacing:
  • .sigma..sub.p.sbsb.X (X).andgate.Y
  • with:
  • .sigma..sub.p (X.andgate.Y)
  • wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p is a predicate on output attributes of an intersection operation .andgate..epsilon.(.andgate..sub.d,.andgate..sub.a).andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, p.sub.X is a selection predicate on operand X, p.sub.Y is a selection predicate on operand Y, p.sub.X and p.sub.Y are obtained from p by renaming attributes referenced in p to corresponding attributes in the operands X and Y, respectively, and .sigma. is a selection operator.
  • 55. The apparatus of claim 46 above, wherein the means for applying further comprises means for replacing: ##EQU95## wherein X=(R.sub.X, X.sub.X, E.sub.X), Y=(R.sub.Y, V.sub.Y, E.sub.Y), and Z=(R.sub.Z, V.sub.Z, E.sub.Z) are relational expressions, p is a predicate on output attributes of an intersection operation .andgate..epsilon.(.andgate..sub.d,.andgate..sub.a), .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, p is obtained by replacing each attribute in J.sub.XY by their corresponding union-compatible attributes from Z, is a join operator, and .sigma..sub.p is a selection operator.
  • 56. A program storage device readable by a computer, tangibly embodying a program of instructions executable by the computer to perform method steps for simplifying an SQL query in a computer having a memory, the SQL query being performed by the computer to retrieve data from a relational database stored in an electronic storage device coupled to the computer, the method comprising the steps of:
  • (a) iteratively calculating, in the memory of the computer, a strong set of attributes referenced in the query; and
  • (b) iteratively replacing, in the memory of the computer, full, left, and right outer join operations found in one or more operands of an intersection operation in the query with outer and inner join operations using the strong set of attributes until no more simplification is possible.
  • 57. The method as set forth in claim 56 above, wherein an attribute A is a member of the strong set of attributes when all tuples defined on schemas containing A have non-null values for attribute A.
  • 58. The method as set forth in claim 56 above, wherein an attribute A is a member of the strong set of attributes when the attribute A is referenced through null-intolerant selection and join predicates.
  • 59. The method as set forth in claim 56 above, wherein an attribute A is a member of the strong set of attributes when all tuples defined on schemas containing A have exactly the same non-null value for attribute A.
  • 60. The method as set forth in claim 56 above, wherein an attribute A is a member of the strong set of attributes when a selection operator referencing the attribute A assigns a constant value to the attribute A.
  • 61. The method as set forth in claim 56 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU96## and the second expression comprises: ##EQU97## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.3 .noteq..o slashed., is a join operator, .fwdarw. is a left outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 62. The method as set forth in claim 56 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU98## and the second expression comprises: ##EQU99## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.2 .noteq..o slashed., .fwdarw. is a left outer join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 63. The method as set forth in claim 56 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU100## and the second expression comprises: ##EQU101## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.2 .noteq..o slashed., sch(p).andgate.R.sub.3 .noteq..o slashed., is a join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 64. The method as set forth in claim 56 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU102## and the second expression comprises: ##EQU103## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.3 .noteq..o slashed., is a join operator, .fwdarw. is a left outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 65. The method as set forth in claim 56 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU104## and the second expression comprises: ##EQU105## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.3 .noteq..o slashed., .fwdarw. is a left outer join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 66. The method as set forth in claim 56 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU106## and the second expression comprises: ##EQU107## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p is a null-intolerant predicate, sch(p).andgate.R.sub.2 .noteq..o slashed., sch(p).andgate.R.sub.3 .noteq..o slashed., is a join operator, .fwdarw. is a left outer join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 67. The method as set forth in claim 56 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU108## and the second expression comprises: ##EQU109## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p* is a join reduced predicate in an attribute in R.sub.3, is a join operator, .fwdarw. is a left outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 68. The method as set forth in claim 56 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU110## and the second expression comprises: ##EQU111## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p* is a join reduced predicate in an attribute in R.sub.2, .fwdarw. is a left outer join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 69. The method as set forth in claim 56 above, wherein the iteratively replacing step comprises the step of replacing a first expression in the query with a second expression, wherein the first expression comprises: ##EQU112## and the second expression comprises: ##EQU113## wherein X.sub.i =(R.sub.i, V.sub.i, E.sub.i) are relational expressions for 1.ltoreq.i.ltoreq.4, p* is a join reduced predicate in an attribute in R.sub.2 and R.sub.3, is a join operator, .revreaction. is a full outer join operator, .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, and .andgate..epsilon.{.andgate..sub.a,.andgate..sub.d }.
  • 70. The method as set forth in claim 56 above, further comprising the steps of:
  • (1) iteratively calculating a strong set of attributes referenced in a sub-expression of the query; and
  • (2) iteratively replacing full, left, and right outer join operations in the sub-expression with outer and inner join operations using the strong set of attributes for the sub-expression until no more simplification is possible.
  • 71. A program storage device readable by a computer, tangibly embodying a program of instructions executable by the computer to perform method steps for simplifying an SQL query in a computer having a memory, the SQL query being performed by the computer to retrieve data from a relational database stored in an electronic storage device coupled to the computer, the method comprising the steps of:
  • (a) generating an expression tree to represent the query in the memory of the computer, the expression tree comprised of a set of leaves corresponding to relations referenced in the query, and a set of inner nodes corresponding to operators occurring in the query;
  • (b) generating a strong set of attributes for the expression tree in the memory of the computer;
  • (c) traversing the expression tree in the memory of the computer until a node representing an intersection operator is encountered;
  • (d) simplifying a subtree of the expression tree below the intersection operator in the memory of the computer;
  • (e) re-generating the strong set of attributes for the subtree in the memory of the computer; and
  • (f) repeating steps (b)-(e) until the strong set of attributes does not change.
  • 72. The method as set forth in claim 71 above, wherein the strong set of attributes is comprised of one or more attributes A, such that all tuples defined on schemas containing A have non-null values for attribute A.
  • 73. The method as set forth in claim 71 above, wherein the strong set of attributes is comprised of one or more attributes A, wherein the attribute A is referenced through null-intolerant selection and join predicates.
  • 74. The method as set forth in claim 71 above, wherein the strong set of attributes is comprised of one or more attributes A, such that all tuples defined on schemas containing A have exactly the same non-null value for attribute A.
  • 75. The method as set forth in claim 71 above, wherein the strong set of attributes is comprised of one or more attributes A, wherein a selection operator referencing the attribute A assigns a constant value to the attribute A.
  • 76. The method as set forth in claim 71 above, wherein the simplifying step comprises replacing an outer join operation with a join operation.
  • 77. The method as set forth in claim 71 above, wherein the simplifying step comprises replacing a full outer join operation with a one-sided outer join operation.
  • 78. A program storage device readable by a computer, tangibly embodying a program of instructions executable by the computer to perform method steps for simplifying an SQL query in a computer having a memory, the SQL query being performed by the computer to retrieve data from a relational database stored in an electronic storage device coupled to the computer, the method comprising the steps of:
  • (a) examining query in the memory of the computer to identify instances where a selection operator is applied to a result of a sub-expression, wherein the sub-expression comprises a first operator applied to first and second operand tables;
  • (b) identifying, in the memory of the computer, classes of attributes for the selection operator and the sub-expression that are equated through the first operator in the sub-expression;
  • (c) generating, in the memory of the computer, selection predicates from the identified classes; and
  • (d) applying, in the memory of the computer, selection operators to the first and second operand tables using the generated selection predicates before the first operator is performed, thereby making intermediate results from the first operator smaller.
  • 79. The method of claim 78 above, wherein the first operator is selected from a group comprising: (1) a join operator, (2) a full outer join operator, (3) a one-sided outer join operator, and (4) an intersect operator.
  • 80. The method of claim 78 above, wherein the applying step further comprises the step of replacing: ##EQU114## when p.sub.X J.sub.XY p.sub.Y, wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p.sub.X is a selection predicate on X, p.sub.Y is a selection predicate on Y, J.sub.XY is a null-intolerant join/outer join predicate, is a join operator, and .sigma. is a selection operator.
  • 81. The method of claim 78 above, wherein the applying step further comprises the step of replacing: ##EQU115## when p.sub.X J.sub.XY p.sub.Y, wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p.sub.X is a selection predicate on X, p.sub.Y is a selection predicate on Y, J.sub.XY is a null-intolerant join/outer join predicate, .fwdarw. is a left outer join operator, and .sigma. is a selection operator.
  • 82. The method of claim 78 above, wherein the applying step further comprises the step of replacing: ##EQU116## when p.sub.X J.sub.XY p.sub.Y, wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p.sub.X is a selection predicate on X, p.sub.Y is a selection predicate on Y, J.sub.XY is a null-intolerant join/outer join predicate, .fwdarw. is a left outer join operator, and .sigma. is a selection operator.
  • 83. The method of claim 78 above, wherein the applying step further comprises the step of replacing: ##EQU117## when p.sub.Y J.sub.XY p.sub.X, wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p.sub.X is a selection predicate on X, p.sub.Y is a selection predicate on Y, J.sub.XY is a null-intolerant join/outer join predicate, is a join operator, and .sigma. is a selection operator.
  • 84. The method of claim 78 above, wherein the applying step further comprises the step of replacing:
  • .sigma..sub.p (X.andgate.Y)
  • with:
  • .sigma..sub.p.sbsb.X (X).andgate..sigma..sub.p.sbsb.Y (Y)
  • wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p is a predicate on output attributes of an intersection operation .andgate..epsilon.(.andgate..sub.d, .andgate..sub.a), .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, p.sub.X is a selection predicate on operand X, p.sub.Y is a selection predicate on operand Y, p.sub.X and p.sub.Y are obtained from p by renaming attributes referenced in p to corresponding attributes in the operands X and Y, respectively, is a join operator, and .sigma. is a selection operator.
  • 85. The method of claim 78 above, wherein the applying step further comprises the step of replacing:
  • .sigma..sub.p.sbsb.X (X).andgate.Y
  • with:
  • .sigma..sub.p (.andgate.Y)
  • wherein X=(R.sub.X, V.sub.X, E.sub.X) and Y=(R.sub.Y, V.sub.Y, E.sub.Y) are relational expressions, p is a predicate on output attributes of an intersection operation .andgate..epsilon.(.andgate..sub.d,.andgate..sub.a), .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, p.sub.X is a selection predicate on operand X, p.sub.Y is a selection predicate on operand Y, p.sub.X and p.sub.Y are obtained from p by renaming attributes referenced in p to corresponding attributes in the operands X and Y, respectively, and .sigma. is a selection operator.
  • 86. The method of claim 78 above, wherein the applying step further comprises the step of replacing: ##EQU118## wherein X=(R.sub.X, X.sub.X, E.sub.X), Y=(R.sub.Y, V.sub.Y, E.sub.Y, and Z=(R.sub.Z, V.sub.Z, E.sub.Z) are relational expressions, p is a predicate on output attributes of an intersection operation .andgate..epsilon.(.andgate..sub.d,.andgate..sub.a), .andgate..sub.a is an intersect all operator, .andgate..sub.d is an intersect distinct operator, p is obtained by replacing each attribute in J.sub.XY by their corresponding union-compatible attributes from Z, is a join operator and .sigma..sub.p is a selection operator.
US Referenced Citations (4)
Number Name Date Kind
4769772 Dwyer Sep 1988
4829427 Green May 1989
5091852 Tsunchida et al. Feb 1992
5367675 Cheng et al. Nov 1994
Non-Patent Literature Citations (18)
Entry
APERS, "Optimization Algorithms for Distributed Queries", IEEE Transactions on Software Engineering, vol. SE9, No. 1, Jan. 1983, pp. 57-68.
Lohman et al., "Research Report--Query Processing in R*", IBM Research Laboratory, San Jose, CA (US) IBM Research Division, Apr. 1984, pp. 1-33.
Lafortune et al., "A State Transition Model for Distributed Query Processing", University of California, ACM transactions on Database Systems, vol. 11, No. 3, Sep. 1986 (294-322).
Kim, Won, IBM Research "On Optimizing an SQL-Like Nested Query", ACM Transactions on Database Systems, vol. 7, No. 3, Sep. 1982, pp. 443-469.
Ganski et al., "Optimization of Nested SQL Queries Revisited", ACM, 1987, pp. 23-33.
Haas et al., "Extensible Query Processing in Starburst", IBM Almaden Research Center, San Jose, CA (US), ACM 1989, pp. 377-388.
Date, C.J. & Darwen, Hugh., "Relational Database Management" Relational Database Writings 1989-1991, Part II, pp. 133-154.
Selinger et al, "Access Path Selection in a Relational Database Management System", IBM Research Division, San Jose, CA (US), ACM, 1979, pp. 23-34.
Dayal et al., "An Extended Relational Algebra with Control Over Duplicate Elimination", Computer Corporation of America, Cambridge, MA, (US), ACM 1982, pp. 117-123.
Galindo-Legaria, C., and Rosenthan, A., "How to Extend a Conventional Optimizer to Handle One- and Two-Sided Outerjoin", IEEE Proceedings of Data Engineering, pp. 402-409, 1992.
Galindo-Legaria, C.A., "Algebraic Optimization of Outerjoin Queries", Ph.D. dissertation, Center for Research in Computing Technology, Harvard University, Cambridge, MA, 1992.
Alon Levy, Inderpal Mumick, Yehoshua Sagiv, "Query Optimization by Predicate Move-Around," Proceedings of the 20th VLDB Conference, Santiago, Chile, Sep., 1994.
Paulley, G.N. and Per-Ake Larson, "Exploiting Uniqueness in Query Optimization", CASCON, pp. 804-822, vol. II, Oct. 1993.
Pirahest, H., Hellerstein, J.M. and Hasan, W. "Extensible/Rule Based Query Rewrite Optimization in Starburst", ACM SIGMOD, pp. 39-48, San Diego, CA, Jun. 1992.
Date, C.J. "The Outer Join", Proceedings of the Second International Conference on Databases, Cambridge, England, Sep. 1983, pp. 76-106.
Dayal, Umeshwar, "Processing Queries with Quantifiers: A Horticultural Approach", Proc. ACM PODS, pp. 125-136, 1983.
Dayal, Umeshwar, "Of Nests and Trees: A Unified Approach to Processing Queries That Contain Nested Subqueries, Aggregates, and Quantifiers", VLDB, pp. 197-208, 1987.
Rosenthal, A. and Galindo-Legaria, C., "Query Graphs, Implementing Trees, and Freely-Reorderable Outerjoins", ACM SIGMOD, pp. 291-299, 1990.