Select Page

Three Ideas for Returning Microsoft SQL Queries Faster

Andy McDermid | | January 13, 2015

Three Ideas for Returning Microsoft SQL Queries FasterWould you like to make your users happy? Give them the information they need through optimization that allows SQL queries to be returned faster.

Here are three quick items to add to your “do” list to generally improve performance by increasing system concurrency.

One caveat: these suggestions may not provide uniform results. These tips should be applicable across different types of databases, but your mileage may vary. Before plunging ahead, you may want to make certain your databases are fully backed up in case problems arise.

Partitioned Tables

Moving large amounts of data is always tough, but using partitioned tables can help you avoid large data moves. If you have SQL Server Enterprise, you can take advantage of this feature.

All tables in SQL Server are partitioned from their creation. They can be further separated into multiple partitions as the user wishes. That’s not necessary for this technique to work properly.

Sean McCown, writing in InfoWorld, says he had a client with a convoluted workaround for loading data at the end of a business day into an archive table before the data was deleted from the live table. Eventually, the multi-step process became cumbersome, taking 1.5 hours for each of several tables to copy.

Using the features in partitioning can alleviate some of these and other bottlenecks. In this case, the single SWITCH command was able to take the place of two other commands. McCown notes:

The SWITCH command allowed the company to avoid all of the writes because it assigned the pages to the archive table. It’s only a metadata change. The SWITCH took on average between two and three seconds to run. If the current load ever fails, you SWITCH the data back into the original table. This is a case where understanding that all tables are partitions slashed hours from a data load.

Forget Cursors

Another way to optimize query returns is to forget cursors. Period.

There’s not a database professional you’ll find who suggests using cursors with SQL Server. These slow the system thanks to the overhead they create.

First, ask yourself if you really need to use cursors. If you don’t, don’t use them! If you can’t escape their use, try using temp tables instead of bogging down the system.

By comparing data in a temp table rather than in a live environment, you reduce the time the UPDATE statement needs to compare data against a live table. And there’s less data to compare. This workaround can eliminate concurrency problems.

Temp-Valued Functions

Using table-valued functions is another great trick to keep the system performing well and one Microsoft advocates:

User-defined functions that return a table data type can be powerful alternatives to views. These functions are referred to as table-valued functions. A table-valued user-defined function can be used where table or view expressions are allowed in Transact-SQL queries. While views are limited to a single SELECT statement, user-defined functions can contain additional statements that allow more powerful logic than is possible in views.

Some additional solutions designed to help you more fully leverage the time and resources invested in your SQL Server are discussed in detail in a white paper Top SQL Server Issues, by Andy McDermid, Datavail’s SQL Server principal database administrator.

To learn more about SQL performance tuning or to find out more about how we can tailor a solution for your organization’s specific SQL needs, please contact Datavail.

Image by nicemonkey/123RF

Oracle EPM Cloud Vs. On-Premises: What’s the Difference?

EPM applications help measure the business performance. This post will help you choose the best EPM solutions for your organization’s needs and objectives.

Bobby Ellis | April 10, 2018

Hyperion Myth #9: SOX Audit Requests Are Time-consuming

With serious financial penalties, SOX audits can be intimidating — but they don’t have to be. Find out how you can use Datavail’s software to automatically prove SOX compliance.

Jonathan Berry | March 13, 2018

12c Upgrade Bug with SQL Tuning Advisor

This blog post outlines steps to take on Oracle upgrade 11.2 to 12.1 if you’re having performance problems. Oracle offers a patch and work around to BUG 20540751.

Megan Elphingstone | March 22, 2017

Work with Us

Let’s have a conversation about what you need to succeed and how we can help get you there.

CONTACT US

Work for Us

Where do you want to take your career? Explore exciting opportunities to join our team.

EXPLORE JOBS