search
HomeDatabaseMysql TutorialOracle使用hash分区优化分析函数查询

在Oracle中的分析函数都是基于某几个字段划分计算窗口,然后在窗口内进行聚合,排名,等等计算。我想如果我们数据表的hash分区字

在Oracle中的分析函数都是基于某几个字段划分计算窗口,然后在窗口内进行聚合,排名,等等计算。我想如果我们数据表的hash分区字段与分析函数中的partition by 字段一致的时候,应该可以大大加快分析函数的运行效率。因为每个分区上的数据可以单独进行运算。互不干涉,下面试验来验证我的想法.

第一步:创建一个分区表和普通表,表结构与DBA_OBJECTS一致:

create table t_partition_hash(

object_name varchar2(128),

subobject_name varchar2(30),

object_id number,

data_object_id number,

object_type varchar2(19),

created date,

last_ddl_time date,

timestamp varchar2(19),

status varchar2(7),

temporary varchar2(1),

generated varchar2(1),

secondary varchar2(1)

)

partition by hash(object_type)(

partition t_hash_p1 tablespace USERS,

partition t_hash_p2 tablespace USERS,

partition t_hash_p3 tablespace USERS,

partition t_hash_p4 tablespace USERS,

partition t_hash_p5 tablespace USERS,

partition t_hash_p6 tablespace USERS,

partition t_hash_p7 tablespace USERS,

partition t_hash_p8 tablespace USERS

);

create table t_big_hash(

object_name varchar2(128),

subobject_name varchar2(30),

object_id number,

data_object_id number,

object_type varchar2(19),

created date,

last_ddl_time date,

timestamp varchar2(19),

status varchar2(7),

temporary varchar2(1),

generated varchar2(1),

secondary varchar2(1)

);

第二步:准备数据,从dba_object中把数据插入到两个表。总共插入数据1610880。

insert into t_partition_hash select * from dba_objects;

insert into t_partition_hash select * from dba_objects;

第三步:本采用RANK函数对两个表进行查询。

begin

insert into  t_rank

select object_id,

rank() over (partition by object_type order by object_id)  r_object_id,

rank() over (partition by object_type order by subobject_name) r_subobject_name ,

rank() over (partition by object_type order by created) r_created,

rank() over (partition by object_type order by last_ddl_time) r_last_ddl_time ,

rank() over (partition by object_type order by status) r_object_type

from t_partition_hash;

end;

使用hash分区表总共执行5次的运行时间分别为:46.156s,33.39s,40.516s 34.875s 38.938s.

begin

insert into  t_rank

select object_id,

rank() over (partition by object_type order by object_id)  r_object_id,

rank() over (partition by object_type order by subobject_name) r_subobject_name ,

rank() over (partition by object_type order by created) r_created,

rank() over (partition by object_type order by last_ddl_time) r_last_ddl_time ,

rank() over (partition by object_type order by status) r_object_type

from t_big_table;

end;

使用非分区表执行5次的执行时间分别为:141.954s,89.656s,77.906s,,98.5s,75.906s.

由此可见采用有效的HASH分区表可以有效提升分析函数在oracle中的执行效率。我相信随着数据量的增加,将会有更明显的效果,回头再测试一个项目中遇到的类似问题。

linux

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
MySQL String Types: Storage, Performance, and Best PracticesMySQL String Types: Storage, Performance, and Best PracticesMay 10, 2025 am 12:02 AM

MySQLstringtypesimpactstorageandperformanceasfollows:1)CHARisfixed-length,alwaysusingthesamestoragespace,whichcanbefasterbutlessspace-efficient.2)VARCHARisvariable-length,morespace-efficientbutpotentiallyslower.3)TEXTisforlargetext,storedoutsiderows,

Understanding MySQL String Types: VARCHAR, TEXT, CHAR, and MoreUnderstanding MySQL String Types: VARCHAR, TEXT, CHAR, and MoreMay 10, 2025 am 12:02 AM

MySQLstringtypesincludeVARCHAR,TEXT,CHAR,ENUM,andSET.1)VARCHARisversatileforvariable-lengthstringsuptoaspecifiedlimit.2)TEXTisidealforlargetextstoragewithoutadefinedlength.3)CHARisfixed-length,suitableforconsistentdatalikecodes.4)ENUMenforcesdatainte

What are the String Data Types in MySQL?What are the String Data Types in MySQL?May 10, 2025 am 12:01 AM

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,2)VARCHARforvariable-lengthtext,3)BINARYandVARBINARYforbinarydata,4)BLOBandTEXTforlargedata,and5)ENUMandSETforcontrolledinput.Eachtypehasspecificusesandperformancecharacteristics,sochoose

How to Grant Permissions to New MySQL UsersHow to Grant Permissions to New MySQL UsersMay 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

How to Add Users in MySQL: A Step-by-Step GuideHow to Add Users in MySQL: A Step-by-Step GuideMay 09, 2025 am 12:14 AM

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

MySQL: Adding a new user with complex permissionsMySQL: Adding a new user with complex permissionsMay 09, 2025 am 12:09 AM

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

MySQL: String Data Types and CollationsMySQL: String Data Types and CollationsMay 09, 2025 am 12:08 AM

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

MySQL: What length should I use for VARCHARs?MySQL: What length should I use for VARCHARs?May 09, 2025 am 12:06 AM

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

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

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

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

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor