search
HomeDatabaseMysql TutorialOracle 性能优化

Oracle 性能优化

Jun 07, 2016 pm 03:38 PM
oracleselectoptimizationuseperformancestatementavoid

1、在select语句中避免使用 “*” 2、尽可能减小记录集行数 限制记录集获取到的记录行数同样可以缩短语句执行时间,提高查询效率。 SELECT USER_NAME, ADDRESS, LOGIN_ADTE FROM LOG_EVENT WHERE ROWNUM = 100 ORDER BY LOGON_DATE DESC; 3、使用ROWID 高效

1、在select语句中避免使用 “*”

2、尽可能减小记录集行数

         限制记录集获取到的记录行数同样可以缩短语句执行时间,提高查询效率。

         SELECT USER_NAME, ADDRESS, LOGIN_ADTE

FROM LOG_EVENT

WHERE ROWNUM

3、使用ROWID 高效删除重复数据

         在重复的记录中,可能所有列的内容都相同,但是ROWID 不会重复。

         DELETE FROM STU S

WHERE S.ROWID > (SELECT MIN(T.ROWID)

FROM STU T

WHERE T.SNO = S.SNO);

4、使用TRUNCATE 替代DELETE删除记录

5、高效统计记录行数(实际应用中并没有使用价值)

         使用USER_TABLES 视图查询记录行数

         SELECT TABLE_NAME, NUM_ROWS

         FROM USER_TABLES

         WHERE TABLE_NAME = ‘STU’

         补充:USER_TABLES 视图中保存了Oracle的所有用户表基本信息,包括表空间、状态、缓存等。

6、尽量多使用COMMIT

         执行COMMIT 语句后能释放的资源主要包括:

l  回滚段上用于回复数据的信息

l  被程序语句获取的锁

l  REDO LOG BUFFER 中的空间

l  Oracle 为管理上述3 种资源的内部花销

7、避免使用HAVING 语句

         HAVING 语句只会在检索出所有记录之后才对结果集进行过滤。若能通过WHERE 子句限制查询的数目,可以减少这方面的开销。

8、用EXISTS 替代IN 谓词

         带有EXISTS 谓词的子查询不返回任何实际数据,只产生逻辑真值TRUE 或逻辑假值FALSE。

9、使用 “>=” 代替 “>” 运算符

10、避免在SELECT 子句中使用DISTINCT 关键字

         补充:消除重复记录可以通过子查询、GROUPBY 等其他方式实现,对于大数据来说,尽量避免使用DISTINCT。

11、用索引提高查询效率

12、避免在索引列上进行运算

         在索引列上进行运算,将导致索引失效。

13、在索引列上使用UNION替代OR

         在SELECT 语句中对索引列进行OR操作,此时索引将不会被引用。对索引列使用OR 运算符将造成全表扫描。

         补充:使用UNION 代替OR 操作规则只针对多个索引列有效,如果有的列没有索引,检索效率可能反而会因为没有选择OR 而降低。

14、避免在索引列上使用ISNULL 或 IS NOT NULL 条件

         对于Oracle 索引来说,如果一个索引列的某个值为空,该值将不存在于索引列中。

15、使用WHERE 子句优化GROUP BY (内容同7)

         使用WHERE 子句实现部分HAVING 子句的功能。

16、处理预定义异常

 

17、处理自定义异常

 

本内容摘自《Oracle 数据库编程经典300例》

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
What Are the Limitations of Using Views in MySQL?What Are the Limitations of Using Views in MySQL?May 14, 2025 am 12:10 AM

MySQLviewshavelimitations:1)Theydon'tsupportallSQLoperations,restrictingdatamanipulationthroughviewswithjoinsorsubqueries.2)Theycanimpactperformance,especiallywithcomplexqueriesorlargedatasets.3)Viewsdon'tstoredata,potentiallyleadingtooutdatedinforma

Securing Your MySQL Database: Adding Users and Granting PrivilegesSecuring Your MySQL Database: Adding Users and Granting PrivilegesMay 14, 2025 am 12:09 AM

ProperusermanagementinMySQLiscrucialforenhancingsecurityandensuringefficientdatabaseoperation.1)UseCREATEUSERtoaddusers,specifyingconnectionsourcewith@'localhost'or@'%'.2)GrantspecificprivilegeswithGRANT,usingleastprivilegeprincipletominimizerisks.3)

What Factors Influence the Number of Triggers I Can Use in MySQL?What Factors Influence the Number of Triggers I Can Use in MySQL?May 14, 2025 am 12:08 AM

MySQLdoesn'timposeahardlimitontriggers,butpracticalfactorsdeterminetheireffectiveuse:1)Serverconfigurationimpactstriggermanagement;2)Complextriggersincreasesystemload;3)Largertablesslowtriggerperformance;4)Highconcurrencycancausetriggercontention;5)M

MySQL: Is it safe to store BLOB?MySQL: Is it safe to store BLOB?May 14, 2025 am 12:07 AM

Yes,it'ssafetostoreBLOBdatainMySQL,butconsiderthesefactors:1)StorageSpace:BLOBscanconsumesignificantspace,potentiallyincreasingcostsandslowingperformance.2)Performance:LargerrowsizesduetoBLOBsmayslowdownqueries.3)BackupandRecovery:Theseprocessescanbe

MySQL: Adding a user through a PHP web interfaceMySQL: Adding a user through a PHP web interfaceMay 14, 2025 am 12:04 AM

Adding MySQL users through the PHP web interface can use MySQLi extensions. The steps are as follows: 1. Connect to the MySQL database and use the MySQLi extension. 2. Create a user, use the CREATEUSER statement, and use the PASSWORD() function to encrypt the password. 3. Prevent SQL injection and use the mysqli_real_escape_string() function to process user input. 4. Assign permissions to new users and use the GRANT statement.

MySQL: BLOB and other no-sql storage, what are the differences?MySQL: BLOB and other no-sql storage, what are the differences?May 13, 2025 am 12:14 AM

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

MySQL Add User: Syntax, Options, and Security Best PracticesMySQL Add User: Syntax, Options, and Security Best PracticesMay 13, 2025 am 12:12 AM

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

MySQL: How to avoid String Data Types common mistakes?MySQL: How to avoid String Data Types common mistakes?May 13, 2025 am 12:09 AM

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

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 Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

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.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor