Articles

MySQL SQL Performance Tuning: The Pros & Cons of Indexes

by Tosska Technologies sql server performance tuning- Tosska Technologies

The SQL Server database engine can benefit a lot from indexes in terms of performance for a range of various queries. At times, such performance boosts are significant. A crucial characteristic of SQL Server is a feature called the query optimizer.


The main task of the query optimizer is to locate the quickest and minimum resource taking way of executing incoming statements, which is why choosing optimum indexes to do the job is an important aspect of MySQL SQL performance tuning. In this article, we will discuss some of the queries that have the highest possibility of improving with the use of an index. 

One of the most common uses for an index is to locate one of more records that fit a WHERE clause. It can help statements by searching for values in between a certain range and also a value in particular. 


Let us consider an example, where the statements mentioned below can all gain from an index on UnitCost -  


DELETE FROM Items WHERE UnitCost = 1

 

UPDATE Items SET Discontinued = 1 WHERE UnitCost > 15

 

SELECT * FROM ITEMS WHERE UnitCost BETWEEN 14 AND 16


Indexes operate equally efficiently in MySQL database and SQL while looking for a record in DELETE and UPDATE queries as they do for SELECT commands. 

What about sorting records? When a user requests for a sorted section of data, the database will make an attempt to locate an index and refrain from rearranging the results when the statement is being executed. 

The user monitors dataset sorting after mentioning one or multiple fields for a specific range of information. This is done with the help of the ORDER BY clause, and deciding the sort order as ASC (ascending) or DESC (descending). 

Preserving a column that is unique, also requires the application of a unique index, such as in the case of primary columns. There are multiple ways that one can use to make a unique index during MySQL SQL performance tuning. The most well-known method is by marking a column with the primary key clause, but it can also be created by ticking the Create UNIQUE tick box in the dialog prompt that appears at that instant. Defining a new index that is not applied in the enforcement of a primary key will enable us to tick the Create UNIQUE tick box.

 

One more way you can create a unique index in SQL is with the following query -


CREATE UNIQUE INDEX IDX_ItemName On Items (ItemName)


This SQL statement will reject any repetitive values in the ItemName column - a rule most conveniently enforced by an index, which is why it is the most recommended tool in this regard.


Every instance that involved the addition or modification of a row in the table required the database to locate each prevalent record in order to make sure that the values being entered now are not duplicating any of the ones existing in the database so far. Indexes, as you might have guessed by now, will help reduce the search time in this case.


Using an index in sql tuning for MySQL also involves a few downsides, however, and one of the major tradeoffs includes disk space. After all, these are saved on the disk, and there is no one-size-fits-all when it comes to indexes, which means the space requirement may vary according to table size as well as the quantity and nature of the columns utilized in the index.


Nevertheless, disk space is usually a forgivable compromise when we get improved application performance in return, which is especially true in the case of a database with numerous users.



Sponsor Ads


About Tosska Technologies Advanced   sql server performance tuning- Tosska Technologies

91 connections, 0 recommendations, 216 honor points.
Joined APSense since, August 29th, 2019, From Kowloon, Hong Kong.

Created on Dec 11th 2020 01:59. Viewed 1,229 times.

Comments

No comment, be the first to comment.
Please sign in before you comment.