Solved

Insert into using concantenated index

Posted on 2013-06-25
4
358 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 31

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

760 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

19 Experts available now in Live!

Get 1:1 Help Now