Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 04B979FB686 for ; Tue, 3 Jul 2007 08:34:02 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 94775-04 for ; Tue, 3 Jul 2007 08:33:53 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 367179FB632 for ; Tue, 3 Jul 2007 08:33:57 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.8/8.13.8) with ESMTP id l63BXh6U030317 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 3 Jul 2007 05:33:45 -0600 (MDT) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.8/8.13.8) with ESMTP id l63BXgvj041297; Tue, 3 Jul 2007 05:33:42 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.8/8.13.8/Submit) id l63BXgdL041296; Tue, 3 Jul 2007 05:33:42 -0600 (MDT) (envelope-from mfuhr) Date: Tue, 3 Jul 2007 05:33:42 -0600 From: Michael Fuhr To: Patric de Waha Cc: pgsql-performance@postgresql.org Subject: Re: Delete Cascade FK speed issue Message-ID: <20070703113342.GA41193@winnie.fuhr.org> References: <4689E727.5020408@p-dw.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4689E727.5020408@p-dw.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200707/8 X-Sequence-Number: 25692 On Tue, Jul 03, 2007 at 08:05:27AM +0200, Patric de Waha wrote: > Is there a way I can find out what postgres does, and where it hangs > around, so I know where the FK might not be indexed. (The dbase is > to big to analyze it by hand). You could query the system catalogs to look for foreign key constraints that don't have an index on the referencing column(s). Something like the following should work for single-column foreign keys: select n1.nspname, c1.relname, a1.attname, t.conname, n2.nspname as fnspname, c2.relname as frelname, a2.attname as fattname from pg_constraint t join pg_attribute a1 on a1.attrelid = t.conrelid and a1.attnum = t.conkey[1] join pg_class c1 on c1.oid = t.conrelid join pg_namespace n1 on n1.oid = c1.relnamespace join pg_class c2 on c2.oid = t.confrelid join pg_namespace n2 on n2.oid = c2.relnamespace join pg_attribute a2 on a2.attrelid = t.confrelid and a2.attnum = t.confkey[1] where t.contype = 'f' and not exists ( select 1 from pg_index i where i.indrelid = t.conrelid and i.indkey[0] = t.conkey[1] ) order by n1.nspname, c1.relname, a1.attname; -- Michael Fuhr