0
0
SQLquery~20 mins

Index impact on INSERT and UPDATE in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Index Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How do indexes affect INSERT operations?

When you insert a new row into a table that has multiple indexes, what happens behind the scenes?

AThe database updates all indexes related to the table to include the new row, which can slow down the INSERT.
BThe database duplicates the inserted row in each index without updating the main table.
COnly the primary key index is updated during INSERT; other indexes update later asynchronously.
DIndexes are ignored during INSERT operations to speed up data entry.
Attempts:
2 left
💡 Hint

Think about what must happen to keep indexes accurate when new data is added.

🧠 Conceptual
intermediate
2:00remaining
Why can UPDATE operations be slower on indexed columns?

Updating a column that is part of an index can be slower than updating a non-indexed column. Why?

ABecause the database duplicates the entire table when an indexed column is updated.
BBecause updates on indexed columns are blocked until all queries finish.
CBecause the database must update the index entries related to the changed column, adding extra work.
DBecause indexed columns cannot be updated once created.
Attempts:
2 left
💡 Hint

Consider what happens to the index when the data it tracks changes.

query_result
advanced
2:00remaining
Effect of indexes on INSERT speed

Given a table users with 3 indexes, you run two INSERT queries: one on the table with indexes and one after dropping all indexes. Which query runs faster?

SQL
INSERT INTO users (id, name, email) VALUES (101, 'Alice', 'alice@example.com');
AThe INSERT on the table without indexes runs slower because indexes optimize data storage.
BThe INSERT on the table without indexes runs faster because no index updates are needed.
CBoth INSERTs run at the same speed because indexes do not affect INSERT performance.
DThe INSERT on the table with indexes runs faster because indexes speed up data insertion.
Attempts:
2 left
💡 Hint

Think about the extra work indexes require during data insertion.

query_result
advanced
2:00remaining
Impact of updating indexed vs non-indexed columns

Consider a table products with an index on the price column. You run these two UPDATE queries:

UPDATE products SET price = price * 1.1 WHERE id = 5;
UPDATE products SET description = 'New model' WHERE id = 5;

Which UPDATE is expected to take longer?

AThe UPDATE on the <code>price</code> column takes longer because it updates the index.
BThe UPDATE on the <code>description</code> column takes longer because it is a text field.
CBoth UPDATEs take the same time because indexes do not affect UPDATE speed.
DThe UPDATE on the <code>description</code> column takes longer because it triggers index rebuilds.
Attempts:
2 left
💡 Hint

Consider which columns have indexes and what updating them requires.

📝 Syntax
expert
3:00remaining
Identify the error in index update during INSERT trigger

Given this trigger code to update a custom index table after INSERT, what error will it cause?

CREATE TRIGGER update_index AFTER INSERT ON orders
FOR EACH ROW
BEGIN
  INSERT INTO orders_index(order_id, customer_id) VALUES (NEW.order_id, NEW.customer_id);
END;
ARuntime error because NEW keyword cannot be used in AFTER INSERT triggers.
BNo error; the trigger works correctly.
CLogical error because the trigger causes infinite recursion.
DSyntax error due to missing delimiter declaration before trigger creation.
Attempts:
2 left
💡 Hint

Check if the trigger syntax requires special delimiter handling.