search
HomeDatabaseMysql TutorialDB2面向OLTP环境的物理数据库设计:查询设计

在最基本的层面,包括选择、插入、更新和删除在内的 SQL 操作是应用程序与 DB2 数据库进行交互的方式。应用程序的总体性能和体验受到该应用程序所用的 SQL 操作的影响。 设计、维护、监视和调优 SQL 查询的完整处理超出了本文的范围。然而,我们从较高层次概

在最基本的层面,包括选择、插入、更新和删除在内的 SQL 操作是应用程序与 DB2 进行交互的方式。应用程序的总体性能和体验受到该应用程序所用的 SQL 操作的影响。 设计、维护、监视和调优 SQL 查询的完整处理超出了本文的范围。然而,我们从较高层次概述了查询设计的工具和一般准则,因为查询设计和物理设计彼此密切相关。

大多数物理数据库设计的特征对 SQL 语句并不明显,但为了更好地使用 DB2 特性,在编写查询时需要考虑到数据库的物理特征,如索引。例如,使用范围分区表时,选择查询即使没有包含谓词和范围分区键,也仍然可以正常工作。然而,它可能没有分区消除的性能优势。 另一方面,如果由于数据增长或其他任何原因,导致某个 SQL 操作无法满足业务服务水平协议,那么可能必须修改物理数据库设计。物理数据库设计变更的示例包括:增加索引、将常规表转换为范围分区表,或更改缓冲池的大小或关联,以达到预期的性能目标。

OLTP 工作负载查询

OLTP 工作负载中的查询通常较短,涉及极少的表,并返回较小的结果集。不过,相比其他类型的工作负载,在 OLTP 工作负载中有更多并发查询。 对于 OLTP 工作负载,设计可以快速返回结果的查询对于获得良好的性能是至关重要的。 此外,考虑到 OLTP 工作负载系统中一般有大量并发运行的查询。死锁、因超时等待锁定而回滚,甚至“死机”之类的事务可能会经常发生。导致较少的死锁和回滚的查询设计可以使查询性能有明显差异。

OLTP 应用程序对于使用范围分隔谓词的索引扫描是很好的候选者,因为它们往往只返回几个行,具有能够对一个键列使用平等谓词的资格。如果您的 OLTP 单查询使用表扫描,您可能想对解释设施 (explain facility) 数据进行分析,以确定不使用索引扫描的原因。

隔离级别

DB2 数据库管理器支持以下四种类型的隔离级别。它们按对性能的影响以降序排列,但在访问和更新数据时,它们需要的维护则是以升序排列的。

可重复读 (RR)

RR 隔离级别将锁定应用程序在某个工作单元内引用的所有行。使用此隔离级别,丢失更新、访问未提交的数据和幻像行 (phantom row) 是不可能的。

读稳定性 (RS)

RS 隔离级别只锁定应用程序在工作单元内检索的那些行。

游标稳定性 (CS)

CS 隔离级别锁定应用程序的事务所访问的任何行,同时将游标定位到该行上。 未提交的读 (UR) UR 隔离级别允许应用程序访问其他事务未提交的变更。未提交读对只读和可更新游标的工作方式不同。

应用程序死锁

死锁影响数据库系统的性能。当死锁发生时,数据库管理器会选出要停止或回滚哪些事务(受害者)。这种影响会导致用户获得不好的体验。如果数据库配置参数设置不正确,那么用户可能会遇到停留在死锁状态的情况,最终可能需要数据库管理员来解决死锁。

当您发出包含 WITH RELEASE 子句的 CLOSE CURSOR 语句来关闭游标时,数据库管理器会尝试释放游标持有的所有读锁。表读锁是 IS、S 和 U 表锁。行读锁是 S、NS 和 U 行锁。块读锁是 IS、S 和 U 块锁。 WITH RELEASE 子句对在 CS 或 UR 隔离级别下操作的游标没有影响。对于在 RS 或 RR 隔离级别下操作的游标,WITH RELEASE 子句取消了这些隔离级别的部分保证。具体来说,一个 RS 游标可能会遇到不可重复读现象,一个 RR 游标可能会遇到一个不可重复读或幻读。

如果在关闭原本在 RR 或 RS 隔离级别下操作的游标后,您通过 WITH RELEASE 子句重新打开它,那么您会获得新的读锁。 在某些情况下,在结果集关闭后会仍然保持锁定,并且提交事务。如果在发出 COMMIT 语句之前关闭 CURSOR WITH HOLD,可以确保锁定被释放。即使在使用动态 SQL 的未提交读应用程序中,也会获得目录锁。要释放目录锁,请显式发出 COMMIT 语句。

LOCK TABLE 语句锁定整个表。只锁定在 LOCK TABLE 语句中指定的表,没有锁定指定表的父表和依赖表。直到提交或回滚工作单元,才会释放锁定。您可以使用该语句防止锁升级。您必须确定是否锁定整个表及相关表是必要的,然后才能在并发性和性能方面实现想要的结果。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain the InnoDB Buffer Pool and its importance for performance.Explain the InnoDB Buffer Pool and its importance for performance.Apr 19, 2025 am 12:24 AM

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL vs. Other Programming Languages: A ComparisonMySQL vs. Other Programming Languages: A ComparisonApr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Learning MySQL: A Step-by-Step Guide for New UsersLearning MySQL: A Step-by-Step Guide for New UsersApr 19, 2025 am 12:19 AM

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL: Essential Skills for Beginners to MasterMySQL: Essential Skills for Beginners to MasterApr 18, 2025 am 12:24 AM

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL: Structured Data and Relational DatabasesMySQL: Structured Data and Relational DatabasesApr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL: Key Features and Capabilities ExplainedMySQL: Key Features and Capabilities ExplainedApr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

The Purpose of SQL: Interacting with MySQL DatabasesThe Purpose of SQL: Interacting with MySQL DatabasesApr 18, 2025 am 12:12 AM

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

MySQL for Beginners: Getting Started with Database ManagementMySQL for Beginners: Getting Started with Database ManagementApr 18, 2025 am 12:10 AM

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor