Showing posts with label sql optimizer for sql server. Show all posts
Showing posts with label sql optimizer for sql server. Show all posts

Tuesday, 26 April 2022

Why Improve MySQL Database Performance with SQL Query Tuning

Database performance may take a backseat if the SQL queries are running slow. If the SQL queries fail to perform as per standards, it may affect the database performance adversely.

Thus, to avoid such consequences, you need to improve MySQL database performance. It is essential to optimize SQL queries to enhance server performance. Failing to do so may entail utilizing more resources that can degrade the server's performance.


The Necessity of SQL Tuning for Oracle

To ensure the exceptional performance of the MySQL or Oracle database, you need to optimize it. This refers to database tuning which future entails the aspects of performance tuning in SQL MySQL. This means for the high performance of your oracle database; one needs to focus on SQL tuning for Oracle.

 

The purpose of SQL tuning is to

  1. Increase throughput
  2. Reduce response time
  3. Minimize recovery time
  4. Increase load capabilities

 


To accomplish the above scenarios, it is vital that we improve MySQL database performance. To better understand SQL query optimization, you need to shift your focus to high load and poorly written SQL queries. If query time is higher, you need to give at the following key areas.

 

Spotting Out High Load Queries to Improve MySQL Database Performance

To figure out what is increasing the workload of the application and increasing the query time, you need to look at high load queries. They often consist of one or more of the following elements:

 

    Indexes: If the search is slow on the database, you can employ indexes to fasten the search process. If the table or SQL needs indexing, you have to carefully analyze and create an index that will help in SQL tuning for Oracle.

    Joins: Joins can also impede performance and result in slow query processing. If the query is joining multiple tables, it may retrieve the column with the same column names, resulting in increasing the row count. To avoid this, proper usage of joins is essential.

  Table size: Table size matters greatly. Your query performance can be relatively slow, especially when you have millions of records to cater to. For the query to work well, you need to shorten the table size or probably divide it into multiple tables. In the case of time-series data, we can also limit it to a time window to generate faster results.

    Aggregations: SQL aggregations can cause the SQL query to run slowly. Aggregation is nothing but combing a set of values to return a single value. Sum, average, and count are some of the aggregate functions. It is imperative to look into whether combining multiple rows is causing the underlying concern.

 


Using Query Optimizer to Automate SQL Tuning for Oracle

We can use the Query optimizer in oracle to improve MySQL database performance as well as to enhance the performance of SQL statements in oracle. The query optimizer works in two modes: Normal and Tuning.

The normal mode generates the execution plan by compiling SQL queries while the Tuning mode is an advanced mode that analysis whether further improvements are possible in the execution plan generated in the normal mode,

The execution plan includes prime points like creating SQL Profile, creating new indexes, restructuring SQL statements, reducing table size, and much more.

 

Summing up

SQL query tuning is an integral part of speeding up database performance. Slow query processing can be time taking and resource-draining. To increase the performance of SQL queries, it becomes vital to apply query optimization techniques.

Aside from the suggestions and tips for SQL tuning for Oracle in this blog, you can also take the help of optimizing tools that third-party developers offer. There’s a huge variety in the market that caters to a wide range of requirements.

Thursday, 29 July 2021

How an Execution Plan is Picked by SQL Optimizer for SQL Server


The Query Optimizer for SQL Server is designed to be cost-based. This means it assesses several execution plans and estimates each one’s cost before picking the plan that seems the most cost-effective.

Since this tool is unable to take every single plan into consideration, it ends up performing a balancing act by taking into account the costs involved in both - locating possible plans and implementing them. In this blog, we will look at the SQL optimizer for SQL Server and the steps involved in its process of identifying the best execution plan.


Oracle SQL Query Execution Plan Picking Process

The SQL Server Database Engine is made of two major parts - the Relational Engine (Query Processor) and the Storage Engine. The Relational Engine is responsible for all the statements sent to the SQL Server. It is tasked with creating a plan that ensures optimal execution to deliver the best results.

The Storage Engine, on the other hand, is in charge of optimally reading data from both memory and disk while preserving data integrity. Statements are sent to SQL Server through SQL language(s). SQL only specifies what type of data needs to be fetched and not the methods that can be used for this purpose. Neither does it present any of the algorithms that can be applied to process the request.



Therefore, the first step the relational engine takes when it gets an Oracle SQL query is devising a plan as fast as it can. The plan must mention the most favorable or even efficient method to run said statement. The next thing to do is to use that plan to execute the statement.

All the steps are assigned to individual parts inside the query processor. Inside, it is the job of the Query Optimizer to design a plan, which it submits to the Execution Engine to execute to receive results accordingly.

Steps Involved in Creating an Execution Plan to Carry Out a Query

Considering the SQL optimizer for SQL Server, it takes a certain number of steps before the Relational Engine can provide the Execution Engine with the best or an efficient-enough execution plan. These steps have been mentioned here:

       Parsing

       Binding

       Optimizing the Query

       Running it

 


  1. Parsing & binding - The statement, supposing it is correct, undergoes the parsing and binding process. A valid query has its output in the form of a logical tree that has nodes symbolizing each logical operation being mentioned in the statement. For example, performing an inner join or a read action in the specific table will both be represented as separate nodes in the logical tree.
  2. Query Optimization - The logical tree helps in the query optimization procedure that is made up of the following steps -

    1. Creating Potential Execution Plans – With the help of the logical tree, the Relational Engine or the Query Optimizer generates more than one potential method (execution plan) to run the query without incurring excessive costs. An Execution plan is essentially a bundle of physical tasks that must be carried out in order to provide the expected results as represented by the logical tree. These operations are part of the Oracle SQL query and include tasks such as nested loop joins and index seeks.
    2. Evaluating the Cost of Every Plan – Even though the Relational Engine doesn’t create each and every execution plan that can be generated, it does examine the expenses incurred by every plan it actually creates, in terms of cost and resources. Among these, it selects the plan whose expenses are evaluated and found to be the lowest. This plan is then relayed to the Execution Engine.
  1. Running the Query and Caching the Plan – The statement is run as per the plan that has been selected and sent to the Execution Engine by the Query Optimizer. This plan can be saved in a designated area known as the plan cache, which is located in memory.

 


Tuesday, 15 June 2021

SQL Optimizer for SQL Server: Deleting Old Backup Files

SQL Server

Creating and maintaining backups are an essential part of a DBA’s responsibilities. There are several tasks associated with backups, such as automation and execution of backup command scripts.

Sometimes, it is important to know how to automate the deletion of outdated backup files as well, even if you already have a SQL optimizer for SQL Server. In this post, we will discuss a simple approach to help you remove older backup data and save space.


How to Delete Backup Files without SQL Optimizer for SQL Server

Here, we will make use of Windows Scripting to traverse every subfolder in order to locate files preceding a specific date. We will then delete the older files, once they have all been located.

First, we need to consider two parameters that must be modified for this purpose:

 

       iDaysOld - this helps you set the exact timeframe to determine how old the file has to be for the command to select and delete it

       strPath - this is the path to the folder where the backup files are created and stored.

 

SQL optimizer for SQL Server

Steps to establish the script before you get to SQL Server performance tuning:


  1. You need to create a text file where you can copy and paste the following code -

iDaysOld = 15

strPath = “C:\Backup”

Set objFSO = CreateObject("Scripting.FileSystemObject") 

Set objFolder = objFSO.GetFolder(strPath) 

Set colSubfolders = objFolder.Subfolders 

Set colFiles = objFolder.Files 

 

For Each objFile in colFiles 

   If obj!File.Date!LastModified < (Date() - iDays!Old) Then 

       Msg!Box "Dir: " & obj!Folder.Name & vbCrLf & "File: " & objFile.Name!

       'obj!File.Delete! 

   End If 

Next 

 

For Each objSubfolder in colSubfolders 

   Set colFiles = objSubfolder.Files 

   For Each objFile in colFiles 

       If obj!File.Date!LastModified < (Date!() - iDaysOld) Then 

           Msg!Box "Dir: " & obj!Subfolder.Name & vb!CrLf & "File: " & obj!File.Name

           'objFile.Delete 

       End If 

   Next 

Next

Use the path of your choice as strPath - for instance, “strPath = “C:\Backup””. Remove the exclamation marks before or after you paste this code.

 

SQL Server performance tuning

  1. Save it using a suitable name like this - C:\RemoveBackupFilesOld.vbs

 

  1. Create one more text file in which you will copy-paste the code mentioned below, and save it as a BAT file in the same location. For instance, you can name it as - C:\RemoveBackupFilesOld.bat.

The code: C:\RemoveBackupFilesOld.vbs

 

Please note that this script serves as a safeguard, so it will only show a message box that displays the name of the file and folder. If you’re using an optimization of SQL queries SQL optimizer for SQL Server and you want to actually delete the files, simply remove the single quote character that’s present right next to the two delete lines (the ones with ‘objFile.Delete).

 

  1. Running the BAT file will delete all the files matching the specified criteria from their subfolders.

 

How the Script Works

 

The script will pick out and eliminate any files found in the subfolders beyond the initial point. The type of the files doesn’t matter as it will only consider the time of creation and whether it fulfils the specified criteria.

It will also remove files from subfolders in the next level as well as the root folder but it won’t fetch files past the first subfolder level. In other words, if you put the strPath as “C:\Backup” for instance, the script will remove backup files older than the iDaysOld that are present in the “C:\Backup” folder and those present in the first level subfolders inside this folder.

You may set this script up to run at a scheduled time according to your need - just call the BAT file. This is because, as you may have learned during SQL Server performance tuning, the Agent is not accustomed to running .vbs (VBScript) files directly, which is why we’re calling a BAT to set it up as a scheduled task instead.






What do You Mean by Oracle Performance Tuning?

Performance tuning is a process in which we fine-tune a database to improve its operational performance. This process includes working on pe...