Solved

Insert into using concantenated index

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle RAC 12c 8 74
Consolidating oracle query results to a single line 8 60
'G_F01' is not a procedure or is undefined 3 26
make null the repeated levels 2 25
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

831 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