Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do "implicit sequence" and "implicit index" mean in Postgres?

Tags:

postgresql

I just created a table in Postgres and received a notice message that I do not completely understand regarding implicit indexes and sequences. Any clarification would be appreciated.

my_database=# CREATE TABLE sites
my_database-# (
my_database(# site_id_key serial primary key,
my_database(# site_url VARCHAR(255),
my_database(# note VARCHAR(255),
my_database(# type INTEGER,
my_database(# last_visited TIMESTAMP
my_database(# ) ;
NOTICE:  CREATE TABLE will create implicit sequence "sites_site_id_key_seq" for serial column "sites_to_search.site_id_key"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "sites_pkey" for table "sites_to_search"
CREATE TABLE
like image 245
HMLDude Avatar asked Nov 02 '13 02:11

HMLDude


People also ask

What is implicit and explicit index?

"Implicit" indexes have the advantage that they are part of the table definition. "Explicit" indexes have the advantage that they are created explicitly. Other than the definition, the use of the index in queries should be the same.

What does an index do in Postgres?

An index allows the database server to find and retrieve specific rows much faster than it could do without an index. But indexes also add overhead to the database system as a whole, so they should be used sensibly.

Is primary key always indexed Postgres?

PostgreSQL automatically creates an index for each unique constraint and primary key constraint to enforce uniqueness. Thus, it is not necessary to create an index explicitly for primary key columns.

Why do we create index in PostgreSQL?

Description. CREATE INDEX constructs an index on the specified column(s) of the specified relation, which can be a table or a materialized view. Indexes are primarily used to enhance database performance (though inappropriate use can result in slower performance).


1 Answers

Certain things in PostgreSQL are handled by indexes and sequences. These include serial and bigserial types, unique constraints, and primary keys. These are not implicit in PostgreSQL (so the notice is a little misleading) but rather implicit in the DDL that PostgreSQL is running.

In other words, the indexes and sequences are just normal indexes and sequences. They are just automatically created by PostgreSQL in order to provide the guarantees and features you have requested in your DDL.

like image 153
Chris Travers Avatar answered Sep 18 '22 15:09

Chris Travers