Estructuras Postgre SQL2
Estructuras Postgre SQL2
• Partial Indexes
Partial indexes (sometimes called filtered indexes) are indexes that cover only
rows fitting a predefined WHERE condition.
The resulting indexes can be faster because more of them can fit into RAM, plus
you’ll save a bit of disk space on the index itself.
Example:
CREATE TABLE subscribers (id serial PRIMARY KEY, name varchar(50) NOT NULL, type
varchar(50), is_active boolean);
CREATE UNIQUE INDEX uq ON subscribers USING btree(lower(name)) WHERE
is_active;
You can create functional indexes using more than one underlying
column. Example:
The PostgreSQL planner uses a strategy called bitmap index scan that
automatically tries to combine indexes on the fly, often from single-
column indexes, to achieve the same goal as a multicolumn index.
If you have a compound B-Tree index on type, upper(name) .., then there
is no need for an index on just type, because the planner can happily use
the compound index for cases in which you just need to filter by type.
• Normally PostgreSQL locks the table to be indexed against writes and performs
the entire index build with a single scan of the table.
• Other transactions can still read the table, but if they try to insert, update, or
delete rows in the table they will block until the index build is finished.
• This could have a severe effect if the system is a live production database. Very
large tables can take many hours to be indexed, and even for smaller tables, an
index build can lock out writers for periods that are unacceptably long for a
production system.
• Thus this method requires more total work than a standard index build and
takes significantly longer to complete.
• To create an index on the column code in the table films and have the
index reside in the tablespace indexspace:
CREATE INDEX code_idx ON films (code) TABLESPACE indexspace;