Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 81745 invoked from network); 19 Mar 2007 21:49:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Mar 2007 21:49:43 -0000 Received: (qmail 64395 invoked by uid 500); 19 Mar 2007 21:49:49 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 64366 invoked by uid 500); 19 Mar 2007 21:49:49 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 64355 invoked by uid 99); 19 Mar 2007 21:49:49 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Mar 2007 14:49:49 -0700 X-ASF-Spam-Status: No, hits=1.4 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (herse.apache.org: 32.97.182.144 is neither permitted nor denied by domain of Stan.Bradbury@gmail.com) Received: from [32.97.182.144] (HELO e4.ny.us.ibm.com) (32.97.182.144) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 19 Mar 2007 14:49:37 -0700 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e4.ny.us.ibm.com (8.13.8/8.13.8) with ESMTP id l2JLnFri030120 for ; Mon, 19 Mar 2007 17:49:15 -0400 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v8.3) with ESMTP id l2JLnFOt280276 for ; Mon, 19 Mar 2007 17:49:15 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id l2JLnFPr001193 for ; Mon, 19 Mar 2007 17:49:15 -0400 Received: from [127.0.0.1] (sig-9-48-111-200.mts.ibm.com [9.48.111.200]) by d01av02.pok.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id l2JLnC31001090 for ; Mon, 19 Mar 2007 17:49:14 -0400 Message-ID: <45FF0555.1020709@gmail.com> Date: Mon, 19 Mar 2007 14:49:09 -0700 From: Stanley Bradbury User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: Derby Discussion Subject: Re: Foreign key -- implicit index? References: <1384897708.43121174255006520.JavaMail.root@dogfood.liquidsys.com> In-Reply-To: <1384897708.43121174255006520.JavaMail.root@dogfood.liquidsys.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Dan Karp wrote: >>> Just to make sure, this foreign key declaration >>> >>> CONSTRAINT fk_mail_item_parent_id FOREIGN KEY (mailbox_id, parent_id) >>> REFERENCES ${DATABASE_NAME}.mail_item(mailbox_id, id), >>> >>> implicitly creates an index on (mailbox_id, parent_id), right? >>> >> Yes, that is correct. Copied following from the CREATE INDEX page in >> Derby's documentation: >> >> Unique, primary key , and foreign key constraints generate indexes >> that enforce or "back" the constraint (and are thus sometimes called >> backing indexes ). >> > > Is there any way to explicitly assign a name to this backing index? In my case, I want to force the optimizer to choose the backing index using "-- DERBY-PROPERTIES index=". > > Hi again - Of course Dan is correct that using "-- DERBY-PROPERTIES constraint= " is the way to get the optimizer to use the backing index of the key. Before I noticed this syntax in the manual, I confirmed the following kludgey approach which will, in effect, provide a name for the backing index. Steps: 1) Create the table without the key defined. 2) Create an standard, named index on the foreign key column. 3) Define the Foreign key using the ALTER TABLE statement. Derby will use the existing index created in step 2 as the backing index for the foreign key. This name can be used for the optimizer override. There will be two index names in the data dictionary that point to the same physical index (same conglomeratenumber).