Unique contraint and index

Allgemeines zu PostgreSQL.
Neuer Benutzer
Beiträge: 7
Registriert: Do 20. Apr 2017, 10:32

Unique contraint and index

Beitrag von Nunki » Di 14. Aug 2018, 10:52

Dear all,

When I define a unique contraint like

Code: Alles auswählen

ALTER TABLE Documents ADD CONSTRAINT Documents_pk PRIMARY KEY (id,bid);
will that be enough to prevent full table scans ?
Or should I also define the index

Code: Alles auswählen

CREATE INDEX DocumentsI ON Documents(id,bid);

Erfahrener Benutzer
Beiträge: 7480
Registriert: So 29. Okt 2006, 13:35
Wohnort: Kaufbach, Sachsen, Germany, Germany

Re: Unique contraint and index

Beitrag von akretschmer » Di 14. Aug 2018, 11:39

the primary key constraint will implicit create the index. If the index will be usefull to prevent full table scans depends on the query. You can use explain to check.

And yes: this is a germany speaking forum, can we switch to german?
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services