Model PostgreSQL schemas, data types, and indexes
Unlock the complete study guide + 1,040 practice questions across 16 full exams.
Bundled into the existing Developing AI Cloud Solutions on Azure premium course — no separate purchase.
14-day money-back guarantee — no questions asked.
Included in this chapter:
- What the schema decides and what the index decides
- Choosing column types for data you will query
- Surrogate keys and index locality
- Constraints and the indexes that come with them
- Normalizing, and when to denormalize the retrieval path
- The index types PostgreSQL offers
- Column order in a multicolumn index
- Indexing fewer rows or more columns
- Confirming the index is used: reading EXPLAIN
- What an index costs, and finding the ones not earning it
Choosing an index type by the operator your query uses
| Property | B-tree | GIN | GiST | BRIN |
|---|---|---|---|---|
| Operators it serves | < <= = >= > and ordered scans | Containment and membership: jsonb @>, array overlap, full-text @@ | Whatever the operator class implements: range overlap, geometric, distance ordering | Range comparisons resolved against block-range summaries |
| Column shape it suits | Any scalar with a sort order | Values holding multiple component values (jsonb, arrays, tsvector) | Ranges, geometry and other extensible types | Columns well correlated with the physical order of the rows |
| Can order results (ORDER BY, nearest neighbour) | Yes, ordered scans | No | Yes, including nearest-neighbour ordering | No |
| Can be declared UNIQUE | Yes, and only B-tree can | No | No, but it backs exclusion constraints | No |
| Supports INCLUDE payload columns | Yes | No | Yes | No |
| Created automatically by a constraint | Yes, by PRIMARY KEY and UNIQUE | No | No | No |
Decision tree
Cheat sheet
Unlock with Premium — includes all practice exams and the complete study guide.
References
- JSON Types
- Supported versions of PostgreSQL in Azure Database for PostgreSQL flexible server
- Date/Time Types
- Numeric Types
- UUID Type
- Identity Columns
- UUID Functions
- UUID Functions (PostgreSQL 17)
- Constraints
- Unique Indexes
- Partial Indexes
- Architecture strategies for optimizing data performance (PE:08) Well-Architected
- CREATE INDEX
- Optimize performance when using pgvector in Azure Database for PostgreSQL flexible server
- Index Types
- GIN and GiST Index Types for Text Search
- Multicolumn Indexes
- Indexes and ORDER BY
- Index-Only Scans and Covering Indexes
- Using EXPLAIN
- Introduction to Indexes
- Heap-Only Tuples (HOT)
- Autonomous tuning in Azure Database for PostgreSQL flexible server