X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 6C6A1D1B541; Fri, 10 Oct 2003 21:32:43 +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 14800-03; Fri, 10 Oct 2003 18:31:55 -0300 (ADT) Received: from lakemtao03.cox.net (lakemtao03.cox.net [68.1.17.242]) by svr1.postgresql.org (Postfix) with ESMTP id 1CE43D1B522; Fri, 10 Oct 2003 18:31:53 -0300 (ADT) Received: from lhosts ([68.11.66.83]) by lakemtao03.cox.net (InterMail vM.5.01.06.05 201-253-122-130-105-20030824) with ESMTP id <20031010213156.EJOS17519.lakemtao03.cox.net@lhosts>; Fri, 10 Oct 2003 17:31:56 -0400 Subject: Re: [PERFORM] Index/Foreign Key Question From: Ron Johnson To: PgSQL General ML , PgSQL Performance ML In-Reply-To: <006a01c38f72$25461720$1100000a@busbydev> References: <006a01c38f72$25461720$1100000a@busbydev> Content-Type: text/plain Message-Id: <1065821515.16433.10.camel@haggis> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.4.4 Date: Fri, 10 Oct 2003 16:31:55 -0500 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/530 X-Sequence-Number: 50603 On Fri, 2003-10-10 at 16:04, David Busby wrote: > List, > I'm creating this multi company POS database. > My inventory table looks like (all items are unique): > > id,category_id,invoice_id,x,y,z,gid,uid > > I have a primary key on id, and then an foreign keys on category_id and > invoice_id. > GID is the group ID of the company, UID is the companies user, they are also > connected via foreign key to the respective tables. My question is this: Do > I need to create more indexes on this table when inventory selects look like > > select * from inventory where > category_id = 1 and invoice_id is null and gid = 2 > > So where would the indexes need to be placed? Or since I have the FK setup > are the indexes already in place? I expect to soon have >500K items in the > inventory table and don't want it to slow down. I'll have the same type of > issue with clients, invoices, purchase_orders and perhaps more I'd make a multi-segment (non-unique?) index on: GID CATEGORY_ID INVOICE_ID -- ----------------------------------------------------------------- Ron Johnson, Jr. ron.l.johnson@cox.net Jefferson, LA USA LUKE: Is Perl better than Python? YODA: No... no... no. Quicker, easier, more seductive. LUKE: But how will I know why Python is better than Perl? YODA: You will know. When your code you try to read six months from now.