|
终于把89楼改对了,性能测试
loadjava -u rk/rk -v -resolve d:\app\oop3.java
create or replace FUNCTION isprimo(x NUMBER) RETURN NUMBER AS LANGUAGE JAVA NAME 'oop.getisp(int) return int';
/
create or replace FUNCTION init(x NUMBER) RETURN NUMBER AS LANGUAGE JAVA NAME 'oop.init(int) return int';
/
SQL> select count(l) from(select level l, pkg_prim2.isprimj(level)i from dual connect by level<=1000000)where i=0;
COUNT(L)
--------
78499
已用时间: 00: 00: 49.82
SQL>
SQL> select count(l) from(select level l, pkg_prim2.isprim(level)i from dual connect by level<=1000000)where i=0;
COUNT(L)
--------
78498
已用时间: 00: 00: 19.23
SQL> select rk.init(1000000)x from dual;
X
--------
1
已用时间: 00: 00: 00.24
SQL> select count(l) from(select level l, rk.isprimo(level)i from dual connect by level<=1000000)where i=1;
COUNT(L)
--------
78498
已用时间: 00: 00: 13.64
但
with t as (select /*+ MATERIALIZE */ column_value p from table(pkg_prim2.seive_numlist(10000)) where column_value not in (2,5))
, t2 as (select t1.p p1, t2.p p2 from t t1, t t2
where t2.p>t1.p
and isprimo(t1.p||t2.p)=0 and isprimo(t2.p||t1.p)=0)
, t3 as (select t2.p1, t2.p2, t3.p2 p3 from t2, t2 t3, t2 pairs
where t3.p1=t2.p2
and t2.p1=pairs.p1 and t3.p2=pairs.p2
)
, t4 as (select t3.p1, t3.p2, t3.p3, t4.p3 p4 from t3, t3 t4, t2 pairs
where t3.p2=t4.p1 AND t3.p3=t4.p2
and t3.p1=pairs.p1 and t4.p3=pairs.p2
)
, t5 as (select t4.p1, t4.p2, t4.p3, t4.p4, t5.p4 p5 from t4, t4 t5, t2 pairs
where t4.p2=t5.p1 AND t4.p3=t5.p2 AND t4.p4=t5.p3
and t4.p1=pairs.p1 and t5.p4=pairs.p2
)
select p1,p2,p3,p4,p5, p1+p2+p3+p4+p5 total from t5;
20分钟了也不出结果
终于明白错在哪里了,原来我的函数用1表示质数,而tnb用0
SQL> select rk.init(100000000) from dual;
RK.INIT(100000000)
------------------
1
已用时间: 00: 00: 28.11
SQL> @d:\app\oop.txt
P1 P2 P3 P4 P5 TOTAL
-------- -------- -------- -------- -------- --------
13 5197 5701 6733 8389 26033
已用时间: 00: 00: 13.01
SQL> @d:\app\oop1.txt
SQL> /
P1 P2 P3 P4 P5 TOTAL
---------- ---------- ---------- ---------- ---------- ----------
13 5197 5701 6733 8389 26033
已用时间: 00: 00: 16.94
SQL> 3
3* where t2.p>t1.p
SQL> c/>/<
3* where t2.p<t1.p
SQL> /
P1 P2 P3 P4 P5 TOTAL
---------- ---------- ---------- ---------- ---------- ----------
8389 13 5197 5701 6733 26033
已用时间: 00: 00: 17.45
[ 本帖最后由 〇〇 于 2011-1-4 20:01 编辑 ] |
|