B-tree structure
- SQL course
- Expert
- Lesson 7/45
- 5 min
Learn the B-tree index structure.
B-tree structure
B-tree is the most common index structure. It is a balanced tree of root, branch and leaf nodes. Search, insert and delete run in O(log n) time.
CREATE INDEX idx_products_name
ON products(name);B-tree supports equality and range queries.
The index idx_products_name is created.
B-tree structure — details
Leaves are kept sorted; this makes range queries like BETWEEN, > and < fast. Each leaf carries a pointer to the table row.
Practice B-tree structure
Create the idx_products_name index on the name column of products.
Starter code
-- B-tree index
CREATE INDEXSample solution
CREATE INDEX idx_products_name ON products(name);Expected output
CREATE INDEX
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which query type does B-tree support?
- Range queries Correct answer
- Full-text search only
- Geographic data only
- Arrays only
Explanation: B-tree supports range queries.
2 Create an index
CREATE INDEX idx_products_name ON ____
CREATE INDEX idx_products_name ON products(name)
Explanation: products(name) is the right answer.
3 B-tree structure: match the terms
| Term | Meaning |
|---|---|
B-tree |
balanced tree |
leaf |
leaf |
range |
range |
pointer |
pointer |