全表扫描的成本计算公式 如下: Cost = ( #SRds * sreadtim + #MRds * mreadtim + CPUCycles / cpuspeed ) / sreadtim 全表扫描的时候,单块读次数=0,#SRds表示单块读次数。全表扫描的成本里面,CPU消耗其实非常少,可以忽略不计,所以全表扫描的公式可以改
全表扫描的成本计算公式 如下:
Cost = ( #SRds * sreadtim + #MRds * mreadtim + CPUCycles / cpuspeed ) / sreadtim
全表扫描的时候,单块读次数=0,#SRds表示单块读次数。全表扫描的成本里面,CPU消耗其实非常少,可以忽略不计,所以全表扫描的公式可以改写为:
Cost = #MRds * mreadtim / sreadtim
#MRds 表示多块读io次数
mreadtim 表示一次多块读耗费时间
sreadtim 表示一次单块读耗费时间
全表扫描的COST意思其实就是 多块读io次数 * 多块读时间 / 单块读时间
那么为什么 全表扫描成本公式里面要除以 sreadtim呢? 我们来看一下 索引扫描的成本计算公式:
cost = blevel + celiling(leaf_blocks *effective index selectivity) + celiling(clustering_factor * effective table selectivity)
blevel 是 扫描索引 的 root到branch ---单块读
celiling(leaf_blocks *effective index selectivity) 是扫描的 也在块的个数 ---单块读
ceiling(clustering_factor*effective table selectivity) 是 通过索引的rowid回表的次数 ---单块读
那么 索引扫描的成本公式的本质含义 其实就是 单块读的 io次数
对于单表访问(什么是单表访问? 就是只select一个表),要么走全表扫描,要么走索引扫描,当然了还可以走物化视图(这个不考虑)
ORACLE 究竟是走全表扫描还是走索引扫描呢? 它是计算全表扫描的COST,计算索引扫描的COST 哪个COST消耗少就走哪个。
问题来了,为啥ORACLE计算COST能准确的判断走哪个是最优的呢? 现在我们来比较一下 全表扫描的 COST 与 索引扫描的COST
全表扫描COST 多块读io次数 * 多块读时间 / 单块读时间
索引扫描COST 单块读io次数
那么现在 我们都对 全表扫描 COST , 都对 索引扫描 COST 乘以一个 单块读时间
全表扫描COST* 单块读时间 = 多块读io次数*多块读时间 = 总的耗费时间
索引扫描COST* 单块读时间 = 单块读io次数*单块读时间 = 总的耗费时间
说白了,就是比较全表扫描与索引扫描谁 总的耗费的时间最少,就选谁。
到这里你应该看懂了吧。 不得不佩服ORACLE 设计 人员的头脑,真是牛逼。

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.

MySQL is an efficient relational database management system suitable for storing and managing data. Its advantages include high-performance queries, flexible transaction processing and rich data types. In practical applications, MySQL is often used in e-commerce platforms, social networks and content management systems, but attention should be paid to performance optimization, data security and scalability.

The relationship between SQL and MySQL is the relationship between standard languages and specific implementations. 1.SQL is a standard language used to manage and operate relational databases, allowing data addition, deletion, modification and query. 2.MySQL is a specific database management system that uses SQL as its operating language and provides efficient data storage and management.

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft