Re: Foreign key slows down copy/insert

От: PFC
Тема: Re: Foreign key slows down copy/insert
Дата: ,
Msg-id: op.so8fvhlwth1vuj@localhost
(см: обсуждение, исходный текст)
Ответ на: Foreign key slows down copy/insert  (Richard van den Berg)
Ответы: Re: Foreign key slows down copy/insert  (Richard van den Berg)
Re: Foreign key slows down copy/insert  (PFC)
Список: pgsql-performance

Скрыть дерево обсуждения

Foreign key slows down copy/insert  (Richard van den Berg, )
 Re: Foreign key slows down copy/insert  (Christopher Kings-Lynne, )
  Re: Foreign key slows down copy/insert  (Richard van den Berg, )
   Re: Foreign key slows down copy/insert  (Christopher Kings-Lynne, )
    Re: Foreign key slows down copy/insert  (Richard van den Berg, )
     Re: Foreign key slows down copy/insert  (Christopher Kings-Lynne, )
      Re: Foreign key slows down copy/insert  (Richard van den Berg, )
       Re: Foreign key slows down copy/insert  (Christopher Kings-Lynne, )
        Re: Foreign key slows down copy/insert  (Marko Ristola, )
      Re: Foreign key slows down copy/insert  (Tom Lane, )
   Re: Foreign key slows down copy/insert  (Stephan Szabo, )
    Re: Foreign key slows down copy/insert  (Tom Lane, )
     Re: Foreign key slows down copy/insert  (Stephan Szabo, )
 Re: Foreign key slows down copy/insert  (PFC, )
  Re: Foreign key slows down copy/insert  (Richard van den Berg, )
  Re: Foreign key slows down copy/insert  (PFC, )
   Re: Foreign key slows down copy/insert  (Richard van den Berg, )
    Re: Foreign key slows down copy/insert  (Christopher Kings-Lynne, )
     Re: Foreign key slows down copy/insert  (Richard van den Berg, )
      Re: Foreign key slows down copy/insert  (Tom Lane, )
       Re: Foreign key slows down copy/insert  (Richard van den Berg, )

> I have a table A with an int column ID that references table B column
> ID. Table B has about 150k rows, and has an index on B.ID. When trying
> to copy 1 million rows into A, I get the following \timings:

    You're using 7.4.5. It's possible that you have a type mismatch in your
foreign keys which prevents use of the index on B.
    First of all, be really sure it's THAT foreign key, ie. do your COPY with
only ONE foreign key at a time if you have several, and see which one is
the killer.

    Then, supposing it's the column in A which REFERENCE's B(id) :

    SELECT id FROM A LIMIT 1;
    (check type)

    SELECT id FROM B LIMIT 1;
    (check type)

    EXPLAIN ANALYZE the following :

    SELECT * FROM B WHERE id = (SELECT id FROM A LIMIT 1);

    It should use the index. Does it ?



В списке pgsql-performance по дате сообщения:

От: Alex Turner
Дата:
Сообщение: Re: Intel SRCS16 SATA raid?
От: Geoffrey
Дата:
Сообщение: Re: Intel SRCS16 SATA raid?