Subject Any Suggestion(s)?
Author Tom Conlon
Hi All,

If anyone can assist speeding up this query I'd appreciate it.

CREATE TABLE CONTSKILL
(
SKILLID INTEGER NOT NULL,
CONTID INTEGER NOT NULL,
RATING SMALLINT DEFAULT 9999 NOT NULL
);
ALTER TABLE CONTSKILL ADD CONSTRAINT PK_CONTSKILL PRIMARY KEY (CONTID,
SKILLID);
CREATE UNIQUE INDEX IDXCONTSKILL ON CONTSKILL (SKILLID, RATING, CONTID);

Note:
The original metadata consisted of the following but was changed as
per advice from this group:
ALTER TABLE CONTSKILL ADD CONSTRAINT PK_CONTSKILL PRIMARY KEY
(SKILLID, CONTID);
ALTER TABLE CONTSKILL ADD CONSTRAINT FK_CONTSKILL1 FOREIGN KEY
(SKILLID) REFERENCES SKILL (ID);
ALTER TABLE CONTSKILL ADD CONSTRAINT FK_CONTSKILL2 FOREIGN KEY
(CONTID) REFERENCES CONT (CONTID);


SELECT DISTINCT c.contid, c.surname, c.forename, c.dob, c.postcode,
c.filed, c.available, c.email
FROM cont c
JOIN contskill t1 ON (c.contid=t1.contid) AND (t1.skillid=10 )
where exists
(select distinct t2.contid
from contskill t2
JOIN contskill t3 ON (c.contid=t3.contid) AND (t3.skillid=18 )
JOIN contskill t4 ON (c.contid=t4.contid) AND (t4.skillid=22 )
JOIN contskill t5 ON (c.contid=t5.contid) AND (t5.skillid=24 )
JOIN contskill t6 ON (c.contid=t6.contid) AND (t6.skillid=29 )
JOIN contskill t7 ON (c.contid=t7.contid) AND (t7.skillid=30 )
JOIN contskill t8 ON (c.contid=t8.contid) AND (t8.skillid=34 )
JOIN contskill t9 ON (c.contid=t9.contid) AND (t9.skillid=4209 )
JOIN contskill t10 ON (c.contid=t10.contid) AND (t10.skillid=62 )
where (t1.contid=t2.contid) AND (t2.skillid=17 )
)

------ 1st time ran: Performance info ------
PLAN SORT (JOIN (T2 INDEX (PK_CONTSKILL),T10 INDEX (PK_CONTSKILL),T9
INDEX (PK_CONTSKILL),T8 INDEX (PK_CONTSKILL),T7 INDEX
(PK_CONTSKILL),T6 INDEX (PK_CONTSKILL),T5 INDEX (PK_CONTSKILL),T4
INDEX (PK_CONTSKILL),T3 INDEX (PK_CONTSKILL))) PLAN SORT (JOIN (T1
INDEX (IDXCONTSKILL),C INDEX (PK_CONT)))


Prepare time = 125ms
Execute time = 2m 13s 469ms
Current memory = 3,796,832
Max memory = 3,846,572
Memory buffers = 10,000
Reads from disk to cache = 21,324
Writes from cache to disk = 0
Fetches from cache = 131,681


------ 2nd time ran: Performance info ------
PLAN SORT (JOIN (T2 INDEX (PK_CONTSKILL),T10 INDEX (PK_CONTSKILL),T9
INDEX (PK_CONTSKILL),T8 INDEX (PK_CONTSKILL),T7 INDEX
(PK_CONTSKILL),T6 INDEX (PK_CONTSKILL),T5 INDEX (PK_CONTSKILL),T4
INDEX (PK_CONTSKILL),T3 INDEX (PK_CONTSKILL))) PLAN SORT (JOIN (T1
INDEX (IDXCONTSKILL),C INDEX (PK_CONT)))

Prepare time = 62ms
Execute time = 594ms

Thanks,
Tom