{
  "slug": "composite-index",
  "term": "Composite index",
  "aliases": [
    "Multicolumn index",
    "Multi-column index",
    "Compound index"
  ],
  "definition": "A composite index is a database index whose search key contains more than one column or expression.",
  "note": "In a B-tree on (a, b), a orders entries first and b breaks ties under the comparison rules. Reversing keys changes the ordering. SQL still needs ORDER BY for output order. [sqlite-planner]\n\nLeading equalities and the first range bound a conventional B-tree lookup; later conditions can filter entries. A missing leading equality does not make every lookup impossible: SQLite and PostgreSQL 18 can choose skip scans across leading-key groups. Statistics and costs affect that choice. [sqlite-skip] [pg-multi]\n\nSeparate single-column indexes are different structures. PostgreSQL can combine row-location bitmaps but loses index ordering. SQLite does not generally intersect separate indexes for AND-connected terms. [pg-combine] [sqlite-planner]\n\nUNIQUE(a, b) constrains combinations under the comparison rules, not each key individually. SQLite NOCASE folds ASCII only. NULL-bearing pairs may repeat, while GROUP BY groups NULLs together. PostgreSQL offers NULLS NOT DISTINCT. [sqlite-create] [sqlite-types] [sqlite-group] [pg-unique]\n\nMultiple key columns differ from included payload columns. Multicolumn GiST, GIN and BRIN have access-method-specific rules; B-tree ordering does not describe all of them. [pg-multi]",
  "related": [
    "b-tree"
  ],
  "citations": [
    {
      "id": "sqlite-planner",
      "title": "SQLite: Query Planning, multicolumn keys and search/sort",
      "url": "https://www.sqlite.org/queryplanner.html",
      "accessed": "2026-11-18"
    },
    {
      "id": "sqlite-skip",
      "title": "SQLite: Query Optimizer Overview, skip-scan optimization",
      "url": "https://www.sqlite.org/optoverview.html#the_skip_scan_optimization",
      "accessed": "2026-11-18"
    },
    {
      "id": "sqlite-create",
      "title": "SQLite: CREATE INDEX, key expressions and uniqueness",
      "url": "https://www.sqlite.org/lang_createindex.html",
      "accessed": "2026-11-18"
    },
    {
      "id": "pg-multi",
      "title": "PostgreSQL 18: Multicolumn Indexes, key versus payload and scan bounds",
      "url": "https://www.postgresql.org/docs/18/indexes-multicolumn.html",
      "accessed": "2026-11-18"
    },
    {
      "id": "pg-combine",
      "title": "PostgreSQL 18: Combining Multiple Indexes, bitmap ordering",
      "url": "https://www.postgresql.org/docs/18/indexes-bitmap-scans.html",
      "accessed": "2026-11-18"
    },
    {
      "id": "pg-unique",
      "title": "PostgreSQL 18: Unique Indexes, combinations and NULLS NOT DISTINCT",
      "url": "https://www.postgresql.org/docs/18/indexes-unique.html",
      "accessed": "2026-11-18"
    },
    {
      "id": "sqlite-eqp",
      "title": "SQLite: EXPLAIN QUERY PLAN, diagnostic output stability",
      "url": "https://www.sqlite.org/eqp.html",
      "accessed": "2026-11-18"
    },
    {
      "id": "selinger",
      "title": "Selinger et al. (1979): Access Path Selection in a Relational Database Management System, SIGMOD, sections 4-5; DOI 10.1145/582095.582099",
      "url": "https://cs.stanford.edu/people/chrismre/cs345/rl/selinger.pdf",
      "accessed": "2026-11-18"
    },
    {
      "id": "hesela",
      "title": "Hesela: composite-index key order and native SQLite controls",
      "url": "https://hesela.com/analyses/sqlite-index-runtime-dependencies/#composite-index-order",
      "accessed": "2026-11-18"
    },
    {
      "id": "sqlite-types",
      "title": "SQLite Datatypes: BINARY and ASCII-only NOCASE collation",
      "url": "https://www.sqlite.org/datatype3.html#collation",
      "accessed": "2026-11-18"
    },
    {
      "id": "sqlite-group",
      "title": "SQLite SELECT: NULL equality and collation in GROUP BY",
      "url": "https://www.sqlite.org/lang_select.html#resultset",
      "accessed": "2026-11-18"
    },
    {
      "id": "unique-evidence",
      "title": "Hesela: composite UNIQUE, NULL grouping and native replay",
      "url": "https://hesela.dev/research/unique-equality/README.md",
      "accessed": "2026-11-18"
    }
  ],
  "status": "shipping",
  "advantages": [],
  "limitations": [],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-18",
  "provenance": [
    "Primary-documentation synthesis. The linked five-query SQLite demonstration uses 400 constructed rows and tests answers independently of plan text; it is not a performance benchmark or PostgreSQL execution. [hesela]",
    "EXPLAIN QUERY PLAN output is diagnostic and can change between SQLite releases. [sqlite-eqp]",
    "Historical context: System R retained alternatives for useful output orders and compared their costs with unordered access plus sorting. This 1979 design is not a claim about the internals of current SQLite or PostgreSQL. [selinger]",
    "A separate four-fixture, 48-insert SQLite control records full typed rows and exact errors; nullable UNIQUE acceptance differs from a GROUP BY duplicate audit. This is not a recovery or timing test. [unique-evidence]"
  ]
}
