Theory and Applications of Categories, Vol. 10, No. 3, 2002, pp. 94–112.

ENTITY-RELATIONSHIP-ATTRIBUTE DESIGNS AND SKETCHES

MICHAEL JOHNSON, ROBERT ROSEBRUGH AND R.J. WOOD

ABSTRACT. Entity-Relationship-Attribute ideas are commonly used to specify and design information systems. They use a graphical technique for displaying the objects of the system and relationships among them. The design process can be enhanced by specifying constraints of the system and the natural environment for these is the categorical notion of sketch. Here we argue that the finite-limit, finite-sum sketches with a terminal node are the appropriate class and call them EA sketches. A model for an EA sketch in a lextensive category is a ‘snapshot’ of a database with values in that category. The category of models of an EA sketch is an object of models of the sketch in a 2-category of lextensive categories. Moreover, modelling the same sketch in certain objects in other 2-categories defines both the query language for the database and the updates (the dynamics) for the database.

1. Introduction

It should be said at the outset that there is a conflict between the terminology used in the study of databases and that used in category theory. Since this paper is an application of the latter to the former we find ourselves with several words that must be sorted out. Most troubling of these is ‘model’. Because the primary audience for this paper is the category theory community we will use categorical terminology. In particular we will use ‘model’ as it is already understood in category theory and in Section 2 we will present a categorical generalization of the idea.

Thus, other than in this paragraph, we will avoid speaking of ‘information models’ and ‘entity-relationship-attribute models’. In [10] information models based on entityrelationship-attribute (ERA) diagrams were shown to be enhanced by the inclusion of commutative diagrams and specification of finite limits and finite sums to model constraints and queries. In this article we extend that work by defining a class of sketches called EA sketches that are suitable for description of ERA models and their constraints. As the categorical reader may already suspect, ‘ERA models’ are more nearly described as ‘ERA theories’ from a categorical perspective. Still, we will try to avoid adding such new terminology.

Early database writers used to exhort their readers to avoid confusing the formal ‘database design’ with particular instances or states of the database. For us the former is the sketch and the latter are its models. We will use ‘database state’ to mean a model of an EA sketch in a lextensive category. The interesting result in this article is that the categorical model idea, applied to a fixed EA sketch, can be used to capture not only the category of states or ‘statics’ but also both the category of queries on the database design and the updates (or ‘dynamics’) of database states.

The authors gratefully acknowledge financial support from the Australian Research Council and the Canadian NSERC. Diagrams typeset using M. Barr’s diagram macros.

Received by the editors 1999 November 26 and, in revised form, 2001 November 1.

Transmitted by Jiri Rosicky. Published on 2002 January 17.

2000 Mathematics Subject Classification: 18C30, 68P15.

Key words and phrases: sketch, model, database, update.

\begin{matrix}c \\ ◯ \end{matrix} Michael Johnson, Robert Rosebrugh and R.J. Wood, 2002. Permission to copy for private use granted.

Certain sketches, in particular our EA sketches, have what has been called in [2] an associated theory which is, in a sense, an enlargement of the sketch to include all possible derived operations and specifications. There are a number of special cases of such theories that may come to mind but an early observation of ours was that the theory expresses the query language of the given database design. It transpires though that the theory of an EA sketch can itself be seen as an object of models of the sketch in a special object in a special 2-category.

In order to understand updates of a database we were led to spans of monic arrows between database states, incorporating the idea that an update involves a deletion followed by an insertion. For an EA sketch 𝔼 and a lextensive category S, there are various ways that spans in the models of 𝔼 in S, Mod(𝔼, S), can be regarded as a mathematical structure. Most common is the structure of a bicategory. However, if spans in Mod(𝔼, S) is regarded as an equipment in the sense of [4] it turns out to be an object of models of 𝔼 in the starred, pointed equipment of spans in S, in the 2-category of all such equipments.

We include here a brief discussion of our categorical view of the entity-relationship-attribute idea. For a fuller description see [6, 10]. An entity is a class of objects about which a database owner has information. For example a school might include STUDENT, COURSE, PROFESSOR, ... as entities in its information specification. Entities have certain attributes or properties — for example students have a name, address, degree programme and so on. Among the attributes of an entity there may be a specified key attribute. A relationship among entities is a (many-many) relation — for example students are enrolled in courses. Graphically, entities are represented by boxes, attributes by ovals, and relationships by lines joining the boxes (with “crows-feet” indicating a ‘many-many’ relationship) as in:

[figure: STUDENT; COURSE; Name; Addr; Num]

The information in such a diagram can be represented by a directed graph in the following way. The first step is to replace a line representing a relationship by a new entity and (e. g. in the case of a binary relationship, two) directed edges (arrows) to the entities related. Thus we represent the relationships by tabulating spans. This places entities and relationships on the same level (represented by boxes) with arrows among them. Then we drop the distinction between entities and relationships. This point of view is also espoused by other writers on database theory, for example C. J. Date, [7]. It explains why we have chosen to speak of ‘EA’ sketches rather than ‘ERA’ sketches.

Next we replace the lines joining entities and attributes with edges directed towards the attributes. The attributes are meant to stand for fixed finite domains of values. To specify this we add a terminal object 1 and then an edge from the terminal object to an attribute for each element of the domain of values of the attribute. The resulting directed graph has entities (now including the former relationships!), the attributes and the terminal 1 as nodes. It has edges as described above and underlies the EA sketch.

The cocone of all edges (arrows) from 1 to an attribute will be a finite sum specification in the EA sketch.

Some of the constraints in data specifications may be modelled using commutative diagrams. An example which illustrates this follows. Suppose there are entities TEACHER, DEPARTMENT, and EQUIPMENT. A teacher is a member of a department so there is an edge (arrow) TEACHER \overline{}DEPARTMENT. An equipment item belongs to a department and is assigned to a teacher. These two facts generate two more arrows, one from EQUIPMENT to TEACHER and a second from EQUIPMENT to DEPARTMENT, giving a triangle. If it is a rule that equipment must be assigned to a teacher who is a member of the department to which the equipment belongs, then the triangle of three arrows just described is a commutativity specification in the EA sketch.

Finite limit specifications may also be used to model constraints. For example the arrow from an entity to a key attribute is necessarily monic. An example of a more complex constraint, taken from [10] follows. A database involving students, courses, classes and class-times may require that no student have a timetable conflict. We assume that courses may have several classes with corresponding time-slots. The pullback of the arrows from ENROL and CLASS into COURSE provides a time-table entity T-TABLE with an arrow to the product of STUDENT and TIME-SLOT. The non-conflict constraint requires this arrow to be monic (see Figure 1).

We continue with an outline of the article. In Section 2 we make precise what we mean by modelling a sketch in an object in a 2-category. We examine what becomes an obvious construction of the required object. It seems to be of independent interest. The modellings that we mentioned earlier which describe queries and updates actually take place in 2-categories that are quite different from the 2-category of categories. We should also point out that in this paper we need to have objects of models in the 2-category whose objects are categories with pullbacks and whose arrows are functors that preserve pullbacks. While this is merely a non-full sub-2-category of the 2-category of categories, the modelling formalism here will underscore the need to model database ‘statics’ in a lextensive category.

Not all of our readers will have read [4] or know otherwise about equipments. We have made no attempt to make this paper self-contained by repeating the material from [4]. To do so would have made this paper unbalanced and obscured our main points. In Section 3 we review CAT-powers of equipments since the material on this topic in [4] is somewhat STUDENT COURSE

TIME-SLOT

ENROL

CLASS

P.B.

T-TABLE

STUDENT x TIME-SLOT

[figure]

[figure]

[figure]

[figure]

[figure]

[figure]

∨

[figure] [figure]

Figure 1: A finite limit constraint

scattered. In Section 3 we also include a discussion about inverters in a certain 2-category of equipments, for inverters did not appear in [4] and we need them for a full account here. We have put an asterisk beside this section and subsection 5.8 and Theorem 5.9 to identify them as containing material about equipments. They can be skipped without interrupting continuity but at the expense of losing what we have to say about database updates.

In Section 4 we formally define EA sketches. The category of models Mod(𝔼, S) of an EA sketch 𝔼 in an appropriate — lextensive — category S are called 𝔼-database states in S. Mod(𝔼, S) is an object of models of 𝔼 in S. We show some properties of the category of models. As a special case we mention the ‘keyed’ EA sketches in which every entity has a specified monomorphism to a key attribute. Here we find that database states have the property that transition arrows are monic. Furthermore, the category of models simplifies to a preorder which is finite if 𝔼 is so and S has finitely many subobjects of 1.

Finally, in Section 5 we describe the associated theory of an EA sketch and show how to view it as the query language. We are able to exploit the considerations of Section 2 and see the query language as the object of models of 𝔼 in the free lextensive category on 1 in the opposite of the 2-category of lextensive categories. In this Section we also consider spans of models of EA sketches. We interpret a span of models as an update of database states. In the special case of keyed EA sketches, where the arrows in a span are necessarily monic, this interpretation coincides exactly with our intuition about updates. Since the category of database states has pullbacks we get a bicategory, with database states as objects and with spans as arrows. This expresses database dynamics. However, by considering the equipment, in the sense of [4], which underlies this bicategory we are able to say more. In fact, the equipment of spans of models of an EA sketch 𝔼 in S is the object of models of 𝔼 in the equipment of of all spans in S in the 2-category of starred, pointed equipments.

We should point out that using sketches for data specification has led to recent progress in understanding the view updatability problem [11]. Before proceeding we note that some other authors have also proposed sketches for data specification. Piessens and Steegmans [12, 13] also consider models of sketches, but give less consideration to the query language and updates. Motivated by the problem of view integration they obtain some very interesting results on algorithmic determination of equivalence of model categories for certain classes of sketches. Diskin and Cadish [8] describe extensions to entity-relationship-attribute specifications using sketches. Benson [3] has proposed viewing the dual of a Diers category (which is sketchable and viewed as a category of data) as the category of queries. Some results about query languages and updates in a categorical model of relational databases can be found in [14].

2. Modelling a Sketch in an Object in a 2-Category

2.1. A sketch 𝕊 = (𝔾, D, L, R) is usually understood to consist of a directed graph 𝔾 together with a set D of diagrams in 𝔾, a set L of cones in 𝔾 and a set R of cocones in 𝔾. A model M of 𝕊 in a category C is a graph homomorphism M : 𝔾 \overline{}C which sends diagrams belonging to D to commutative diagrams, cones belonging to L to limit cones and cocones belonging to R to colimit cocones. A homomorphism of models h : M \overline{}N is a natural transformation. For a fuller treatment we refer the reader to [1] or [2]. Models and their homomorphisms determine a category that we denote by Mod(𝕊, C).

If we write ℂ for the category generated by 𝔾 subject to the relations D then a graph homomorphism M : 𝔾 \overline{}C that sends diagrams in D to commutative diagrams is the same thing as a functor M : ℂ \overline{}C. A natural transformation h : M \overline{}N : 𝔾 \overline{}C between such graph homomorphisms is the same thing as a natural transformation h : M \overline{}N : ℂ \overline{}C. The presentation of ℂ in terms of generators and relations is significant for the applications but somewhat cumbersome for our observations in this section. Thus we will also write 𝕊 = (ℂ, L, R) for a sketch, where ℂ is a category, and then models M of 𝕊 in C are functors M : ℂ \overline{}C which send cones belonging to L to limit cones and cocones belonging to R to colimit cocones. It is even more convenient to write 𝕊 for both the sketch 𝕊 and the category ℂ. We continue to write Mod(𝕊, C) for the category of models of sketch 𝕊 in category C.

If 𝕊 = (𝕊, L, R) is a sketch and k : E \overline{}A is an arrow in 𝕊 then, for the diagram k : E \overline{}A \overline{}E : k in 𝕊, consider the following cone to it:

[figure: E; A; k; F; E; w; w; k]

If this cone is in L then it follows that, for any model D of 𝕊, Dk is a monomorphism. When this is the case it is convenient to say k is a specified monomorphism of 𝕊.

2.2. Definition. For a sketch 𝕊 = (𝕊, L, R) and an object K in a 2-category K, an object of models of 𝕊 in K is an object Mod(𝕊, K) in K, together with a model M of 𝕊 in the category K(Mod(𝕊, K), K), for which, for all A in K, the assignment

A ^{\overline{}^{F}} Mod(𝕊, K) \overline{}𝕊 ^{\overline{}^{M}} K(Mod(𝕊, K), K) ^{\overline{}^{K(F,K)}} K(A, K)

provides an equivalence of categories

K(A, Mod(𝕊, K)) ^{\overline{}^{∼}} Mod(𝕊, K(A, K))

2.3. We are taking the point of view that Mod(𝕊, K) is a weighted bilimit in K and, as such, may or may not exist. It may be useful to point out an aspect of the definition that is somewhat masked in familiar 2-categories of categories. Consider a typical element π of the set L of cones of 𝕊 and a typical element σ of the set R of cocones of 𝕊.

[figure: Π; 𝕊; P; 1; !; P; π; Σ; 𝕊; S; 1; !; S; σ]

It follows from our definition that MP is a limit of the diagram MP in the category K(Mod(𝕊, K), K), which is preserved by composition with all F : A \overline{}Mod(𝕊, K) in K. Similarly, MS is a colimit of the diagram MS, which is preserved by composition with all such F. The preservation properties are often automatic for complete objects K in familiar K, such as CAT. With reference to the diagrams above, note that we will write Π = Π(π), P = P(π), S = S(σ), and so on, to name the data implicit in the statement that π is a cone or that σ is a cocone.

2.4. The question immediately arises as to how Mod(𝕊, K) might be calculated in terms of more familiar bilimits. The only answer that we need for our present work is a generalization of the description of Mod(𝕊, C) for C a category. We will assume that the 2-category K admits CAT-powers (being what most authors call CAT-cotensor-products.) Thus, for all K in K and ℂ in CAT there is an object K^{ℂ} in K and a functor E : ℂ \overline{}K(K^{ℂ}, K) for which, for all A in K, the assignment

A ^{\overline{}^{F}} K^{ℂ} \overline{}ℂ ^{\overline{}^{E}} K(K^{ℂ}, K) ^{\overline{}^{K(F,K)}} K(A, K)

provides an equivalence of categories

K(A, K^{ℂ}) ^{\overline{}^{∼}} CAT(ℂ, K(A, K))

For all K in K, we have a 2-functor K^{(−)} : CAT^{op} \overline{}CAT. In particular, for all K in K and all ℂ in CAT there is an arrow K^{!} : K \overline{}K^{ℂ} in K arising from ! : ℂ \overline{}1, where we have identified K^{1} with K. The object K in K is said to have ℂ-limits if K^{!} : K \overline{}K^{ℂ} has a right adjoint, denoted lim_{←} : K^{ℂ} \overline{}K, in K. Similarly, K is said to have ℂ-colimits if K^{!} : K \overline{}K^{ℂ} has a left adjoint, denoted lim_{→} : K^{ℂ} \overline{}K.

2.5. Consider the elements π of L and σ of R displayed in 2.3. We will now suppose that K has Π(π)-limits, for all π in L, and Σ(σ)-colimits, for all σ in R. Consider also

[figure: K^{𝕊}; K^{Π}; K^{P}; K; K^{p}; K^{!}; K^{π}; K^{𝕊}; K^{Σ}; K^{S}; K; K^{s}; K^{!}; K^{σ}]

[figure: K^{𝕊}; K^{Π}; K^{P}; K; K^{p}; lim_{←}; π̃; K^{𝕊}; K^{Σ}; K^{S}; K; K^{s}; lim_{→}; σ̃]

where the first pair of triangles result from applying the 2-functor K^{(−)} to π and σ and the second pair are obtained from the first pair by adjointness. Define a transformation

[figure: K^{𝕊}; K^{L+R}; 𝕊̃]

whose π-component, for all π in L, is π̃ and whose σ-component, for all σ in R, is σ̃.

Observe that if K is CAT, then K^{𝕊} is the usual functor category. In this case, to say that the M-component of π̃ is invertible is precisely to say that M sends the cone π to a limit cone and to say that the M-component of σ̃ is invertible is precisely to say that M sends the cocone σ to a colimit cocone. It follows that the M-component of 𝕊̃ is invertible if and only if M sends every cone belonging to L to a limit cone and every cocone belonging to R to a colimit cocone.

2.6. Proposition. For a sketch 𝕊 = (𝕊, L, R) and an object K in a bicategory K, if K has powers and inverters and K has Π(π)-limits, for all π in L, and Σ(σ)-colimits, for all σ in R, then Mod(𝕊, K) exists and is given by the following inverter diagram:

with the required model M : 𝕊 \overline{}K(Mod(𝕊, K), K) given by

𝕊 ^{\overline{}^{E}} K(K^{𝕊}, K) ^{\overline{}^{K(I,K)}} K(Mod(𝕊, K), K)

[figure: Mod(𝕊, K); I; K^{𝕊}; K^{L+R}; 𝕊̃]

Proof. The discussion preceding the Proposition provides the result in CAT, from which the general result follows since the definitions of powers, inverters and objects of models in K are all given in terms of CAT-valued representability.

2.7. Corollary. If F : K \overline{}L is a 2-functor that preserves powers and inverters then it preserves modelling of 𝕊 in the sense that the evident comparison arrow

F(Mod(𝕊, K)) \overline{}Mod(𝕊, FK)

in L is an equivalence.

Proof. The only point that requires comment is the construction of the transformation 𝕊̃ in L. However, 2-functors send adjunctions to adjunctions and since F preserves powers, it follows that FK has the necessary limits and colimits when K does.

2.8. A comment on the presentation of 𝕊 = (𝕊, L, R) in the form 𝕊 = (𝔾, D, L, R) as touched on in 2.1 is in order. In a 2-category K, it might well be the case that powers K^{𝕊} are constructed in a fairly concrete way and one can hope to exploit a presentation of a category 𝕊 in terms of a graph 𝔾 and a set of diagrams D. Here it is understood that a diagram δ in 𝔾 is to consist of a pair of vertices S(δ) and T (δ) of 𝔾 together with a pair of paths p(δ), q(δ) : S(δ) [figure] T (δ) which we wish to see as

[figure: S(δ); 1; 𝔾; T (δ); p(δ); q(δ)]

and that 𝕊 is obtained from the free category on 𝔾 by identifying, for each δ ∈ D, the arrows resulting from p(δ) and q(δ). If K admits powers of an object K for all the data in the display above then we obtain

[figure: K^{S(δ)}; K^{𝔾}; K; K^{T (δ)}; K^{p(δ)}; K^{q(δ)}]

and if such is taken as the δ-component, for δ ∈ D, of a diagram

[figure: K^{𝔾}; K^{D}]

then it is a straightforward matter to show that an equifier for it will provide the power K^{𝕊} as in:

[figure: K^{𝕊}; K^{𝔾}; K^{D}]

In the 2-category to be considered in subsection 5.8 it is clear that the considerations of this subsection do apply.

3.^{∗} Powers and Inverters in a 2-Category of Equipments

3.1. As pointed out in the Introduction, one of the main points in this paper, Theorem 5.9 and the subsection 5.8 preceding it, does require some knowledge of equipments as studied in [4]. In particular, our work requires an understanding of the formation of spans for a category K with pullbacks, herein and in [4] denoted spnK, as a 2-functor. In this paper we can restrict our attention to the case where the domain of spn is PBK_{pbk}, the 2-category of categories with pullbacks, pullback-preserving functors and all natural transformations between these. In this case spn takes values in ^{∗}EQT_{∗hom}. Here the objects are starred pointed equipments, arrows are homomorphisms of equipments, and transformations are all equipment transformations between these.

3.2. In PBK_{pbk}, CAT-powers exist and are constructed as in CAT. More precisely, if K is in PBK_{pbk} and ℂ is in CAT then the functor category K^{ℂ}, together with evaluation of functors, provides a power object in PBK_{pbk}. The 2-category ^{∗}EQT_{∗hom} also has all CAT-powers. For an equipment (K, M) and a category ℂ, we will follow [4] to describe (K, M)^{ℂ}. It is helpful to recall first the category grM associated to the equipment (K, M). The objects of grM are triples (K, μ, L), where K and L are objects of the category of scalars K and μ is an object of the vector category M(K, L). It is convenient to call μ a vector arrow and write μ : K \overline{}L. Arrows between vector arrows are given by squares

[figure: L; L′; l; K; K′; k; μ; μ′; Φ]

Here Φ : lμ \overline{}μ′k is an arrow in the vector category M(K, L′), whose domain lμ employs the left action of K on vectors and whose codomain μ′k employs the right action of K on vectors. Arrows such as Φ from the vector categories are also known as vector transformations of the equipment (K, M). Composition in grM is given by horizontal pasting of squares. There are evident domain and codomain functors ∂_{0}, ∂_{1} : grM \overline{}K.

The category of scalars of (K, M)^{ℂ} is just the functor category K^{ℂ}. For P and Q in K^{ℂ}, the objects of the vector category (K, M)^{ℂ}(P, Q) are given by functors ρ : ℂ \overline{}grM with ∂_{0}ρ = P and ∂_{1}ρ = Q. Arrows T : ρ \overline{}σ in (K, M)^{ℂ}(P, Q) are given by natural transformations T : ρ \overline{}σ : ℂ \overline{}grM with the property that ∂_{0}T = 1_{P} and ∂_{1}T = 1_{Q}. For p : P′ \overline{}P in K^{ℂ} and ρ : P \overline{}Q in (K, M)^{ℂ}(P, Q), (ρ.p)(C) = ρ(C)p(C) and, similarly, for q : Q \overline{}Q′ in K^{ℂ}, (q.ρ)(C) = q(C)ρ(C). If (K, M) has the structure of a pointing given by vectors ι_{K} : K \overline{}K then (K, M)^{ℂ} is pointed by ι_{P} (C) = ι_{P (C)}. If (K, M) has the starred property then so does (K, M)^{ℂ}.

3.3. For K a category with pullbacks, spnK = (K, spnK). In other words, the scalar category of the equipment spnK is K and, for K and L objects of K, the vector category spnK(K, L) is the usual category of spans from K to L. Great detail about this example of an equipment can be found in [4]. In the case of spnK the squares of 3.2, arrows in gr(spnK), take the form of comutative diagrams:

[figure: K; K′; k; m_{0}; m′_{0}; L; L′; l; M; M′; f; m_{1}; m′_{1}]

With this observation at hand it is easy to verify:

3.4. Proposition. The 2-functor spn : PBK_{pbk} \overline{}^{∗}EQT_{∗hom} preserves powers.

3.5. Inverters exist in PBK_{pbk} and are constructed as in CAT. Inverters also exist in the 2-category ^{∗}EQT_{∗hom} but these were not described in [4]. We find it convenient here to use further notation from [4] and write A = (A_{#}, A) for an equipment. In fact, extraction of scalar components, (−)_{#} : ^{∗}EQT_{∗hom} \overline{}CAT, is a 2-functor. Consider a transformation in ^{∗}EQT_{∗hom}

[figure: T; A; B; S; u]

and denote its inverter by I : I \overline{}A. The scalar category I_{#} is simply the inverter of u_{#}, which is the full subcategory of A_{#} determined by those objects A in A for which u_{A} : T A \overline{}SA is an isomorphism. The functor I_{#} is the inclusion. The category of vector arrows from A to C in I is I(A, C), given as the inverter of

[figure: A(A, C); B(T A, SC); B(T A, T C); T_{A,C}; B(T A, u_{C}); B(SA, SC); S_{A,C}; B(u_{A}, SC); u_{−}]

where B(T A, u_{C}) is given by post-action of u_{C}, B(u_{A}, SC) is given by pre-action of u_{A} and, for μ : A \overline{}C, the μ-component of u_{−} is

[figure: T C; SC; u_{C}; T A; SA; u_{A}; T μ; Sμ; u_{μ}]

as provided by the definition of a transformation in ^{∗}EQT_{∗hom}. Thus I(A, C) is the full subcategory of A(A, C) determined by those μ for which u_{μ} is an isomorphism. The scalar actions for I are inherited from those in A — this making sense because T and S are homomorphisms of equipments. Because u is a transformation of pointed equipments it follows that u_{ι_{A}} is an isomorphism whereupon ι_{A} is in I(A, A) and provides the components for a pointing for I. The starred property for I is inherited from that of A.

3.6. Given an inverter diagram in PBK_{pbk}

[figure: D; H; G; E; F; F; t]

we consider the induced arrow K : spnD \overline{}I in ^{∗}EQT_{∗hom}, where I is the inverter of spnt. Because (−)_{#}spn : PBK_{pbk} \overline{}CAT is the inclusion, it follows from 3.5 that K_{#} is invertible — in fact it can even be taken to be the identity on D, provided that the inverter of t is constructed by the canonical full sub-category construction both in PBK_{pbk} and when seen as (−)_{#}spnt. Moreover the vector arrows in I are certain spans, with mediating object in E. However, given a vector arrow a : A \overline{}S \overline{}C : c in spnE, the square for (spnt)_{(a,S,c)}, as in the last diagram of 3.5 takes here the form of a commutative diagram

[figure: GS; F S; GA; F A; t_{A}; Ga; F a; GC; F C; t_{C}; t_{S}; Gc; F c]

Said otherwise, (spnt)_{(a,S,c)} = t_{S} and hence is invertible precisely if S is in D; so a vector arrow in I is a span in D. With slight elaboration one has:

3.7. Proposition. The 2-functor spn : PBK_{pbk} \overline{}^{∗}EQT_{∗hom} preserves inverters.

4. EA Sketches and Database States

4.1. Definition. An EA sketch 𝔼 = (𝔼, L, R) is a sketch for which

i) every π in L has Π(π) finite;

ii) every σ in R has Σ(σ) finite and discrete;

iii) there is an object 1 in 𝔼 and the cone

[figure: 0; 𝔼; !; 1; !; 1; 1_{!}]

is in L.

If

[figure: Σ; 𝔼; 1; !; A; σ; 1; !; 1]

is a cocone in R then A is called an attribute. An EA sketch is keyed if, for each object E in 𝔼, there is a specified monomorphism k_{E} : E[figure] A_{E}, where A_{E} is an attribute.

The fragment of a data specification for a school outlined in the Introduction provides an example of an EA sketch. Indeed, our thesis is that sketches with the special properties of an EA sketch have precisely the expressive power needed to describe entity-relationship-attribute data specifications with constraints.

The objects in which EA sketches are modelled must necessarily have finite limits and finite sums. In the applications sums need to be well-behaved so that, at least when modelling in a category, the lextensive axiom should hold. Recall that a category is said to be lextensive if it has finite limits and finite sums which are disjoint and universal. A basic reference for lextensive categories is [5]. It is possible to define lextensive objects in 2-categories other than CAT but we do not need to do so here. Henceforth, S will denote a lextensive category. We will write LXT for the 2-category of lextensive categories, functors that preserve finite limits and finite sums, and natural transformations between these. Note that for S in LXT, − + − : S × S \overline{}S preserves pullbacks — in fact it preserves all finite connected limits.

4.2. Remark. Notice that the definition of EA-sketch does not rule out the possibility of an inconsistent sketch, that is one for which models are trivial. From Definition 4.1 it follows that for any M : 𝔼 \overline{}S to be a model we have, in particular, M1 ^{\overline{}^{≃}} 1. Thus if, for example, the cocone 1 \overline{}1 \overline{}1 is in R then we must have 1 \overline{}1 \overline{}1 a sum diagram in S. In a lextensive category this implies 0 ^{\overline{}^{≃}} 1 so that either Mod(𝔼, S) is empty or S ^{\overline{}^{∼}} 1. Of course, an inconsistency in a sketch can be quite subtle.

4.3. Definition. For an EA sketch 𝔼, an 𝔼-database state in S is a model of 𝔼 in S. The category of 𝔼-database states in S is the category Mod(𝔼, S).

An example of a database state in the lextensive category of finite sets, for the EA sketch of our school data specification is provided by any database which models the specifications described and the constraints implied by the commutative diagrams, the limit cones, and the sum cocones. The next proposition gives a property of the category of models of an EA sketch which is crucial to our discussion of database updates.

4.4. Proposition. For 𝔼 an EA sketch and S a lextensive category, Mod(𝔼, S) has pullbacks (in fact finite connected limits) and these are computed pointwise. If S is a Grothendieck topos then Mod(𝔼, S) has filtered colimits.

Proof. For D_{1} \overline{}D_{0} \overline{}D_{2} in Mod(𝔼, S) and E in 𝔼, define D(E) to be the pullback

[figure: D_{1}(E); D_{0}(E); D(E); D_{2}(E)]

in S. By the universality of pullbacks we can extend D to arrows of 𝔼 so that the commutative diagrams of 𝔼 are respected. Because D is defined by pullbacks, it is immediate that D sends cones in L to limit cones in S, since finite limits commute with pullbacks. To complete the proof we need to show that D sends cocones in R to sums in S. However, since S is lextensive the finite sum functors S^{n} \overline{}S preserve pullbacks (more generally all finite connected limits) and from this it follows that D is a model of 𝔼 and the pullback of D_{1} \overline{}D_{0} \overline{}D_{2} in S^{𝔼} is the pullback in Mod(𝔼, S).

If S is a Grothendieck topos then filtered colimits commute with finite limits in S. In this case, filtered colimits can be constructed pointwise in Mod(𝔼, S).

We will need later the 2-category PBK_{pbk} of categories with pullbacks, functors which preserve pullbacks, and all natural transformations between these. In particular, we will need:

4.5. Proposition. For 𝔼 an EA sketch and S a lextensive category, Mod(𝔼, S) provides an object of models of 𝔼 in S in the 2-category PBK_{pbk}.

Proof. Since PBK_{pbk} has inverters and powers which are constructed as in CAT, this follows from Proposition 2.6 as soon as we show that the transformation 𝔼̃ lies in PBK_{pbk} for 𝔼 a finite-limit, finite-sum sketch and S lextensive. This last follows by inspection of the construction of 𝔼̃ in 2.5. One must check that all (1-)arrows in the case at hand are pullback-preserving functors. The only ones which require comment are those of the form lim_{→} : S^{Σ(σ)} \overline{}S, for σ ∈ R. Again, all these are finite summations since 𝔼 is an EA sketch and finite summations are pullback-preserving since S is lextensive.

The values of a database state at an attribute are determined up to a canonical isomorphism:

4.6. Proposition. For D and D′ database states and A an attribute of 𝔼, there is a canonical isomorphism i_{A} : D(A) ^{\overline{}^{≃}} D′(A). Moreover, for any α : D \overline{}D′ in Mod(𝔼, S),

α_{A} = i_{A} : D(A) ^{\overline{}^{≃}} D′(A).

Proof. We have already observed that for any D in Mod(𝔼, S), D1 ^{\overline{}^{≃}} 1. If A is an attribute in virtue of an element σ in R, with Σ(σ) the discrete category with n objects, then DA ≅ n · 1 in S. Explicitly, if σ is ⟨a_{j} : 1 \overline{}A⟩_{j∈n} then we can define i_{A} to be the unique arrow making all n of the following squares commute

[figure: D′(1); D′(A); D′(a_{j}); D(1); D(A); D(a_{j}); i_{1}; i_{A}]

where i_{1} is the unique isomorphism. For any α : D \overline{}D′ in Mod(𝔼, S), α_{1} = i_{1}, from which it follows by naturality and D(A) being a sum that α_{A} = i_{A}.

4.7. Proposition. If α : D \overline{}D′ is a morphism of database states for a keyed EA sketch 𝔼 and E is an entity of 𝔼 then α_{E} : D(E)[figure] D′(E) is monic and determined by a key for E.

Proof. Suppose that the monic specification k_{E} : E[figure] A_{E} in 𝔼 is a key for E where A_{E} is an attribute. Now consider the commutative square:

[figure: D′(E); D′(A_{E}); D′(k_{E}); D(E); D(A_{E}); D(k_{E}); α_{E}; α_{A_{E}}]

By the previous proposition, we have α_{A_{E}} = i_{A_{E}} : D(A_{E}) ^{\overline{}^{≃}} D′(A_{E}) an isomorphism determined by the cocone structure of A_{E}. The horizontal arrows are monic since D and D′ are models, so α_{E} is monic as claimed.

4.8. Proposition. Let 𝔼 be a keyed EA sketch and S a lextensive category. The model category Mod(𝔼, S) is a preorder which has meets of bounded pairs of models. If 𝔼 is finite and sub(1) in S is finite then Mod(𝔼, S) is finite.

Proof. By Propositions 4.6 and 4.7, all components α_{E} of any α : D \overline{}D′ are monic so all α are monic. To see that Mod(𝔼, S) is a preorder suppose that α, α′ : D \overline{}D′ are model homomorphisms and E is an entity. Since 𝔼 is keyed there is a monic specification k_{E} : E \overline{}A so D′(k_{E}) is monic. By Proposition 4.6 we have α_{A} = i_{A} = α′_{A}. Using this and naturality we get

D′(k_{E})α_{E} = α_{A}D(k_{E}) = α′_{A}D(k_{E}) = D′(k_{E})α′_{E}

so α_{E} = α′_{E} since D′(k_{E}) is monic. Thus α = α′ and hence Mod(𝔼, S) is a preorder. Since Mod(𝔼, S) has pullbacks by Proposition 4.4 it has meets of bounded pairs. For the last statement of the proposition, note that any D(A) has finitely many sub-

objects since sums in S are disjoint and universal and so there are only finitely many possible values for any D(E).

5. Database Queries and Updates

5.1. We first note that EA sketches are examples of the finite-sum sketches, abbreviated FS sketches, in [2]. For 𝔼 an FS sketch, Barr and Wells constructed in [2] a lextensive category T (𝔼) called the associated FS theory. The construction begins with the finite limit completion of 𝔼 and uses a suitable subcategory of sheaves for a Grothendieck topology built using the finite sum cocones in 𝔼. Note that, for an EA sketch 𝔼, T (𝔼) determines an EA sketch by taking the graph, commutativities, finite limit cones and finite sum cocones of T (𝔼) itself. With this point of view, arrows T (𝔼) \overline{}S in LXT, being functors that preserve finite limits and finite sums, can be seen as models of T (𝔼) in S. If 𝔼 is finite, T (𝔼) is not necessarily so but T (𝔼) should be thought of as the category of ‘derived operations’ of the sketch. There is a model J of 𝔼 in T (𝔼) and its rôle as described in Section 8.2 of [2] can be summarised as follows:

5.2. Theorem. For 𝔼 an FS sketch, composition with J : 𝔼 \overline{}T (𝔼) provides, for any lextensive category S, an equivalence of categories

LXT(T (𝔼), S) ^{\overline{}^{∼}} Mod(𝔼, S)

5.3. Our interest in the lextensive category T (𝔼), for an EA sketch 𝔼, is that it is precisely the query language for the data specification that is described by the EA sketch. Indeed, T (𝔼) is exactly the classifying category for the EA information specification as described in [10]. For example, the result of a simple query such as select STUDENT where NAME = `Jones' is the equalizer of the attribute-defining arrow STUDENT \overline{}NAME and the composite STUDENT \overline{}1 ^{`Jones' \overline{}}NAME. As another example, equi-joins are simply pullbacks—as we saw in the Introduction in the context of expressing a constraint. Now T (𝔼) has objects for all such finite limits, and so it has an object for each of the ‘select, project, join’ queries which can be expressed using the entities and attributes of the EA sketch. Since T (𝔼) has disjoint universal sums it also includes expressions for queries involving sums. In short, T (𝔼) is a syntactic category whose objects Q are precisely queries on the original sketch.

To answer a query Q on database state D in S is to extend D : 𝔼 \overline{}S to \overline{D} : T (𝔼) \overline{}S, as in Theorem 5.2, and evaluate \overline{D}(Q).

5.4. The free lextensive category on a category ℂ can be constructed as the free finite sum completion of the free finite limit completion of ℂ. In fact LXT is the 2-category of algebras for the distributive law

LexFam \overline{}FamLex

where Fam is the KZ-doctrine whose algebras are categories with finite sums and Lex is the co-KZ-doctrine whose algebras are categories with finite limits. (Details of this will appear elsewhere.) In particular, the free lextensive category on 1, which we will denote by F, can be seen as Fam(set_{0}^{op}), where set_{0} is the category of finite sets. The free finite sum completion Fam is given by finite families and described, for example, in [9]. Now, referring to Section 2, we consider what it is to model an EA sketch 𝔼 in the particular object F in the 2-category LXT^{op}. An object of models of 𝔼 in F in LXT^{op} is a lextensive category L together with a model M of 𝔼 in LXT^{op}(L, F) so that composition with M mediates an equivalence of categories

LXT^{op}(S, L) ^{\overline{}^{∼}} Mod(𝔼, LXT^{op}(S, F))

For any lextensive category S we have an equivalence S ^{\overline{}^{∼}} LXT(F, S) = LXT^{op}(S, F) and for any F : L \overline{}S in LXT we have a natural isomorphism:

[figure: L; S; F; LXT^{op}(L, F); LXT^{op}(S, F); LXT^{op}(F, F); ∼; ∼; ≃]

It follows that if we take L = T (𝔼) and M to be the composite

𝔼 ^{\overline{}^{J}} T (𝔼) ^{\overline{}^{∼}} LXT^{op}(T (𝔼), F)

where J : 𝔼 \overline{}T (𝔼) is as in Theorem 5.2, then that result can be paraphrased as saying 5.5. Corollary. For 𝔼 an FS sketch (in particular an EA sketch), T (𝔼) provides Mod(𝔼, F), an object of models of 𝔼 in F in LXT^{op}, where F is the free lextensive category on the category 1.

So if an EA sketch has been constructed to model the statics of a particular data specification then the same sketch also serves to model the queries of the data specification.

The remainder of this article is concerned with updating database states and we begin with a definition. 5.6. Definition. For 𝔼-database states D and D′ in S, an update from D to D′ is a span from D to D′ in Mod(𝔼, S).

The motivation for this definition is as follows. An update of D should change it to a new state D′. In general, the value of the database state D at an entity E (which is not an attribute) can have data inserted, deleted or changed. The last operation, however, can be expressed by a deletion of data followed by an insertion of new data. Because of this it can be expressed by a span of monic arrows D(E) [figure]S(E)[figure] D′(E), where S(E) is D(E) after deletions and the mono from S(E) to D′(E) expresses all necessary insertions. Note that for an update from D to D′ we require that S be a model — that is a database state — and also that a simple arrow D(E) \overline{}D′(E) will not do the job. There may be many models S which represent the same update, possibly including a maximal such S. In the case of a keyed EA sketch, where all arrows in Mod(𝔼, S) are monic, our definition of update matches the motivation. In any event, by Proposition 4.4, Mod(𝔼, S) is a category with pullbacks. 5.7. Proposition. Using pullbacks to compose updates, we obtain a bicategory that we call Upd(𝔼, S), which has 𝔼-database states in S as objects and updates as arrows.

5.8.^{∗} Of course Upd(𝔼, S) is simply the bicategory of spans in Mod(𝔼, S). The latter provides the maps — arrows with right adjoints — for the bicategory Upd(𝔼, S). We have

Mod(𝔼, S) \overline{}Upd(𝔼, S)

whereby an arrow is sent to its graph, regarded as a span. The point of view of [4] is that this displayed homomorphism of bicategories can be regarded as making Upd(𝔼, S) into a Mod(𝔼, S)-algebra, meaning at first no more than an analogy with ring theory. Underlying this Mod(𝔼, S)-algebra structure is a Mod(𝔼, S)-bimodule structure that forgets the general horizontal composites of Upd(𝔼, S). It remembers those special horizontal composites in which precisely one factor is a map and regards these as actions of the category Mod(𝔼, S). In the terminology of [4], spn(Mod(𝔼, S)) is the starred, pointed equipment of spans in Mod(𝔼, S) underlying the bicategory Upd(𝔼, S). Following [4] we have written ∗EQT_{∗hom} for the 2-category of starred, pointed equipments; pointed equipment homomorphisms; and transformations between these. (It is crucial for our closing point that equipments form 2-categories in natural ways, rather than 3-dimensional structures as is the case with bicategories.) We recall from Proposition 4.5 that, for any finite-limit, finite-sum sketch 𝔼 and lextensive category S, Mod(𝔼, S) can be seen as an object of models of 𝔼 in S in the 2-category PBK_{pbk}. Our final theorem shows that the equipment of updates spn(Mod(𝔼, S)) can be seen as an object of models of 𝔼 in spnS in the 2-category of starred pointed equipments and their homomorphisms.

5.9. Theorem.^{∗} For any finite-limit, finite-sum sketch 𝔼 and lextensive category S, the 2-functor spn : PBK_{pbk} \overline{}^{∗}EQT_{∗hom} preserves modelling of 𝔼 in the sense that the evident arrow

spn(Mod(𝔼, S)) \overline{}Mod(𝔼, spnS)

is an equivalence of starred pointed equipments.

Proof. This follows immediately from Corollary 2.7, Proposition 3.4 and Proposition 3.7.

So if an EA sketch has been constructed to model the statics of a particular data specification then the same sketch also serves to model the dynamics and, as remarked after Corollary 5.5, the queries of the data specification.

References

[1] M. Barr and C. Wells. Category theory for computing science, second edition. Prentice-Hall, 1995.

[2] M. Barr and C. Wells. Toposes, Triples and Theories. Grundlehren Math. Wiss. 278, Springer Verlag, 1985.

[3] David B. Benson. Stone duality between queries and data. 1996. preprint.

[4] Aurelio Carboni, G. M. Kelly, D. Verity, and R. J. Wood. A 2-categorical approach to change of base and geometric morphisms 2. Theory and Applications of Categories 4 (1998), 82–136.

[5] Aurelio Carboni, Steven Lack, and R. F. C. Walters. Introduction to extensive and distributive categories. Journal of Pure and Applied Algebra 84 (1993), 145–158.

[6] C. N. G. Dampney, Michael Johnson, and G. P. Monro. An illustrated mathematical foundation for era. In The unified computation laboratory, 77–84, Oxford University Press, 1992.

[7] C. J. Date. Introduction to Database Systems, Sixth Edition. Addison-Wesley, 1995.

[8] Zinovy Diskin and Boris Cadish. Algebraic graph-based approach to management of multidatabase systems. In Proceedings of The Second International Workshop on Next Generation Information Technologies and Systems (NGITS ’95), 1995.

[9] Robbie Gates. On extensive and distributive categories. Thesis, University of Sydney, 1997

[10] Michael Johnson and C. N. G. Dampney. On the value of commutative diagrams in information modelling. In Springer Workshops in Computing, Springer-Verlag, 1994.

[11] Michael Johnson and Robert Rosebrugh. View updatability based on the models of a formal specification. Lecture Notes in Computer Science 2021, 534–549, Springer-Verlag, 2001.

[12] Frank Piessens and Eric Steegmans. Categorical data specifications. Theory and Applications of Categories 1 (1995), 156–173.

[13] Frank Piessens and Eric Steegmans. Proving semantical equivalence of data specifications. Journal of Pure and Applied Algebra 116 (1997), 291–322.

[14] Robert Rosebrugh and R. J. Wood. Relational databases and indexed categories. In Proceedings of the International Category Theory Meeting 1991, CMS Conference Proceedings, 13, 391–407, American Mathematical Society, 1992.

School of Mathematics and Computing Macquarie University Sydney 2109, Australia

Department of Mathematics and Computer Science Mount Allison University Sackville, NB, E0A 3C0 Canada

Department of Mathematics and Statistics Dalhousie University Halifax, NS, B3H 3J5 Canada

Email: mike@ics.mq.edu.au
      rrosebrugh@mta.ca
      rjwood@mathstat.dal.ca

This article may be accessed via WWW at http://www.tac.mta.ca/tac/ or by anony-

mous ftp at ftp://ftp.tac.mta.ca/pub/tac/html/volumes/10/3/10-03.{dvi,ps}

THEORY AND APPLICATIONS OF CATEGORIES (ISSN 1201-561X) will disseminate articles that significantly advance the study of categorical algebra or methods, or that make significant new contributions to mathematical science using categorical methods. The scope of the journal includes: all areas of pure category theory, including higher dimensional categories; applications of category theory to algebra, geometry and topology and other areas of mathematics; applications of category theory to computer science, physics and other mathematical sciences; contributions to scientific knowledge that make use of categorical methods.

Articles appearing in the journal have been carefully and critically refereed under the responsibility of members of the Editorial Board. Only papers judged to be both significant and excellent are accepted for publication.

The method of distribution of the journal is via the Internet tools WWW/ftp. The journal is archived electronically and in printed paper format.

Subscription information. Individual subscribers receive (by e-mail) abstracts of articles as they are published. Full text of published articles is available in .dvi, Postscript and PDF. Details will be e-mailed to new subscribers. To subscribe, send e-mail to tac@mta.ca including a full name and postal address. For institutional subscription, send enquiries to the Managing Editor, Robert Rosebrugh,

rrosebrugh@mta.ca.

Information for authors. The typesetting language of the journal is TEX, and L^{A}TEX is the preferred flavour. TEX source of articles for publication should be submitted by e-mail directly to an appropriate Editor. They are listed below. Please obtain detailed information on submission format and style files from the journal’s WWW server at http://www.tac.mta.ca/tac/. You may also write to tac@mta.ca to receive details by e-mail.

Editorial board.

John Baez, University of California, Riverside: baez@math.ucr.edu Michael Barr, McGill University: barr@barrs.org, Associate Managing Editor Lawrence Breen, Université Paris 13: breen@math.univ-paris13.fr Ronald Brown, University of North Wales: r.brown@bangor.ac.uk Jean-Luc Brylinski, Pennsylvania State University: jlb@math.psu.edu Aurelio Carboni, Università dell Insubria: aurelio.carboni@uninsubria.it P. T. Johnstone, University of Cambridge: ptj@dpmms.cam.ac.uk G. Max Kelly, University of Sydney: maxk@maths.usyd.edu.au Anders Kock, University of Aarhus: kock@imf.au.dk F. William Lawvere, State University of New York at Buffalo: wlawvere@acsu.buffalo.edu Jean-Louis Loday, Université de Strasbourg: loday@math.u-strasbg.fr Ieke Moerdijk, University of Utrecht: moerdijk@math.uu.nl Susan Niefield, Union College: niefiels@union.edu Robert Paré, Dalhousie University: pare@mathstat.dal.ca Andrew Pitts, University of Cambridge: Andrew.Pitts@cl.cam.ac.uk Robert Rosebrugh, Mount Allison University: rrosebrugh@mta.ca, Managing Editor Jiri Rosicky, Masaryk University: rosicky@math.muni.cz James Stasheff, University of North Carolina: jds@math.unc.edu Ross Street, Macquarie University: street@math.mq.edu.au Walter Tholen, York University: tholen@mathstat.yorku.ca Myles Tierney, Rutgers University: tierney@math.rutgers.edu Robert F. C. Walters, University of Insubria: robert.walters@uninsubria.it R. J. Wood, Dalhousie University: rjwood@mathstat.dal.ca