X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 2C4F49DC820 for ; Thu, 19 Jan 2006 11:42:28 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 38658-05 for ; Thu, 19 Jan 2006 11:42:31 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from barracuda1.biscit.net (barracuda0-tel.biscit.net [82.195.96.18]) by postgresql.org (Postfix) with ESMTP id 0D5829DC80D for ; Thu, 19 Jan 2006 11:42:24 -0400 (AST) X-ASG-Debug-ID: 1137685349-24680-56-0 X-Barracuda-URL: http://82.195.96.18:80/cgi-bin/mark.cgi Received: from web1-glo.biscit.net (web1-glo.biscit.net [82.195.96.53]) by barracuda1.biscit.net (Spam Firewall) with ESMTP id BCB9646C8F for ; Thu, 19 Jan 2006 15:42:29 +0000 (GMT) Received: from bolek.coachhouse ([62.7.150.137]) by web1-glo.biscit.net (8.10.2/8.10.2) with ESMTP id k0JFgPi02837 for ; Thu, 19 Jan 2006 15:42:26 GMT Received: (Exim 3.36) #1 (Debian)) protocol: esmtp id 1Ezbug-0002Md-00 ; Thu, 19 Jan 2006 15:41:26 +0000 Message-ID: <43CFB325.9060306@numerixtechnology.de> Date: Thu, 19 Jan 2006 15:41:25 +0000 From: T E Schmitz Reply-To: mailreg@numerixtechnology.de User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql X-ASG-Orig-Subj: indexing for left join Subject: indexing for left join Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by Biscit Outgoing Spam Firewall at biscit.net X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=7.0 tests= X-Barracuda-Spam-Report: Code version 3.02, rules version 3.0.7555 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Barracuda-Rcpt: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[UPPERCASE_25_50=0] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200601/130 X-Sequence-Number: 23919 I have two tables: TABLE ITEM ( ITEM_PK serial, RETAIL_PRICE numeric (7,2) NOT NULL, ... PRIMARY KEY (ITEM_PK) ) TABLE SERIAL_NO ( SERIAL_NO_PK serial, NO varchar (20) NOT NULL, NAME varchar (20), ITEM_FK integer NOT NULL, PRIMARY KEY (SERIAL_NO_PK) ); common query: SELECT ITEM.ITEM_PK FROM ITEM LEFT JOIN SERIAL_NO ON SERIAL_NO.ITEM_FK = ITEM.ITEM_PK WHERE SERIAL_NO.NO ='WX1234' GROUP BY ITEM.ITEM_PK Table ITEM will eventually grow very big and SERIAL_NO will grow with it. There will normally be zero or one SERIAL_NO per ITEM; few ITEMs will have more than one SERIAL_NO. I have created an index for SERIAL_NO.NO and one for SERIAL_NO.ITEM_FK for the above query. I ran an EXPLAIN: HashAggregate (cost=1.06..1.06 rows=1 width=4) -> Nested Loop (cost=0.00..1.06 rows=1 width=4) Join Filter: ("inner".item_fk = "outer".item_pk) -> Seq Scan on item (cost=0.00..0.00 rows=1 width=4) -> Seq Scan on serial_no (cost=0.00..1.05 rows=1 width=4) Filter: (("no")::text = 'WX1234'::text) Sequential despite the indices? Or is this because the tables of my test DB are virtually empty? Many thanks in advance. -- Regards, Tarlika Elisabeth Schmitz