Indexes and Constraints

Range, point, text indexes + UNIQUE / EXISTS constraints — your single biggest perf lever.

0/2 done

Overview

Indexes and Constraints

Range, point, text indexes + UNIQUE / EXISTS constraints — your single biggest perf lever.

Why it matters

Without an index, the first MATCH in a query scans every node of the given label — fine for 10k nodes, catastrophic at 10M.

Going deeper

What each index type buys you and when to reach for it:

Index typeBest forDon't use for
Range (BTREE default)=, <, >, range scans on most typesSubstring searches
TextSTARTS WITH, CONTAINS, ENDS WITHNumeric ranges
PointGeospatial distance and bounding-boxNon-geospatial properties
Token-lookupMATCH (n:Label) with no property filterAnything requiring property predicates
CompositeQueries that filter on N properties togetherSingle-property predicates (the composite isn't used)

A constraint also creates the matching index for free, so for any field you want unique you should prefer the constraint form over a bare CREATE INDEX.

Analogy

An index is the book's index, not the book's table of contents.

Without it, every lookup of 'where does Voltaire appear in this 800-page volume?' is a flip-every-page scan. With it, the lookup is one glance — the index says 'pages 12, 84, 309' and you jump straight to them.

A constraint is the publisher's promise that the index is honest: there will be only one entry for 'Voltaire' (UNIQUE), and every book chapter has a title (EXISTS). The DB enforces those promises so the index can stay correct.

Make it stick

Use the prompts below to anchor indexes and constraints to a real graph you own.

  • List the top 3 read queries on your biggest label. For each, is the right index *type* in place?
  • Where have you used `CREATE INDEX` when a `CREATE CONSTRAINT ... REQUIRE ... IS UNIQUE` would have given you both the index and an integrity check?
  • Which composite index in your schema is *never* used because queries always filter on just one of its columns?

Reading in progress · 0 of 2 activities done