[20171225]查看並行執行計劃註意的問題.txt

来源:https://www.cnblogs.com/lfree/archive/2017/12/26/8116717.html
-Advertisement-
Play Games

[20171225]查看並行執行計劃註意的問題.txt--//如果使用dbms_xplan.display_cursor查看並行執行計劃註意一些問題,通過例子說明:1.環境:SCOTT@book> @ &r/ver1PORT_STRING VERSION BANNER x86_64/Linux 2. ...


[20171225]查看並行執行計劃註意的問題.txt

--//如果使用dbms_xplan.display_cursor查看並行執行計劃註意一些問題,通過例子說明:

1.環境:

SCOTT@book> @ &r/ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.測試:
SCOTT@book> create table t1 as select * from dba_objects ;
Table created.

SCOTT@book> alter session set statistics_level=all;
Session altered.

--//分析表略.

SCOTT@book> select /*+ parallel(t1,4) */ count(*) from t1;
  COUNT(*)
----------
     87016

SCOTT@book> @ &r/dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  6yhkc72j9mnnt, child number 0
-------------------------------------
select /*+ parallel(t1,4) */ count(*) from t1
Plan hash value: 3110199320
-----------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation              | Name     | Starts | E-Rows | Cost (%CPU)| E-Time   |    TQ  |IN-OUT| PQ Distrib | A-Rows |   A-Time   | Buffers | Reads  |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |          |      1 |        |    96 (100)|          |        |      |            |      1 |00:00:00.02 |       5 |      1 |
|   1 |  SORT AGGREGATE        |          |      1 |      1 |            |          |        |      |            |      1 |00:00:00.02 |       5 |      1 |
|   2 |   PX COORDINATOR       |          |      1 |        |            |          |        |      |            |      4 |00:00:00.02 |       5 |      1 |
|   3 |    PX SEND QC (RANDOM) | :TQ10000 |      0 |      1 |            |          |  Q1,00 | P->S | QC (RAND)  |      0 |00:00:00.01 |       0 |      0 |
|   4 |     SORT AGGREGATE     |          |      0 |      1 |            |          |  Q1,00 | PCWP |            |      0 |00:00:00.01 |       0 |      0 |
|   5 |      PX BLOCK ITERATOR |          |      0 |  87016 |    96   (0)| 00:00:02 |  Q1,00 | PCWC |            |      0 |00:00:00.01 |       0 |      0 |
|*  6 |       TABLE ACCESS FULL| T1       |      0 |  87016 |    96   (0)| 00:00:02 |  Q1,00 | PCWP |            |      0 |00:00:00.01 |       0 |      0 |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1
   6 - SEL$1 / T1@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   6 - access(:Z>=:Z AND :Z<=:Z)

--//全表掃描,但是註意看A-Rows實際上根本不對.看到是0行.而E-Rows看到是正確的.

SCOTT@book> select * from table(dbms_xplan.display_cursor('6yhkc72j9mnnt',NULL,'ALLSTATS LAST PEEKED_BINDS cost partition -projection -outline parallel'));
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  6yhkc72j9mnnt, child number 0
-------------------------------------
select /*+ parallel(t1,4) */ count(*) from t1
Plan hash value: 3110199320
---------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation              | Name     | Starts | E-Rows | Cost (%CPU)|    TQ  |IN-OUT| PQ Distrib | A-Rows |   A-Time   | Buffers |
---------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |          |      1 |        |    96 (100)|        |      |            |      1 |00:00:00.11 |       5 |
|   1 |  SORT AGGREGATE        |          |      1 |      1 |            |        |      |            |      1 |00:00:00.11 |       5 |
|   2 |   PX COORDINATOR       |          |      1 |        |            |        |      |            |      4 |00:00:00.11 |       5 |
|   3 |    PX SEND QC (RANDOM) | :TQ10000 |      0 |      1 |            |  Q1,00 | P->S | QC (RAND)  |      0 |00:00:00.01 |       0 |
|   4 |     SORT AGGREGATE     |          |      0 |      1 |            |  Q1,00 | PCWP |            |      0 |00:00:00.01 |       0 |
|   5 |      PX BLOCK ITERATOR |          |      0 |  87016 |    96   (0)|  Q1,00 | PCWC |            |      0 |00:00:00.01 |       0 |
|*  6 |       TABLE ACCESS FULL| T1       |      0 |  87016 |    96   (0)|  Q1,00 | PCWP |            |      0 |00:00:00.01 |       0 |
---------------------------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   6 - access(:Z>=:Z AND :Z<=:Z)
--//加入parallel提示也是一樣.
--//鏈接:raajeshwaran.blogspot.com/2017/12/gatherplanstatistics-hint-for-parallel.html
In a parallel execution the last process to execute the cursor is the Query coordinator (QC), typically this QC will
execute a small number of operations in the execution plan, while the majority of the operations in the plan was done by
the parallel execution server process. So when we issue the DBMS_XPLAN.DISPLAY_CURSOR and ask for the last execution we
only get the information about the operations in the plan that the QC actually executed. In this case the only operation
that QC did was return the final result to our SQL*Plus session, which is why the line 0 and 1 and 2 have entries in the
A-rows column.

In order to see A-rows values for all the operations in the plan, we have to use the FORMAT value as ALLSTATS ALL, which
will show you the execution statistics for ALL executions of the cursor.

SCOTT@book> select * from table(dbms_xplan.display_cursor('6yhkc72j9mnnt',NULL,'ALLSTATS ALL PEEKED_BINDS cost partition -projection -outline parallel'));
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  6yhkc72j9mnnt, child number 0
-------------------------------------
select /*+ parallel(t1,4) */ count(*) from t1
Plan hash value: 3110199320
-----------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation              | Name     | Starts | E-Rows | Cost (%CPU)| E-Time   |    TQ  |IN-OUT| PQ Distrib | A-Rows |   A-Time   | Buffers | Reads  |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |          |      2 |        |    96 (100)|          |        |      |            |      2 |00:00:00.13 |      10 |      1 |
|   1 |  SORT AGGREGATE        |          |      2 |      1 |            |          |        |      |            |      2 |00:00:00.13 |      10 |      1 |
|   2 |   PX COORDINATOR       |          |      2 |        |            |          |        |      |            |      8 |00:00:00.13 |      10 |      1 |
|   3 |    PX SEND QC (RANDOM) | :TQ10000 |      0 |      1 |            |          |  Q1,00 | P->S | QC (RAND)  |      0 |00:00:00.01 |       0 |      0 |
|   4 |     SORT AGGREGATE     |          |      7 |      1 |            |          |  Q1,00 | PCWP |            |      7 |00:00:00.10 |    2265 |   2179 |
|   5 |      PX BLOCK ITERATOR |          |      8 |  87016 |    96   (0)| 00:00:02 |  Q1,00 | PCWC |            |    152K|00:00:00.09 |    2590 |   2486 |
|*  6 |       TABLE ACCESS FULL| T1       |    104 |  87016 |    96   (0)| 00:00:02 |  Q1,00 | PCWP |            |    174K|00:00:00.04 |    2590 |   2486 |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1
   6 - SEL$1 / T1@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   6 - access(:Z>=:Z AND :Z<=:Z)

--//而這裡看到的A-Rows實際上多次執行後的累積,並不能反應真實的情況.使用參數all的情況導致的結果.

--//加入提示,生成新的執行計劃:
SCOTT@book> select /*+ parallel(t1,4) test */ count(*) from t1;
  COUNT(*)
----------
     87016

SCOTT@book> select * from table(dbms_xplan.display_cursor(NULL,NULL,'ALLSTATS ALL PEEKED_BINDS cost partition -projection -outline parallel'));
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  6a3vj021614ft, child number 0
-------------------------------------
select /*+ parallel(t1,4) test */ count(*) from t1
Plan hash value: 3110199320
-----------------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation              | Name     | Starts | E-Rows | Cost (%CPU)| E-Time   |    TQ  |IN-OUT| PQ Distrib | A-Rows |   A-Time   | Buffers | Reads  |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT       |          |      1 |        |    96 (100)|          |        |      |            |      1 |00:00:00.11 |       5 |      0 |
|   1 |  SORT AGGREGATE        |          |      1 |      1 |            |          |        |      |            |      1 |00:00:00.11 |       5 |      0 |
|   2 |   PX COORDINATOR       |          |      1 |        |            |          |        |      |            |      4 |00:00:00.11 |       5 |      0 |
|   3 |    PX SEND QC (RANDOM) | :TQ10000 |      0 |      1 |            |          |  Q1,00 | P->S | QC (RAND)  |      0 |00:00:00.01 |       0 |      0 |
|   4 |     SORT AGGREGATE     |          |      4 |      1 |            |          |  Q1,00 | PCWP |            |      4 |00:00:00.06 |    1295 |   1243 |
|   5 |      PX BLOCK ITERATOR |          |      4 |  87016 |    96   (0)| 00:00:02 |  Q1,00 | PCWC |            |  87016 |00:00:00.05 |    1295 |   1243 |
|*  6 |       TABLE ACCESS FULL| T1       |     52 |  87016 |    96   (0)| 00:00:02 |  Q1,00 | PCWP |            |  87016 |00:00:00.02 |    1295 |   1243 |
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1
   6 - SEL$1 / T1@SEL$1
Predicate Information (identified by operation id):
---------------------------------------------------
   6 - access(:Z>=:Z AND :Z<=:Z)

--//這樣看到的執行計劃才是比較真實的數值.

--//我的dpc.sql腳本如下:
select * from table(dbms_xplan.display_cursor(NVL('&1',NULL),NULL,'ALL ALLSTATS LAST PEEKED_BINDS cost partition -projection -outline &2'));
--//我寫的腳本也存在問題,不過最後的last掩蓋前面all參數的設置.^_^.

3.總結:
--//在設置statistics_level=all;或者提示gather_plan_statistics時,看到的並行執行計劃要特別註意.


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 需要查兩個表之間的差集 首先,想到的是主鍵直接not in 好吧!這個是可以,但是數據多了的話,想到這個查詢的邏輯有點受不住 於是再改為下麵的這樣: 利用了left join的,然後進行對比,並且利用where進行篩選。 後面也在網上找了這條: 概念上與第二條同理。 好吧! 回顧了一下left jo ...
  • Redis概述 Redis是一種key-value型資料庫,運行於記憶體中,與它相似的資料庫有memcached,現在基本被Redis替代。 Redis適用場景 我們要與傳統的關係型資料庫進行對比才能更好的瞭解與使用Redis 1.高併發場景, redis是個單線程的程式對於純記憶體操作如hash查找可 ...
  • 學習目標: -使用ROLLUP操作符產生小計值 -使用CUBE操作符產生交叉製表 -使用GROUPING函數來標識ROLLUP或CUBE運算符生成的結果集中的聚合級別 -使用GROUPING SETS生成一個相當於UNION ALL方法的結果集 ROLLUP操作符 SELECT [column,] ...
  • (本人初次接觸spark可能有些地方理解的不夠到位,希望各位讀者多多指正,對於不恰當的地方也會進行改進) 1、RDD定義:是彈性分散式數據集,是分佈到各個節點的數據集合,具有自動容錯性、位置感知調度和可伸縮性等。 2、RDD的特性: 2.1 分區(partition) 分區是RDD的基本組成單位(s ...
  • hadoop是基於磁碟的,它的運算結果保存在磁碟當中;而spark的運算是基於記憶體的。因此spark的運算速度是 hadoop的100倍;即使在磁碟當中運算,spark也是hadoop的10倍左右,原因就是spark具有優秀的作業調度策略。 故spark的速度快與hadoop的兩個原因: (1)sp ...
  • Mapper Mapper的maps階段將輸入鍵值對經過計算得到中間結果鍵值對,框架會將中間結果按照key進行分組,然後傳遞給reducer以決定最終的輸出。用戶可以通過Job.setGroupingComparatorClass(Class)來指定一個Comparator。 Mapper的輸出會被 ...
  • 使用mysql資料庫的朋友, 經常會使用mysqldump備案資料庫, 然後到新伺服器還原, 這個過程中, 有朋友會遇到ERROR 1046 (3D000) No database selected的提示, 這個原因是沒有在命令中指定對應的資料庫。 解決的方法也很簡單, 假設mysqldump備案的 ...
  • 一、 Oracle自動備份單表一個月數據 方式一:三步處理(建批處理文件,寫sql文件,設置任務計劃) 1、 第一步:建立一個批處理文件 2、 第二步、寫清除資料庫並釋放空間的sql文件 3、 第三步、使用windows自帶的任務計劃程式 A) 打開任務計劃程式,新建一個基本任務計劃 B) 填上名和 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...