
Exploring Category-Theoretic Approaches to Databases Aaron J. Walter Division of Science and Mathematics University of Minnesota, Morris Morris, Minnesota, USA 56267 [email protected] ABSTRACT An n-tuple is a generalization of an ordered pair { n el- As organizations are formed, split up, merge, or collaborate, ements given in order from left to right, enclosed in paren- they must often work to integrate different database struc- theses. tures. Database migration accounts for a substantial por- Definition 2. Given sets X1;X2; :::; Xn, the Cartesian prod- tion of information technology (IT) budgets, and database uct X1 ×X2 ×:::×Xn is the set of all n-tuples (x1; x2; :::; xn) migration failure is common. This paper explores how to such that each xi is in Xi. avoid database migration failure. Concepts from category theory, a branch of mathematics, can help. If X is the set fapple; hamg and Y is the set fpie; burgerg, the Cartesian product X × Y is the set Keywords f(apple; pie); (apple; burger); (ham; pie); (ham; burger)g. Relational database, database migration, category theory Definition 3. A relation over sets X1;X2; :::; Xn is a sub- set of the Cartesian product X1 × X2 × ::: × Xn. 1. INTRODUCTION The set f(apple; pie); (ham; burger)g is a relation over X; Y . Database migration accounts for approximately 40% of More often than describing a relation by explicitly giving IT budgets, and it is believed that over half of database mi- its members, we will describe a relation by giving the rule or grations fail [1]. This motivates a framework for databases property that its members satisfy. For example, we might that allows us to guarantee correctness of translations be- define a relation R to be the following set: tween database schemas. Category theory serves as the basis of this framework, which is primarily concerned with rela- R := f(x; y) 2 Z × Z : x < yg tional databases. Category theory is a branch of mathemat- Here, Z is the set of integers: f:::; −2; −1; 0; 1; 2; :::g. The ics which focuses on the relationships between objects and Cartesian product Z × Z is the set of all ordered pairs of the structures of those relationships. In Section 2 I pro- integers, and the relation R is the set of all of those ordered vide the mathematical and computer science background of pairs such that the first integer in the pair is less than the the paper { relations, relational databases, graphs, and the second. So the ordered pair (1; 2) belongs in R, but the building blocks of category theory. In Section 3 I describe ordered pairs (2; 1) and (1; 1) do not. If the ordered pair the category-theoretic formulation of relational databases (a; b) is in R, we might write this as aRb, and say \a is proposed by Spivak and Wisnesky. In Section 4 I draw related to b (by R)". It can be helpful to think of a relation conclusions about the practicality and applicability of this as having a short verb phrase. For R, that phrase might be framework. \is less than". It's important to recognize that relations can be defined 2. BACKGROUND on the iterated Cartesian product of a single set with itself I will give background on relations, which are the mathe- (for example, Z × Z above) or on the Cartesian product of matical foundation for relational databases. I will describe several distinct sets. For example, we might define a relation graphs as a foundation for categories. I will discuss the basic S on the set X × Y × Z, where X is the set of students who elements of category theory { categories, functors, natural have attended the University of Minnesota Morris, Y is the transformations, and adjoints. set of professors who have taught a course at Morris, and Z is the set of semesters where Morris has held courses. We could 2.1 Relations define S to be the set of all 3-tuples (x; y; z) { each with one student x, one professor y, and one semester z { such that x Definition 1. An n-tuple is an ordered list of n elements. took a course with y in z. For example, if the author took a course with David Roberts in the spring of 2020, the 3-tuple The ordered pair (0; 0) is a tuple with n = 2. (Aaron Walter, David Roberts, spring 2020) would belong in S. We call a relation n-ary if its objects are n-tuples. For example, R above is a binary (2-ary) relation, while S is a This work is licensed under the Creative Commons Attribution- ternary (3-ary) relation. NonCommercial-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/. Relations often have useful properties, such as symmetry, UMM CSci Senior Seminar Conference, October 2020 Morris, MN. transitivity, and reflexivity. A relation that has all of these properties is called an equivalence relation. A reader who is for the specification of database schemas, a data manipula- unfamiliar with these concepts can refer to an undergraduate tion language (DML) which allows for the access and mod- textbook on set theory, such as [5]. ification of stored data, and a data control language (DCL) which allows for the configuration of security protocols for 2.2 Relational databases a database [7]. The database definition language functions The relational model of databases was proposed by Codd essentially the same way as we will see later in the category- in 1970 and later refined by Darwen and Date in 1995 [3]. theoretic framework. The data control language is outside It provides \a simple and intuitive method for defining a the scope of the question of database migration. So, for our database, storing and updating data in it, and submitting purposes we will focus on the data manipulation language, queries of arbitrary complexity to it" [3]. A query is a which has features which violate the four principles from structured request for information. If we built a relational Section 2.2. database of information about the University of Minnesota, Darwen and Date condemn SQL as a \perversion" of the Morris, it might have a record (Abstract Algebra, David relational model of data [4]. They note that SQL has cer- Roberts, spring 2020). This record is a tuple. A record be- tain properties which are forbidden by the relational model. longs to a collection of similar records, called a table. For For example, SQL-managed relational databases allow for example, this table might also include the records (CSci Se- duplicate rows in a table and allow null values in columns nior Seminar, Elena Machkasova, fall 2020) and (Algorithms rather than requiring every entry correspond to the attribute and Computability, Peter Dolan, fall 2020). If all the records name of its column. Further, SQL can operate on relations in this collection can be read as \Course x was taught by y in a \tuple-at-a-time" level rather than handling them as a in z", we could think of this collection as representing an set. These properties can be problematic for data migration. analogous relation. So in relational databases, tables (col- Graph theory will serve as our foundation for a category- lections of records) are relations, records (rows in a table) theoretic treatment of relational databases, as a potential are tuples, and attributes (the columns in a table) are the alternative to SQL. underlying sets of the relation that table represents. Every attribute in a table is associated to a particular table (when 2.4 Graph theory its entries are foreign keys) or to a particular type of raw data. Definition 4. A graph An ideal relational database adheres to four key princi- G := fV; A; s; tg ples [3]: has a set of vertices V , a set of arrows A, and functions 1. Every row/column intersection has exactly one value. s; t : A ! V which take arrows in A to vertices in V . s can In terms of relations, we might say \every record is be thought of as sending each arrow to its source vertex, and an n-tuple", where n is the number of columns in the t can be thought of sending each arrow to its target vertex. table. Readers familiar with graphs might recognize that Defi- 2. The order of rows in a table doesn't matter. This nition 4 describes a directed multigraph. This paper is not reflects the fact that a relation is a set, and the order concerned with other types of graphs, so the distinction is ig- of elements in a set doesn't matter. nored here. Further, note that what we call arrows are often 3. The order of columns in a table doesn't matter, as long called edges by graph theorists. We choose the term arrow as each column is associated with the correct attribute to emphasize the idea of movement, or transition between name. states. Arrow is also the term that Spivak and Wisnesky use [9]. 4. Rows in a table are unique. This reflects the fact that Table 1 describes a graph G. duplicate elements in a set don't matter. A database schema is a description of the structure of a Table 1: An example graph G database { its tables, the attributes of those tables (other A s t tables or data types) and any \business logic" that goes with a 1 1 V them. As an example of business logic, a schema might b 1 2 1 specify that a worker's next pay check amount is equal to c 2 1 2 their pay rate times the amount of hours they've worked over d 2 3 3 the last pay period.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages6 Page
-
File Size-