Hey all --
I need to map an old database into a redesigned database. Right now, I've got an n^3 loop that'll do it -- but with the number of records I have, that loop will take a while (>20 hours by my last test!).
The problem is with the auto_increment id on the new tables and their PK/FK relationships.
Here's the current loop to keep the constraints intact, in pseudocode:
For each Client do
For each Invoice for Client do
For each Item in Invoice do
Insert Item
Get Item.PK
Loop
Insert Invoice with FK -> Item.PK
Get Invoice.PK
Loop
Insert Client with FK -> Invoice.PK
Loop
[This is simplified, the actual transfer involves about ten tables, but this is a similar problem]
Is there a better way to bulk-map the data and still keep the FK->PK constraints intact? Would a trigger be more efficient? From my experience, it wouldn't seem so, especially with a lot of data (>170,000 rows of Invoices for >25,000 Clients).
Note that this is a REDESIGN, column names have changed from the original.
Thanks for any advice! ~Andrew __________________________________
You don't see with your eyes, you perceive with your mind.
I need to map an old database into a redesigned database. Right now, I've got an n^3 loop that'll do it -- but with the number of records I have, that loop will take a while (>20 hours by my last test!).
The problem is with the auto_increment id on the new tables and their PK/FK relationships.
Here's the current loop to keep the constraints intact, in pseudocode:
For each Client do
For each Invoice for Client do
For each Item in Invoice do
Insert Item
Get Item.PK
Loop
Insert Invoice with FK -> Item.PK
Get Invoice.PK
Loop
Insert Client with FK -> Invoice.PK
Loop
[This is simplified, the actual transfer involves about ten tables, but this is a similar problem]
Is there a better way to bulk-map the data and still keep the FK->PK constraints intact? Would a trigger be more efficient? From my experience, it wouldn't seem so, especially with a lot of data (>170,000 rows of Invoices for >25,000 Clients).
Note that this is a REDESIGN, column names have changed from the original.
Thanks for any advice! ~Andrew __________________________________
You don't see with your eyes, you perceive with your mind.