help for not equal and index usage [message #161708] |
Mon, 06 March 2006 18:04 |
mjschwenger
Messages: 137 Registered: July 2005 Location: US
|
Senior Member |
|
|
I have a query bellow. Because of the not equal sign the index on Status is not in use. I receive FTS on Search_result or Search (if I use exists subselect on search_result).
The tables ae growing in the last days and that startedto cause problems.
Please, help me to tune up the query.
Thanks a lot,
mj
SELECT codes.code_desc, search_result.status
AS searchResultStatus, COUNT(*) AS cnt
FROM search_result, search, codes
WHERE search_result.search_id = search.search_id
AND search.reason_code = codes.code
AND search.search_group ='DEFAULT'
AND search.sys_delete_dt IS NULL
AND (search_result.status IS NULL
OR (search_result.status <> 'ASSIGNED'
AND search_result.status <> 'CLOSED'))
AND SEARCH.SYS_EXPIRE_DT >= search.sys_create_dt
GROUP BY codes.code_desc, search_result.status
|
|
|
Re: help for not equal and index usage [message #161717 is a reply to message #161708] |
Mon, 06 March 2006 19:15 |
rleishman
Messages: 3728 Registered: October 2005 Location: Melbourne, Australia
|
Senior Member |
|
|
So, you want the following clause to use an index:AND (search_result.status IS NULL
OR (search_result.status <> 'ASSIGNED'
AND search_result.status <> 'CLOSED')) Right?
I assume that only a small percentage of the table has values other than ASSIGNED and CLOSED. If not, then indexing this clause will not help. When you select a significant proportion (say, >10%) of a table via an index, performance goes DOWN.
You can do it with a function based index, but you will have to change your SQL.CREATE INDEX index_name ON search_result (
decode(status, 'ASSIGNED', NULL, 'CLOSED', NULL, 'Y')
);
And in your SQL:AND decode(search_result.status, 'ASSIGNED', NULL, 'CLOSED', NULL, 'Y') = 'Y'
_____________
Ross Leishman
|
|
|
Re: help for not equal and index usage [message #161867 is a reply to message #161717] |
Tue, 07 March 2006 10:08 |
mjschwenger
Messages: 137 Registered: July 2005 Location: US
|
Senior Member |
|
|
Thank you very much. It's a great idea.
The only problem is if I'll be allowed to use it.
This query runs on Oracle, DB2, and SQL server (from different app versions). Usually I'm not allow to change Oracle if the other 2 cannot be changed similar way... have to check with the other system people.
If I cannot use decode for creating the index, what else I could look to improve the performance?
Thanks a lot again, mj
|
|
|
|
Re: help for not equal and index usage [message #162104 is a reply to message #161908] |
Wed, 08 March 2006 15:10 |
mjschwenger
Messages: 137 Registered: July 2005 Location: US
|
Senior Member |
|
|
Well, It looks I'm even in a bigger trouble...
I cannot change the table structure as this is a third party product and I do not have right to touch any of their tables.
I cannot use IN() clause as this statuses are user defined and can change at any time through the GUI except the 2 bellow.
I guess, I got to accept that there's no better solution then the regular indexes I have now...
Thanks a lot Ross, it was a great help.
mj
|
|
|