1 | drop table testdata;
|
---|
2 |
|
---|
3 | create table testdata (
|
---|
4 | id number primary key,
|
---|
5 | streetname varchar2(100),
|
---|
6 | streetno varchar2(10)
|
---|
7 | );
|
---|
8 |
|
---|
9 | -- Create testdata
|
---|
10 | declare
|
---|
11 | type name_va is varray(5) of VARCHAR2(100);
|
---|
12 | v_street1 name_va;
|
---|
13 | v_street2 name_va;
|
---|
14 | id number;
|
---|
15 | begin
|
---|
16 | id := 1;
|
---|
17 | v_street1 := name_va('Fancy', 'Django', 'Pink Pony');
|
---|
18 | v_street2 := name_va('Street', 'Way', 'Alley');
|
---|
19 | for a in v_street1.first..v_street1.last
|
---|
20 | loop
|
---|
21 | for b in v_street2.first..v_street2.last
|
---|
22 | loop
|
---|
23 | for c in 1..100
|
---|
24 | loop
|
---|
25 | insert into testdata(id, streetname, streetno) values (id, v_street1(a) || ' ' || v_street2(b), c);
|
---|
26 | id := id + 1;
|
---|
27 | end loop;
|
---|
28 | commit;
|
---|
29 | end loop;
|
---|
30 | end loop;
|
---|
31 | end;
|
---|
32 | /
|
---|
33 |
|
---|
34 | commit;
|
---|
35 |
|
---|
36 | create index ix_streetname on testdata(streetname);
|
---|
37 | create index ix_streetno on testdata(streetno);
|
---|
38 |
|
---|
39 | -- Make sure that statistics are computed.
|
---|
40 | analyze table testdata compute statistics;
|
---|
41 |
|
---|
42 | -- Clean plan table
|
---|
43 | delete from plan_table;
|
---|
44 |
|
---|
45 | -- Explain what happens
|
---|
46 | explain plan for select * from testdata where streetname like 'Fancy%';
|
---|
47 |
|
---|
48 | -- Show results
|
---|
49 | select
|
---|
50 | substr (lpad(' ', level-1) || operation || ' (' || options || ')',1,30 ) "Operation",
|
---|
51 | object_name "Object"
|
---|
52 | from
|
---|
53 | plan_table
|
---|
54 | start with id = 0
|
---|
55 | connect by prior id=parent_id;
|
---|
56 |
|
---|
57 | -- Should return:
|
---|
58 | --SELECT STATEMENT ()
|
---|
59 | -- TABLE ACCESS (BY INDEX ROWID) TESTDATA
|
---|
60 | -- INDEX (RANGE SCAN) IX_STREETNAME
|
---|
61 |
|
---|
62 | -- Clean plan table
|
---|
63 | delete from plan_table;
|
---|
64 |
|
---|
65 | -- Explain what happens
|
---|
66 | explain plan for select * from testdata where streetname likec 'Fancy%';
|
---|
67 |
|
---|
68 | -- Show results
|
---|
69 | select
|
---|
70 | substr (lpad(' ', level-1) || operation || ' (' || options || ')',1,30 ) "Operation",
|
---|
71 | object_name "Object"
|
---|
72 | from
|
---|
73 | plan_table
|
---|
74 | start with id = 0
|
---|
75 | connect by prior id=parent_id;
|
---|
76 |
|
---|
77 | -- Should return:
|
---|
78 | -- SELECT STATEMENT ()
|
---|
79 | -- TABLE ACCESS (FULL) TESTDATA
|
---|