Search Postgresql Archives

Re: Will PG use composite index to enforce foreign keys?

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

 



Gregory Stark wrote:

I guess a generalization of my question is whether the FK- checking machinery
simply does a SELECT against the referencing column.

It does

Actually the query is (effectively, assuming your equality operators are named
"=" and the columns match in type)

SELECT 1
  FROM ONLY B x
 WHERE col1=?
   AND col2=?
   ...
   FOR SHARE OF x

Since it has to take a lock on the record found to ensure it doesn't disappear
before your transaction finishes.

Awesome, this tells me a lot! So I can use EXPLAIN ANALYZE and a query like this to reason about what indexes I might need on my foreign key references. Thanks!

- John D. Burger
  MITRE



---------------------------(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