From: T E Schmitz <mailreg@numerixtechnology.de>
To: pgsql-sql <pgsql-sql@postgresql.org>
Subject: indexing for left join
Date: Thu, 19 Jan 2006 15:41:25 +0000
Message-ID: <43CFB325.9060306@numerixtechnology.de> (raw)
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: mailreg@numerixtechnology.de
Subject: Re: indexing for left join
In-Reply-To: <43CFB325.9060306@numerixtechnology.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox