CARDINALITY HINT用法小試
select * from wxh_tbd1 a where a.object_type='TABLE' and a.object_id in ( select object_id from wxh_tbd2 where object_type='TABLE');
Execution Plan
----------------------------------------------------------
Plan hash value: 3614068701
---------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 4030 | 909K| 121 (1)| 00:00:02 |
|* 1 | HASH JOIN RIGHT SEMI| | 4030 | 909K| 121 (1)| 00:00:02 |
|* 2 | TABLE ACCESS FULL | WXH_TBD2 | 4026 | 96624 | 60 (0)| 00:00:01 |
|* 3 | TABLE ACCESS FULL | WXH_TBD1 | 4219 | 852K| 60 (0)| 00:00:01 |
---------------------------------------------------------------------------------
預設走了HASI JOIN。執行計劃是對的,因為object_type為table的非常多。
如果我想先掃描WXH_TBD2再去nest loop wxh_tbd1呢。可以透過這個CARDINALITY去解決select * from wxh_tbd1 a where a.object_type='TABLE' and a.object_id in ( select /*+ CARDINALITY(wxh_tbd2 1) */object_id from wxh_tbd2 where object_type='TABLE');
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 231 | 63 (2)| 00:00:01 |
| 1 | NESTED LOOPS | | | | | |
| 2 | NESTED LOOPS | | 1 | 231 | 63 (2)| 00:00:01 |
| 3 | SORT UNIQUE | | 1 | 24 | 60 (0)| 00:00:01 |
|* 4 | TABLE ACCESS FULL | WXH_TBD2 | 1 | 24 | 60 (0)| 00:00:01 |
|* 5 | INDEX RANGE SCAN | OJ | 1 | | 1 (0)| 00:00:01 |
|* 6 | TABLE ACCESS BY INDEX ROWID| WXH_TBD1 | 1 | 207 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------
This hint specifies the estimated cardinality returned by a query or portions of the query. Note if no table is specified, the cardinality is the total number of rows returned by the entire query.
For example:
SELECT /*+ CARDINALITY ( [tablename] card ) */
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22034023/viewspace-694500/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- LightDB 22.4 新特性之支援Oracle cardinality和ordered_predicates hintOracle
- 【TUNE_ORACLE】Oracle Hint之概念與用法Oracle
- 7.40 CARDINALITY
- Are we ready for learned cardinality estimation?
- webpack用法小結Web
- Less用法小記
- 【TUNE_ORACLE】Oracle Hint之常用Hint功能概述(五)Oracle
- 【TUNE_ORACLE】Oracle Hint之常用Hint功能概述(四)Oracle
- 【TUNE_ORACLE】Oracle Hint之常用Hint功能概述(三)Oracle
- 【TUNE_ORACLE】Oracle Hint之常用Hint功能概述(二)Oracle
- 【TUNE_ORACLE】Oracle Hint之常用Hint功能概述(一)Oracle
- [20180928]exists與cardinality.txt
- [ORM 小技巧] withDefault() 用法ORM
- While True用法小例子While
- ORACLE的HINT詳解Oracle
- Oracle中的sql hintOracleSQL
- openGauss 支援SQL-hintSQL
- Deep Upsupervised Cardinality Estimation 解讀(2019 VLDB)
- oracle不走hint原因1:依據hint會出現錯誤結果Oracle
- Oracle中常見的Hint(一)Oracle
- Oracle之Hint使用總結Oracle
- [20200801]sql hint衝突.txtSQL
- Apache ShardingSphere HINT 實用指南Apache
- ES6 Promise用法小結Promise
- PHP中ZendCache用法的小例子PHP
- 簡單解析MySQL中的cardinality異常MySql
- [20190430]注意sql hint寫法.txtSQL
- Multiparty Cardinality Testing for Threshold Private Set-2021:解讀
- Oracle中Hint深入理解(原創)Oracle
- 學習達夢hint注入筆記筆記
- JS/TS 的 import 和 export 用法小結JSImportExport
- spring mvc中的@RequestMapping value用法小結SpringMVCAPP
- 模板字串的一些用法小記字串
- C++ 指標常見用法小結C++指標
- PostgreSQL多值列的選擇性-Statistics,Cardinality,Selectivity,EstimateSQL
- 硬碟測試工具fio用法總結硬碟
- Pytest測試框架(三):pytest fixture 用法框架
- [20200718]注意sql hint寫法2.txtSQL
- What is OPAQUE_TRANSFORM Hint and how to Control it [ID 780503.1]OpaqueORM