对于重复执行的SQL,需要使用绑定变量,避免SQL的重复解析。但是,并不是说使用了绑定变量,就一定能避免硬解析。
以下举例说明 参数 plan_cache_mode 对于游标共享的影响。
使用绑定变量时,系统自动根据数据情况,使用软解析。用时1345ms.
test=# declare
test-# v_temp integer;
test-# begin
test-# for i in 1..100000 loop
test-# select count(*) into v_temp from tab1 where id=i;
test-# end loop;
test-# end;
test-# /
ANONYMOUS BLOCK
Time: 1345.537 ms (00:01.346)使用绑定变量,但是强制硬解析。用时 4691ms
test=# set plan_cache_mode=force_custom_plan;
SET
Time: 0.318 ms
test=# declare
test-# v_temp integer;
test-# begin
test-# for i in 1..100000 loop
test-# select count(*) into v_temp from tab1 where id=i;
test-# end loop;
test-# end;
test-# /
ANONYMOUS BLOCK
Time: 4691.001 ms (00:04.691)「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




