DataBurst Data Engineering Wiki - Roadmap Step-by-Step: https://wiki.databurst.tech/docs/roadmap/ - Introduction: https://wiki.databurst.tech/docs/roadmap/introduction/ - Programming Language: https://wiki.databurst.tech/docs/roadmap/programming-language/ - Python: https://wiki.databurst.tech/docs/roadmap/programming-language/python/ - Java: https://wiki.databurst.tech/docs/roadmap/programming-language/java/ - Scala: https://wiki.databurst.tech/docs/roadmap/programming-language/scala/ - Go: https://wiki.databurst.tech/docs/roadmap/programming-language/go/ - Rust: https://wiki.databurst.tech/docs/roadmap/programming-language/rust/ - Operating System: https://wiki.databurst.tech/docs/roadmap/operating-system/ - Windows: https://wiki.databurst.tech/docs/roadmap/operating-system/windows/ - Linux: https://wiki.databurst.tech/docs/roadmap/operating-system/linux/ - Networking: https://wiki.databurst.tech/docs/roadmap/networking/ - Protocols: https://wiki.databurst.tech/docs/roadmap/networking/protocols/ - TCP/IP: https://wiki.databurst.tech/docs/roadmap/networking/protocols/tcp/ - DNS: https://wiki.databurst.tech/docs/roadmap/networking/protocols/dns/ - HTTP: https://wiki.databurst.tech/docs/roadmap/networking/protocols/http/ - HTTPS: https://wiki.databurst.tech/docs/roadmap/networking/protocols/https/ - SSH: https://wiki.databurst.tech/docs/roadmap/networking/protocols/ssh/ - UDP: https://wiki.databurst.tech/docs/roadmap/networking/protocols/udp/ - Concepts: https://wiki.databurst.tech/docs/roadmap/networking/concepts/ - IP addressing: https://wiki.databurst.tech/docs/roadmap/networking/concepts/ip-addressing/ - DHCP: https://wiki.databurst.tech/docs/roadmap/networking/concepts/dhcp/ - Firewalls: https://wiki.databurst.tech/docs/roadmap/networking/concepts/firewalls/ - VPN: https://wiki.databurst.tech/docs/roadmap/networking/concepts/vpn/ - General Software Engineering Skills: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/ - OAuth: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/oauth/ - JWT: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/jwt/ - GraphQL: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/graphql/ - REST: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/rest/ - gRPC: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/grpc/ - Caching: https://wiki.databurst.tech/docs/roadmap/general-software-engineering-skills/caching/ - Web Frameworks and API Development: https://wiki.databurst.tech/docs/roadmap/web-frameworks-and-api-development/ - Python: https://wiki.databurst.tech/docs/roadmap/web-frameworks-and-api-development/python/ - Go: https://wiki.databurst.tech/docs/roadmap/web-frameworks-and-api-development/go/ - Java: https://wiki.databurst.tech/docs/roadmap/web-frameworks-and-api-development/java/ - Version Control System: https://wiki.databurst.tech/docs/roadmap/version-control-system/ - git: https://wiki.databurst.tech/docs/roadmap/version-control-system/git/ - Version Control System Hosting: https://wiki.databurst.tech/docs/roadmap/version-control-system-hosting/ - Github: https://wiki.databurst.tech/docs/roadmap/version-control-system-hosting/github/ - Gitlab: https://wiki.databurst.tech/docs/roadmap/version-control-system-hosting/gitlab/ - BitBucket: https://wiki.databurst.tech/docs/roadmap/version-control-system-hosting/bitbucket/ - Distributed Systems Concepts: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/ - CAP: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/cap/ - PACELC: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/pacelc/ - Sharding: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/sharding/ - Clock: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/clock/ - ACID: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/acid/ - Replication: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/replication/ - Distributed Transactions: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/transaction/ - Indexing: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/indexing/ - Batch and Stream Processing: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/batch-and-stream-processing/ - Consistency vs Eventual Consistency: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/consistency-vs-eventual-consistency/ - Normalization or Denormalization: https://wiki.databurst.tech/docs/roadmap/distributed-systems-concepts/normalization-or-denormalization/ - SQL Fundamentals: https://wiki.databurst.tech/docs/roadmap/sql-fundamentals/ - Basic SQL: https://wiki.databurst.tech/docs/roadmap/sql-fundamentals/basic-sql/ - Advanced SQL: https://wiki.databurst.tech/docs/roadmap/sql-fundamentals/advanced-sql/ - Databases: https://wiki.databurst.tech/docs/roadmap/databases/ - Relational: https://wiki.databurst.tech/docs/roadmap/databases/relational/ - NoSQL: https://wiki.databurst.tech/docs/roadmap/databases/nosql/ - Columnar: https://wiki.databurst.tech/docs/roadmap/databases/nosql/columnar/ - Document Based: https://wiki.databurst.tech/docs/roadmap/databases/nosql/document-based/ - Key-Value: https://wiki.databurst.tech/docs/roadmap/databases/nosql/key-value/ - Time Series: https://wiki.databurst.tech/docs/roadmap/databases/nosql/time-series/ - Vector: https://wiki.databurst.tech/docs/roadmap/databases/nosql/vector/ - Graph: https://wiki.databurst.tech/docs/roadmap/databases/nosql/graph/ - NewSQL: https://wiki.databurst.tech/docs/roadmap/databases/nosql/newsql/ - Data Modeling: https://wiki.databurst.tech/docs/roadmap/data-modeling/ - Star Schema (Ralph Kimball): https://wiki.databurst.tech/docs/roadmap/data-modeling/star-schema/ - Snowflake: https://wiki.databurst.tech/docs/roadmap/data-modeling/snowflake/ - Data Vault: https://wiki.databurst.tech/docs/roadmap/data-modeling/data-vault/ - Data Management Architecture: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/ - Relational Data Warehouse: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/relational-data-warehouse/ - Data Lake: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/data-lake/ - Modern Data Warehouse: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/modern-data-warehouse/ - Data Fabric: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/data-fabric/ - Data Mart: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/data-mart/ - Data Lakehouse: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/data-lakehouse/ - Data Mesh: https://wiki.databurst.tech/docs/roadmap/data-management-architecture/data-mesh/ - Data Integration: https://wiki.databurst.tech/docs/roadmap/data-integration/ - ETL: https://wiki.databurst.tech/docs/roadmap/data-integration/etl/ - ELT: https://wiki.databurst.tech/docs/roadmap/data-integration/elt/ - CDC: https://wiki.databurst.tech/docs/roadmap/data-integration/cdc/ - Reverse ETL: https://wiki.databurst.tech/docs/roadmap/data-integration/reverse-etl/ - Storage: https://wiki.databurst.tech/docs/roadmap/storage/ - Block Storage: https://wiki.databurst.tech/docs/roadmap/storage/block-storage/ - Object Storage: https://wiki.databurst.tech/docs/roadmap/storage/object-storage/ - File Formats and Serialization: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/ - File Formats: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/file-formats/ - CSV: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/file-formats/csv/ - JSON: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/file-formats/json/ - Parquet: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/file-formats/parquet/ - XML: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/file-formats/xml/ - Serialization: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/serialization/ - Avro: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/serialization/avro/ - Protocol Buffers: https://wiki.databurst.tech/docs/roadmap/file-formats-and-serialization/serialization/protobuf/ - Query Engine: https://wiki.databurst.tech/docs/roadmap/query-engine/ - Apache Hive: https://wiki.databurst.tech/docs/roadmap/query-engine/hive/ - SparkSQL: https://wiki.databurst.tech/docs/roadmap/query-engine/sparksql/ - Trino: https://wiki.databurst.tech/docs/roadmap/query-engine/trino/ - Presto: https://wiki.databurst.tech/docs/roadmap/query-engine/presto/ - Data Architecture: https://wiki.databurst.tech/docs/roadmap/data-architecture/ - Kappa: https://wiki.databurst.tech/docs/roadmap/data-architecture/kappa/ - Lambda: https://wiki.databurst.tech/docs/roadmap/data-architecture/lambda/ - Data Processing: https://wiki.databurst.tech/docs/roadmap/data-processing/ - Pipeline Orchestration: https://wiki.databurst.tech/docs/roadmap/pipeline-orchestration/ - Messaging and Streaming Platform: https://wiki.databurst.tech/docs/roadmap/messaging-and-streaming-platform/ - Data Governance: https://wiki.databurst.tech/docs/roadmap/data-governance/ - Data Quality: https://wiki.databurst.tech/docs/roadmap/data-governance/data-quality/ - Data Visualization: https://wiki.databurst.tech/docs/roadmap/data-visualization/ - Containerization: https://wiki.databurst.tech/docs/roadmap/containerization/ - Docker: https://wiki.databurst.tech/docs/roadmap/containerization/docker/ - Podman: https://wiki.databurst.tech/docs/roadmap/containerization/podman/ - containerd: https://wiki.databurst.tech/docs/roadmap/containerization/containerd/ - Container Orchestration: https://wiki.databurst.tech/docs/roadmap/container-orchestration/ - Kubernetes: https://wiki.databurst.tech/docs/roadmap/container-orchestration/kubernetes/ - Docker Swarm: https://wiki.databurst.tech/docs/roadmap/container-orchestration/docker-swarm/ - Apache Mesos: https://wiki.databurst.tech/docs/roadmap/container-orchestration/apache-mesos/ - CI/CD: https://wiki.databurst.tech/docs/roadmap/cicd/ - DataOps: https://wiki.databurst.tech/docs/roadmap/cicd/dataops/ - Infrastructure as Code: https://wiki.databurst.tech/docs/roadmap/infrastructure-as-code/ - Configuration Management: https://wiki.databurst.tech/docs/roadmap/infrastructure-as-code/configuration-management/ - Infrastructure Provisioning: https://wiki.databurst.tech/docs/roadmap/infrastructure-as-code/infrastructure-provisioning/ - Observability: https://wiki.databurst.tech/docs/roadmap/observability/ - Logging: https://wiki.databurst.tech/docs/roadmap/observability/logging/ - Monitoring: https://wiki.databurst.tech/docs/roadmap/observability/monitoring/ - Tracing: https://wiki.databurst.tech/docs/roadmap/observability/tracing/ - Glossary: https://wiki.databurst.tech/docs/roadmap/glossary/
$ EXPLAIN SELECT * FROM orders WHERE id = 642;
# Indexing An **index** is an extra data structure that lets a database find rows without reading the whole table, the same way a book's index lets you jump to a page instead of reading every page. It is a sorted, compact copy of one or more columns with pointers back to the rows. Indexes make reads dramatically faster and make every write a little slower, because each insert or update must also update the index. ## From full scan to index lookup {{< fig kicker="$ SELECT * FROM orders WHERE id = 642" title="Full table scan vs B-tree index lookup" >}} orders: 16 pages on disk HEAP · table pages, rows in insert order SEQ SCAN · 16 / 16 pages read ROOT · 400 | 800 < 200 | ≥ 200< 600 | ≥ 600< 1000 | ≥ 1000 1–199200–399400–599 600–799800–9991000+ INDEX SCAN · 3 index + 1 heap page id 642 → page 12 leaves are linked: id BETWEEN 600 AND 999 = 1 descent + walk right
  1. The orders table is stored as pages on disk, rows in the order they were inserted. We want one row: id = 642.
  2. With no index, the database must read every page and check every row: a sequential scan. Cost grows with the table.
  3. A B-tree index on id keeps keys sorted in a shallow tree. Each node holds many keys and points to the right child for each range.
  4. Lookup: root says 642 is between 400 and 800, the next node sends it right of 600, the leaf holds 642 → page 12. Four page reads instead of sixteen. On a billion rows, the tree is still only 3 to 5 levels deep.
  5. Leaves are linked in key order, so range queries and ORDER BY id descend once and then walk sideways.
{{< /fig >}} ## Index types | Type | Structure | Good for | Found in | |---|---|---|---| | **B-tree** | Balanced sorted tree | Equality, ranges, sorting; the default | PostgreSQL, MySQL, SQL Server, Oracle, SQLite | | **Hash** | Hash table | Equality only | PostgreSQL hash, in-memory stores | | **LSM-tree** | Sorted in-memory buffer flushed to sorted files, merged in the background | Very high write rates | Cassandra, RocksDB, ScyllaDB, ClickHouse MergeTree (similar idea) | | **Inverted (GIN)** | Term → list of rows | Full-text search, JSON, arrays | Elasticsearch, OpenSearch, PostgreSQL GIN | | **BRIN / zone maps** | Min/max per block of rows | Huge, naturally ordered tables (time series) | PostgreSQL BRIN, Parquet statistics, Snowflake micro-partitions | | **Bitmap** | One bit-array per distinct value | Low-cardinality columns in analytics | Oracle, Druid, Pinot | | **Vector (HNSW, IVF)** | Graph or clusters of embeddings | Nearest-neighbour search | pgvector, Milvus, Elasticsearch | Analytical warehouses rarely use B-trees. They rely on **columnar storage, partitioning and min/max statistics** to skip data instead, as explained on the [Parquet]({{< relref "/docs/roadmap/file-formats-and-serialization/file-formats/parquet" >}}) page. ## Designing good indexes - **Index what you filter and join on.** Start from real slow queries and their `EXPLAIN` plans, not from guesses. - **Selectivity matters.** An index on `status` with three values rarely helps; the database will scan anyway. - **Composite indexes follow the leftmost-prefix rule.** An index on `(customer_id, created_at)` serves `WHERE customer_id = 7` and `WHERE customer_id = 7 AND created_at > ...`, but not `WHERE created_at > ...` alone. - **Covering indexes** (`INCLUDE (amount)` in PostgreSQL) answer a query from the index alone, skipping the heap. - **Every index costs** disk space, memory and write time. A table with ten indexes does eleven writes per insert. ## Indexes in sharded systems When data is [sharded]({{< relref "/docs/roadmap/distributed-systems-concepts/sharding" >}}) by one key, an index on a different column has two possible shapes: | | Local (document-partitioned) index | Global (term-partitioned) index | |---|---|---| | Where it lives | Each shard indexes only its own rows | The index itself is sharded by the indexed value | | Writes | Cheap: one shard | Touch the data shard and an index shard, often asynchronously | | Reads by indexed column | Ask every shard (scatter-gather) | Ask one index shard | | Examples | Elasticsearch, MongoDB, Cassandra secondary indexes | DynamoDB global secondary indexes, Spanner, CockroachDB | DynamoDB global secondary indexes are updated asynchronously, so they are eventually consistent: a read right after a write can miss it. See [Consistency vs Eventual Consistency]({{< relref "/docs/roadmap/distributed-systems-concepts/consistency-vs-eventual-consistency" >}}). ## Common mistakes - **Wrapping the column in a function.** `WHERE LOWER(email) = ...` cannot use a plain index on `email`; create an expression index or store the normalized value. - **Leading wildcards.** `LIKE '%gmail.com'` cannot use a B-tree; use a trigram (pg_trgm) or full-text index. - **Indexing everything "just in case".** Unused indexes slow every write. Check `pg_stat_user_indexes` and drop the dead ones. - **Forgetting bulk loads.** For a big backfill, drop or disable secondary indexes, load, then rebuild. - **Implicit type casts.** Comparing a `varchar` column to a number can disable the index. ## Learning Resources ### Books and sites - [Use The Index, Luke](https://use-the-index-luke.com/): Markus Winand's free guide to SQL indexing - [Database Internals](https://www.oreilly.com/library/view/database-internals/9781492040330/), Alex Petrov: B-trees and LSM-trees in depth - *Designing Data-Intensive Applications* (2nd ed.), Martin Kleppmann and Chris Riccomini: storage and retrieval, and the partitioning chapter on secondary indexes ### Docs - [PostgreSQL: Indexes](https://www.postgresql.org/docs/current/indexes.html) - [PostgreSQL: Using EXPLAIN](https://www.postgresql.org/docs/current/using-explain.html) - [DynamoDB: Global secondary indexes](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html) ### Videos - [How indexes work in distributed databases, their trade-offs, and challenges](https://www.youtube.com/watch?v=eQ3eNd5WbH8)