Ticket #11017: index_testing.sql

File index_testing.sql, 2.0 KB (added by Jani Tiainen, 15 years ago)

Script to test index usage in case of LIKE and LIKEC

Line 
1drop table testdata;
2
3create table testdata (
4 id number primary key,
5 streetname varchar2(100),
6 streetno varchar2(10)
7);
8
9-- Create testdata
10declare
11 type name_va is varray(5) of VARCHAR2(100);
12 v_street1 name_va;
13 v_street2 name_va;
14 id number;
15begin
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;
31end;
32/
33
34commit;
35
36create index ix_streetname on testdata(streetname);
37create index ix_streetno on testdata(streetno);
38
39-- Make sure that statistics are computed.
40analyze table testdata compute statistics;
41
42-- Clean plan table
43delete from plan_table;
44
45-- Explain what happens
46explain plan for select * from testdata where streetname like 'Fancy%';
47
48-- Show results
49select
50 substr (lpad(' ', level-1) || operation || ' (' || options || ')',1,30 ) "Operation",
51 object_name "Object"
52from
53 plan_table
54start with id = 0
55connect 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
63delete from plan_table;
64
65-- Explain what happens
66explain plan for select * from testdata where streetname likec 'Fancy%';
67
68-- Show results
69select
70 substr (lpad(' ', level-1) || operation || ' (' || options || ')',1,30 ) "Operation",
71 object_name "Object"
72from
73 plan_table
74start with id = 0
75connect by prior id=parent_id;
76
77-- Should return:
78-- SELECT STATEMENT ()
79-- TABLE ACCESS (FULL) TESTDATA
Back to Top