Practice
Solution
Step 1: Understand cardinality's role in join order selection
Cardinality estimates predict the number of rows flowing between operators, which directly impacts join cost and order.Step 2: Analyze scenarios
Queries involving multiple joins with large tables and selective predicates require accurate cardinality estimates to avoid expensive join orders.Step 3: Why other options are incorrect
When the query involves only simple projections without any filtering or joins: Simple projections without joins do not rely heavily on cardinality for join order.
When the query only scans a single small table without any joins: Single small table scans do not involve join order decisions.
When the query uses aggregate functions without any filtering conditions: Aggregates without filters have less impact on join order and cardinality estimates.Final Answer:
Option B -> Option BQuick Check:
Cardinality is most critical when join order decisions affect performance, especially with large datasets and selective filters.
- Assuming cardinality is equally important for single-table queries
- Confusing cardinality with total table size
- Ignoring the effect of predicates on cardinality
Solution
Step 1: Understand table-level locking characteristics
Table-level locking locks the entire table, blocking other transactions from accessing it concurrently during writes.Step 2: Analyze concurrency implications
Because it locks the whole table, concurrency is generally lower than with row-level locking.Step 3: Evaluate each statement
A is true: fewer deadlocks due to coarse granularity. C is true: blocks all concurrent writes and reads depending on lock mode. D is true: simpler but less concurrent. B is false: it does not allow higher concurrency than row-level locking.Final Answer:
Option C -> Option CQuick Check:
Table-level locking sacrifices concurrency for simplicity and reduced deadlock risk.
- Assuming table-level locking is more concurrent than row-level
- Confusing deadlock frequency with concurrency level
- Overlooking blocking effects of table locks
Solution
Step 1: Understand function side effects
Functions are expected to be deterministic and free of side effects; they should not modify table data.Step 2: Validate other statements
Functions must return a value, can be used in SELECT, and typically cannot call stored procedures.Final Answer:
Option D -> Option DQuick Check:
Functions are designed to be side-effect free for predictability.
- Thinking functions can modify data
- Confusing functions with stored procedures
- Assuming functions can call procedures
Solution
Step 1: Analyze query pattern filtering on status and recent dates
Queries filter on status and recent dates, so both columns are used in WHERE clause.Step 2: Evaluate current indexes
Clustered index on date helps range scans; non-clustered on status helps filtering but not combined efficiently.Step 3: Consider composite index benefit
A composite non-clustered index on (status, date) supports filtering by status and ordering by date efficiently.Step 4: Assess other options
Changing clustered index to status loses physical ordering benefits for date range queries; dropping indexes reduces performance; separate indexes cause extra lookups.Final Answer:
Option C -> Option CQuick Check:
Composite index on (status, date) + clustered on date -> best for combined filters [OK]
- Assuming clustered index must be on single most filtered column
- Ignoring composite index advantages
- Believing separate indexes always suffice for multi-column filters
Solution
Step 1: Understand system constraints
The system is geo-distributed, prioritizing availability and partition tolerance, but needs strict consistency for some transactions.Step 2: Evaluate options
Switch the entire system to a strongly consistent SQL database cluster sacrifices availability globally, which is undesirable. Accept eventual consistency for all transactions to maintain availability ignores strict consistency needs. Use synchronous replication across all nodes for all data to guarantee consistency sacrifices availability due to synchronous replication delays.Step 3: Hybrid solution
Implement a hybrid approach using multi-model databases or selective consistency zones for critical data proposes selective consistency zones or multi-model databases, allowing critical transactions to be strongly consistent while maintaining availability elsewhere.Final Answer:
Option C -> Option CQuick Check:
Hybrid approaches balance consistency and availability per data criticality [OK]
- Thinking entire system must switch to SQL for consistency
- Assuming eventual consistency suffices for critical transactions
- Believing synchronous replication is always feasible in geo-distributed setups
