Nosql 的飞跃— 使用mysql 更加安全可靠便利地管理JSON 数据

Total Page:16

File Type:pdf, Size:1020Kb

Nosql 的飞跃— 使用mysql 更加安全可靠便利地管理JSON 数据 NoSQL的飞跃 使用MySQL 更加安全可靠便利地管理JSON 数据 马楚成 (Ivan Ma) 周彦伟 MySQL 亚太区资深方案工程师 极数云舟CEO [email protected] Oracle MySQL ACE Director 2019-04-16 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of Oracle Corporation. Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 2 Outline 1 MySQL作为文档存储 (Ivan) 2 使用 X DevAPI / Connector (Ivan) 3 接管NoSQL,MySQL 管理平台设计和案例 (周彦伟) 4 总结 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 3 2018年4月19日 2018年7月27日 2018年10月22日 8.0.11 GA 8.0.12 发布 8.0.13 发布 2019年2月1日 8.0.15 发布 8.0.16 …… 8.0 The world's most popular open source database Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | MySQL作为文档存储 使用Document Store and X-DevAPI Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 5 NoSQL的魅力 • 越来越多 用户/公司 开始尝试NoSQL 对 RDBMS 的疑惑 后来发现NoSQL 的不足, 限制和问题 RDBMS扩展性低 缺乏“参照完整性””Referential Integrity” 开发人员不喜欢SQL ,等等 缺乏ACID支持 • 结果:SQL + NoSQL - 对传统数据库上开发NoSQL接口(例如 Uber使用Schemaless) - 开发存储引擎,实现NoSQL(例如 Facebook 使用MyRocks /RocksDB) - 使用一些支持JSON的 RDBMS Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | Relational Databases vs Document Store Systems Relational Model Table Document Model customer id name email city_id { _id: 3412, Document 3412 John Smith [email protected] 45 ROW name: "John Smith", {date: "2017-10-02", total: 24.95} city ] } CO id city country_id LL 45 San Francisco US ROW ECT I { _id: 3412, O { _id: 3412, Document N na{ me:_id: "Joh 341n2 S, mith", Document shop_order {dnaate:{ me:_i "2d: "Joh0 31471-n102 S, -mi02th",",total: 24.95} {dnatame:{ e:_i "20d "Jo: 3147h1-n102S, -mith"02", to, tal: 24.95} id id_customer date total ] } {dnate:ame: "2 "Jo017h-n10S-mi02th",",total: 24.95} ] } {dnaate:me: "2 "Joh017-n10 S-mi02th",",to tal: 24.95} 381 3412 2017-08-24 312.20 ROW ] } ] }{date: "2017-10-02", total: 24.95} 412 3412 2017-10-02 24.95 ROW ] } Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 7 主要组件 App 应用 MySQL X DevAPI [Connector] Router MySQL 连接器 路由 X Plugin X 插件 MySQL Shell Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 8 文档 【Document 】和集合 【Collections】 • 文档在文档型数据库( Docstore )里以 JSON的形式展现 - MySQL完美支持 • 多个文档存储在一个集合里 – 数据库 - InnoDB 表为 Collection Table Collection - JSON 类型为常规列 Row [GenCol, JSON, …] Document [ _id, doc ] - 以虚拟列建索引 Row [ GenCol, JSON, …] Document [ _id, doc ] - 应用 - X-DevAPI - 管理 - MySQL Shell Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 9 Document Store with MySQL JSON Datatype CREATE TABLE employees (data JSON); INSERT INTO employees VALUES ('{"id": 1, "name": "Jane"}'), ('{"id": 2, "name": "Joe"}'); SELECT * FROM employees; +-------------------------------------+ | data | +-------------------------------------+ | {"id": 1, "name": "Jane"} | | {"id": 2, "name": "Joe"} | +-------------------------------------+ Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 10 MySQL Connectors include X DevAPI • Use SQL, CRUD APIs – Document (NoSQL) and Relational (SQL), or “All of the Above” – All of this is in addition to the Classic APIs Operation Document Relational Create Collection.add() Table.insert() Read Collection.find() Table.select() Update Collection.modify() Table.update() Delete Collection.remove() Table.delete() Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | . COMMIT和 SAVEPOINT 的支持 • 在会话范围内,提供原子性操作 – 在会话范围内创建, try { 提交或回滚事务 session.startTransaction() // run some operations (1) – 在这些事务中创建, session.createSavepoint('foo') 释放或回滚到中间保存点 // run more operations (2) session.releaseSavepoint('foo') session.commit() } catch (err) { try { session.rollbackTo('foo') // go to (2) } catch (err) { session.rollback() // revert the entire thing } } Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 12 NoSQL + 执行 SQL • 对于ETL ,结构化分析和报表,SQL始终是一种选择 • 允许使用尚未成为X DevAPI 一部分的功能,例如: - 关系表的DDL操作 - 管理键约束 session.sql( ‘< SQL Statement> ‘).execute - 使用JOIN // create a table session.sql('CREATE TABLE foo (bar VARCHAR(3))').execute() // add a unique constraint session.sql('ALTER TABLE foo ADD COLUMN bar VARCHAR(3) GENERATED ALWAYS AS doc->>"$.bar" VIRTUAL UNIQUE KEY NOT NULL').execute() // execute a JOIN query session.sql('SELECT DISTINCT t1.bar FROM foo t1 JOIN baz t2 ON t1.bar = t2.qux WHERE t1.qux = t2.quux').execute() Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 13 集合 [Collection]的使用 NodeJS // Java collection .find("name = 'foo' AND age > 42") const mysqlx = require('@mysql/xdevapi'); .fields("name", "age") .groupBy("name", "age") (async function () { .sort("name ASC", "age DESC") try { const session = await mysqlx.getSession({ user: 'root' }); .limit(4) const schema = session.getSchema('products') .offset(2) .execute() const collection = await schema.createCollection('servers', { ReuseExistingObject : true }); console.log(collection); // { schema: 'products', collection: 'servers' } const collections = await schema.getCollections(); console.log(collections); // [{ schema: 'products', collection: 'servers' }] # Python await session.close(); collection \ .find("name = 'foo' AND age > 42") \ process.exit(); .fields("name", "age") \ } catch (err) { console.error(err.message); .group_by("name", "age") \ process.exit(1); .sort("name ASC", "age DESC") \ } .limit(4) \ })(); .offset(2) \ .execute() Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 14 跨集合的原子更新 const mysqlx = require('@mysql/xdevapi'); (async function () { let session, release; try { session = await mysqlx.getSession({ user: 'root' }); const db = session.getSchema('products'); await db.createCollection('clients', { ReuseExistingObject: true }); await session.startTransaction(); await db.getCollection('servers').find('version = 8.0 AND revision = 11').lockExclusive(mysqlx.LockContention.DEFAULT) .execute(doc => { release = doc.release; }); await db.getCollection('clients').add({ name: 'c-nodejs' }).execute(); await db.getCollection('clients').modify('true').set('serverType', release).execute(); await session.commit(); await session.close(); process.exit(); } catch (err) { if (session) { await session.rollback(); } console.error(err.message); process.exit(1); } })(); Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 15 接管NoSQL MySQL管理平台设计和案例 周彦伟 极数云舟CEO Oracle MySQL ACE Director Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 17 MySQL管理JSON的优势 • 可靠的MySQL 整体技术框架 • MySQL Server+InnoDB • 完备的关系数据库核心功能 • REDO、 UNDO、 MVCC 、Transaction、 Isolation… • 丰富的技术资源和技术人才 • ACMUG /《 MySQL 运维内参》《MySQL 8 Cookbook 》 • 成熟的管理平台和运维方案 • Arkcontrol/Arkgate/Arkproxy/Arksentinel Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 18 MySQL管理平台功能 • 安装部署 • 监控告警 • 备份恢复 • 操作变更 • 审核审计 • 资源管理 高可用切换 • Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 19 实现案例:Arkcontrol • Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 20 Title • Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 21 总结 • 简化 并 保护数据库 的 安装 • 利用广泛和成熟MySQL技术 • 达到双赢 - RDBMS 和NoSQL 的好处 • InnoDB 集群为 高可用 的第一级别方案 • 标准化和简单的Node.js工作流程( async,npm) • 减小对ORM和其他无关的中间件的依赖 • Node.js 优越的部署场景(容器,微服务,无服务器和FaaS ,桌面,物联网等) • 通过利用标准API,避免平台锁定 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 22 链接和资源 • https://github.com/mysql/mysql-connector-nodejs • https://www.npmjs.com/package/@mysql/xdevapi • https://dev.mysql.com/doc/refman/8.0/en/document-store.html • https://dev.mysql.com/doc/x-devapi-userguide/en/ • https://dev.mysql.com/doc/dev/connector-nodejs/8.0/ • https://ruiquelhas.github.io/percona-live-europe-2017/ • https://www.mysql.com/news-and-events/web-seminars/mysql-document- store-and-node-js/ • https://insidemysql.com/mysql-document-store-crud-quick-start/ Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 23 Copyright © 2019, Oracle and/or its affiliates. All rights reserved. | 24 .
Recommended publications
  • ACS-3902 Ron Mcfadyen Slides Are Based on Chapter 5 (7Th Edition)
    ACS-3902 Ron McFadyen Slides are based on chapter 5 (7th edition) (chapter 3 in 6th edition) ACS-3902 1 The Relational Data Model and Relational Database Constraints • Relational model – Ted Codd (IBM) 1970 – First commercial implementations available in early 1980s – Widely used ACS-3902 2 Relational Model Concepts • Database is a collection of relations • Implementation of relation: table comprising rows and columns • In practice a table/relation represents an entity type or relationship type (entity-relationship model … later) • At intersection of a row and column in a table there is a simple value • Row • Represents a collection of related data values • Formally called a tuple • Column names • Columns may be referred to as fields, or, formally as attributes • Values in a column are drawn from a domain of values associated with the column/field/attribute ACS-3902 3 Relational Model Concepts 7th edition Figure 5.1 ACS-3902 4 Domains • Domain – Atomic • A domain is a collection of values where each value is indivisible • Not meaningful to decompose further – Specifying a domain • Name, data type, rules – Examples • domain of department codes for UW is a list: {“ACS”, “MATH”, “ENGL”, “HIST”, etc} • domain of gender values for UW is the list (“male”, “female”) – Cardinality: number of values in a domain – Database implementation & support vary ACS-3902 5 Domain example - PostgreSQL CREATE DOMAIN posint AS integer CHECK (VALUE > 0); CREATE TABLE mytable (id posint); INSERT INTO mytable VALUES(1); -- works INSERT INTO mytable VALUES(-1); -- fails https://www.postgresql.org/docs/current/domains.html ACS-3902 6 Domain example - PostgreSQL CREATE DOMAIN domain_code_type AS character varying NOT NULL CONSTRAINT domain_code_type_check CHECK (VALUE IN ('ApprovedByAdmin', 'Unapproved', 'ApprovedByEmail')); CREATE TABLE codes__domain ( code_id integer NOT NULL, code_type domain_code_type NOT NULL, CONSTRAINT codes_domain_pk PRIMARY KEY (code_id) ) ACS-3902 7 Relation • Relation schema R – Name R and a list of attributes: • Denoted by R (A1, A2, ...,An) • E.g.
    [Show full text]
  • Oracle Database Advanced Application Developer's Guide, 11G Release 2 (11.2) E17125-03
    Oracle® Database Advanced Application Developer's Guide 11g Release 2 (11.2) E17125-03 August 2010 Oracle Database Advanced Application Developer's Guide, 11g Release 2 (11.2) E17125-03 Copyright © 1996, 2010, Oracle and/or its affiliates. All rights reserved. Primary Author: Sheila Moore Contributing Authors: D. Adams, L. Ashdown, M. Cowan, J. Melnick, R. Moran, E. Paapanen, J. Russell, R. Strohm, R. Ward Contributors: D. Alpern, G. Arora, C. Barclay, D. Bronnikov, T. Chang, L. Chen, B. Cheng, M. Davidson, R. Day, R. Decker, G. Doherty, D. Elson, A. Ganesh, M. Hartstein, Y. Hu, J. Huang, C. Iyer, N. Jain, R. Jenkins Jr., S. Kotsovolos, V. Krishnaswamy, S. Kumar, C. Lei, B. Llewellyn, D. Lorentz, V. Moore, K. Muthukkaruppan, V. Moore, J. Muller, R. Murthy, R. Pang, B. Sinha, S. Vemuri, W. Wang, D. Wong, A. Yalamanchi, Q. Yu This software and related documentation are provided under a license agreement containing restrictions on use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license, transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is prohibited. The information contained herein is subject to change without notice and is not warranted to be error-free. If you find any errors, please report them to us in writing. If this software or related documentation is delivered to the U.S.
    [Show full text]
  • SQL Stored Procedures
    Agenda Key:31MA Session Number:409094 DB2 for IBM i: SQL Stored Procedures Tom McKinley ([email protected]) DB2 for IBM i consultant IBM Lab Services 8 Copyright IBM Corporation, 2009. All Rights Reserved. This publication may refer to products that are not currently available in your country. IBM makes no commitment to make available any products referred to herein. What is a Stored Procedure? • Just a called program – Called from SQL-based interfaces via SQL CALL statement • Supports input and output parameters – Result sets on some interfaces • Follows security model of iSeries – Enables you to secure your data – iSeries adopted authority model can be leveraged • Useful for moving host-centric applications to distributed applications 2 © 2009 IBM Corporation What is a Stored Procedure? • Performance savings in distributed computing environments by dramatically reducing the number of flows (requests) to the database engine – One request initiates multiple transactions and processes R R e e q q u u DB2 for i5/OS DB2DB2 for for i5/OS e e AS/400 s s t t SP o o r r • Performance improvements further enhanced by the option of providing result sets back to ODBC, JDBC, .NET & CLI clients 3 © 2009 IBM Corporation Recipe for a Stored Procedure... 1 Create it CREATE PROCEDURE total_val (IN Member# CHAR(6), OUT total DECIMAL(12,2)) LANGUAGE SQL BEGIN SELECT SUM(curr_balance) INTO total FROM accounts WHERE account_owner=Member# AND account_type IN ('C','S','M') END 2 Call it (from an SQL interface) over and over CALL total_val(‘123456’, :balance) 4 © 2009 IBM Corporation Stored Procedures • DB2 for i5/OS supports two types of stored procedures 1.
    [Show full text]
  • Reactive Relational Database Connectivity
    R2DBC - Reactive Relational Database Connectivity Ben Hale<[email protected]>, Mark Paluch <[email protected]>, Greg Turnquist <[email protected]>, Jay Bryant <[email protected]> Version 0.8.0.RC1, 2019-09-26 © 2017-2019 The original authors. Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically. 1 Preface License Specification: R2DBC - Reactive Relational Database Connectivity Version: 0.8.0.RC1 Status: Draft Specification Lead: Pivotal Software, Inc. Release: 2019-09-26 Copyright 2017-2019 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Foreword R2DBC brings a reactive programming API to relational data stores. The Introduction contains more details about its origins and explains its goals. This document describes the first and initial generation of R2DBC. Organization of this document This document is organized into the following parts: • Introduction • Goals • Compliance • Overview • Connections • Transactions 2 • Statements • Batches • Results • Column and Row Metadata • Exceptions • Data Types • Extensions 3 Chapter 1.
    [Show full text]
  • JDBC Mock Test
    JJDDBBCC MMOOCCKK TTEESSTT http://www.tutorialspoint.com Copyright © tutorialspoint.com This section presents you various set of Mock Tests related to JDBC Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself. JJDDBBCC MMOOCCKK TTEESSTT IIIIII Q 1 - Which of the following is used generally used for altering the databases? A - boolean execute B - ResultSet executeQuery C - int executeUpdate D - None of the above. Q 2 - How does JDBC handle the data types of Java and database? A - The JDBC driver converts the Java data type to the appropriate JDBC type before sending it to the database. B - It uses a default mapping for most data types. C - Both of the above. D - None of the above. Q 3 - Which of the following can cause 'No suitable driver' error? A - Due to failing to load the appropriate JDBC drivers before calling the DriverManager.getConnection method. B - It can be specifying an invalid JDBC URL, one that is not recognized by JDBC driver. C - This error can occur if one or more the shared libraries needed by the bridge cannot be loaded. D - All of the above. Q 4 - Why will you set auto commit mode to false? A - To increase performance. B - To maintain the integrity of business processes. C - To use distributed transactions D - All of the above. Q 5 - Which of the following is correct about savepoint? A - A savepoint marks a point that the current transaction can roll back to.
    [Show full text]
  • Concurrency Control and Recovery ACID • Transactions • Recovery Transaction Model Concurency Control Recovery
    Data Management Systems • Transaction Processing • Concurrency control and recovery ACID • Transactions • Recovery Transaction model Concurency Control Recovery Gustavo Alonso Institute of Computing Platforms Department of Computer Science ETH Zürich Transactions-CC&R 1 A bit of theory • Before discussing implementations, we will cover the theoretical underpinning behind concurrency control and recovery • Discussion at an abstract level, without relation to implementations • No consideration of how the concepts map to real elements (tuples, pages, blocks, buffers, etc.) • Theoretical background important to understand variations in implementations and what is considered to be correct • Theoretical background also key to understand how system have evolved over the years Transactions-CC&R 2 Reference Concurrency Control and Recovery in Database Systems Philip A. Bernstein, Vassos Hadzilacos, Nathan Goodman • https://www.microsoft.com/en- us/research/people/philbe/book/ Transactions-CC&R 3 ACID Transactions-CC&R 4 Conventional notion of database correctness • ACID: • Atomicity: the notion that an operation or a group of operations must take place in their entirety or not at all • Consistency: operations should take the database from a correct state to another correct state • Isolation: concurrent execution of operations should yield results that are predictable and correct • Durability: the database needs to remember the state it is in at all moments, even when failures occur • Like all acronyms, more effort in making it sound cute than in
    [Show full text]
  • March 2017 Report
    BCS THE CHARTERED INSTITUTE FOR IT BCS HIGHER EDUCATION QUALIFICATIONS BCS Level 6 Professional Graduate Diploma in IT ADVANCED DATABASE MANAGEMENT SYSTEMS March 2017 Answer any THREE questions out of FIVE. All questions carry equal marks. Time: THREE hours Answer any Section A questions you attempt in Answer Book A Answer any Section B questions you attempt in Answer Book B The marks given in brackets are indicative of the weight given to each part of the question. Calculators are NOT allowed in this examination. Section A Answer Section A questions in Answer Book A A1 Examiner's General Comments This was a fairly popular question, attempted by around half of the candidates, with two-thirds of the attempts achieving pass level marks. Therefore, the performance was generally quite good with a wide range of marks, some candidates producing near correct solutions. The definition of a true distributed database system is that it consists of a collection of geographically remote sites of physical databases, connected together via some kind of communication network, in which a user at any site can access data anywhere in the network exactly as if the data were all stored in one single database at the user’s own site. a) Explain the problems associated with achieving a true distributed database in practice. 12 marks ANSWER POINTER Fragmentation of tables requires maintenance of unique keys across horizontal fragments and consistency of primary keys that are reflected in vertical fragments. Also increased network traffic occurs as many fragments may need to be consulted to perform one query.
    [Show full text]
  • IBM DB2 11 for Z/OS Technical Overview
    IBM® Information Management Software Front cover IBM DB2 11 for z/OS Technical Overview Understand the synergy with System z platform Enhance applications and avoid incompatibilities Run business analytics and scoring adapter Paolo Bruni Felipe Bortoletto Ravikumar Kalyanasundaram Sabine Kaschta Glenn McGeoch Cristian Molaro ibm.com/redbooks International Technical Support Organization IBM DB2 11 for z/OS Technical Overview December 2013 SG24-8180-00 Note: Before using this information and the product it supports, read the information in “Notices” on page xxi. First Edition (December 2013) This edition applies to Version 11, Release 1 of DB2 for z/OS (program number 5615-DB2) and Version 11, Release 1 of DB2 Utilities Suite for z/OS (program number 5655-W87). Note: This book is based on a pre-GA version of a product and may not apply when the product becomes generally available. We recommend that you consult the product documentation or follow-on versions of this book for more current information. © Copyright International Business Machines Corporation 2013. All rights reserved. Note to U.S. Government Users Restricted Rights -- Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Figures . xi Tables . xiii Examples . .xv Notices . xxi Trademarks . xxii Summary of changes. xxiii December 2013, First Edition. xxiii May 2014, First Update. xxiii Preface . .xxv Authors. xxv Now you can become a published author, too! . xxvii Comments welcome. .xxviii Stay connected to IBM Redbooks publications . .xxviii Chapter 1. DB2 11 for z/OS at a glance . 1 1.1 Subsystem . 2 1.2 Application functions . 2 1.3 Operations and performance .
    [Show full text]
  • Models of Transactions Structuring Applications Flat Transaction Flat
    Structuring Applications • Many applications involve long transactions Models of Transactions that make many database accesses • To deal with such complex applications many transaction processing systems Chapter 19 provide mechanisms for imposing some structure on transactions 2 Flat Transaction Flat Transaction • Consists of: begin transaction – Computation on local variables • Abort causes the begin transaction • not seen by DBMS; hence will be ignored in most future discussion execution of a program ¡£ ¤¦©¨ – Access to DBMS using call or ¢¡£ ¥¤§¦©¨ that restores the statement level interface variables updated by the ¡£ ¤¦©¨ • This is transaction schedule; commit ….. applies to these operations ¢¡£ ¤§¦©¨ ….. transaction to the state • No internal structure they had when the if condition then abort • Accesses a single DBMS transaction first accessed commit commit • Adequate for simple applications them. 3 4 Some Limitations of Flat Transactions • Only total rollback (abort) is possible – Partial rollback not possible Providing Structure Within a • All work lost in case of crash Single Transaction • Limited to accessing a single DBMS • Entire transaction takes place at a single point in time 5 6 1 Savepoints begin transaction S1; Savepoints Call to DBMS sp1 := create_savepoint(); S2; sp2 := create_savepoint(); • Problem: Transaction detects condition that S3; requires rollback of recent database changes if (condition) {rollback (sp1); S5}; S4; that it has made commit • Solution 1: Transaction reverses changes • Rollback to spi causes
    [Show full text]
  • SQL Procedures, Triggers, and Functions on IBM DB2 for I
    Front cover SQL Procedures, Triggers, and Functions on IBM DB2 for i Jim Bainbridge Hernando Bedoya Rob Bestgen Mike Cain Dan Cruikshank Jim Denton Doug Mack Tom Mckinley Simona Pacchiarini Redbooks International Technical Support Organization SQL Procedures, Triggers, and Functions on IBM DB2 for i April 2016 SG24-8326-00 Note: Before using this information and the product it supports, read the information in “Notices” on page ix. First Edition (April 2016) This edition applies to Version 7, Release 2, of IBM i (product number 5770-SS1). © Copyright International Business Machines Corporation 2016. All rights reserved. Note to U.S. Government Users Restricted Rights -- Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Notices . ix Trademarks . .x IBM Redbooks promotions . xi Preface . xiii Authors. xiii Now you can become a published author, too! . xvi Comments welcome. xvi Stay connected to IBM Redbooks . xvi Chapter 1. Introduction to data-centric programming. 1 1.1 Data-centric programming. 2 1.2 Database engineering . 2 Chapter 2. Introduction to SQL Persistent Stored Module . 5 2.1 Introduction . 6 2.2 System requirements and planning. 6 2.3 Structure of an SQL PSM program . 7 2.4 SQL control statements. 8 2.4.1 Assignment statement . 8 2.4.2 Conditional control . 11 2.4.3 Iterative control . 15 2.4.4 Calling procedures . 18 2.4.5 Compound SQL statement . 19 2.5 Dynamic SQL in PSM . 22 2.5.1 DECLARE CURSOR, PREPARE, and OPEN . 23 2.5.2 PREPARE then EXECUTE. 26 2.5.3 EXECUTE IMMEDIATE statement .
    [Show full text]
  • PL/SQL Transactions
    PPLL//SSQQLL -- TTRRAANNSSAACCTTIIOONNSS http://www.tutorialspoint.com/plsql/plsql_transactions.htm Copyright © tutorialspoint.com A database transaction is an atomic unit of work that may consist of one or more related SQL statements. It is called atomic because the database modifications brought about by the SQL statements that constitute a transaction can collectively be either committed, i.e., made permanent to the database or rolled back undone from the database. A successfully executed SQL statement and a committed transaction are not same. Even if an SQL statement is executed successfully, unless the transaction containing the statement is committed, it can be rolled back and all changes made by the statements can be undone. Starting an Ending a Transaction A transaction has a beginning and an end. A transaction starts when one of the following events take place: The first SQL statement is performed after connecting to the database. At each new SQL statement issued after a transaction is completed. A transaction ends when one of the following events take place: A COMMIT or a ROLLBACK statement is issued. A DDL statement, like CREATE TABLE statement, is issued; because in that case a COMMIT is automatically performed. A DCL statement, such as a GRANT statement, is issued; because in that case a COMMIT is automatically performed. User disconnects from the database. User exits from SQL*PLUS by issuing the EXIT command, a COMMIT is automatically performed. SQL*Plus terminates abnormally, a ROLLBACK is automatically performed. A DML statement fails; in that case a ROLLBACK is automatically performed for undoing that DML statement.
    [Show full text]
  • Mysql Transactionstransactions
    MySQLMySQL TransactionsTransactions SangSang ShinShin www.JPassion.comwww.JPassion.com ““LearnLearn withwith JPassion!”JPassion!” 1 Topics • What is a transaction? • ACID properties • Transaction support in MySQL • Savepoints • Transaction isolation levels • Table locks 2 WhatWhat isis aa Transaction?Transaction? What is a Transaction? • A transaction is a sequential group of database manipulation operations, which is performed as if it were one single work unit. • Example: Transfer $100 from Savings account to Checking account is made of two update operations - these two operations need to be performed as a single unit > Update Savings table > Update Checking table 4 ACIDACID PropertiesProperties ACID Properties • Atomicity • Consistency • Isolation • Durability 6 ACID Properties • Atomicity > Ensures that all operations within the work unit are completed successfully; otherwise, the transaction is aborted at the point of failure, and previous operations are rolled back to their former state • Consistency > Ensures that the database properly changes states upon a successfully committed transactions 7 ACID Properties • Isolation > Ensures transactions to operate independently of and transparent to each other • Durability > Ensures that the result or effect of a committed transaction persists in case of a system failure 8 TransactionTransaction SupportSupport inin MySQLMySQL MySQL Support of Transactions • Only InnoDB storage engine supports transactions > Other storage engines ignore transaction statements • Starting a transaction > START
    [Show full text]