Sql 这个Oracle查询需要多少额外的计算时间?

Sql 这个Oracle查询需要多少额外的计算时间?,sql,plsql,oracle11g,Sql,Plsql,Oracle11g,我正在编写pl/sql代码。以下两种方法的计算时间请提供帮助 方法1: if count(x)>1 then select sum(price) into vprice from table1 where x between var1 and var2; else select price into vprice from table1 where x=var1; end; 方法2: select sum(price) from table1 where x between va

我正在编写pl/sql代码。以下两种方法的计算时间请提供帮助

方法1:

if count(x)>1
then
  select sum(price) into vprice from table1 where x between var1 and var2;
else
  select price into vprice from table1 where x=var1;
end;
方法2:

select sum(price) from table1 where x between var1 and var2;
我们正在根据其他条件确定代码上方某个地方的var1和var2的值。在大约五分之四的情况下,var1和var2的值将是相同的


注意:请忽略任何语法或逻辑错误。我试图了解我的程序中发生了什么,以了解实现更高效率的更好方法。

上面给出了估计的执行计划,以获得实际结果-或者,您可以使用“您不能测试”来找出答案吗?Method1似乎根据某个值执行两个查询中的一个。如果countx>1不是有效的PL/SQL,我知道您说过要忽略它,但我不知道它试图做什么。Method2似乎与Method1中的第一个查询相似。这两个“方法”与“计算时间”有什么关系,不管是什么,都还不清楚。我假设您在问,使用=而不是between(如果有的话)所节省的时间是否被额外的PL/SQL逻辑所抵消,以决定遵循哪个分支?
DECLARE
    tsStartTime TIMESTAMP;
    tsEndTime TIMESTAMP;
BEGIN
    -- Start the timer
    tsStartTime := CURRENT_TIMESTAMP;
    DBMS_OUTPUT.PUT_LINE(tsStartTime);

    -- DO SOMETHING HERE WHICH YOU WANT TO TIME <------

    -- Display some information, and how long "something" took
    tsEndTime := CURRENT_TIMESTAMP;
    DBMS_OUTPUT.PUT_LINE(tsEndTime);

    DBMS_OUTPUT.PUT_LINE('Time elapsed:' || to_char(tsEndTime - tsStartTime));
END;
/
EXPLAIN PLAN FOR select sum(price) from table1 where x between var1 and var2;
SELECT * FROM TABLE (dbms_xplan.display); -- take this output and compare it to the next one

EXPLAIN PLAN FOR select price from table1 where x=var1;
SELECT * FROM TABLE (dbms_xplan.display); -- compare it to this output