Sequence and INSERT ALL INTO with parallelism problem
I want to use the INSERT ALL INTO style of multiple-inserts (with 10gR2) to normalize a wide table into a skinny table. The large table has a few fk columns and 100 numeric columns. I want to insert them into another table as 100 rows in a single SQL pass.
CREATE TABLE WIDE_SOURCE(
FKEY_1 INTEGER,
FKEY_2 INTEGER,
FKEY_3 INTEGER,
AMT001 INTEGER,
AMT002 INTEGER,
AMT100 INTEGER);
CREATE TABLE SKINNY_DEST(
PKEY INTEGER NOT NULL,
FKEY_1 INTEGER,
FKEY_2 INTEGER,
FKEY_3 INTEGER,
AMT INTEGER,
CONSTRAINT PK_SKINNY_DEST PRIMARY KEY(PKEY)
CREATE SEQUENCE KEY_GEN MINVALUE 1 INCREMENT BY 100 START WITH 1;
INSERT ALL
INTO SKINNY_DEST VALUES(KEY_GEN.NEXTVAL+001, FKEY_1, FKEY_2, FKEY_3, AMT001)
INTO SKINNY_DEST VALUES(KEY_GEN.NEXTVAL+002, FKEY_1, FKEY_2, FKEY_3, AMT002)
INTO SKINNY_DEST VALUES(KEY_GEN.NEXTVAL+003, FKEY_1, FKEY_2, FKEY_3, AMT003)
INTO SKINNY_DEST VALUES(KEY_GEN.NEXTVAL+100, FKEY_1, FKEY_2, FKEY_3, AMT100)
SELECT * FROM WIDE_SOURCE;
With this query, each row in WIDE_SOURCE will generate 100 rows in SKINNY_DEST. I know that works. Unfortunately, it appears that the sequence isn't working the way I thought it should- with multiple nodes and parallel insert, there's some overlap in the generated key.
Is there a better way? I've considered 100 separate sequences, but that just seems plain silly. Am I trying to have my cake (the parallelism) and eat it too (by disregarding limitations of Oracle's sequence construct)?
Have not tested this on a RAC, but it seems to work fine - as expected without any overlaps. (version 10.2.0.1.0)
SQL> create sequence seq_id start with 1 increment by 10 nomaxvalue nocycle;
Sequence created.
SQL> create table skinny ( id number, fk_key1 number );
Table created.
SQL> create table wide( fk_key1 number, name varchar2(32) ) parallel( degree 2 );
Table created.
SQL> insert into wide select object_id, object_name from all_objects where rownum < 100000;
51853 rows created.
SQL> commit;
Commit complete.
SQL> exec DBMS_STATS.Gather_Table_Stats( USER, 'WIDE' );
PL/SQL procedure successfully completed.
SQL> alter session enable parallel dml;
Session altered.
SQL> set autotrace on
SQL> insert all
2 into skinny values( seq_id.nextval+0, fk_key1 )
3 into skinny values( seq_id.nextval+1, fk_key1 )
4 into skinny values( seq_id.nextval+2, fk_key1 )
5 into skinny values( seq_id.nextval+3, fk_key1 )
6 into skinny values( seq_id.nextval+4, fk_key1 )
7 into skinny values( seq_id.nextval+5, fk_key1 )
8 into skinny values( seq_id.nextval+6, fk_key1 )
9 into skinny values( seq_id.nextval+7, fk_key1 )
10 into skinny values( seq_id.nextval+8, fk_key1 )
11 into skinny values( seq_id.nextval+9, fk_key1 )
12 select
13 /*+ FULL(o) PARALLEL(w,2) */
14 fk_key1
15 from wide w
16 /
518530 rows created.
Execution Plan
Plan hash value: 1585486391
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | TQ |IN-OUT| PQ Distrib |
| 0 | INSERT STATEMENT | | 51853 | 253K| 37 (14)| 00:00:01 | | | |
| 1 | MULTI-TABLE INSERT | | | | | | | | |
| 2 | INTO | SKINNY | | | | | | | |
| 3 | INTO | SKINNY | | | | | | | |
| 4 | INTO | SKINNY | | | | | | | |
| 5 | INTO | SKINNY | | | | | | | |
| 6 | INTO | SKINNY | | | | | | | |
| 7 | INTO | SKINNY | | | | | | | |
| 8 | INTO | SKINNY | | | | | | | |
| 9 | INTO | SKINNY | | | | | | | |
| 10 | INTO | SKINNY | | | | | | | |
| 11 | INTO | SKINNY | | | | | | | |
| 12 | SEQUENCE | SEQ_ID | | | | | | | |
| 13 | PX COORDINATOR | | | | | | | | |
| 14 | PX SEND QC (RANDOM)| :TQ10000 | 51853 | 253K| 37 (14)| 00:00:01 | Q1,00 | P->S | QC (RAND) |
| 15 | PX BLOCK ITERATOR | | 51853 | 253K| 37 (14)| 00:00:01 | Q1,00 | PCWC | |
| 16 | TABLE ACCESS FULL| WIDE | 51853 | 253K| 37 (14)| 00:00:01 | Q1,00 | PCWP | |
Statistics
37168 recursive calls
26542 db block gets
7610 consistent gets
0 physical reads
12696752 redo size
498 bytes sent via SQL*Net to client
1084 bytes received via SQL*Net from client
6 SQL*Net roundtrips to/from client
3 sorts (memory)
0 sorts (disk)
518530 rows processed
SQL> set autotrace off
SQL> commit;
Commit complete.
SQL> select
2 id, count(*)
3 from skinny
4 group by id
5 having count(*) > 1
6 /
no rows selected
SQL>
I checked the PQ V$ views and PQ slaves were used.
Similar Messages
-
Hi,
WIFI stopped working after I woke the computer up, now says connected to the network but not the internet, all other coputers and devices connected still with no problems, have pinged IP address from router and got the message "4 packets sent none received"... Help
I have tried network diagnostics which doesnt help... The only other ting is, when I woke the computer up it said tat another device was using my IP... My wife had plugged her phone into the computer to charge etc but even when i turn wifi off on the phone there is no change... also in settings on the phone the IP address is different...The answer to your question is - neither!
Your PC should to configured to obtain an IP address automatically, and to obtain DNS server IP addresses automatically, from the Airport Express. This is the way Windows (and Macs for that matter) are configued by default, and that is the way most people have their computers set up. If you manually configured your PC's IP address to be the same as your wife's Mac, it certainly explains why your PC is not able to access the internet. -
I have a wireless network at home. I run my iphone and ipad on it with no problems. Just purchased a MacBook Pro, and now my wi-fi keeps disconnecting and i get an error message saying another device is using the same IP address. What does all this mean?
Hello AKCamus
To give you some ideas of what to do next, I have provided a few articles that will give some troubleshooting Wi-Fi connections and recommended Wi-Fi settings.
iOS and OS X: Recommended settings for Wi-Fi routers and access points
http://support.apple.com/kb/HT4199
iOS: Troubleshooting Wi-Fi networks and connections
http://support.apple.com/kb/ts1398
Troubleshooting Wi-Fi issues in OS X Lion and Mac OS X v10.6
http://support.apple.com/kb/HT4628
Thanks for using Apple Support Communities.
Regards,
-Norm G. -
I want to cut out a head from a photo and insert it into another photo again. In the head hair flying in the wind and the blue sky can be seen between the hairs. This blue sky I want to remove, so I can only use the head with hair flying in another photo. Is it possible to simply delete this blue color of the sky?
Make your selection and then use Refine Edge.
See this video tutorial from Bob Gager.
https://www.youtube.com/watch?v=xrl3Qwg6zSc -
how to get all how to get all paragraphs style and their fonts of a indesign file and write all info with para info into txt file with scriptingstyle and their fonts of a indesign file and write all info with para info into txt file with scripting
I write the script this one works
var par=doc.stories.everyItem().paragraphs.everyItem().getElements();
for(var i=par.length-1;i>=0;i--)
var font=par[i].appliedParagraphStyle.name;
var font1=par[i].appliedFont.name;
var size=par[i].pointSize;
WriteToFile (par[i].contents + "\r" + "Style : " + font + "\r" + "FONT1 : " + font1 + "\r" + "Size : " + size + "\r", reportFilePath);
function WriteToFile(text, reportFilePath) {
file = new File(reportFilePath);
file.encoding = "UTF-8";
if (file.exists) {
file.open("e");
file.seek(0, 2);
else {
file.open("w");
file.writeln(text);
file.close();
Thanks for all your support -
Data from table in xml Format and Inserting it into Table
Hi All
I have table where xml data is stored in long format with xml tag know i have read the entire xml xoulmn which is xml tag and insert it into diffrent table can any suggest me the code
Thanks & RegardsI believe you are on the wrong forum. You want the XML DB forum.
See:
XML DB -
Hi,
I'm using a sequence in INSERT ALL statement. I want to insert multiple rows using a sequence number which will be generating the unique values for my table. But as far as i know, Oracle treats all occurances of a seq.nextval as a single reference and all of them retains the same value and not different one. My query is as below.
insert all
into t1(c1, c2) values (seq_1.nextval, 'A')
into t1(c1, c2) values (seq_1.nextval, 'B')
select * from dual;
select * from t1;
C1 C2
8 A
8 B
Can some one tell me how can i have different values for each row in insert all statement?Create a function:
SQL> create or replace
2 function get_seq_1
3 return number
4 is
5 v_ret number;
6 begin
7 select seq_1.nextval into v_ret from dual;
8 return v_ret;
9 end;
10 /
Function created.
SQL> insert all
2 into t1(c1, c2) values (seq_1.nextval, 'A')
3 into t1(c1, c2) values (seq_1.nextval, 'B')
4 select * from dual;
2 rows created.
SQL>
SQL> select * from t1;
C1 C2
1 A
1 B
SQL> insert all
2 into t1(c1, c2) values (get_seq_1, 'A')
3 into t1(c1, c2) values (get_seq_1, 'A')
4 select * from dual;
2 rows created.
SQL> select * from t1;
C1 C2
1 A
1 B
2 A
3 A
SQL> SY. -
Hello all,
I'm pulling my hair out--thank you for any help you can give
me.
I have a form that a person fills out that has a field that
asks "How
many visitors including you" and I'd like them to type in a
number, and
on submit of the form, have that value -2 multiplied by 20
and inserted
into a "total cost" column.
I'm using the standard DW server behaviors and I've searched
the
internet. How do I perform basic math on that value and
insert it into
the database?
If you have any pointers, that would be great.
Thank you!
-JohnJohn R. Lenz wrote:
> Your code below works great, and I just noticed links to
your book were
> available on your web site, and it's in the mail to me.
Looking forward
> to it.
Thanks, hope you find it useful.
> After the form is posted, I'd like to address the person
who posted it
> by their first name and last name, as well as some of
the details. How
> would you go about doing this in the best way? Would you
set a variable
> and echo it on the 'Thank you' page, or are there better
ways of doing
> it with a recordset and filtering it on form submit?
To pass the details to a thank you page, you would need to
store the
information in $_SESSION variables. You could amend the
earlier script
like this:
<?php
session_start();
if (isset($_POST['visitors'])) {
if ($_POST['visitors'] < 3) {
$num = 0;
} else {
$num = $_POST['visitors'] - 2;
$_POST['total_cost'] = $num * 20;
$_SESSION['total_cost'] = $_POST['total_cost'];
$_SESSION['first_name'] = $_POST['first_name'];
$_SESSION['last_name'] = $_POST['last_name'];
?>
In the thank you page, put the following at the top of the
page:
<?php session_start(); ?>
It must go before anything is output to the browser, so put
it above the
DOCTYPE declaration, and make sure there's no space before
it.
You can then use the $_SESSION variables in the thank you
page.
At the end of the page, add this to clear up the session
variables:
<?php
$_SESSION = array();
destroy_session();
?>
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of
ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/ -
Difference between Insert and Insert all
Hi,
I tried to understand what INSERT ALL syntax is doing, but I cannot find any difference between INSERT and INSERT ALL.
I replicated the test scenario using the data from the below mentioned URL:
http://psoug.org/reference/insert.html
I also did a google on finding up the difference between them, but could not find any...
Please advice if both are same as I have planned to use INSERT statement with a WHEN clause if INSERT ALL is same as INSERT.
Thanks!Hello
The key difference is that INSERT ALL will allow you to insert into multiple different tables in a single statement whereas INSERT will only insert into 1 table. Each of the WHEN clauses allows a different table to be specified.
SQL> create table t1
2 ( id number
3 )
4 /
Table created.
Elapsed: 00:00:00.01
SQL> create table t2
2 ( id number
3 )
4 /
Table created.
Elapsed: 00:00:00.00
SQL> create table t3
2 ( id number
3 )
4 /
Table created.
SQL> INSERT
2 ALL
3 WHEN id < 10 THEN
4 INTO t1 VALUES(id)
5 WHEN MOD(id,2) = 0 THEN
6 INTO t2 VALUES(id)
7 WHEN MOD(id,2) != 0 THEN
8 INTO t3 VALUES(id)
9 SELECT
10 rownum id
11 FROM
12 dual
13 CONNECT BY
14 LEVEL <=20
15 /
29 rows created.
Elapsed: 00:00:00.01
SQL> select * from t1;
ID
1
2
3
4
5
6
7
8
9
9 rows selected.
Elapsed: 00:00:00.01
SQL> select * from t2;
ID
2
4
6
8
10
12
14
16
18
20
10 rows selected.
Elapsed: 00:00:00.00
SQL> select * from t3
2 /
ID
1
3
5
7
9
11
13
15
17
19
10 rows selected.
Elapsed: 00:00:00.01So you can see that in a single statement, I've inserted all rows with an ID <10 into t1, all even numbered rows into t2 and all odd numbered rows into t3. This was also done with a single pass of the source table - in this case dual.
David -
I am having a lot of trouble downloading itunes.My latest error message is that MediaToolbox.dll is missing. I have been trying to fix this for three days now .And it all started with the last update .Can anyone help?
Taken at face value, you're having trouble with an Apple Application Support program file there. (Apple Application Support is where single copies of program files used by multiple different Apple programs are kept.)
Let's try something relatively simple first. Restart the PC. If you're using Vista or 7, now head into your Uninstall a program control panel, select "Apple Application Support" and then click "Repair". If you're using XP, head into your Add or Remove Programs control panel, select "Apple Application Support", click "Change" and then click "Repair".
If no joy after that, try the more rigorous uninstall/reinstall procedure from the following post. (If you've got XP, although the procedure is for Vista and 7, just read "Computer" as "My Computer", read "Uninstall a program control panel" as "Add or Remove programs control panel" and assume the system is 32-bit, and you'll be doing the right things.)
Re: I recently updated to vista service pack 2 and I updated to itunes 10.2.1 and ever -
Drop, create and insert data into few intermediate tables
Hi All,
I need to schedule a process to drop, create and insert data into few intermediate tables on a weekly basis. Here is what i need to do in the stored procedure, which can be scheduled weekly.
DROP TABLE TABLE_NAME1;
DROP TABLE TABLE_NAME2;
DROP TABLE TABLE_NAME3;
CREATE TABLE TABLE_NAME1
CREATE TABLE TABLE_NAME2
CREATE TABLE TABLE_NAME3
INSERT INTO TABLE_NAME1 SELECT ....;
INSERT INTO TABLE_NAME2 SELECT ....;
INSERT INTO TABLE_NAME3 SELECT ....;
Any suggestions, examples or code on how to accomplish this task would be very helpful. Any question pls let me know.
Thanks in advance.I am using the intermediate tables in an extract process. The idea was that the table would be created prior to calling the extract procedure and once the data written to the intermediate table had been processed the table would be dropped. This would be repeated each time the extract process is run. From a DBA's point or view, would it be better to just leave the table on the database and truncate it after each run or is removing it entirely best?
-
My screen on my mac has become loose and goes all glitchy with vertical lines
My screen on my mac has become loose and goes all glitchy with the whole screen covered in vertical lines, it also has a lump at the base of the screen when it closes but that can be pushed down, All can be fixed by placing the screen carefully but it is increasingly difficult - HELP
Bring it into an Apple store genius bar for a free evaluation. If your MBP is not under warranty, you will br told what the costs are which you can accept or decline. Look at iFixit.com or Powerbookmedic.com for do it yourself options.
Ciao. -
Please recommend if we have options to read xml file and insert data into table without a temporary table.
DECLARE @data XML;
SET @data =N'<Root>
<List RecordID="946236" />
<List RecordID="946237" />
<List RecordID="946238" />
<List RecordID="946239" />
<List RecordID="946240" />
</Root>'
INSERT INTO t (id) SELECT T.customer.value('@RecordID', 'INT') AS id
FROM @data.nodes('Root/List')
AS T(customer);
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
I get an "unable to connect" message yet I can connect and use Internet Explorer with no problem. I tried updating to Firefox4 and still get the same message. What do I do?
JungleTaxi Cabbie wrote:
Csound1: iCloud: Configuring Mail with Mac OS X v10.6 or iOS 4
Enter your Incoming Mail Server, User Name, and Password using the following settings:
Incoming Mail Server: mail.me.com
User Name: Your iCloud email address (excluding @me.com)
Password: Your password
Last Modified: Jun 27, 2013
Maybe you should test these things before calling people out, because these settings do function perfectly well.
iCloud is not supported on Snow Leopard or lower, why bother to mention it?
The OP has an iCloud account, and that can not be opened without Lion or Mountain Lion (on a Mac), IOS5 or 6 (on an iPhone/iPad)
The document I linked to is Apples documentation for iCloud on current devices,I don't care whether you believe that you know better than they do, but it will affect the people who follow your advice as it won't work
JungleTaxi Cabbie wrote:
Also, if you're not running Lion or Mountain Lion, there is no "Mail, Contacts & Calendars" prefpane.
I never said that there was, perhaps you imagined it. -
Why does my battery drain fast? I've had my phone for a year and a half now with no problems until recently.
Try to delete the mimeTypes.rdf file in the Firefox Profile Folder.
* http://kb.mozillazine.org/mimeTypes.rdf
* http://kb.mozillazine.org/File_types_and_download_actions#Resetting_download_actions
You can use this button to go to the Firefox profile folder:
*Help > Troubleshooting Information > Profile Directory: Open Containing Folder
Maybe you are looking for
-
How come adobe flash player does not work on my macbook air
when on yahoo and i select to watch a video it doesn't play and any other website with a similar format. But i have downloaded and installed adobe flash player but yet i am still experiencing these problems. Is there another way or am i just missing
-
Where can I find new display drivers for Satellite P100
Hello, i need new display drivers for my Notebook (Satellite P100), but it's only Version 84.0 to download. I need version 162.0 or higher. On Nvidia Web-Site is the new 167.0 beta, but does it work with my system?
-
Hi, I am using Swing and building my own Dialog box, because Java doesn't provide a dialog box that asks for username/password. My Question: I like the icons Java uses for its dialog boxes (example here: http://java.sun.com/docs/books/tutorial/figure
-
Pricing item 20 based on material of item 10 - can this work?
I want to determine a price for line item 20 based on the material# of line item 10. If item 10 material = 123 and item 20 material = abc, item 20 price = $100 and because item 10 material = 123, discount = 10%. How can I do this? I'm willi
-
Deleting photos out of camera roll leaves black spaces where pics used to b
Only happens on my iPhone 4. 3GS with os4 it doesn't. Any ideas For info they do disappear if u sync in iTunes.