Re: Creating a foreign key

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

 




When you create a foreign key to a table is there an index that is
created on the foreign key automatically?

No, Postgres doesn't do it for you, because if you create (ref_id) references table.id, you will perhaps create an index on (ref_id, date) which would then fill the purpose (and other purposes), or perhaps your table will have 10 rows (but postgres doesnt' know that when you create it) and having an index would be useless, or your table could have many rows but only a few distinct referenced values, in which case again the index would only slow things down. PG does not presume to know better than yourself what you're gonna do with your data ;)
	UNIQUE and PRIMARY KEY do create UNIQUE INDEXes, of course.


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux