indexing for left join
От | T E Schmitz |
---|---|
Тема | indexing for left join |
Дата | |
Msg-id | 43CFB325.9060306@numerixtechnology.de обсуждение исходный текст |
Ответы |
Re: indexing for left join
Re: indexing for left join Re: indexing for left join |
Список | 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 по дате отправления: