Search Postgresql Archives

INDEX and JOINs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
       subscribe-nomail command to majordomo@xxxxxxxxxxxxxx so that your
       message can get through to the mailing list cleanly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux