SQL - Indexes and Query PerformanceIf a composite index is created on columns (A, B), which query will NOT fully benefit from this index?ASELECT * FROM table WHERE B = 20;BSELECT * FROM table WHERE A = 10;CSELECT * FROM table WHERE A = 10 ORDER BY B;DSELECT * FROM table WHERE A = 10 AND B = 20;Check Answer
Step-by-Step SolutionSolution:Step 1: Review composite index usageComposite index on (A, B) helps queries filtering on A or both A and B, but not on B alone.Step 2: Analyze each queryQuery filtering only on B cannot use the index efficiently because A is the first column.Final Answer:SELECT * FROM table WHERE B = 20; -> Option AQuick Check:Index on (A,B) can't optimize filter on B alone = D [OK]Quick Trick: Index first column must be in WHERE for full benefit [OK]Common Mistakes:Assuming index helps filtering on second column aloneIgnoring column order in composite indexThinking ORDER BY always uses index
Master "Indexes and Query Performance" in SQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More SQL Quizzes Advanced Window Functions - LAG function for previous row access - Quiz 2easy CASE Expressions - COALESCE and NULLIF as CASE shortcuts - Quiz 4medium Database Design and Normalization - Third Normal Form (3NF) - Quiz 2easy Indexes and Query Performance - Covering index concept - Quiz 7medium Indexes and Query Performance - Single column index - Quiz 4medium Indexes and Query Performance - When indexes help and when they hurt - Quiz 14medium Stored Procedures and Functions - Function vs procedure decision - Quiz 10hard Transactions and Data Integrity - COMMIT and ROLLBACK behavior - Quiz 8hard Triggers - DELETE trigger - Quiz 5medium Window Functions Fundamentals - ROW_NUMBER function - Quiz 3easy