title: Very slow SQL DELETE query on table with foreign key constraint
body: <p>I have got some trouble with a SQL DELETE query. 
  I work on a database <em>(postgres 9.3)</em> with 2 tables <em>(Parent and Child)</em>.
  The child has a relation to the parent with a foreign key.</p>
  
  <p>Parent Table</p>
  
  <pre><code>CREATE TABLE parent
  (
    id bigint NOT NULL,
    ...
    CONSTRAINT parent_pkey PRIMARY KEY (id)
  )
  </code></pre>
  
  <p>Child Table</p>
  
  <pre><code>CREATE TABLE child
  (
    id bigint NOT NULL,
    parent_id bigint,
    ...
    CONSTRAINT child_pkey PRIMARY KEY (id),
    CONSTRAINT fk_adc9xan172ilseglcmi1hi0co FOREIGN KEY (parent_id)
        REFERENCES parent (id) MATCH SIMPLE
        ON UPDATE NO ACTION ON DELETE NO ACTION
  )
  </code></pre>
  
  <p>I inserted in both tables 200'000 entries without any relation <em>( Child.parent_id = NULL)</em>.</p>
  
  <p>But a DELETE query like below has a duration of more than 20 minutes.
  And that even without a WHERE conditions.</p>
  
  <pre><code>DELETE FROM Parent;
  </code></pre>
  
  <p>If I don't add the relation constraints the execution time will be done in 400 ms.</p>
  
  <p>What did I miss? </p>
  
  <p>A workable solution is the example below. But I don't know if this is a good idea. Maybe anyone could tell me a better way to do that.</p>
  
  <pre><code>BEGIN WORK;
  ALTER TABLE Parent DISABLE TRIGGER ALL;
  DELETE FROM Parent;
  ALTER TABLE Parent ENABLE TRIGGER ALL;
  COMMIT WORK;
  </code></pre>