Home Database Mysql Tutorial Oracle调优专家秘籍

Oracle调优专家秘籍

Jun 07, 2016 pm 05:07 PM
oracle database

第二:SQL的优化永远只针对大表之间的连接才用得上。不要怀疑,首先,我说的大表是指包含大表,不管是大表与大表,还是大表与小表

注:本文不是给你一个案例,而是讲调优的方法,古人云:授人鱼不如授人渔,这里要讲的,就是教你怎么捕鱼。

这里要说的sql调优很有意思,得先从感恩节说起。

感恩节(英语:Thanksgiving Day)是美国和加拿大共有的节日,由美国人民独创,原意是为了感谢上天赐予的好收成。11月的第四个星期四是感恩节。感恩节是美国人民独创的一个古老节日,也是美国人合家欢聚的节日,因此美国人提起感恩节总是备感亲切。感恩节是美国国定假日中最地道、最美国式的节日。

感恩节之后的第一天,是星期五,在这一天,美国人有疯狂购物的习惯,所以被称之为黑色星期五,近来己经由传统的商场购物改为网上购物,所以我的愕运便由此而生,我的DB便在这一天被疯狂购物给访问爆了。

客户提供了一份高峰时段的AWR报告,仔细分析后,发现竟然是一条高耗CPU的SQL给整跨了,仅仅一条,占了85%的CPU,这才深入去了解了SQL的优化,以前也做过DB的一些优化,基本上通过分析表、建索引、调参数、打PATCH等等都能解决,但这次,持续了一周,学了几天,还没解决。最终决定潜心研究SQL的优化,得出以下几点关于优化的结论:

第 一:1/9原则,引用Oracle大牛Tom大师的原话:数据库中90%的性能问题都可以由调整10%的SQL语句来解决。

Tom say: Sql tuning constitute a good 90 percent or more of the effort. Thats right; before we even get the DBAs involved, we the developers have done 90 percent of  the work. This is why I think most people do not understand database tuning.

第二:SQL的优化永远只针对大表之间的连接才用得上。不要怀疑,,首先,我说的大表是指包含大表,不管是大表与大表,还是大表与小表,只要是有大表就行,因为小表与小表之间不会出现性能问题;其次:有连接才有优化的价值,我真的不知道单表的SQL有什么优化可言,对单表查询无非是三点:全表/索引/分区表,这三点,你肯定会。

第 三:说第三条之间,先说明:正如前面两条所言,数据库90%的优化在SQL,SQL的优化关键在“大表连接”,所以下面说的SQL优化都是指大表连接。

SQL的执行中,Oracle提供的执行计划,不是什么神秘的东西,其实就是oracle去表中查找我们所需结果的一个算法,算法这东西太熟了,在大学《数据结构》这门课中就学过(惭愧,这堂课从来都是去睡觉,因为当时根本不知道那位老朽在说什么),算法就是运算过程,在这里,就是指查找路径,说白了:执行计划=算法=查找路径,要找最优的执行计划,就是要找出最优算法,最优算法熟吧? 不熟我跟你说几个名词:"冒泡算法",“折中算法”,“快速查找”,去过软件公司面试的人很多人肯定都做过这种题。而Oracle提供的执行计划中,恰恰就提供这些详细的过程在里面。你能看到Oracle先去哪个表/索引拿数据、根据什么条件拿多少行,再把拿到的结果去连接哪个表、等等,经过一系列的运算,最后得出什么结果给你。

但是,ORACLE也是一款软件,不是神,你给它一条SQL,它在开始运算之前,是不知道哪种算法是最优的,不可能每个都试一遍,再做比较吧,而且每条语句的执行计划上百种,每条语句都执行上百次,那服务器干脆别活了。所以,它只能预估一种针对这条SQL认为最优的算法,然后去执行。请注意:

1.永远没有最优算法,如果有最优算法a,那优化还需要做吗?每次都按最优算法a做行了。

2. Oracle认为最优的算法也不一定是最优算法,如果是的话,我们还需要做吗?

说到这里:我们就明白了,ORACLE调优的90%=SQL调优=大表连接调优=执行计划调优=算法调优,而大表连接就2点:1.连接顺序。2.连接算法(嵌套/哈希/合并)。

结论:SQL的调优就是手动设计出最优连接顺序和算法的执行计划。

linux

Statement of this Website
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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to check which table space a table belongs to in Oracle How to check which table space a table belongs to in Oracle Jul 06, 2023 pm 01:31 PM

How to check which table space a table belongs to in Oracle: 1. Use the "SELECT" statement and specify the table name to find the table space to which the specified table belongs; 2. Use the database management tools provided by Oracle to check the table space to which the table belongs. Tools usually provide a graphical interface, making the operation more intuitive and convenient; 3. In SQL*Plus, you can view the table space to which the table belongs by entering the "DESCRIBEyour_table_name;" command.

How to connect to Oracle database using PDO How to connect to Oracle database using PDO Jul 28, 2023 pm 12:48 PM

Overview of how to use PDO to connect to Oracle database: PDO (PHPDataObjects) is an extension library for operating databases in PHP. It provides a unified API to access multiple types of databases. In this article, we will discuss how to use PDO to connect to an Oracle database and perform some common database operations. Step: Install the Oracle database driver extension. Before using PDO to connect to the Oracle database, we need to install the corresponding Oracle

How to retrieve only one piece of duplicate data in oracle How to retrieve only one piece of duplicate data in oracle Jul 06, 2023 am 11:45 AM

Steps for Oracle to fetch only one piece of duplicate data: 1. Use the SELECT statement combined with the GROUP BY and HAVING clauses to find duplicate data; 2. Use ROWID to delete duplicate data to ensure that accurate duplicate data records are deleted, or use "ROW_NUMBER" ()" function to delete duplicate data, which will delete all records except the first record in each set of duplicate data; 3. Use the "select count(*) from" statement to return the number of deleted records to ensure the result.

Implement data import into PHP and Oracle databases Implement data import into PHP and Oracle databases Jul 12, 2023 pm 06:46 PM

Implementing data import into PHP and Oracle databases In web development, using PHP as a server-side scripting language can conveniently operate the database. As a common relational database management system, Oracle database has powerful data storage and processing capabilities. This article will introduce how to use PHP to import data into an Oracle database and give corresponding code examples. First, we need to ensure that PHP and Oracle database have been installed, and that PHP has been configured to

Does oracle database require jdk? Does oracle database require jdk? Jun 05, 2023 pm 05:06 PM

The oracle database requires jdk. The reasons are: 1. When using specific software or functions, other software or libraries included in the JDK are required; 2. Java JDK needs to be installed to run Java programs in the Oracle database; 3. JDK provides Develop and compile Java application functions; 4. Meet Oracle's requirements for Java functions to help implement and implement specific functions.

How to use PHP and Oracle database connection pools efficiently How to use PHP and Oracle database connection pools efficiently Jul 12, 2023 am 10:07 AM

How to efficiently use connection pooling in PHP and Oracle databases Introduction: When developing PHP applications, using a database is an essential part. When interacting with Oracle databases, the use of connection pools is crucial to improving application performance and efficiency. This article will introduce how to use Oracle database connection pool efficiently in PHP and provide corresponding code examples. 1. The concept and advantages of connection pooling Connection pooling is a technology for managing database connections. It creates a batch of connections in advance and maintains a

How to use php to extend PDO to connect to Oracle database How to use php to extend PDO to connect to Oracle database Jul 29, 2023 pm 07:21 PM

How to use PHP to extend PDO to connect to Oracle database Introduction: PHP is a very popular server-side programming language, and Oracle is a commonly used relational database management system. This article will introduce how to use PHP extension PDO (PHPDataObjects) to connect to Oracle database. 1. Install the PDO_OCI extension. To connect to the Oracle database, you first need to install the PDO_OCI extension. Here are the steps to install the PDO_OCI extension: Make sure

How oracle determines whether a table exists in a stored procedure How oracle determines whether a table exists in a stored procedure Jul 06, 2023 pm 01:20 PM

Oracle's steps to determine whether a table exists in a stored procedure: 1. Use the "user_tables`" system table to query the table information under the current user, compare the incoming table name "p_table_name" with the "table_name" field, and if the conditions are met, then "COUNT(*)" will return a value greater than 0; 2. Use the "SET SERVEROUTPUT ON;" statement and the "EXEC`" keyword to execute the stored procedure and pass in the table name to determine whether the table exists.

See all articles