Flashcard Deck · 20 cards · Public

SQL Performance Tuning & Indexing Strategies

Master high-yield database performance concepts, execution plan operators, B-Tree and Hash indexing strategies, locking mechanisms, and SARGable query refactoring techniques for backend developers and DBAs.

Cards in this deck

(20 cards)

Preview terms and definitions before starting your study session.

#1
Term
Shared Lock (S) vs. Exclusive Lock (X)
Definition
  • Shared Lock (S): Placed during read operations (SELECT). Multiple transactions can hold shared locks concurrently, but writes are blocked.
  • Exclusive Lock (X): Placed during write operations (INSERT, UPDATE, DELETE). Blocks all other concurrent reads and writes.
#2
Term
Intent Locks (IS / IX)
Definition
Hierarchy-level locks (placed at Table or Page levels) indicating that a transaction holds or intends to acquire fine-grained locks (Row level) beneath it. Prevents coarse high-level locks (e.g., full table lock) from conflicting with ongoing row-level transactions.
#3
Term
Deadlock
Definition
A circular dependency where Transaction A waits for a resource locked by Transaction B, while Transaction B waits for a resource locked by Transaction A. The DBMS automatically detects deadlocks and terminates one transaction (the 'deadlock victim') to allow the other to complete.
#4
Term
Optimistic vs. Pessimistic Concurrency Control
Definition
  • Pessimistic: Locks resources aggressively upfront assuming conflicts will happen; best for high-contention write workloads.
  • Optimistic: Uses row versioning/timestamps without upfront locks; validates changes at commit time and rolls back on conflicts. Ideal for high-concurrency read-heavy workloads.
#5
Term
Filtered (Partial) Index
Definition
An index created with a WHERE condition to index only a specific subset of rows (e.g., CREATE INDEX idx_unprocessed ON jobs(created_at) WHERE status = 'PENDING'). Reduces index size, lowers write maintenance overhead, and speeds up selective queries.
#6
Term
Refactoring OR Conditions to UNION ALL
Definition
Queries using OR across multiple columns often fail to utilize individual indexes efficiently, falling back to full scans. Rewriting as two separate SELECT statements joined by UNION ALL enables separate, optimized index seeks for each predicate.
#7
Term
Subquery Performance: EXISTS vs. IN
Definition
EXISTS short-circuits and returns true as soon as a single match is found in the subquery. IN evaluates the entire subquery result set before filtering and can produce incorrect results or poor plans if the subquery returns NULL values.
#8
Term
Execution Plan Join Operators: Nested Loop vs. Hash vs. Merge
Definition
  • Nested Loop: Iterates over outer rows matching inner rows; ideal for small sets and indexed inner lookups ( worst-case).
  • Hash Match: Builds an in-memory hash table for large, unsorted datasets.
  • Merge Join: Blazingly fast join that requires both input datasets to be pre-sorted on join keys.
Showing 8 of 20 cards in this deck.
Study All Now