Beginning SQL

Beginning SQL Beginning SQL

marjan.fesb.hr
from marjan.fesb.hr More from this publisher
20.07.2013 Views

13 Database Tuning SQL is a language that describes how you retrieve data from a database. Just as in any language, you can say things that make sense but that may not mean what you intend or that can be misinterpreted and cause results that are not what you expect. By now you should be pretty good at expressing yourself in SQL and you should be getting the results, or at least the data, that you intend. On the other hand, you might get exactly the data you expect but it takes a long time to get the data back. That is the subject that this chapter addresses. Specifically, this chapter addresses the following questions: ❑ Why does your query take so long to execute? ❑ Is this just normal, or is there something you can do to get the results faster? ❑ When does it matter? In fact, tuning SQL is just one piece of the bigger puzzle, which is tuning the system itself. Indepth system tuning is outside the scope of this chapter, but an overview of the subject is useful since it is possible to get large improvements in speed at this level. You may find that the database is administered by professionals and that they have already done all that can be done at this level. On the other hand, you may find yourself playing system administrator and realize that you are the only one around who can look at whether some of these issues can be addressed. Or you may find that the database is being administered by a network administrator with no real experience as a database administrator and that a little friendly advice to him will get you a long way. For all these reasons, this chapter covers some subjects that you might not expect to find in a book on basic SQL. Tuning Hardware If you have any control over the subject, the first place to start tuning is at the hardware level. It is a common misconception that servers don’t necessarily need to be extremely powerful machines, and so you may find that while the workstations are the latest and greatest multi-gigahertz machines with a half-gigabyte of RAM, the server is a five-year-old machine running at a few hundred megahertz with a few hundred megabytes of memory. Indeed, since servers tend to be

13<br />

Database Tuning<br />

<strong>SQL</strong> is a language that describes how you retrieve data from a database. Just as in any language,<br />

you can say things that make sense but that may not mean what you intend or that can be misinterpreted<br />

and cause results that are not what you expect. By now you should be pretty good at<br />

expressing yourself in <strong>SQL</strong> and you should be getting the results, or at least the data, that you<br />

intend. On the other hand, you might get exactly the data you expect but it takes a long time to get<br />

the data back. That is the subject that this chapter addresses. Specifically, this chapter addresses<br />

the following questions:<br />

❑ Why does your query take so long to execute?<br />

❑ Is this just normal, or is there something you can do to get the results faster?<br />

❑ When does it matter?<br />

In fact, tuning <strong>SQL</strong> is just one piece of the bigger puzzle, which is tuning the system itself. Indepth<br />

system tuning is outside the scope of this chapter, but an overview of the subject is useful<br />

since it is possible to get large improvements in speed at this level. You may find that the database<br />

is administered by professionals and that they have already done all that can be done at this level.<br />

On the other hand, you may find yourself playing system administrator and realize that you are<br />

the only one around who can look at whether some of these issues can be addressed. Or you may<br />

find that the database is being administered by a network administrator with no real experience as<br />

a database administrator and that a little friendly advice to him will get you a long way. For all<br />

these reasons, this chapter covers some subjects that you might not expect to find in a book on<br />

basic <strong>SQL</strong>.<br />

Tuning Hardware<br />

If you have any control over the subject, the first place to start tuning is at the hardware level. It is<br />

a common misconception that servers don’t necessarily need to be extremely powerful machines,<br />

and so you may find that while the workstations are the latest and greatest multi-gigahertz<br />

machines with a half-gigabyte of RAM, the server is a five-year-old machine running at a few hundred<br />

megahertz with a few hundred megabytes of memory. Indeed, since servers tend to be

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!