前言:存储过程可能涉及很多的SQL及控制块,我们看到的执行时间是整个过程块的执行时间,如果我们认为性能有问题,我们只能逐条SQL的分析,查找问题SQL,效率非常低下。KingbaseES 提供了 plsql_plprofiler 扩展插件, 可以方便用户跟踪分析过程的每条语句的执行情况,能让我们快速定位问题。

以下以例子的方式演示plsql_plprofiler的使用。

1、创建扩展插件

create extension plsql_plprofiler

2、创建演示的存储过程

create or replace procedure p1 as
cnt integer;
begin
for i in 1..100 loop
select count(*) into cnt from t1;
end loop;
select count(*) into cnt from t2;
end;
/

3、收集数据

test=# select pl_profiler_reset_local();          --清理本地数据
pl_profiler_reset_local
------------------------- (1 row) test=# select pl_profiler_reset_shared(); --清理全局数据
pl_profiler_reset_shared
-------------------------- (1 row) test=# select pl_profiler_set_enabled_local(true); --启动本地会话分析器
pl_profiler_set_enabled_local
-------------------------------
t
(1 row) test=# call p1();
CALL
test=# select pl_profiler_set_enabled_local(false); --关闭本地会话分析器
pl_profiler_set_enabled_local
-------------------------------
f
(1 row) test=# select pl_profiler_collect_data();
pl_profiler_collect_data
--------------------------
0
(1 row)

4、分析数据

test=# select pl_profiler_func_oids_shared();
pl_profiler_func_oids_shared
------------------------------
{16485}
(1 row) test=# select func_oid, func_oid::regproc as funcname,line_number, source from pl_profiler_funcs_source(pl_profiler_func_oids_shared());
func_oid | funcname | line_number | source
----------+----------+-------------+---------------------------------------
16485 | p1 | 0 | -- Line 0
16485 | p1 | 1 |
16485 | p1 | 2 | cnt integer;
16485 | p1 | 3 | begin
16485 | p1 | 4 | for i in 1..100 loop
16485 | p1 | 5 | select count(*) into cnt from t1;
16485 | p1 | 6 | end loop;
16485 | p1 | 7 | select count(*) into cnt from t2;
16485 | p1 | 8 | end
(9 rows) SELECT L.func_oid::regproc as funcname,
L.func_oid as func_oid,
L.line_number,
sum(L.exec_count)::bigint AS exec_count,
sum(L.total_time)::bigint AS total_time,
max(L.longest_time)::bigint AS longest_time,
S.source
FROM pl_profiler_linestats_shared() L
JOIN pl_profiler_funcs_source(pl_profiler_func_oids_shared) S
ON S.func_oid = L.func_oid AND S.line_number = L.line_number
GROUP BY L.func_oid, L.line_number, S.source
ORDER BY L.func_oid, L.line_number;

funcname | func_oid | line_number | exec_count | total_time | longest_time | source
----------+----------+-------------+------------+------------+--------------+---------------------------------------
p1 | 16485 | 0 | 1 | 1296 | 1296 | -- Line 0
p1 | 16485 | 1 | 0 | 0 | 0 |
p1 | 16485 | 2 | 0 | 0 | 0 | cnt integer;
p1 | 16485 | 3 | 1 | 1294 | 1294 | begin
p1 | 16485 | 4 | 1 | 1098 | 1098 | for i in 1..100 loop
p1 | 16485 | 5 | 100 | 946 | 202 | select count(*) into cnt from t1;
p1 | 16485 | 6 | 0 | 0 | 0 | end loop;
p1 | 16485 | 7 | 1 | 193 | 193 | select count(*) into cnt from t2;
p1 | 16485 | 8 | 0 | 0 | 0 | end
(9 rows)

从收集到的数据可以某条SQL 执行次数、总执行时间(单位us)。

注意:控制块是包含内部所有语句的执行时间的,如:本例的for 循环

使用plsql_plprofiler 分析过程块的执行的更多相关文章

  1. Java的初始化块及执行过程详解

    问题:Java对象初始化方式主要有哪几种?分别是什么?针对上面的问题,想必大家脑海中首先浮现出的答案是构造器,没错,构造器是Java中常用的对象初始化方式. 还有一种与构造器作用非常相似的是初始化块, ...

  2. 精尽MyBatis源码分析 - MyBatis 的 SQL 执行过程(一)之 Executor

    该系列文档是本人在学习 Mybatis 的源码过程中总结下来的,可能对读者不太友好,请结合我的源码注释(Mybatis源码分析 GitHub 地址.Mybatis-Spring 源码分析 GitHub ...

  3. javascript引擎执行的过程的理解--执行阶段

    一.概述 同步更新sau交流学习社区(nodeJSBlog):javascript引擎执行的过程的理解--执行阶段 js引擎执行过程主要分为三个阶段,分别是语法分析,预编译和执行阶段,上篇文章我们介绍 ...

  4. 九、dbms_ddl(提供了在PL/SQL块中执行DDL语句的方法)

    1.概述 作用:提供了在PL/SQL块中执行DDL语句的方法,并且也提供了一些DDL的特殊管理方法. 2.包的组成 1).alter_compile说明:用于重新编译过程.函数和包语法:dbms_dd ...

  5. angularjs源码分析之:angularjs执行流程

    angularjs用了快一个月了,最难的不是代码本身,而是学会怎么用angular的思路思考问题.其中涉及到很多概念,比如:directive,controller,service,compile,l ...

  6. 左右 Java 于 finally 深度分析语句块

    首先,让我们来问你一个问题:finally 声明块将运行? 很多人认为 finally 语句块是一定要运行.其中还包括了一些非常有经验的 Java 程序猿.不幸的是,没有像很多像人们想象,对于这个问题 ...

  7. LL(1)文法分析表的构造和分析过程示例

    在考完编译原理之后才弄懂,悲哀啊.不过懂了就好,知识吗,不能局限于考试. 文法: E→TE' E'→+TE'|ε T→FT ' T'→*FT'|ε F→id| (E) 一.首先判断是不是 LL(1)文 ...

  8. 一个杀不死的小强,kill进程无效的原因 记录故障排查过程中kill进程无效的分析过程

    今天在处理一个机器异常负载(1000+)的问题,碰到了一个从未碰到过的情况,遇到了一个异常顽固的分子.我使用了所能想到的所有杀进程的方法,却始终无法干掉这个顽固分子,最后终于在谷歌大神的指引下,干掉了 ...

  9. HDFS源码分析数据块校验之DataBlockScanner

    DataBlockScanner是运行在数据节点DataNode上的一个后台线程.它为所有的块池管理块扫描.针对每个块池,一个BlockPoolSliceScanner对象将会被创建,其运行在一个单独 ...

随机推荐

  1. ABAP CDS - Annotations 注解

    Syntax ... annotation[.annotation1[.annotation2]][:value]  ... Effect Annotation that can be specifi ...

  2. 一条 SQL 语句是如何执行的

    一条 SQL 语句是如何执行的 SQL查询语句 select * from user where ID=10; MySQL 的基本架构可以分为 Server 层和存储引擎两部分.Server 层又包含 ...

  3. 论文阅读 Exploring Temporal Information for Dynamic Network Embedding

    10 Exploring Temporal Information for Dynamic Network Embedding 5 link:https://scholar.google.com.sg ...

  4. mysql InnoDB通过.frm和.ibd恢复表和数据

    ibdata1是一个用来构建innodb系统表空间的文件,这个文件包含了innodb表的元数据.撤销记录.修改buffer和双写buffer.如果file-per-table选项打开的话,该文件则不一 ...

  5. SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器

    我们来做一个头为6位报文总长度,并且长度不包含长度域自身的例子.比如这样的Socket报文000006123456. 添加SuperSocket.Engine,直接使用Nuget搜索SuperSock ...

  6. 数据孤岛下的新破局 Real Time DaaS:面向 AP+TP 业务的数据平台架构

    从传统数仓,到大数据平台,再到数据中台和湖仓一体新数据平台,在日益加重的数据孤岛困扰下,面向AP场景的解决方案可谓浩如烟海.但实际上,企业在TP类型业务上的投入和AP的比率却高达9:1,为什么没有为T ...

  7. 简单的数据结构_via牛客网

    题面 链接:https://ac.nowcoder.com/acm/contest/28537/K 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语 ...

  8. springmvc源码笔记-HandlerMapping注入

    在springmvc中,如何根据url找到controller以及对应方法,依赖的是HandlerMapping接口的getHandler方法 在spring容器中默认注册的HandlerMappin ...

  9. LyScript 内存交换与差异对比

    LyScript 针对内存读写函数的封装功能并不多,只提供了内存读取和内存写入函数的封装,本篇文章将继续对API进行封装,实现一些在软件逆向分析中非常实用的功能,例如内存交换,内存区域对比,磁盘与内存 ...

  10. 日志(logging模块)

    1. 为什么要使用日志(作用) 在学习过程中,写一个小程序或小demo时,遇到程序出错时,我们一般会将一些信息打印到控制台进行查看,方便排查错误.这种方法在较小的程序中很实用,但是当你的程序变大,或是 ...