Bird
Raised Fist0
Interview Prepdatabase-management-systemseasyAmazonGoogleMicrosoftFlipkartRazorpayPhonePeZepto

ACID Properties - Atomicity, Consistency, Isolation, Durability

Choose your preparation mode3 modes available
▶
Steps
setup

Initialize B-tree with ACID Properties

We start by creating a B-tree with a single root node containing all four ACID properties as keys: Atomicity, Consistency, Isolation, Durability. This sets the stage for exploring each property.

💡 Initializing the B-tree with all ACID properties as keys helps visualize them as interconnected parts of a whole, rather than isolated concepts.
Line:b_tree = BTree(order=4) b_tree.root = Node(keys=['Atomicity', 'Consistency', 'Isolation', 'Durability'], is_leaf=True)
💡 The ACID properties can be represented as keys in a balanced tree structure, emphasizing their equal importance and interrelation.
📊
ACID Properties - Atomicity, Consistency, Isolation, Durability - Watch the Algorithm Execute, Step by Step
Watching this step-by-step visualization helps you understand how each ACID property functions individually and collectively to ensure reliable database transactions, which is difficult to grasp from text alone.
Step 1/11
·Active fill★Answer cell
setup
AtomicityConsistencyIsolationDurability
leaf
Initialize root node with all ACID properties as keys.
traverseKey: Atomicity
AtomicityConsistencyIsolationDurability
leaf
Highlight 'Atomicity' to explain its role in transactions.
traverseKey: Atomicity
AtomicityConsistencyIsolationDurability
leaf
Simulate commit or rollback to enforce Atomicity.
traverseKey: Consistency
AtomicityConsistencyIsolationDurability
leaf
Highlight 'Consistency' to explain its role.
traverseKey: Consistency
AtomicityConsistencyIsolationDurability
leaf
Check constraints to enforce Consistency.
traverseKey: Isolation
AtomicityConsistencyIsolationDurability
leaf
Highlight 'Isolation' to explain concurrency control.
traverseKey: Isolation
AtomicityConsistencyIsolationDurability
leaf
Acquire locks to enforce Isolation.
traverseKey: Durability
AtomicityConsistencyIsolationDurability
leaf
Highlight 'Durability' to explain persistence.
traverseKey: Durability
AtomicityConsistencyIsolationDurability
leaf
Write logs before commit to ensure Durability.
traverse
AtomicityConsistencyIsolationDurability
leaf
Highlight all ACID properties to summarize their combined effect.
traverse
AtomicityConsistencyIsolationDurability
leaf
Final state showing all ACID properties together.

Key Takeaways

✓ ACID properties can be conceptually represented as nodes in a balanced tree, emphasizing their equal importance and interrelation.

This visual metaphor helps learners see ACID as a cohesive system rather than isolated rules.

✓ Each ACID property enforces a specific guarantee: Atomicity ensures all-or-nothing, Consistency enforces rules, Isolation controls concurrency, and Durability guarantees persistence.

Seeing each property highlighted separately clarifies their distinct roles.

✓ The mechanisms like rollback, constraint checks, locking, and write-ahead logging are practical implementations of ACID properties.

Understanding these mechanisms visually connects theory to real database operations.

Practice

(1/5)
1. In which scenario is the cardinality estimate most critical for the query optimizer to choose an efficient join order?
easy
A. When the query involves only simple projections without any filtering or joins
B. When the query involves multiple joins with large tables and selective predicates
C. When the query uses aggregate functions without any filtering conditions
D. When the query only scans a single small table without any joins

Solution

  1. 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.
  2. Step 2: Analyze scenarios

    Queries involving multiple joins with large tables and selective predicates require accurate cardinality estimates to avoid expensive join orders.
  3. 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.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Cardinality is most critical when join order decisions affect performance, especially with large datasets and selective filters.
Hint: Cardinality matters most when join order impacts cost in multi-join queries.
Common Mistakes:
  • Assuming cardinality is equally important for single-table queries
  • Confusing cardinality with total table size
  • Ignoring the effect of predicates on cardinality
2. Which of the following statements about using hash indexes for range queries is TRUE regarding performance trade-offs?
medium
A. Hash indexes do not support range queries efficiently because keys are distributed non-sequentially, requiring a full scan.
B. Hash indexes perform better than B+ trees for range queries because hashing reduces disk I/O.
C. Hash indexes can efficiently support range queries by scanning only relevant buckets, resulting in O(log n) time.
D. Hash indexes can be modified to support range queries by sorting keys within each bucket.

Solution

  1. Step 1: Understand hash index key distribution

    Hash indexes distribute keys across buckets based on hash values, losing key order.
  2. Step 2: Range query implications

    Because keys are unordered, range queries require scanning all buckets or the entire table.
  3. Step 3: Evaluate distractors

    Hash indexes can efficiently support range queries by scanning only relevant buckets, resulting in O(log n) time. incorrectly claims efficient bucket scanning for ranges. Hash indexes perform better than B+ trees for range queries because hashing reduces disk I/O. wrongly states hash indexes outperform B+ trees for range queries. Hash indexes can be modified to support range queries by sorting keys within each bucket. suggests sorting within buckets, which is not standard and does not solve global ordering.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Hash index + range query -> full scan needed [OK]
Hint: Hash indexes lose order -> no efficient range queries
Common Mistakes:
  • Assuming hash buckets are ordered
  • Believing hash indexes reduce I/O for range queries
  • Thinking sorting within buckets enables global range queries
3. Which of the following statements about B+ tree indexes is INCORRECT?
medium
A. B+ trees maintain keys in sorted order, enabling efficient range queries.
B. B+ trees store all data only in leaf nodes, with internal nodes storing keys for navigation.
C. B+ trees provide O(1) time complexity for equality lookups due to balanced structure.
D. B+ trees link leaf nodes to allow sequential access without traversing internal nodes.

Solution

  1. Step 1: Review B+ tree properties

    B+ trees keep keys sorted, store data in leaves, and link leaves for sequential access.
  2. Step 2: Analyze time complexity

    Equality lookups require O(log n) time due to tree traversal, not O(1).
  3. Step 3: Evaluate distractors

    Options B, C, and D correctly describe B+ tree features.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    B+ tree equality lookup is O(log n), not O(1) [OK]
Hint: B+ tree lookup = O(log n), not O(1)
Common Mistakes:
  • Confusing B+ tree lookup with hash index lookup time
  • Assuming internal nodes store data
  • Ignoring leaf node linkage
4. What is the time complexity of using a correlated subquery with EXISTS to find all customers who have orders, assuming n customers and m orders?
medium
A. O(n * m) because for each customer the orders table is scanned
B. O(n + m) because each table is scanned once
C. O(m) because only orders are scanned
D. O(n log m) because of index lookups on orders

Solution

  1. Step 1: Understand correlated subquery execution

    For each of the n customers, the subquery scans orders (m rows) to check existence.
  2. Step 2: Calculate total complexity

    This leads to O(n * m) time complexity, as the orders table is scanned repeatedly.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Repeated scans cause multiplicative complexity [OK]
Hint: Correlated subqueries scan inner table per outer row [OK]
Common Mistakes:
  • Assuming single scan of orders
  • Confusing correlated with non-correlated subqueries
  • Ignoring repeated scans in correlated subqueries
5. Identify the bug in the following Python code that attempts to find customers with orders using a JOIN simulation:
medium
A. Line 3: The return statement should remove duplicates explicitly with DISTINCT.
B. Line 2: The list comprehension incorrectly filters customers by order IDs instead of customer IDs.
C. Line 1: Using a list instead of a set for order_customer_ids causes duplicates and slower lookups.
D. Line 1: The variable name order_customer_ids is misleading and should be order_ids.

Solution

  1. Step 1: Analyze data structure used for order_customer_ids

    Using a list causes O(m) lookup per customer, leading to O(n*m) time and duplicates.
  2. Step 2: Identify impact on performance and correctness

    Using a set enables O(1) lookups and avoids duplicates, improving performance and correctness.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Replacing list with set fixes performance and duplicate issues [OK]
Hint: Sets provide O(1) membership checks, lists do not [OK]
Common Mistakes:
  • Using list instead of set for membership
  • Confusing customer_id with order_id
  • Assuming duplicates are handled automatically
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard