Scroll to Top Go to Home Page
Go to Admin

Lack of Indexes on Ultimate Tag Warrior Tables By michael | March 10th, 2007

Over the last week or so I’ve been on a mission to improve the performance of my web server, and especially MySQL. I took Arne’s advice and turned on the query cache. That helped but I still needed to do more. After doing some research I discovered MySQL’s slow query log, which does exactly what it sounds like. I enabled slow query logging and set “long_query_time” to 5 seconds. Shortly after I restarted MySQL the slow query count started to rise.

Every query in the slow query log was sent from the Ultimate Tag Warrior WordPress plugin which I use on my other blog. Here are some of the queries:

SELECT count( p2t.post_id ) cnt
FROM wp_tags t
INNER JOIN wp_post2tag p2t ON t.tag_id = p2t.tag_id
INNER JOIN wp_posts p ON p2t.post_id = p.ID
WHERE post_date_gmt < '2007-03-08 21:49:06'
AND (
post_type = 'post'
)
GROUP BY t.tag
ORDER BY cnt DESC
LIMIT 1 ;

and

SELECT tag, t.tag_id, count( p2t.post_id ) AS count, (
(
count( p2t.post_id ) /3661
) *100
) AS weight, (
(
count( p2t.post_id ) /1825
) *100
) AS relativeweight
FROM wp_tags t
INNER JOIN wp_post2tag p2t ON t.tag_id = p2t.tag_id
INNER JOIN wp_posts p ON p2t.post_id = p.ID
WHERE post_date_gmt < '2007-03-09 02:27:39'
AND (
post_type = 'post'
)
GROUP BY t.tag
ORDER BY weight DESC
LIMIT 50 ;

That led me to take a look at what was going on with the wp_tags and wp_post2tag tables. I did EXPLAINs on the queries and saw that they were doing table scans instead of using the indexes. So I went to look at the table definitions and was surprised at what I saw. The only index on the wp_post2tag table was rel_id, the auto-incremented primary key. So the columns that were actually used to do joins with, tag_id and post_id, had no indices. My SQL is very rusty but I knew that wasn’t a good thing. I also took a look at the wp_tags table and saw that it only had an index on the tag_id column. I’ve seen some queries with “tag = ‘tag_name’ ” in the WHERE clause so I figured that it would be good to have an index on the tag column as well.

After consulting with my brother, whose SQL skills are much more up to date than my own I decided to add indexes to those tables. I created an index called ‘tags_tag_idx’ on the wp_tags.tag column. On the wp_post2tag column I created two indexes — the post2tag_tag_post_idx index is on tag_id then post_id and the post2tag_post_tag_idx index is on post_id then tag_id. I’m not sure if using concatenated indexes is better than just creating separate single column indexes for each column but I think it’s the way to go after discussing with my brother and looking at how the wp_post2cat and wp_linktocat tables are indexed. They both have concatenated indices.

I ran some queries on the tables before and after to see if things were sped up and indeed they were. Unfortunately when I ran the EXPLAIN on the queries in the slow query log I saw mixed results. The keys that I added were now showing up as “possible_keys” and the actual keys but the queries still ended up doing table scans. For the tags table the EXPLAIN shows the dreaded “Using temporary; Using filesort”.

So while I didn’t completely solve my slow query problem the new indexes do help for many of the simpler queries which access wp_post2tag and wp_tag. If you’re using Ultimate Tag Warrior and are concerned about your database load you may want to add some indexes to the tag tables.

No Comments » | Posted in Blogging, Technology

My Top 20+ Movies By michael | March 4th, 2007

In answer to Trader X’s question, here are some of my favorite movies. There’s no way I can rank them beyond maybe the first three. Nor could I stop at just twenty so with the help of my historical rankings on NetFlix I’ve gone 40 deep. Depending on my mood, any of [...]

Continue reading...


6 Comments » | Posted in Movies

Archived for Posterity: Kenneth Eng’s ‘Why I Hate Blacks’ Article By michael | March 1st, 2007

Just thought I’d archive some (more) ignorance:
This is a copy of the controversial opinion piece by Kenneth Eng in Asian Week magazine:
Here is a list of reasons why we should discriminate against blacks, starting from the most obvious down to the least obvious:
• Blacks hate us. Every Asian who has ever come across them knows [...]

Continue reading...


No Comments » | Posted in Current Events, Race

“The Secret” on Oprah By michael | February 6th, 2007

(In case anybody’s still reading this blog I just posted this on my main blog and thought I’d post it here too…)
I think the movie The Secret is about to hit its tipping point. On Thursday Oprah Winfrey’s show will be all about that movie — or more specifically the topic of [...]

Continue reading...


No Comments » | Posted in TV

Dear Santa… By michael | December 20th, 2005

It’s been a while since I’ve posted a Boondocks (or anything to this blog for that matter). The first one below moved me to post. BTW, am I the only one who isn’t feeling the TV version of the Boondocks? The boys’ voices are just a bit too high pitched IMHO and [...]

Continue reading...


Comments are off | Posted in Entertainment

WeFunk’s PodCast By michael | November 5th, 2005

I just discovered WeFunk’s podcast. It’s by far the best podcasts I’ve come across. They’re spinning hip-hop, reggae, rare groove, funk, etc. Here’s the playlist from the latest episode to give you an idea of what you’re in for:

intro
gene harris - don’t call me nigger, whitey
talk (over ?? - be happy)
cymande - [...]

Continue reading...


Comments are off | Posted in Music

Foiling Phishers By michael | October 30th, 2005

Recently the editor of Kiplinger’s magazine asked readers to suggest (nonviolent) ways to punish phishers. This month they printed the most popular response: overwhelm the phishers with false information. I think that’s a great idea. And since I got a phishing email just hours after reading that this (obvious) fake Wells Fargo [...]

Continue reading...


Comments are off | Posted in Internet

Kanye West’s ‘Gold Digger’ Remixed into ‘George Bush Doesn’t Like Black People’ By michael | September 10th, 2005

If you haven’t heard the new reworking of ‘Gold Digger’ take a listen to the MP3 of ‘George Bush Doesn’t Like Black People’

Continue reading...


Comments are off | Posted in Music, Radio.Blog

Winners of the 2005 Black Weblog Awards By michael | September 5th, 2005

Congratulations to all of the winners of the 2005 Black Weblog Awards. Here they are:

Daily Views, Pop Culture, Rants and News — Blogger of the Year, Best Humor Blog, Best Writing in a Blog and Blog of the Year
The Heiress Diaries — Best New Blog
Crunk and Disorderly — Best Entertainment Blog
Brown Glasses — Best [...]

Continue reading...


Comments are off | Posted in Blogging

Video of Kanye West’s Rant on NBC By michael | September 3rd, 2005

Negritu.de has the video of Kanye West going off on President Bush and his response to hurricane Katrina. It’s worth watching for the look on Mike Myers’ face alone.

Continue reading...


Comments are off | Posted in Current Events, Race