CS FundamentalsHardAmazon · Microsoft MCQ pattern
A database stores timestamps in UTC and converts to local time only at the application layer. A query does `WHERE created_at BETWEEN '2024-01-01' AND '2024-01-31'` directly in UTC, but the business requirement was 'all of January in IST (UTC+5:30)'. What subtle bug can this cause?
- A. It only affects leap years
- B. No bug is possible since dates are always unambiguous
- C. Rows from the last few hours of December 31 in UTC (which are already January 1 in IST) or the first few hours of February 1 UTC (still January 31 evening in IST) can be included or excluded incorrectly, because the UTC date boundary doesn't line up with the IST date boundary
- D. It would cause a SQL syntax error
Correct answer: C. Rows from the last few hours of December 31 in UTC (which are already January 1 in IST) or the first few hours of February 1 UTC (still January 31 evening in IST) can be included or excluded incorrectly, because the UTC date boundary doesn't line up with the IST date boundary
Because IST is 5.5 hours ahead of UTC, a UTC-based date range filter is shifted relative to the 'local' calendar day boundaries actually intended, systematically miscategorizing rows created near midnight in either timezone — a classic timezone-handling bug when timestamp storage (correctly UTC) and business date semantics (local calendar day) aren't reconciled in the query itself.
More DBMS and SQL questions
- A column price NUMERIC (arbitrary precision decimal) is compared against a literal using price = 19.99. Why is this generally SAFE from…
- A relation R(A, B, C, D) has candidate key ABD (the ONLY candidate key) and FD AB → C (C is non-prime). Which normal form violation does…
- A query optimizer must decide between two equivalent plans for A JOIN B: (1) nested-loop join using an index on B, with A as the outer…
- A relation R(A, B, C, D, E) has FDs AB → C, C → DE. Which of the following is the candidate key, and how many non-prime attributes does R…
- Which pair of properties must every primary key satisfy?
- Which ACID property guarantees that a transaction's changes are applied completely or not at all?