8000 GitHub - TolkienRools/postgresql
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

TolkienRools/postgresql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PostgreSQL Cheat Sheet

This is a simple guide to working with PostgreSQL, covering key concepts like indexes and the PARTITION BY clause.


Table of Contents

  1. Indexes
  2. Partitioning with PARTITION BY

Indexes

What are Indexes?

Indexes in PostgreSQL are used to speed up data retrieval operations on a database table. They work similarly to an index in a book, allowing the database to quickly locate rows without scanning the entire table.

Types of Indexes

PostgreSQL supports several types of indexes:

  • B-Tree: Default index type, suitable for equality and range queries.
  • GIN (Generalized Inverted Index): Useful for full-text search and multi-value data (e.g., arrays, JSON).
  • GiST (Generalized Search Tree): Suitable for geometric and text search.
  • BRIN (Block Range Index): Efficient for large tables with sorted data.
  • Hash: Optimized for equality comparisons.

Creating Indexes

To create an index, use the CREATE INDEX statement:

Example of creating and running select (before)

Example of creating and running select (after)

-- Basic B-Tree Index
CREATE INDEX idx_user_email ON users (email);

CREATE EXTENSION pg_tgrim;

-- GIN Index for Full-Text Search
CREATE INDEX idx_trgm_user_name ON users USING gin (name gin_trgm_ops);

![Example of using gin index for multiple columns](9.jpg)

About

No description, website, or topics provided.

Resources

Releases

No releases published

Packages

No packages published
0