Performance tuning
Karen pointed out recently that an important part of our submissions database was being really really slow. I had noticed, but thought it was just a fluke; when Karen mentioned it, I decided it was worth looking into.
So I spent a while on Saturday morning looking for and re-learning about the "explain" command in SQL (the standard database language), which lets you see some of the details of how the database is carrying out your queries.
In SQL, when you try to match items from two different tables of data, the database may have to test all possible combinations of rows from those two tables. And it turns out that in one particular common query we were running, there were 36,000 items in one table and 9,000 items in another table, so every time we ran that query to generate a particular list, the database was (if I understand this right) looking at about 320 million combinations of items from the two tables.
So I added something called an "index" (which took only about a second to do once I understood how to do it) and now each time we run that query it only has to look at the 9,000 items from one of the tables. Which means, more or less, that the query takes 1/36000 of the amount of time it used to take. Which means that the system is usable again; it really wasn't before.
So yay for pointing out slownesses, and yay for performance tuning!
Sadly, I still don't really understand this stuff. I tried to do something similar to speed up the slow loading of the front page of Mary Anne's journal; unfortunately, the command to create that index took three minutes to run (instead of about one second), and having that index in place actually caused Mary Anne's journal page to load slower than it used to. So I removed that index from Mary Anne's page. I did add another index that I think will speed up the page load a little bit; if you've been seeing slow load times for Mary Anne's journal, take a look and see if it's faster now, and let me know either way.
And if you're an expert on improving MySQL database performance, I'd love to get some pointers from you. Any recommended pages/sites/tutorials?