indexing for left join - Mailing list pgsql-sql

From T E Schmitz
Subject indexing for left join
Date
Msg-id 43CFB325.9060306@numerixtechnology.de
Whole thread Raw
Responses Re: indexing for left join  (Rod Taylor <pg@rbt.ca>)
Re: indexing for left join  (Richard Huxton <dev@archonet.com>)
Re: indexing for left join  (Zulq Alam <zulq@orange.net>)
List pgsql-sql
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
onitem  (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



pgsql-sql by date:

Previous
From: Juris
Date:
Subject: Re: Error calling self-made plpgsql function "function XYZ(bigint) does not exist"
Next
From: Rod Taylor
Date:
Subject: Re: indexing for left join