Solved

Insert into using concantenated index

Posted on 2013-06-25
4
359 Views
Last Modified: 2013-06-25
I have two tables:
SourceTable
-----------------
Name
ExpDate
Type
OtherStuff

MasterTable
-----------------
Name
ExpDate
Type

We would like to take the info from SourceTable to Master Table where the incoming three fields do not exist in Master.
We placed a concantenated index on Master for these fields thinking it would be faster somehow.  But it looks like we are forced to do something like:
Insert into MasterTable.....
where
 (Name || ExpDate || Type)  
Not in
(select  (Name || ExpDate || Type)  from MasterTable)

Seems like the index is really useless.
What's the fastest way to accomplish this?
0
Comment
Question by:GNOVAK
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 39275424
Given the information provided, I would start out with:

insert into master
select name, expdate, type from source
minus
select name, expdate, type from master
/
0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 500 total points
ID: 39275435
Probably better, use MERGE:

merge into master mas
using (
	select name, expdate, type from source
) src
on (
	src.name = mas.name and
	src.expdate = mas.expdate and
	src.type = mas.type
)
when not matched then
	insert (mas.name, mas.expdate, mas.type) values (src.name, src.expdate, src.type)
;

Open in new window

0
 

Author Closing Comment

by:GNOVAK
ID: 39275666
Thanks ! Great examples.
0
 
LVL 32

Expert Comment

by:awking00
ID: 39275670
Indexes improve performance when data is being retrieved. So, to do the inserts you should have an index on the source table. And there is no need for a concatenated index, just use a compound index. For example, create index src_idx on sourcetable(name, expdate, type). Any index on the mastertable would assist in query performance but actually reduce performance on the inserts. It is fairly normal to disable indexes on target tables during inserts and rebuilding them after inserts are completed.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to recover a database from a user managed backup

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now