Difficulty: Easy
Correct Answer: Use compatible and proper data types to enable sargable predicates and good plans.
Explanation:
Introduction / Context:
SQL performance depends on the optimizer’s ability to use indexes, statistics, and selective predicates. Data-type mismatches and non-sargable expressions often prevent index seeks and force scans. This question tests a reliable, general practice for better performance.
Given Data / Assumptions:
Concept / Approach:
Using compatible types (e.g., comparing INTEGER to INTEGER, DATE to DATE) avoids implicit conversions that block index usage. Writing sargable predicates (Search ARGument ABLE), such as column >= ? and column BETWEEN a AND b, lets the optimizer find efficient plans. Type correctness also prevents needless casts and function-wrapped columns.
Step-by-Step Solution:
Verification / Alternative check:
RDBMS tuning guides consistently highlight data-type compatibility and sargability as universal improvements across engines (PostgreSQL, Oracle, SQL Server, MySQL).
Why Other Options Are Wrong:
Common Pitfalls:
Final Answer:
Use compatible and proper data types to enable sargable predicates and good plans.
Discussion & Comments