New Foreign Keys in 6.1 Konstantin Osipov, Staff Engineer, MYSQL

Slides:



Advertisements
Similar presentations
MSc IT UFCE8K-15-M Data Management Prakash Chatterjee Room 2Q18
Advertisements

Manipulating Data Schedule: Timing Topic 60 minutes Lecture
ERWin Template Overview By: Dave Wentzel. Agenda u Overview of Templates/Macros u Template editor u Available templates u Independent column browser u.
Maintaining Referential Integrity Pertemuan 2 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Introduction to Structured Query Language (SQL)
SQL components In Oracle. SQL in Oracle SQL is made up of 4 components: –DDL Data Definition Language CREATE, ALTER, DROP, TRUNCATE. Creates / Alters.
SQL DDL constraints Restrictions on the columns and tables 1SQL DDL Constraints.
Chapter 5 Data Manipulation and Transaction Control Oracle 10g: SQL
Transforming Data Models into Database Designs
Database Constraints. Database constraints are restrictions on the contents of the database or on database operations Database constraints provide a way.
Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
Data Modeling and Database Design
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
SQL Server 7.0 Maintaining Referential Integrity.
© Logicalis Group Using DB2/400 effectively. Data integrity facilities Traditional iSeries database usage Applications are responsible for data integrity.
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Chapter 7 SQL: Data Definition Pearson Education © 2009.
Objectives Database triggers and syntax
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
Chapter 9 Logical Database Design : Mapping ER Model To Tables.
PL/SQLPL/SQL Oracle11g: PL/SQL Programming Chapter 9 Database Triggers.
PL/SQLPL/SQL Oracle10g Developer: PL/SQL Programming Chapter 9 Database Triggers.
DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E) 1.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Chapter 3: Relational Databases
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
Oracle 11g: SQL Chapter 5 Data Manipulation and Transaction Control.
Database Constraints ICT 011. Database Constraints Database constraints are restrictions on the contents of the database or on database operations Database.
國立臺北科技大學 課程:資料庫系統 Chapter 7 SQL Data Definition.
SQL: Schema Definition and Constraints Chapter 6 week 6
The Basics of Data Manipulation
Constraints and Triggers
Active Database Concepts
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Introduction to Oracle9i: SQL
Minggu 5, Pertemuan 9 SQL: Data Definition
Database Construction (and Usage)
Error Handling Summary of the next few pages: Error Handling Cursors.
Module 5: Implementing Data Integrity by Using Constraints
COS 346 Day 8.
Referential Integrity
STRUCTURED QUERY LANGUAGE
The Relational Model Relational Data Model
Constraints & Triggers
The Basics of Data Manipulation
Constraints.
Referential Integrity
SQL DATA CONSTRAINTS.
CS122 Using Relational Databases and SQL
CMSC-461 Database Management Systems
Oracle9i Developer: PL/SQL Programming Chapter 8 Database Triggers.
Contents Preface I Introduction Lesson Objectives I-2
CS122 Using Relational Databases and SQL
Prof. Arfaoui. COM390 Chapter 9
CS1222 Using Relational Databases and SQL
CS122 Using Relational Databases and SQL
IST 318 Database Administration
SQL – Constraints & Triggers
CS122 Using Relational Databases and SQL
Presentation transcript:

New Foreign Keys in 6.1 Konstantin Osipov, Staff Engineer, MYSQL kostja@sun.com Peter Gulutzan, SQL Architect, MYSQL peter.gulutzan@sun.com

Introduction and agenda WL#148 “Foreign keys” (created in 2001) Project objectives: support all storage engines better standard compliance (SQL 2003) emphasis on consistency In this talk Peter and Kostja will: discuss why new foreign keys are needed and how they are better demonstrate live

Foreign key features – Standard SQL:2003 (Core) From WL#148 specification:

Terminology T1 is a “child” or “referencing” InnoDB/MySQL, or stuff in 5.1 is “old style” or “native InnoDB” WL#148, or stuff in my:mysql-6.1-fk: “new style” or “all-engines” T1 is a “child” or “referencing” T2 is a “parent” or “referenced”

Demonstration begins... To start MySQL server in new mode: peter@linux:~/bin/mysql> mysqld \ --foreign-key-all-engines=1

No child left behind With –foreign-key-all-engines, ordinarily, MySQL prevents a “child” row from having a value that's not in the “parent” table. The following statements are affected: (assuming CREATE TABLE parent) CREATE TABLE child ... – fails if no parent DROP/ALTER TABLE parent ... – fails if child INSERT INTO child ... – fails if no parent value UPDATE child ... – fails if no parent value UPDATE parent ... – fails if a dangling child value DELETE FROM parent – fails if a dangling child value

Foreign key features – referential action From WL#148 specification:

New stuff: ENGINE=Anything Foreign keys will work with MyISAM, Falcon, Maria and so on... Foreign keys will continue to work with InnoDB, either the old style (using code in the storage engine), or the new style (using code in the server). This can cause complications when you mix engines.

New stuff: column referencing This syntax used to do nothing: CREATE TABLE ... column_name TYPE ... REFERENCES parent_table_name (parent_column_name) Now it works properly.

New stuff: statement checks Consider this foreign key relationship: Now let's update the parent table, UPDATE t1 SET a=CASE WHEN a=1 THEN 3 WHEN a=2 THEN 1;

New stuff: recursion T1 can refer to T2 which refers to T3 which refers to T1. Or, more simply, T1 can refer to T1 (“self- reference”).

Engine capabilities Problematic example: UPDATE two rows. First row update succeeds. Second row update fails due to foreign key violation. This works well with InnoDB/Falcon but poorly with MyISAM – one needs to rollback the statement in case of failure. Therefore we disallow foreign key features that could lead to trouble for engines that have no statement rollback.

Old style and new style: different behavior New style is different because: It's more standard. It has to operate on more engines. It can do statement checks. Locking behavior is different. So: Some DDL works differently. Some DML works differently. You have to be aware before upgrading.

Old style and new style: FOREIGN KEY clause Old style: FOREIGN KEY name. New style: CONSTRAINT name. The old style clause is still supported but translated to CONSTRAINT name.

Old style and new style: default actions Old style: assume RESTRICT is the default. New style: assume NO ACTION is the default. It's a change in defaults, you might not notice if you're restoring from a dump. Old style: RESTRICT and NO ACTION are the same. New style: RESTRICT and NO ACTION differ as per SQL standard. The difference is end-of-statement checks.

Old style and new style: non-unique parent Old style: columns in parent table don't have to be unique. New style: parent columns must be unique. So you have to say UNIQUE or PRIMARY KEY when you define the parent table.

Old style and new style: REFERENCES privilege Old style: REFERENCES privilege is not checked. New style: well, um, privilege still not checked. However, WL#4099 "REFERENCES privilege" is part of the task.

Old style and new style: column definition Old style: parent/child column types and lengths can differ. New style: parent/child column types and lengths can not differ.

Old style and new style: cascades activate triggers Old style: ON [UPDATE|DELETE] [CASCADE|SET NULL| SET DEFAULT] doesn't activate triggers. New style: triggers are activated.

Old style and new style: change-distinct behavior Old style: changing 'a' to 'A' can cause cascading. New style: changing 'a' to 'A' can not cause cascading.

Take your time, the old style remains supported. Upgrading Learn all the differences Take a backup Start the server with –foreign-key-all- engines Today: dump and restore. In future: run mysql_upgrade Take your time, the old style remains supported.

Optional foreign key features From WL#148 specification:

Links WL#148 "Foreign keys" task description (MySQL Forge) WL#4099 "REFERENCES privilege" (MySQL Forge) Foreign key bugs (bugs.mysql.com) MySQL + Foreign keys source available at Launchpad These slides, available at Peter Gulutzan's blog

The end – thank you! Surely there are questions? “Konstantin and Peter” show will occur again tomorrow, we'll be demonstrating many 6.0 and 6.1 features. Where: MySQL Camp, Bayshore room When: Thursday 11:55 am – 12:35 pm Title: Test drive MySQL 6.1