Steve Berger
asked on
Improve the Update Query Performance
Hi,
I have written two set of code which will update my staging table after validation. The table can contains more 30000 records. Please let us know which method is good to use and why? Because i am very much bothering about the performance.
Method 1:
Method 2:
I have written two set of code which will update my staging table after validation. The table can contains more 30000 records. Please let us know which method is good to use and why? Because i am very much bothering about the performance.
Method 1:
declare
TYPE sample_tab IS TABLE OF VARCHAR2(100) INDEX BY BINARY_INTEGER;
type_sample_tab sample_tab
begin
SELECT DISTINCT t1.ITEM_NAME
BULK COLLECT INTO type_sample_tab
FROM sample_staging_table t1
WHERE
t1.process_flag = 1
AND t1.request_id = 70440789
AND NOT EXISTS (SELECT
'X'
FROM
qp_list_headers_tl
WHERE
LANGUAGE = 'US'
AND NAME = t1.price_list_name
);
FORALL i IN 1 .. type_sample_tab.COUNT
UPDATE sample_staging_table
SET error_message = 'RECORD NOT EXIST', process_flag = 3
WHERE item_name = type_sample_tab(i)
AND process_flag = 1
AND request_id = 70440789;
end;
Method 2:
UPDATE
XXQP_EPM_PRICE_STG pbs
SET
pbs.process_flag = 3,
pbs.error_message = 'RECORD NOT EXIST'
WHERE
pbs.process_flag = 1
AND pbs.request_id = 70440789
AND NOT EXISTS (SELECT
'X'
FROM
qp_list_headers_tl
WHERE
LANGUAGE = 'US'
AND NAME = pbs.price_list_name
);
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No need to guess. If you want definitive metrics, trace them and run tkprof on the results: 21.4 Using the SQL Trace Facility and TKPROF
http://download.oracle.com/docs/cd/E11882_01/server.112/e16638/sqltrace.htm#PFGRF01020
My guess agrees with angelIII: Method 2.
>>increase the performance and it will not occupy more PGA memory
Where do you think Oracle will store type_sample_tab? In the PGA so it will likely use more PGA not less.
http://download.oracle.com/docs/cd/E11882_01/server.112/e16638/sqltrace.htm#PFGRF01020
My guess agrees with angelIII: Method 2.
>>increase the performance and it will not occupy more PGA memory
Where do you think Oracle will store type_sample_tab? In the PGA so it will likely use more PGA not less.
ASKER
GOOD
ASKER
Method 2 is kind of FOR loop right. So it will check each and every record in the table. But FORALL will update it in onehshot. Please correct me if i am wrong.