Home / Community / SQL Indexing & Query Optimization Techniques
Public

SQL Indexing & Query Optimization Techniques

Master SQL query performance with this high-yield flashcard deck covering B-tree indexes, execution plans, join algorithms, and SARGable query patterns.

20 accessible of 20 cards

Card Preview

20 accessible of 20 cards

A quick, read-only look at the deck content.

Term

B-Tree Index

Definition

A self-balancing search tree structure that maintains sorted data to enable logarithmic time complexity () for searches, sequential access, insertions, and deletions. It is the default index type in most relational database management systems (RDBMS).

Term

Clustered Index vs. Non-Clustered Index

Definition

Clustered Index: Determines the physical storage order of data inside the table. A table can have only one clustered index (usually the Primary Key).
Non-Clustered Index: A separate structure containing sorted keys and pointers (Row IDs or clustered keys) back to the actual data rows. A table can have multiple non-clustered indexes.

Term

Composite Index & Leftmost Prefix Rule

Definition

An index created on multiple columns (e.g., (A, B, C)). It follows the Leftmost Prefix Rule, meaning queries can utilize the index if filtering by A, (A, B), or (A, B, C), but not by B or C alone without A.

Term

Covering Index

Definition

An index that contains all the columns requested by a query (in SELECT, WHERE, JOIN, and ORDER BY clauses). Because all required data resides inside the index itself, the database avoids costly physical table lookups (key lookups).

Term

Include Columns (INCLUDE clause)

Definition

A mechanism to add non-key payload columns to the leaf nodes of a non-clustered index without increasing the size of the B-tree search keys.
Example:
```sql
CREATE INDEX idx_user_status
ON users (status)
INCLUDE (email, name);
```

Term

Query Execution Plan

Definition

A sequence of operations generated by the database optimizer detailing how a query will be executed. It reveals operational steps such as Index Seeks, Table Scans, Join algorithms, and sorting costs.

Term

EXPLAIN vs. EXPLAIN ANALYZE

Definition

  • EXPLAIN: Generates and displays the estimated execution plan based on table statistics without running the query.
  • EXPLAIN ANALYZE: Actually executes the query, returning execution times, actual row counts, memory usage, and structural plan details.

Term

Table Scan vs. Index Scan vs. Index Seek

Definition

  • Table Scan: Reads every data page in the entire table ().
  • Index Scan: Reads through all leaf pages of an index ().
  • Index Seek: Uses the B-tree structure to jump directly to specific matching rows ().