Lectura 2 PDF

You might also like

You are on page 1of 22
Inside the Database Server Now that we have studied how to use a database system, we move to the question of how database systems are built. A good way to understand how a modern database system works is to study the innards of a real database system. The SimpleDB database system was built exactly for this purpose, The basic system, which we shall examine in Part 3, consists of about 3500 lines of Java code, organized into 85 classes and 12 packages; and the efficiency optimizations of Part 4 are half again as large. Although that might seem like a lot of code to wade through, we'll see that SimpleDB is an extremely bare-bones system. that uses the simplest possible algorithms and has only the most necessary functionality. Commercial database systems have the same structure, but use sophisticated algorithms, have robust error checking, and have numerous bells and whistles. As a result, such systems are significantly larger. Derby, for example, has over 100 times more code than SimpleDB, and Oracle is even larger. In this part of the text, we break the database server into 10 layered components. Each component knows only about the layers below it, and provides services to the lay- ers above it. The picture on the following page illustrates the functionality of cach com- ponent, ‘A good way to illustrate the interaction between these components is to trace the execution of an SQL statement, For example, suppose that a JDBC client submits an 309 310 Part 3. Inside the Database Server ‘Remote: Perform requests received from clients Planner: Determine an execution strategy for an SQL statement, and translate it to a plan in relational algebra. Parse: Extract the tables, fields, and predicate mentioned in an SQL statement. Query: Implement queries expressed in relational algebra. ‘Metadata: Maintain metadata about the tables in the database, so that their records and fields are accessible. Record: Provide methods for storing data records in pages. Transaction: Support concurrency by restricting access to pages. Enable recovery by logging changes to disk. Buffer: Maintain a cache of pages in memory to hold recently accessed user data. “Lag: Append log records to the log file, and scan the records in the log file File: Read pages from files on disk, and write pages to files on disk. ‘The components of SimpleDB SQL deletion command to the database server, via the method executeUpdate. The following actions occur: © The remote component handles the call to executeUpdate, passing the SQL string to the planner. © The planner sends the SQL string to the parser, which parses the string and extracts the table name and the deletion predicate. The planner uses this extracted data to determine a plan for the statement. This plan represents a relational algebra query for finding the records to be deleted. It sends the plan to the query processor. © The query processor creates a scan from this plan. A scan contains the runtime infor- mation needed to execute the plan. The query processor then creates a record man- ager for each mentioned table and iterates through the scan, During the iteration, it Inside the Database Server 311 will call the appropriate record manager to retrieve each record and determine if it satisfies the deletion predicate, Ifa record needs to be deleted, the query processor tells the record manager to do so. © The record manager knows how the records are stored in the file. When the query processor asks it for the value of a record, it determines which block contains the record, and calculates the offget of the desired value within that block. It then asks the transaction manager to retrieve the value at that location of the block. ® The transaction manager checks its lock table to make sure that another transaction not using the block. If not, the transaction manager locks the block, and calls the buffer manager to get the requested value. © The buffer manager keeps a cache of blocks in memory. If the requested block is not in the cache, the buffer manager chooses a page from the cache and contacts the file manager. It asks the file manager to write the current contents of that page to disk, and to read the specified block into that page. © The file manager reads and writes a block from disk into a memory page, on request. Some variation of this architecture is used by most every commercial relational data- base system. The rationale for this architecture is heavily influenced by the nature of disk I/O. Thus, in this part of the book, we begin from the lowest level—the disk—and work our way up through the successive levels of database software. Object-oriented developers often refer to an object that calls methods from some other class a client of that class. This use of the term “client” is similar to the client-server usage of Part 2—in each case, the client object makes a request of an object in another class, The difference is that in the client-server case, the request occurs over the network. In the remainder of this book, we shall use “client” to refer to the object-oriented aspect of the term, and “JDBC client” to refer to the client-server aspect.

You might also like