When you insert a new row into a table that has multiple indexes, what happens behind the scenes?
Think about what must happen to keep indexes accurate when new data is added.
When inserting, the database must update all indexes to include the new row so queries using those indexes remain accurate. This adds overhead and can slow down INSERT operations.
Updating a column that is part of an index can be slower than updating a non-indexed column. Why?
Consider what happens to the index when the data it tracks changes.
When an indexed column is updated, the database must update the index entries to reflect the new values, which adds overhead and can slow down the UPDATE operation.
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?
INSERT INTO users (id, name, email) VALUES (101, 'Alice', 'alice@example.com');
Think about the extra work indexes require during data insertion.
Indexes require updating during INSERT, which adds overhead. Without indexes, the database only inserts the row, so it is faster.
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?
Consider which columns have indexes and what updating them requires.
Updating an indexed column requires updating the index entries, which adds overhead. Updating a non-indexed column does not affect indexes and is usually faster.
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;
Check if the trigger syntax requires special delimiter handling.
In many SQL dialects like MySQL, creating triggers requires changing the delimiter temporarily to avoid syntax errors. Missing this causes a syntax error.