Answer: Creating Composite Index
Understand how to create composite indexes on multiple columns to enhance SQL query performance. Learn to use profiling tools to measure query execution time and explore alternatives like optimizer hints and temporary tables for query optimization. This lesson equips you with practical skills to manage indexes and monitor their impact on database efficiency.
Solution
The solution is given below:
Code explanation
The explanation of the solution code is given below:
Line 2: The
CREATE INDEXstatement creates an index namedidx_sales_month_eidon theEIDandMonthcolumns in theSalestable.Line 5: The statement
SET PROFILING = 1;is used to enable profiling.Line 6: The
SELECTquery retrieves all columns from theSalestable and theWHEREclause specifies the condition on which we want to retrieve the data from the table.Line 7: The
SHOW PROFILEScommand displays a list of all queries executed in the current session, along with theirQuery_ID,Duration(execution time), and the query itself. This helps monitor the performance of queries.
Note: The following code can be used to check performance before and after indexing. You need ...