Tài liệu tham khảo |
Loại |
Chi tiết |
10.1 VAR LONDON_SUPPLIER VIEW ( S WHERE CITY = 'London' ) { ALL BUT CITY } ;We omit the CITY attribute here because we know its value must be London for every supplier in the view. Observe, however, that this omission means that any INSERT on the view will necessarily fail (unless the default value for attribute CITY in theunderlying suppliers relvar happens to be London). In other words, a view like this one probably can't support INSERT operations at all. Alternatively, we might consider thepossibility of defining the default value for CITY for tuples inserted via this view to be London. This idea of view-specific defaults requires more study. (Of course, we can achieve this effect by means of triggers, as we saw in Chapter 9. However, a declarative solution is naturally to be preferred.) |
Sách, tạp chí |
Tiêu đề: |
for tuples inserted via this view |
|
10.6 Again c. fails at run time, though for a different reason this time. First, the DBMS will include a default WEIGHT value, w say, in the tuple to be inserted, since the user hasn't provided a"real" WEIGHT value (in fact, of course, the user can't provide a"real" WEIGHT value). Second, it's extremely unlikely thatwhatever WT (not WEIGHT) value the user provides will be equal to w * 454──even if (as is not the case in the INSERT shown) that particular WT value happens to be greater than 6356.0. Thus, the tuple presented for insertion again fails to satisfy the predicate for the view. Note: It could be argued that the WEIGHT value in the tuple to be inserted should properly be set to the specified WT value divided by 454. This possibility requires more study |
Sách, tạp chí |
Tiêu đề: |
real" WEIGHT value (in fact, of course, the user can't provide a "real |
|
10.10 It's obviously impossible to provide a definitive answer to this question. We offer the following observations.• Each view and each snapshot will have an entry in the catalog relvar RELVAR (see the answer to Exercise 6.16), with a RVKIND value of "View" or "Snapshot" as appropriate. (RVKINDhere──"relvar kind"──is an attribute of the catalog relvar RELVAR.)• Each view will also have an entry in a new catalog relvar, which we might as well call VIEW. That entry should include the relevant view-defining expression |
Sách, tạp chí |
Tiêu đề: |
View" or "Snapshot" as appropriate. (RVKIND here──"relvar kind |
|
10.11 Yes!──but note the following. Suppose we replace the suppliers relvar S by two restrictions, SA and SB say, where SA is the suppliers in London and SB is the suppliers not in London. We can now define the union of SA and SB as a view called S. If we now try (through this view) to UPDATE a London supplier's city to something other than London, or a "nonLondon" supplier's city to London, the implementation must map that UPDATE to a DELETE on one of the two restrictions and an INSERT on the other. Now, therules given in Section 10.4 do handle this case correctly──in fact, we (deliberately) defined UPDATE as a DELETE followed by an INSERT; however, there was a tacit assumption that theimplementation would actually use an UPDATE, for efficiencyreasons. This example shows that sometimes mapping an UPDATE to an UPDATE does not work; in fact, determining those cases in which it does work can be regarded as an optimization |
Sách, tạp chí |
|
1. Loosely speaking, DELETE deletes a set of zero or more tuples from a specified relvar. For simplicity, let's assume that the set of tuples is always of cardinality one, and so we can talk, even more loosely, in terms of "deleting a tuple" from the relvar in question |
Sách, tạp chí |
Tiêu đề: |
deleting a tuple |
|
1. An open-ended collection of scalar types (including in particular the type boolean or truth value )Comment: The scalar types can be system- or user-defined, in general; thus, a means must be available for users to define their own types (this requirement is implied, partly, by that"open-ended"). A means must therefore also be available for users to define their own operators, since types without operators are useless. The only built-in (i.e., system-defined) type we insist on is type BOOLEAN, but a real system will surely support integers, strings, etc., as well |
Sách, tạp chí |
|
2. A relation type generator and an intended interpretation for relations of types generated therebyComment: The relation type generator allows users to define their own relation types (in Tutorial D, the definition of a given relation type is, typically, bundled in with thedefinition of a relation variable of that type──there's no |
Sách, tạp chí |
Tiêu đề: |
Comment:" The relation type generator allows users to define their own relation types (in Tutorial D, the definition of a given relation type is, typically, bundled in with the definition of a relation variable "of |
|
3. Facilities for defining relation variables of such generated relation typesComment: Of course! Note that relation variables are the only variables allowed inside a relational database ( The Information Principle, in effect) |
Sách, tạp chí |
Tiêu đề: |
Comment:" Of course! Note that relation variables are the "only" variables allowed inside a relational database ("The Information Principle |
|
4. A relational assignment operation for assigning relation values to such relation variablesComment: Variables are updatable by definition (that's what"variable" means); hence, every kind of variable is subject to assignment (that's how updating is done), and relationvariables are no exception. Of course, INSERT, UPDATE, and DELETE shorthands are legal and indeed useful, but strictly speaking they are only shorthands |
Sách, tạp chí |
|
5. An open-ended collection of generic relational operators for deriving relation values from other relation valuesComment: These operators make up the relational algebra, and they're therefore built-in (though there's no inherent reason why users shouldn't be able to define additional ones). Note that the operators are generic ──i.e., they apply to allpossible relations, loosely speaking.*** End of Chapter 10 *** |
Sách, tạp chí |
Tiêu đề: |
Comment:" These operators make up the relational algebra, and they're therefore built-in (though there's no inherent reason why users shouldn't be able to define additional ones). Note that the operators are "generic |
|
10.16 Regarding part a. of this exercise, here's one example of a view retrieval that certainly does fail in some products at the time of writing. Consider the following SQL view definition:CREATE VIEW PQ ASSELECT SP.P#, SUM ( SP.QTY ) AS TOTQTY FROM SPGROUP BY SP.P# ;Consider also the following attempted query:SELECT AVG ( PQ.TOTQTY ) AS PT FROM PQ ;If we follow the simple substitution process explained in the body of the chapter (i.e., we try to replace references to the view |
Khác |
|
10.17 First, here's a definition of Design b. in terms of Design a.:VAR SSP VIEW S JOIN SP ; VAR XSS VIEWS MINUS ( S JOIN SP ) { S#, SNAME, STATUS, CITY } ;And here's a definition of Design a. in terms of Design b.:VAR S VIEWXSS UNION SSP { S#, SNAME, STATUS, CITY } ; VAR SP VIEWSSP { S#, P#, QTY } ;The applicable database constraints for the two designs can be stated as follows:CONSTRAINT DESIGN_AIS_EMPTY ( SP { S# } MINUS S { S# } ) |
Khác |
|
10.18.1 CREATE VIEW LONDON_SUPPLIER AS SELECT S.S#, S.SNAME, S.STATUS FROM SWHERE S.CITY = 'London' ; 10.18.2 CREATE VIEW NON_COLOCATEDAS SELECT S.S#, P.P#FROM S, PWHERE S.CITY <> P.CITY ; 10.18.3 CREATE VIEW SPAS SELECT SPJ.S#, SPJ.P#, SUM ( SPJ.QTY ) AS QTY FROM SPJGROUP BY SPJ.S#, SPJ.P# ; 10.18.4 CREATE VIEW JCAS SELECT J.J#, J.CITY FROM JWHERE J.J# IN ( SELECT SPJ.J#FROM SPJWHERE SPJ.S# = S# ( 'S1' ) ) AND J.J# IN ( SELECT SPJ.J#FROM SPJWHERE SPJ.P# = P# ( 'P1' ) ) ; 10.19 The criticism mentioned in this exercise is heard quite often. Here's a possible counterargument |
Khác |
|