I would like to improve the performance of the following in aggregate query.
On T_Search_Detail with 30 million records, below Query takes 12 seconds to execute? can it be written better, suggestions to improve performance?
Explain Plan:
Execution Plan
----------------------------------------------------------
Plan hash value: 651646209
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3 | 42 | 27948 (1)| 00:05:36 |
| 1 | SORT GROUP BY | | 3 | 42 | 27948 (1)| 00:05:36 |
| 2 | VIEW | | 56 | 784 | 27947 (1)| 00:05:36 |
| 3 | HASH GROUP BY | | 56 | 1344 | 27947 (1)| 00:05:36 |
|* 4 | TABLE ACCESS BY INDEX ROWID| T_SEARCH_DETAIL | 898 | 21552 | 27946 (1)| 00:05:36 |
|* 5 | INDEX RANGE SCAN | INDEX_CREATE_DT | 1254K| | 3451 (1)| 00:00:42 |
--------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("TSD"."MATCH_SOURCE" IS NOT NULL AND "TSD"."MATCH_TYPE" IS NOT NULL AND
"TSD"."MATCH_TYPE" LIKE '%Exact%')
5 - access("TSD"."CREATE_DT">=TO_DATE(' 2012-12-11 00:00:00', 'syyyy-mm-dd
hh24:mi:ss') AND "TSD"."CREATE_DT"<TO_DATE(' 2013-04-23 00:00:00', 'syyyy-mm-dd
hh24:mi:ss'))
Table DDL:
This query uses two tables T_Search and T_Search_detail, with FOREIGN_KEY as match_id.
SELECT ms,
SUM(ct)
FROM ( SELECT tsd.match_source ms,
tsd.match_type mt,
COUNT(tsd.search_id) ct
FROM t_search ts,
t_search_detail tsd
WHERE tsd.match_source IS NOT NULL
AND tsd.match_type IS NOT NULL
AND ts.match_id = tsd.match_id
AND tsd.match_type LIKE '%Exact%'
AND
(
tsd.create_dt >= to_date('12/11/2012', 'MM/DD/YYYY')
AND tsd.create_dt < (to_date('04/22/2013', 'MM/DD/YYYY')+1)
)
GROUP BY tsd.match_source,
tsd.match_type
)
GROUP BY ms
ORDER BY ms DESC