Zum Inhalt springen
_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
Referenzen Technologien Blog Know-how Tools
Über uns Zusammenarbeit Karriere
CS EN DE
Lassen Sie uns sprechen

PostgreSQL indexy deep dive

13. 11. 2024 1 Min. Lesezeit intermediate

Správné indexy jsou klíčové pro výkon databáze.

Typy

  • B-tree — výchozí, equality + range
  • Hash — pouze equality
  • GIN — full-text, JSONB, arrays
  • GiST — geometrie, range
  • BRIN — velké tabulky s přirozeným řazením

Příklady

CREATE INDEX idx_email ON users (email); CREATE INDEX CONCURRENTLY idx_date ON orders (created_at); CREATE INDEX idx_composite ON orders (user_id, created_at DESC); CREATE INDEX idx_partial ON orders (created_at) WHERE status=’pending’; CREATE INDEX idx_expr ON users (lower(email)); CREATE INDEX idx_gin ON events USING GIN (data);

Analýza

SELECT indexrelname, idx_scan, pg_size_pretty(pg_relation_size(indexrelid)) FROM pg_stat_user_indexes WHERE idx_scan=0;

  • WHERE, JOIN, ORDER BY sloupce
  • Nejselektivnější první
  • Partial pro subset
  • CONCURRENTLY v produkci

Správné indexy = výkon

EXPLAIN ANALYZE a cílené indexy.

postgresqlindexyperformance
Teilen:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.