1.1. What Is a Stored Program?A database stored programsometimes called a stored module or a stored routineis a computer program (a series of instructions associated with a name) that is stored within, and executes within, the database server. The source code and (sometimes) any compiled version of the stored program are almost always held within the database server's system tables as well. When the program is executed, it is executed within the memory address of a database server process or thread. There are three major types of
Throughout this book, we are going to use the term stored programs to refer to stored procedures, functions, and triggers 1.1.1. Why Use Stored Programs?Developers have a multitude of programming languages from which to choose. Many of these are not database languages, which means that the code written in these languages does not reside in, nor is it managed by, a database server. Stored programs offer some very important advantages over more general-purpose languages, including:
While this is an impressive list of advantages (many of which will be explored in greater detail in this book), we do not recommend that you immediately move all your application logic into stored programs. In today's rich and complex world of software technology, you need to understand the strengths and weaknesses of each possible element in your software configuration, and figure out how to maximize each element. We spend most of Chapter 12 evaluating how and where to apply MySQL stored programs. The bottom line is that, used correctly, stored programsprocedures, functions, and triggerscan improve the performance, security, maintainability, and reliability of your applications. Subsequent chapters will explore how to construct MySQL stored programs and use them to best advantage. Before plunging into the details, however, let's look at how the technology developed and take a quick tour of language capabilities. 1.1.2. A Brief History of MySQLMySQL has its roots in an in-house (non-SQL) database system called Unireg The first widely available version of MySQL was 3.11, which was released in mid-1996. Adoption of MySQL grew rapidlyparalleling the adoption of other related open source technologies. By the year 2005, MySQL could lay claim to over 6 million installations of the MySQL database. Version 3 of MySQL, while suitable for many types of applications (particularly read-intensive web applications), lacked many of the features normally considered mandatory in a relational database. For instance, transactions, views, and subqueries were not initially supported. However, the MySQL system was designed to support a particularly extensible data access architecture, in which the SQL layer was decoupled from the underlying data and file access layer. This allowed custom "storage engines" to be employed in place ofor in combination withthe native ISAM (Indexed Sequential Access Method) The 4.0 release in early 2002 fully incorporated the InnoDB option, making transactions easily available for all MySQL users, and also added improved replication capabilities. The 4.1 release in early 2004 built on the 4.0 release and includedamong many other improvementssupport for subqueries and Unicode character sets. With the 5.0 release of MySQL in late 2005, MySQL took an important step closer to functional parity with commercial RDBMS systems; it introduced stored The 5.1 release, scheduled for the second half of 2006, will add important factilities such as an internal scheduler, table partitioning, row-based replication, and many other significant enhancements. 1.1.3. MySQL Stored Procedures, Functions, and TriggersMySQL chose to implement its stored program language within the MySQL server as a subset of the ANSI SQL:2003 SQL/PSM (Persistent Stored Module) specification. What a mouthful! Essentially, MySQL stored programsprocedures, functions, and triggerscomply with the only available open standard for these types of programsthe ANSI standard. Many MySQL and open source aficionados had been hoping for a stored program language implementation based on an open source language such as PHP or Python. Others anticipated a Java?-based implementation. However, by using the ANSI specificationthe same specification adopted within IBM's DB2 databaseMySQL has taken advantage of years of work done by the ANSI committee, which included representatives from all of the major RDBMS companies. The MySQL stored program language is a block-structured language (like Pascal) that includes familiar commands for manipulating variables, implementing conditional execution, performing iterative processing, and handling errors. Users of existing stored program languages, such as Oracle's PL/SQL |
Friday, October 23, 2009
Section 1.1. What Is a Stored Program?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment