22:02:22 SYSTEM@dwal> ed
Wrote file S:\spool\dwal\BUFFER_SYSTEM_386.sql
1 declare
2 type t is table of dual%rowtype;
3 c1 t := t();
4 c2 t := t();
5 begin
6 c1.extend;
7 c1(1).dummy := 'a';
8 c2.extend(2);
9 c2(1).dummy := 'b';
10 c2(2).dummy := 'c';
11 c2 := c1 multiset union all c2;
12 for i in c2.first .. c2.last loop
13 dbms_output.put_line(c2(i).dummy);
14 end loop;
15* end;
22:02:41 SYSTEM@dwal> /
a
b
c
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.26
upd:我从来没有机会对多集操作进行基准测试,aaaaaand,尽管体积很大,但它们实际上似乎更慢:
22:14:56 SYSTEM@dwal> ed
Wrote file S:\spool\dwal\BUFFER_SYSTEM_331.sql
1 declare
2 cnt int := 1e5;
3 type t is table of dual%rowtype;
4 c1 t := t();
5 c2 t := t();
6 timer int;
7 procedure prebuild as
8 begin
9 c1.delete;
10 c2.delete;
11 c1.extend(cnt);
12 c2.extend(cnt);
13 for i in 1 .. cnt loop
14 c1(i).dummy := dbms_random.string('l', 1);
15 c2(i).dummy := dbms_random.string('l', 1);
16 end loop;
17 end;
18 begin
19 -- 1
20 prebuild;
21 timer := dbms_utility.get_cpu_time;
22 for i in 1 .. cnt loop
23 c2.extend;
24 c2(c2.last) := c1(i);
25 end loop;
26 dbms_output.put_line(dbms_utility.get_cpu_time - timer);
27 -- 2
28 prebuild;
29 timer := dbms_utility.get_cpu_time;
30 c2 := c2 multiset union all c1;
31 dbms_output.put_line(dbms_utility.get_cpu_time - timer);
32 -- 3
33 prebuild;
34 timer := dbms_utility.get_cpu_time;
35 c2.extend(c1.count);
36 for i in 1 .. cnt loop
37 c2(c2.count - c1.count + i) := c1(i);
38 end loop;
39 dbms_output.put_line(dbms_utility.get_cpu_time - timer);
40* end;
22:15:00 SYSTEM@dwal> /
15
25
10
PL/SQL procedure successfully completed.
Elapsed: 00:00:03.38
这些数字相当稳定。第三种方法,它只扩展第二个集合一次,然后附加到它,似乎是最快的一种。