Trafodion 查看执行计划

Trafodion数据库一般通过EXPLAIN命令查看SQL的执行计划,部分使用方法如下,

  • explain select ... from ...;
  • explain options 'f' select ... from ...;
  • prepare s from select .. from ...;     explain {options 'f'} s;

下面通过一个简单的两表关联介绍如何用上述几种方法分别去查看SQL的执行计划。


1 创建测试表并插入样例数据

SQL>create table test1(a int not null, b varchar(10));

--- SQL operation complete.

SQL>create table test2(a int not null, b varchar(10));

--- SQL operation complete.

SQL>insert into test1 values(1,'LIU'),(2,'WANG');

--- 2 row(s) inserted.

SQL>insert into test2 values(1,'ZHANG'),(2,'LI');

--- 2 row(s) inserted.

2 explain + sql 查看执行计划

SQL>explain
+>select test1.a, test1.b, test2.b
+>from test1, test2
+>where test1.a = test2.a;

------------------------------------------------------------------ PLAN SUMMARY
MODULE_NAME .............. DYNAMICALLY COMPILED
STATEMENT_NAME ........... NOT NAMED
PLAN_ID .................. 212344925683685481
ROWS_OUT ............. 5,000
EST_TOTAL_COST ........... 0.01
STATEMENT ................
select test1.a, test1.b, test2.b
from test1,
                             test2
where test1.a = test2.a;

------------------------------------------------------------------ NODE LISTING
ROOT ======================================  SEQ_NO 4        ONLY CHILD 3
REQUESTS_IN .............. 1
ROWS_OUT ............. 5,000
EST_OPER_COST ............ 0
EST_TOTAL_COST ........... 0.01
DESCRIPTION
  max_card_est ....... 5,000
  fragment_id ............ 0
  parent_frag ............ (none)
  fragment_type .......... master
  statement_index ........ 0
  affinity_value ......... 0
  est_memory_per_cpu ..... 260 KB
  max_max_cardinality  5,000
  total_overflow_size .... 0.00 KB
  xn_access_mode ......... read_only
  xn_autoabort_interval    0
  auto_query_retry ....... enabled
  plan_version ....... 2,600
  embedded_arkcmp ........ used
  LDAP_USERNAME .......... ZZ
  SHOWCONTROL_SHOW_ALL ... OFF
  GENERATE_EXPLAIN ....... ON
  ObjectUIDs ............. 7186168948089148044, 7186168948089146661
  select_list ............ TRAFODION.SEABASE.TEST1.A,
                             TRAFODION.SEABASE.TEST1.B,
                             TRAFODION.SEABASE.TEST2.B
  input_variables ........ execution_count

HYBRID_HASH_JOIN ==========================  SEQ_NO 3        CHILDREN 2, 1
REQUESTS_IN .............. 1
ROWS_OUT ............. 5,000
EST_OPER_COST ............ 0.01
EST_TOTAL_COST ........... 0.01
DESCRIPTION
  memory_quota ........... 656 MB
  max_card_est ....... 5,000
  fragment_id ............ 0
  parent_frag ............ (none)
  fragment_type .......... master
  est_memory_per_cpu ..... 260 KB
  join_type .............. inner
  join_method ............ hash
  hash_join_predicates ... (TRAFODION.SEABASE.TEST1.A =
                             TRAFODION.SEABASE.TEST2.A)

TRAFODION_SCAN ============================  SEQ_NO 2        NO CHILDREN
TABLE_NAME ............... TEST1
REQUESTS_IN .............. 1
ROWS_OUT ............... 100
EST_OPER_COST ............ 0.01
EST_TOTAL_COST ........... 0.01
DESCRIPTION
  max_card_est ......... 100
  fragment_id ............ 0
  parent_frag ............ (none)
  fragment_type .......... master
  scan_type .............. subset scan of table TRAFODION.SEABASE.TEST1
  object_type ............ Trafodion
  columns ................ all
  begin_keys(incl)
  end_keys(incl)
  cache_size ........... 100
  probes ................. 1
  rows_accessed ........ 100
  column_retrieved ....... #1:1,#1:2,#1:3
  key_columns ............ SYSKEY

TRAFODION_SCAN ============================  SEQ_NO 1        NO CHILDREN
TABLE_NAME ............... TEST2
REQUESTS_IN .............. 1
ROWS_OUT ............... 100
EST_OPER_COST ............ 0.01
EST_TOTAL_COST ........... 0.01
DESCRIPTION
  max_card_est ......... 100
  fragment_id ............ 0
  parent_frag ............ (none)
  fragment_type .......... master
  scan_type .............. subset scan of table TRAFODION.SEABASE.TEST2
  object_type ............ Trafodion
  columns ................ all
  begin_keys(incl)
  end_keys(incl)
  cache_size ........... 100
  probes ................. 1
  rows_accessed ........ 100
  column_retrieved ....... #1:1,#1:2,#1:3
  key_columns ............ SYSKEY

--- SQL operation complete.


3 explain options 'f' + sql 查看执行计划

SQL>explain options 'f'
+>select test1.a, test1.b, test2.b
+>from test1, test2
+>where test1.a = test2.a;

LC   RC   OP   OPERATOR              OPT       DESCRIPTION           CARD
---- ---- ---- --------------------  --------  --------------------  ---------

3    .    4    root                                                  5.00E+003
2    1    3    hybrid_hash_join                                      5.00E+003
.    .    2    trafodion_scan                  TEST1                 1.00E+002
.    .    1    trafodion_scan                  TEST2                 1.00E+002

--- SQL operation complete.

4 prepare + explain 查看执行计划

SQL>prepare s from
+>select test1.a, test1.b, test2.b
+>from test1, test2
+>where test1.a = test2.a;

--- SQL command prepared.

SQL>explain options 'f' s;

LC   RC   OP   OPERATOR              OPT       DESCRIPTION           CARD
---- ---- ---- --------------------  --------  --------------------  ---------

3    .    4    root                                                  5.00E+003
2    1    3    hybrid_hash_join                                      5.00E+003
.    .    2    trafodion_scan                  TEST1                 1.00E+002
.    .    1    trafodion_scan                  TEST2                 1.00E+002

--- SQL operation complete.



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数据源的港湾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值