search
HomeDatabaseMysql TutorialOracle收集直方图信息

直方图在列数据分布不均匀时非常有用,查询优化器需要直方图信息才能做出正确的估算。有频度直方图与等高直方图两种。本篇依然使

直方图在列数据分布不均匀时非常有用,查询优化器需要直方图信息才能做出正确的估算。有频度直方图与等高直方图两种。本篇依然使用上一篇的测试表,文章链接Oracle中收集表与列统计信息

一、频度直方图

频度直方图使用的不是频度,,而是使用累积频度。下面的endpoint_number是取值的累计次数。

SELECT ENDPOINT_VALUE,
      ENDPOINT_NUMBER,
      ENDPOINT_NUMBER - LAG(ENDPOINT_NUMBER, 1, 0) OVER(ORDER BY ENDPOINT_NUMBER) AS FREQUENCY
  FROM USER_TAB_HISTOGRAMS
 WHERE TABLE_NAME = 'T'
  AND COLUMN_NAME = 'VAL2'
 ORDER BY ENDPOINT_NUMBER;

ENDPOINT_VALUE

ENDPOINT_NUMBER

FREQUENCY

101

8

8

102

33

25

103

101

68

104

286

185

105

788

502

106

1000

212

频度直方图的本质特征有:

①桶数(分类数)等于唯一值总数。

②列endpoint_value提供该本身。

③列endpoint_number是取值的累计出现次数。只有当前endpoint_number减去上一endpoint_number才是当前值的出现次数。

下面演示查询优化器怎样使用频度直方图精确地估算出基于列val2过滤后查询返回的基数(cardinality)。

EXPLAIN PLAN SET STATEMENT_ID '101' FOR SELECT * FROM t WHERE val2=101;
EXPLAIN PLAN SET STATEMENT_ID '102' FOR SELECT * FROM t WHERE val2=102;
EXPLAIN PLAN SET STATEMENT_ID '103' FOR SELECT * FROM t WHERE val2=103;
EXPLAIN PLAN SET STATEMENT_ID '104' FOR SELECT * FROM t WHERE val2=104;
EXPLAIN PLAN SET STATEMENT_ID '105' FOR SELECT * FROM t WHERE val2=105;
EXPLAIN PLAN SET STATEMENT_ID '106' FOR SELECT * FROM t WHERE val2=106;

SELECT STATEMENT_ID,CARDINALITY FROM plan_table WHERE ID=0;

STATEMENT_ID

CARDINALITY

101

8

102

25

103

68

104

185

105

502

106

212

当列的唯一值的个数大于桶允许的最大数量(254)时,就不能使用频度直方图了,此时应该使用等高直方图。

更多详情见请继续阅读下一页的精彩内容:

相关阅读:

32个字节限制——Oracle直方图优化

[Oracle新手教程] 用PL/SQL画直方图

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 BLOB : are there any limits?MySQL BLOB : are there any limits?May 08, 2025 am 12:22 AM

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

MySQL : What are the best tools to automate users creation?MySQL : What are the best tools to automate users creation?May 08, 2025 am 12:22 AM

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

MySQL: Can I search inside a blob?MySQL: Can I search inside a blob?May 08, 2025 am 12:20 AM

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

MySQL String Data Types: A Comprehensive GuideMySQL String Data Types: A Comprehensive GuideMay 08, 2025 am 12:14 AM

MySQLoffersvariousstringdatatypes:1)CHARforfixed-lengthstrings,idealforconsistentlengthdatalikecountrycodes;2)VARCHARforvariable-lengthstrings,suitableforfieldslikenames;3)TEXTtypesforlargertext,goodforblogpostsbutcanimpactperformance;4)BINARYandVARB

Mastering MySQL BLOBs: A Step-by-Step TutorialMastering MySQL BLOBs: A Step-by-Step TutorialMay 08, 2025 am 12:01 AM

TomasterMySQLBLOBs,followthesesteps:1)ChoosetheappropriateBLOBtype(TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB)basedondatasize.2)InsertdatausingLOAD_FILEforefficiency.3)Storefilereferencesinsteadoffilestoimproveperformance.4)UseDUMPFILEtoretrieveandsaveBLOBsco

BLOB Data Type in MySQL: A Detailed Overview for DevelopersBLOB Data Type in MySQL: A Detailed Overview for DevelopersMay 07, 2025 pm 05:41 PM

BlobdatatypesinmysqlareusedforvoringLargebinarydatalikeImagesoraudio.1) Useblobtypes (tinyblobtolongblob) Basedondatasizeneeds. 2) Storeblobsin Perplate Petooptimize Performance.3) ConsidersxterNal Storage Forel Blob Romana DatabasesizerIndimprovebackupupe

How to Add Users to MySQL from the Command LineHow to Add Users to MySQL from the Command LineMay 07, 2025 pm 05:01 PM

ToadduserstoMySQLfromthecommandline,loginasroot,thenuseCREATEUSER'username'@'host'IDENTIFIEDBY'password';tocreateanewuser.GrantpermissionswithGRANTALLPRIVILEGESONdatabase.*TO'username'@'host';anduseFLUSHPRIVILEGES;toapplychanges.Alwaysusestrongpasswo

What Are the Different String Data Types in MySQL? A Detailed OverviewWhat Are the Different String Data Types in MySQL? A Detailed OverviewMay 07, 2025 pm 03:33 PM

MySQLofferseightstringdatatypes:CHAR,VARCHAR,BINARY,VARBINARY,BLOB,TEXT,ENUM,andSET.1)CHARisfixed-length,idealforconsistentdatalikecountrycodes.2)VARCHARisvariable-length,efficientforvaryingdatalikenames.3)BINARYandVARBINARYstorebinarydata,similartoC

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

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),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

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.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool