From: | Reg Me Please <regmeplease(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | INDEX and JOINs |
Date: | 2007-10-26 10:34:06 |
Message-ID: | 200710261234.06695.regmeplease@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi all.
I have a setup like this:
CREATE TABLE T_FIELDS (
TABL_ID TEXT NOT NULL,
COLU_ID TEXT NOT NULL,
FIEL_ID TEXT PRIMARY KEY,
UNIQUE( TABL_ID,COLU_ID ) ); -- < 200 ROWS
CREATE TABLE T_DATA (
ITEM_ID INT8 NOT NULL,
FIEL_ID TEXT NOT NULL REFERENCES T_FIELDS,
DATA_T TEXT NOT NULL,
PRIMARY( FIEL_ID,ITEM_ID ) ); -- > 10M ROWS
When I run
SELECT * FROM T_DATA WHERE FIEL_ID='TABL.FIEL';
it's very fast (of course!). But when I run:
SELECT * FROM T_DATA NATURAL JOIN T_FIELDS WHERE TABL_ID='TABL';
it's very slow.
The EXPLAIN says that in the second case it has to do a sequential
scan on T_DATA. And this explains the timing.
Is there a way to avoid such a behaviour by acting on indexes?
Thanks.
From | Date | Subject | |
---|---|---|---|
Next Message | Sam Mason | 2007-10-26 10:58:24 | Re: select count() out of memory |
Previous Message | Vince Negri | 2007-10-26 10:25:09 | TRUNCATE - timing of the return of disk space - caused by long-lived client? |