|
Insert with a select, Insert with a select |
|
|
|
|
Aug 29 2005, 12:27 PM
|
Advanced Member
  
Group: Members
Posts: 110
Joined: 25-February 05
Member No.: 1,517

|
We are using 10g. I have to load about 15million records or more from staging table into another table. It is a OLTP environment. And it is taking about 1 hrs to do this.
I am doing :
insert into t_so(SO_ID, FIRST_NAME, LAST_NAME, ADDRESS1, ADDRESS2, MIDDLE_INITIAL, CITY_STATE_ZIP_ID) SELECT seq_So.nextval, PCFIRST, PCLAST, substr(PCMINIT, 1,1) PCMINIT, PCPADDR, PCSADDR, pkg_so.fn_get_city_state_zip_id ( PCCITY , PCSTATE, PCZIP5) FROM t_stage;
I optimized the function and there is lot of improvement . Could any of you suggest anything more I could do to improve performance in 10g. Please let me know .
Thanks
|
|
|
|
|
|
|
|
Sep 1 2005, 03:51 AM
|
Newbie

Group: Members
Posts: 7
Joined: 23-August 05
Member No.: 2,785

|
I would try to remove the function and to replace it with a join with a table containing (PCCITY , PCSTATE, PCZIP5, state_zip_id).
For large inserts I would recommand to set the CACHE of you sequence to something like 100.
--------------------
[img]http://www.eff.org/br/br.gif[/img]
|
|
|
|
|
|
|
|
Sep 1 2005, 05:49 PM
|
Advanced Member
  
Group: Members
Posts: 547
Joined: 25-May 05
From: Belleville, MI
Member No.: 2,186

|
Couple of quick points: Regarding "a" in Don's first post in this thread, using parallel programs and each using APPEND will not work. APPEND takes an exclusive TM enqueue. This will cause the other parallel processes to serialize, and you won't gain any benefit. If you want to comine parallel processing and the APPEND hint, use Oracle's parallel DML. (See the PARALLEL hint).
Also, if you're going w/ APPEND, consider putting the table into NOLOGGING mode, which will allow Oracle to avoid almost all redo logging. (I assume the database is in archive log mode. In noarchivelog mode, the redo is automatically avoided when using APPEND, and the NOLOGGING setting is not needed.) If you are considering NOLOGGING, consider the backup and recovery implications before proceeding.
Hope that helps,
-Mark
--------------------
-- Mark J Bobak mark@bobak.net Do you want good, clear answers to your questions? Read THIS BEFORE posting!
|
|
|
|
|
|
|
|
Sep 2 2005, 04:20 AM
|
Newbie

Group: Members
Posts: 7
Joined: 23-August 05
Member No.: 2,785

|
How long does it take to execute the following 2 inserts?
insert /*+ append */ into t_so(SO_ID, FIRST_NAME, LAST_NAME, ADDRESS1, ADDRESS2, MIDDLE_INITIAL, CITY_STATE_ZIP_ID) SELECT seq_So.nextval, PCFIRST, PCLAST, substr(PCMINIT, 1,1) PCMINIT, PCPADDR, PCSADDR, pkg_so.fn_get_city_state_zip_id ( PCCITY , PCSTATE, PCZIP5) FROM t_stage;
insert /*+ append */ into t_so(SO_ID, FIRST_NAME, LAST_NAME, ADDRESS1, ADDRESS2, MIDDLE_INITIAL, CITY_STATE_ZIP_ID) SELECT seq_So.nextval, PCFIRST, PCLAST, substr(PCMINIT, 1,1) PCMINIT, PCPADDR, PCSADDR, 1 FROM t_stage;
--------------------
[img]http://www.eff.org/br/br.gif[/img]
|
|
|
|
|
|
|
|
Sep 2 2005, 07:49 AM
|
Advanced Member
  
Group: Members
Posts: 547
Joined: 25-May 05
From: Belleville, MI
Member No.: 2,186

|
Hmm...actually, parallel DELETE and UPDATE don't work on non-partitioned tables. Parallel INSERT is ok. However, there are other restrictions. No referential integrity, for example. See: http://download-west.oracle.com/docs/cd/B1...ns.htm#CNCPT328for more info.
--------------------
-- Mark J Bobak mark@bobak.net Do you want good, clear answers to your questions? Read THIS BEFORE posting!
|
|
|
|
|
|
|
|
Sep 2 2005, 07:55 AM
|

Advanced Member
  
Group: Members
Posts: 7,063
Joined: 26-January 04
Member No.: 13

|
Hi, Question for Mark, You noted: QUOTE using parallel programs and each using APPEND will not work. APPEND takes an exclusive TM enqueue. This will cause the other parallel processes to serialize, and you won't gain any benefit. Thanks! I have updated my notes. It was my undersanding that APPEND will increase the HWM on each freelist independently, and the TM enqueue would only happen if you forgot to define multiple freelists for the table/indexes. - Does this "APPEND" TM serialization apply when using multiple freelists or freelist groups? - What about Automatic Segment Space Management (bitmap freelists)? The documentation implies that there will not be serialization for free space lookups. Can you educate us, please? TIA!
--------------------
|
|
|
|
|
|
|
|
Sep 2 2005, 09:27 AM
|
Advanced Member
  
Group: Members
Posts: 547
Joined: 25-May 05
From: Belleville, MI
Member No.: 2,186

|
Hi Don,
Blocks which have been allocated to a segment can be in one of three situations:
- Above the HWM. They have never been used, or at least, not been used since the segment was last truncated or moved.
- Below the HWM, on a free list. These are blocks which have (or recently had) some data in them, but based on PCTFREE/PCTUSED settings, have space still available. These blocks will be used for conventional (non-direct) inserts.
- Below the HWM, not on a freelist. These are blocks which have data in them, and based on PCTFREE/PCTUSED settings, do not have enough space available to support other inserts.
Now, when you do a direct-path INSERT, it will allocate blocks *above* the HWM. Therefore, none of those blocks are on a free list. The free list(s) is (are) out of the picture. So, it really doesn't matter how many free lists you have. In the direct-path INSERT case, free lists do not play a role.
As to the TM enqueue, well, any DML or DDL will take a TM enqueue. This is to protect the object's data dictionary definition. Conventional DML will take a TM enqueue in shared mode. DDL takes a TM enqueue in exclusive mode. So, a table that's undergoing DML cannot have DDL executed. (The exclusive mode required for DDL is not compatible with the shared mode the DML session already holds.) However, other conventional DML will be able to proceed, cause a shared mode enqueue is comatible with the shared mode already held. In this way, Oracle allows concurrent DML, while preventing DDL on tables undergoing DML. Now, the direct- path INSERT is a special case. A direct-path INSERT takes a TM enqueue in exclusive mode, the same as DDL does. This prevents all other DML from occurring. Honestly, I don't know enough about the details of the mechanism to clearly explain why this is required. I would speculate it's because otherwise, it would be possible to have direct-path INSERT modifying the HWM, and then (if it were permitted) conventional DML could fill all the blocks on the freelists, causing that session to want to raise the HWM. That would be a problem, cause you'd have two different sessions wanting to raise the HWM at the same time. So, seems to me, you either serialize on the TM enqueue, or, you'd serialize on ST enqueue. (ST=space management transaction enqueue)
As to ASSM, I really don't have much experience w/ that feature yet, however, from the point of view of why a direct-path INSERT requires an exclusive TM enqueue, I think the argument is largely the same. you don't want to concurrent DML sessions trying to concurrently access the HWM.
Hope that's clear and answers your questions,
-Mark
--------------------
-- Mark J Bobak mark@bobak.net Do you want good, clear answers to your questions? Read THIS BEFORE posting!
|
|
|
|
|
|
|
|
Sep 2 2005, 09:29 AM
|
Advanced Member
  
Group: Members
Posts: 547
Joined: 25-May 05
From: Belleville, MI
Member No.: 2,186

|
Whoops, David beat me to it....;-)
--------------------
-- Mark J Bobak mark@bobak.net Do you want good, clear answers to your questions? Read THIS BEFORE posting!
|
|
|
|
|
|
|
|
Sep 2 2005, 01:51 PM
|
Advanced Member
  
Group: Members
Posts: 547
Joined: 25-May 05
From: Belleville, MI
Member No.: 2,186

|
Oh, by the way, Don, in point 'c' in that tip, the example insert statement you give: CODE insert /*+ append */ into customer values ('hello',';there'); is not valid. APPEND only works with Insert into table1 select * from table2; It really doesn't make sense for a single-row insert. -Mark
--------------------
-- Mark J Bobak mark@bobak.net Do you want good, clear answers to your questions? Read THIS BEFORE posting!
|
|
|
|
|
|
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
|