Lately, I met a case that the range filter predicates due to wrong cardinality issue. Letrsquo;s check the followin
Lately, I met a case that the range filter predicates due to wrong cardinality issue. Let’s check the following query.
最近遇到一个由于范围过滤导致错误基数而引起的性能问题。让我们来看下面的查询:
The real records number is around 38,000,000.
真实的记录数大约3千8百万
The explain plan shows 72838, optimizer think it has good filtration. So put this JOIN in the first order. Actually , it is totally wrong.
执行计划显示72838,这里优化器认为它有良好的过滤芯,所以把它放在一个多个表JOIN的第一位置。显然,,它完全错了。
SQL> set autotrace traceonly explain;
SQL> set linesize 999
SQL> SELECT
2 T.DURATIONSECSQTY TIMEINSECONDS,
T.MONEYAMT MONEYAMOUNT,
T.WAGEAMT WAGEAMOUNT,
T.APPLYDTM APPLYDATE,
T.ADJAPPLYDTM ADJUSTEDAPPLYDATE,
T.STARTDTM,
T.ENDDTM,
T.HOMEACCOUNTSW
FROM
TKCSOWNER.WFCTOTAL T,
TKCSOWNER.PAYCODE1MMFLAT MP
WHERE
MP.EFFECTIVEDTM
AND MP.EXPIRATIONDTM > T.APPLYDTM
AND MP.PAYCODEID = T.PAYCODEID
/
---------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
---------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 72838 | 5192K| 37450 |
|* 1 | HASH JOIN | | 72838 | 5192K| 37450 |
| 2 | TABLE ACCESS FULL| PAYCODE1MMFLAT | 323 | 6783 | 3 |
| 3 | TABLE ACCESS FULL| WFCTOTAL | 8938K| 443M| 37317 |
Now, let me comment the range filter.
让我注释到范围条件看:
“MP.EFFECTIVEDTM
AND MP.EXPIRATIONDTM > T.APPLYDTM”
SQL> SELECT
2 T.DURATIONSECSQTY TIMEINSECONDS,
T.MONEYAMT MONEYAMOUNT,
T.WAGEAMT WAGEAMOUNT,
T.APPLYDTM APPLYDATE,
T.ADJAPPLYDTM ADJUSTEDAPPLYDATE,
T.STARTDTM,
T.ENDDTM,
T.HOMEACCOUNTSW
FROM
TKCSOWNER.WFCTOTAL T,
TKCSOWNER.PAYCODE1MMFLAT MP
WHERE
/* MP.EFFECTIVEDTM
AND MP.EXPIRATIONDTM > T.APPLYDTM*/
MP.PAYCODEID = T.PAYCODEID 3 4 5 6 7 8 9 10 11 12 13 14 15 16
17 /
Execution Plan
----------------------------------------------------------
Plan hash value: 564403449
---------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
---------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 29M| 1583M| 37405 |
|* 1 | HASH JOIN | | 29M| 1583M| 37405 |
| 2 | INDEX FAST FULL SCAN| PK_PAYCODE1MMFLAT | 323 | 1615 | 1 |
| 3 | TABLE ACCESS FULL | WFCTOTAL | 8938K| 443M| 37317 |
The Cardinality show 29,135,142 , it is already close to the correct value.
基础是29,135,142,已经接近正确结果了。
So how optimizer work out the cardinality with range filter in TABLE JOIN ?
那么优化器怎么出来表连接中的范围扫描呢?
The answer is 5%, always 5%.
答案是5%
29135142 * 5% * 5% = 72837.8 , This is exact equal to the result of test 1.
So if you meet any performance issue with range filter in TBALE JOIN, I am not surprise. I think Oracle need to improve the CBO to get better support on such situation.

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

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

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

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

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.

Dreamweaver CS6
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)
