Redian新闻
>
How to Import a Datatable as fast as possible?
avatar
How to Import a Datatable as fast as possible?# Database - 数据库
n*u
1
Sorry I can not write Chinese here.
In MySQL, I have two databases: newdb and olddb
table1 in newdb, table2 and table3 in olddb
table1 has userid, nickname, msn
table2 has userid, nickname
table3 has userid msn
First I use NaviCat to import table2 into table1, very fast! 320,000 records
in 2 mins!
Then I tried to import table 3 into table1, now I have to check userid first
, then UPDATE table1. Very slow. 50,000 records in 12 hours
Anyway I can make it fast?
Thanks
avatar
n*u
2
If I innerjoin table2 and table3 first, will it be faster?
avatar
t*i
3
yes you should join first then import.
My estimate is the total time would be comparable to only import table2.
avatar
n*u
4
How long will it take to inner join table2 and table 3 (each has 320,00
records)

【在 t*********i 的大作中提到】
: yes you should join first then import.
: My estimate is the total time would be comparable to only import table2.

avatar
t*i
5
That really depend on your system, how much memory, how much undo space ( I
am from Oracle side, but mysql should have have similar structure), do you
have indexes on tables or not. You need to talk to your DBA to know that.
If I need to do this, I probably will do the join and insert in chunks(id in
certain range is good candidate; again, you need to have good index in
place). commit in chunks will reduce requirement to system resources.
.........................................................
avatar
n*u
6
Thanks for your reply.
I test INNER JOIN:
INNER JOIN table 2 and table 3, 40 seconds (not sure it's good or bad for
320,000 records)
So I started to work on my real task
INNER JOIN table 2, table 3 and table 4, 3 mins (320,000 records)
export result to dbf file, 10 mins
import dbf into Table1, 10 mins
Finally I finished my task in half hour, instead of 3 days.
Now how can I improve export and import process?
PS. I am a .net programmer, but team leader asked me to migrate database.
The next task
avatar
B*g
7
1. check if table2, table3 has primary key userid.
if not, add.
2.
insert into tables1(userid, nickname, msn)
select a.userid, a.nickname, b.msn
from table2 a, table3 b
where a.userid = b.userid.
1. check if table1 has primary key userid.
if not, add.
Note: IF userid is not unique in table 2, table3, kick the person who design
these tables.

records
first

【在 n****u 的大作中提到】
: Sorry I can not write Chinese here.
: In MySQL, I have two databases: newdb and olddb
: table1 in newdb, table2 and table3 in olddb
: table1 has userid, nickname, msn
: table2 has userid, nickname
: table3 has userid msn
: First I use NaviCat to import table2 into table1, very fast! 320,000 records
: in 2 mins!
: Then I tried to import table 3 into table1, now I have to check userid first
: , then UPDATE table1. Very slow. 50,000 records in 12 hours

avatar
B*g
8
tell them to start to use sql server, hehe

【在 n****u 的大作中提到】
: Thanks for your reply.
: I test INNER JOIN:
: INNER JOIN table 2 and table 3, 40 seconds (not sure it's good or bad for
: 320,000 records)
: So I started to work on my real task
: INNER JOIN table 2, table 3 and table 4, 3 mins (320,000 records)
: export result to dbf file, 10 mins
: import dbf into Table1, 10 mins
: Finally I finished my task in half hour, instead of 3 days.
: Now how can I improve export and import process?

avatar
n*u
9
I love you both tangyuanlai and Beijing! hehe
Yes, I tried this way, it's sooooooo fast!
Insert new table
select
from inner join of old tables
21.891 ms (migrated 320,000 records)
Previously I used C# code, it would take me 1 week
Then I used NaviCat import wizard, it would take me 3 days
Yesterday I exported query result and imported into new table, it took me 30
mins
Now, 21.891 ms haha
Thank you very much!!!
avatar
B*g
10
check record number in 3 tables see if they match.

30

【在 n****u 的大作中提到】
: I love you both tangyuanlai and Beijing! hehe
: Yes, I tried this way, it's sooooooo fast!
: Insert new table
: select
: from inner join of old tables
: 21.891 ms (migrated 320,000 records)
: Previously I used C# code, it would take me 1 week
: Then I used NaviCat import wizard, it would take me 3 days
: Yesterday I exported query result and imported into new table, it took me 30
: mins

avatar
n*u
11
Thank you reminding me.
If table 2 has an id=5, but table 3 does not have this id, what can I do?

【在 B*****g 的大作中提到】
: check record number in 3 tables see if they match.
:
: 30

avatar
n*u
12
I check the number
Table2: 319,928
Table3: 319,927
Table4: 319,927
So my result has 319,927 records
How to find this missing one?

【在 B*****g 的大作中提到】
: check record number in 3 tables see if they match.
:
: 30

avatar
B*g
13
SELECT CASE
WHEN a.userid IS NULL
THEN b.userid
ELSE a.userid
END AS userid,
a.nickname,
b.msn
FROM table2 a FULL OUTER JOIN table3 b ON a.userid = b.userid

【在 n****u 的大作中提到】
: Thank you reminding me.
: If table 2 has an id=5, but table 3 does not have this id, what can I do?

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。