SQL: Think Optimize! Feb05 '05

My "Base" section

My Base section contains "a little bit of everything," and is a nice way to take an "all around" peek at my site, without having to manually visit each section.

I enjoy the challenge this section brings to my development capabilities.

There are various aspects that I want to portray, as development of this section continues in the future:

Less is more

The page should not scroll down very long, if at all. As a "base" page, it should just briefly "touch" on everything, without going into too much detail. This allows readers to jump at whatever grabs their attention first.

Visually–confined spaces

Visually, everything has to fit inside a 585 pixel width box. This is challenging both content–wise, and styling–wise.

My goal is to have neat and ordered boxes, each containing different content – but not too much content. I also use CSS float techniques to position the boxes, rather than HTML tables.

Backend database calls

Behind the scenes, every "CSS box" queries a separate table in my database, simply because all the content is unique. Each box pertains to a completely different topic, but all under the same roof.

Since there are many queries being performed on a single page – calls to the database are quite high, and can slow the page load speed.

This is not ideal.

Fewer calls to the database means faster page loads, and increased performance.

Optimize those queries!

While it’s hard to just "cut out" queries on a page, there are techniques to "cut down" your existing queries, and overall page code.

The number one most important technique to optimize queries is to specify the columns!

Rather than using the "grab everything" symbol (*):

SELECT * FROM...

Specify the columns, instead:

SELECT log_index.date, log_index.time FROM...

This is a good habit to get into. Optimized queries will speed up performance and communication from the scripting language to the database.

And, most of the time, we only need to use two or three columns anyway! So, why pull them all?

Combine multiple queries

Another option to optimize your queries is to combine multiple queries into a single query.

This is much easier said, than done.

Thinking in SQL

Even the most talented SQL programmers can stumble over finding the right way to "talk" to the database.

As your queries become more complex, and your sleeping hours decrease, you may begin wondering how anyone can claim that SQL is "easy." It’s anything BUT easy.

Pretty soon your everyday life actions will make you think things like:

"If I could somehow write a query to pull out each outfit, that I will wear to work, every day of the week, then I’d be set."

Or, how about this thought... at your local bar:

"Hmmm, there are four beers here to choose from. If I could somehow do a LEFT JOIN on the IMPORTED beers, to grab all similar ingredients, but still have the "born on" dates, as well as the country where they ARE ALL produced.

As you can see, optimizing queries can sometimes mean altering your entire mode of thinking.

Categories: SQL

Add Feedback (view all)

Leave feedback

Feedback

Input format: The editor controls below will assist with Markdown syntax.

Status

Sub-status

Your info

Optimizing SQL queries is important. I use left join a lot to join two tables together for certain information. For example. On my bl ... Read more.

matthom is published and produced by Matt Thommes - an independent publishing enthusiast, mobile blogger, content creator, informative writer, web developer from Chicago. Never one to conform, Matt intends to promote the effect the web has on our lives, in an effort to intensify, instruct, and clarify all that is happening around us.

Contact Matt

Similar Entries

Stats

1 unique visit since September 2008

Syndicate

Advertisements