I'm trying to do a lot of inserts on a detail table, but with foreign
key schema it's too slow.
I made few tests.
1) Master table with 290,000 rows and 4 columns (primary key is SERIAL)
2) Detail table now with 1,300,000 rows and 3 columns (primary key is
SERIAL and I have a column master_id here pointing to a master table
3) If I use:
ALTER TABLE detail ADD CONSTRAINT master_fk FOREIGN KEY master_id
I get 5 INSERTs per second using this:
INSERT INTO master VALUES (DEFAULT, 'Random 1', 'Random 2', 'Random 3');
INSERT INTO detail VALUES (DEFAULT, XX, 999);
(random number of detail records, alternating with a insert into master)
I can insert just 5 rows/second.
4) So, I change it:
ALTER TABLE detail DROP CONSTRAINT master_fk;
And run INSERTs again.
Now, I have 1000 rows/second (with SELECT checking before every INSERT).
Is FOREIGN KEY so slow like that? What can I change in PostgreSQL
Note that I run some VACUUM and CLUSTER. This let my INSERTs a very
My (test) system is:
Pentium IV 1.8Ghz
Could anyone help me?
Ricardo Vaz Mannrich <rvm_l1(at)silcom(dot)com(dot)br>
pgsql-admin by date
|Next:||From: Tom Lane||Date: 2004-03-22 20:56:03|
|Subject: Re: Slow Foreign Key |
|Previous:||From: Mark M. Huber||Date: 2004-03-22 17:13:06|
|Subject: Re: backup and recovery|