In DB2 database management, how does the DB2 optimizer decide which lock size (row, page, table, or table space) to use for a particular operation?

Difficulty: Medium

Correct Answer: DB2 chooses the lock size based on table and tablespace definitions, LOCKSIZE and LOCKMAX settings, and may escalate locks during execution when needed.

Explanation:


Introduction / Context:
Locking and concurrency control are central topics when learning DB2 database administration and performance tuning. This interview question checks whether the candidate understands that DB2 does not randomly pick a lock size, but uses a combination of catalog definitions, bind options, and internal thresholds to decide whether to lock at row, page, table, or tablespace level.


Given Data / Assumptions:

  • The DB2 subsystem supports multiple lock sizes such as row, page, table, and tablespace.
  • Tablespaces and tables have attributes like LOCKSIZE and LOCKMAX defined in the catalog.
  • Applications are bound with specific isolation and lock related options.


Concept / Approach:
DB2 initially chooses a lock size based on DDL definitions such as LOCKSIZE PAGE or LOCKSIZE ROW on the tablespace. It also respects bind options, isolation levels, and concurrency needs. During execution, when the number of locks grows beyond thresholds, DB2 can perform lock escalation, replacing many small locks with a fewer larger locks. The correct explanation therefore must mention catalog definitions, lock parameters, and escalation, rather than simplistic or operating system based rules.


Step-by-Step Solution:
Step 1: Recall that LOCKSIZE is defined at tablespace creation or alteration time and can specify row, page, table, or tablespace. Step 2: Remember that DB2 also considers LOCKMAX and other thresholds that limit how many locks can be held before escalation is attempted. Step 3: Understand that DB2 uses its optimizer and concurrency rules to pick an initial lock size that balances concurrency and overhead. Step 4: When too many locks are acquired, DB2 may escalate to a coarser lock size, such as from row to page or table. Step 5: Therefore, the most accurate description is that DB2 chooses lock size from catalog and configuration settings and may change it through escalation.


Verification / Alternative check:
A quick way to verify is to think about what happens when many rows are updated in a single transaction. DB2 often escalates from row locks to page or table level locks when internal thresholds are exceeded. This behavior directly contradicts the idea that DB2 always uses the largest lock size from the start, and it confirms that the choice is dynamic and based on configuration and runtime conditions.


Why Other Options Are Wrong:
Option B is wrong because DB2 does not always use the largest possible lock; it starts with a configured lock size and only escalates when needed.
Option C is wrong because application programmers do not manually specify the low level lock size for every statement; they influence it indirectly via isolation, but DB2 performs the detailed choice.
Option D is wrong because DB2 itself, not the operating system, contains the locking logic and algorithms for choosing lock size.


Common Pitfalls:
A common misconception is to think that setting LOCKSIZE at tablespace creation fixes lock behavior forever. In reality, lock escalation and different access paths can change which locks are actually used. Another mistake is to underestimate the impact of isolation levels and bind options on locking. Forgetting about these interactions can lead to confusion when explaining how DB2 does its locking decisions in real workloads.


Final Answer:
The correct explanation is that DB2 chooses the lock size based on table and tablespace definitions, LOCKSIZE and LOCKMAX settings, and may escalate locks during execution when needed.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion