View Single Post

   
  #5 (permalink)  
Old 04-09-2008, 11:16 PM
Lew
 
Posts: n/a
Default Re: How to insert on duplicate key?

fdu.xiaojf@gmail.com wrote:
> I have a table like this,
> CREATE TABLE mytable(
> a varchar(40),
> b text,
> c text,
> PRIMARY KEY (a, b)
> );


> Is the update and insert method quick?
>
> I have tried the query and update/insert way, and it was very slow when
> more than 1 million records have been inserted. (I have more than 20
> million records to insert.)


Your data structure is not conducive to "quick". You have a primary key over
two columns, a VARCHAR and a TEXT. That's going to be a very slow comparison
on INSERT when checking for duplicate keys. Is it really true that column b
contributes to the identity of the row?

Find a more compact way to do the PRIMARY KEY. Perhaps there is a way to
label the row uniquely, if column a by itself cannot do it. It'd be good to
avoid having an unbounded character column in the PK.

Can column b get quite large?

--
Lew
Reply With Quote