SQL Query performance Tuning [message #668656] |
Thu, 08 March 2018 00:38 |
|
saketsingare
Messages: 1 Registered: March 2018
|
Junior Member |
|
|
SELECT /* ORDERED (hxc tbb_det tbb_day) */
TO_CHAR (tbb_day.start_time, 'DD-MON-RRRR') Start_Date,
LPAD (TO_CHAR (tbb_day.start_time, 'RRRRMMDD'), 8, '0') slno,
tbb_day.start_time,
tbb_det.resource_id,
TRUNC (hxc.stop_time) stop_time,
tbb_det.resource_type,
tbb_det.measure tot_hrs,
( ( TO_CHAR (
TRUNC (SYSDATE) + (tbb_det.stop_time - tbb_det.start_time),
'HH24')
* 60)
+ TO_CHAR (
TRUNC (SYSDATE) + (tbb_det.stop_time - tbb_det.start_time),
'MI'))
/ 60
TIME,
tbb_det.unit_of_measure uom,
tbb_det.time_building_block_id,
tbb_det.object_version_number parent_building_block_ovn
FROM hxc_time_building_blocks tbb_day,
hxc_time_building_blocks tbb_det,
hxc_timecard_summary hxc,
HXC_TIME_ATTRIBUTE_USAGES HTAU,
HXC_TIME_ATTRIBUTES HTA,
PAY_ELEMENT_TYPES_F PETF
WHERE tbb_det.scope = 'DETAIL'
AND tbb_day.scope = 'DAY'
AND tbb_det.date_to = hr_general.end_of_time
AND tbb_det.parent_building_block_ovn = tbb_day.object_version_number
AND tbb_det.parent_building_block_id = tbb_day.time_building_block_id
AND tbb_day.parent_building_block_ovn = hxc.timecard_ovn
AND tbb_day.parent_building_block_id = hxc.timecard_id
AND TRUNC (tbb_day.start_time) >= ( :P_START_DATE)
AND TRUNC (tbb_day.stop_time) <= ( :P_END_DATE)
AND TBB_DET.TIME_BUILDING_BLOCK_ID = HTAU.TIME_BUILDING_BLOCK_ID
AND TBB_DET.object_version_number = HTAU.TIME_BUILDING_BLOCK_OVN
AND HTAU.TIME_ATTRIBUTE_ID = HTA.TIME_ATTRIBUTE_ID
AND HTA.ATTRIBUTE_CATEGORY = 'ELEMENT - ' || PETF.ELEMENT_TYPE_ID
AND PETF.ELEMENT_NAME = 'Total Payroll Hours'
[EDITED by LF: formatted code, applied [code] tags]
[Updated on: Thu, 08 March 2018 01:23] by Moderator Report message to a moderator
|
|
|
|
|
|
Re: SQL Query performance Tuning [message #668662 is a reply to message #668661] |
Thu, 08 March 2018 03:07 |
cookiemonster
Messages: 13960 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
One obvious thing to do is get rid of the truncs in the where clause. This:
AND TRUNC (tbb_day.start_time) >= ( :P_START_DATE)
AND TRUNC (tbb_day.stop_time) <= ( :P_END_DATE)
can be written as:
AND tbb_day.start_time >= :P_START_DATE
AND tbb_day.stop_time < :P_END_DATE + 1
Then if there are indexes on start_time and/or stop_time oracle can use them and even if there isn't you're still skipping a load of unnecessary function calls.
Past that you need to provide mores details as the others already mentioned.
|
|
|
Re: SQL Query performance Tuning [message #668663 is a reply to message #668661] |
Thu, 08 March 2018 03:08 |
cookiemonster
Messages: 13960 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
mist598 wrote on Thu, 08 March 2018 08:41Hi
Please run the query with one parameter (Time Card id) and see how many rows and how much time it is taking.
It's not obvious what you mean by that, since the posted query doesn't have a card id parameter, and it's certainly not obvious what you think it'll prove.
|
|
|
Re: SQL Query performance Tuning [message #668664 is a reply to message #668663] |
Thu, 08 March 2018 03:13 |
cookiemonster
Messages: 13960 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
This lpad:
LPAD (TO_CHAR (tbb_day.start_time, 'RRRRMMDD'), 8, '0')
is completely pointless. That to_char always returns 8 digits, even if the year is before 1000 A.D.
SQL> select to_char(to_date('1', 'YYYY'), 'RRRRMMDD') from dual;
TO_CHAR(TO_DATE('1','YYYY'),'R
------------------------------
00010301
|
|
|
|
|
Re: SQL Query performance Tuning [message #668761 is a reply to message #668688] |
Tue, 13 March 2018 09:21 |
|
msol25
Messages: 396 Registered: June 2011
|
Senior Member |
|
|
Hi,
Please share the explain plan for the query. Please use below steps for generating explain plan:
//Generate query explain plan
EXPLAIN PLAN FOR
<select query>
//query for formatted explain plan output
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY);
|
|
|