Postgres and Indexes on Foreign Keys and Primary Keys

前端 未结 7 1600
青春惊慌失措
青春惊慌失措 2020-12-02 03:34

Does Postgres automatically put indexes on Foreign Keys and Primary Keys? How can I tell? Is there a command that will return all indexes on a table?

相关标签:
7条回答
  • 2020-12-02 04:40

    For a PRIMARY KEY, an index will be created with the following message:

    NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "index" for table "table" 
    

    For a FOREIGN KEY, the constraint will not be created if there is no index on the referenced table.

    An index on referencing table is not required (though desired), and therefore will not be implicitly created.

    0 讨论(0)
提交回复
热议问题