X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 61491D1B528 for ; Mon, 29 Sep 2003 12:24:14 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 70277-08 for ; Mon, 29 Sep 2003 09:23:45 -0300 (ADT) Received: from fuji.krosing.net (silmet.estpak.ee [194.126.97.78]) by svr1.postgresql.org (Postfix) with ESMTP id 14BC7D1B522 for ; Mon, 29 Sep 2003 09:23:38 -0300 (ADT) Received: from fuji.krosing.net (localhost.localdomain [127.0.0.1]) by fuji.krosing.net (8.12.8/8.12.8) with ESMTP id h8TCNUbd003086; Mon, 29 Sep 2003 15:23:30 +0300 Received: (from hannu@localhost) by fuji.krosing.net (8.12.8/8.12.8/Submit) id h8TCNRBE003084; Mon, 29 Sep 2003 15:23:27 +0300 X-Authentication-Warning: fuji.krosing.net: hannu set sender to hannu@tm.ee using -f Subject: Re: ADD FOREIGN KEY (was Re: [GENERAL] 7.4Beta) From: Hannu Krosing To: Shridhar Daithankar Cc: PostgreSQL-development In-Reply-To: <200309291604.57988.shridhar_daithankar@persistent.co.in> References: <200309281940.h8SJe3O01852@candle.pha.pa.us> <1064829433.2645.2.camel@fuji.krosing.net> <3F78095C.5080507@familyhealth.com.au> <200309291604.57988.shridhar_daithankar@persistent.co.in> Content-Type: text/plain Content-Transfer-Encoding: 7bit Message-Id: <1064838206.2645.5.camel@fuji.krosing.net> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.5 Date: Mon, 29 Sep 2003 15:23:26 +0300 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/1529 X-Sequence-Number: 44541 Shridhar Daithankar kirjutas E, 29.09.2003 kell 13:34: > On Monday 29 September 2003 15:58, Christopher Kings-Lynne wrote: > > >>So a db designer made a bloody mistake. > > >>The problem is there's no easy way to find out what's missing. > > >>I'd really like EXPLAIN to display all subsequent triggered queries > > >>also, to see the full scans caused by missing indexes. > > > > > > It could probably be doable for EXPLAIN ANALYZE (by actually tracing > > > execution), but then you will see really _all_ queries, i.e. for a 1000 > > > row update you would see 1 UPDATE query and 1000 fk checks ... > > > > > > OTOH, you probably can get that already from logs with right logging > > > parameters. > > > > Actually - it shouldn't be too hard to write a query that returns all > > unindexed foreign keys, surely? > > Correct me if I am wrong but I remember postgresql throwing error that foreign > key field was not unique in foreign table. Obviously it can not detect that > without an index. Either primary key or unique constraint would need an > index. > > What am I missing here? > > > IOW, how do I exactly create foreign keys without an index? hannu=# create table pkt(i int primary key); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index 'pkt_pkey' for table 'pkt' CREATE TABLE hannu=# create table fkt(j int references pkt); NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s) CREATE TABLE hannu=# now the *foreygn key* column (fkt.j) is without index. As foreign keys are enforced both ways, this can be a problem when changing table pkt or bulk creating FK's on big tables. ---------------- Hannu