13. April 2008, 07:29, by Silvan Mühlemann
There’s a number of pitfalls one should be aware of when working with AUTO_INCREMENT fields in MySQL. Last week, we fell in each of them:
We have the table photos which contains all 15 million pictures on tilllate.com. This table is MyISAM and has id INT NOT NULL AUTO_INCREMENT as the primary key. The position of the auto increment counter was at 112′606′834.
(more…)
22. February 2008, 12:12, by Steven Varco
Our Dell PowerEdge 2950 Servers for the new DB Cluster has just arrived and I’m very excited, unpacking them.

(more…)
5. February 2008, 17:09, by Silvan Mühlemann
EXPLAIN is not the only way to analyze query perfomance im MySql because some things are not being taken into account. For example LIMIT clauses or the cost of the optimizer. There is also the mk-query-profiler.
An interesting way to compare the performance of two queries is to use mk-query-profiler along with diff
Here’s how you do it. As an example I take the queries from this mysql performance blog article
article. Because I’d like to learn what excactly SQL_CALC_FOUND_ROWS does.
(more…)
5. January 2008, 22:16, by Leo Büttiker
On the view of your database the worst thing you can do in your web app is paging. Paging is horrible in the view of performance. To explain let me make a little example:
SELECT SQL_CALC_FOUND_ROWS gb.*,
u.username,
u.uid,
u.geschlecht,
u.mitfoto,
[... some more fields...]
FROM member_gold_guestbook gb
LEFT JOIN users u ON u.uid=gb.uid_from
[... some more left joins...]
WHERE gb.uid_to=’22152′
AND visible=’1′
LIMIT 0,10;
That’s not that bad at all, but when you go to page 300 your database server will hate you for this. The database server has not only to calculate the 10 items you want to show but also all 3000 previous items.
Sure you may argue nobody will ever go to page 300. Somebody will not, but “googlebot” and his evil brothers will. And the bad thing is that you can do nothing against it, as long as you need paging. There are just a few tricks that may reduce your server load a bit.
(more…)
18. November 2007, 19:29, by Silvan Mühlemann
Busy week for the open source IT pros around Zürich: On Thursday Vint Cerf will talk at Google. On Wednesday, Nov 21st tilllate is happy to announce a presentation of Peter Zaitsev of the MySQL Performance Blog. He will talk about query optimization for high traffic sites.
Peter Zaitsev was manager of the High Performance Group at MySQL Inc. He specializes in MySQL Server performance as well as in performance of application stacks using MySQL, especially LAMP. Web sites handling millions of visitors a day dealing with terabytes of data and hundreds of servers is king of applications he loves the most.
(more…)
7. November 2007, 23:04, by Silvan Mühlemann
Every few months at tilllate we play the query optimization game. At this game I use the slow query log to find out those queries the most load on the servers.
With the queries I found I then either: optimize the query or cache the results to avoid the query.
I prefer the former because caching means data duplication. Which is not very DRY.
(more…)
28. January 2007, 21:09, by Silvan Mühlemann
Pro Sekunde werden auf tilllate.com 5000 Abfragen von den Datenbank-Servern beantwortet. Wie können wir diese Last auf 30 Datenbank-Server verteilen? Mit Replikation. Aber auch nach fünf Jahren Erfahrung habe ich dieses Feature noch nicht ganz im Griff.
Auf Datenbank-Ebene besitzt tilllate.com vier Servergruppen mit unterschiedlichen Funktionen (= “horizontale Skalierung”): Werbung, Statistik, Chat und schliesslich der Rest der Website tilllate.com. Werbung, Statistik und Chat kommen mit einem einzelnen Datenbank-Server aus.
Der “Rest” macht 90% der Abfragen aus. Der Rest sind 27 MySQL Datenbank-Server. Auf diesen 27 Server befindet sich eine identische Kopie der Haupt-Datenbank. Damit dies so bleibt, muss jede Änderung der Datenbank (z.B. eine UPDATE-Query) wird über einen definierten Weg auf alle 27 Maschinen repliziert. Wir benutzen hier die Replikations-Features von MySQL.

(more…)
7. January 2007, 18:32, by Silvan Mühlemann
Vor zwei Wochen habe ich erklärt, wie man mit dem Slow-Query-Log die langsamsten Datenbank-Abfragen identifizieren kann. Nun möchte ich besprechen, wie man diese langsamen Queries beschleunigen kann. Nutze den Index ist die Zauberformel.
Die erste Frage: Was ist der Index? - Nun, das ist Euch bestimmt bekannt. Sonst hilft Wikipedia.
Schaut man sich an, wie die Dateien bei MySQL (MyISAM-Struktur) auf der Disk gespeichert ist, so ist die Index-Datei an der Endung MYI zu erkennen (MYD sind die effektiven Daten, frm die Tabellendefinition):
cameron tilllate # ls -lh users.*
-rw-rw---- 1 mysql mysql 65M Jan 7 16:51 users.MYD
-rw-rw---- 1 mysql mysql 90M Jan 7 16:51 users.MYI
-rw-rw---- 1 mysql mysql 15K Jan 6 06:20 users.frm
Die Index-Datei users.MYI wird bei MySQL im RAM gehalten, während die effektiven Daten (Usernamen, Passwörter, Adressen) auf der Disk bleiben. Ein Grund, dass der Zugriff schnell ist.
(more…)
23. December 2006, 20:39, by Silvan Mühlemann
Den Feedbacks von meinem letzten Beitrag nach zu schliessen, stösst das Thema Query-Optimierung auf Interesse. Ich werde deshalb in nächster Zeit mehrere Artikel zu diesem Thema schreiben. Schritt 1: Die langsamen Queries identifizieren.
Unser erste Blick geht jeweils in den Slow-Query-Log. Braucht eine Abfrage mehr als 10 Sekunden, so wird sie in hostname.slow aufgelistet. Dieses Logging wird im my.cnf mit dem Keyword log-slow-queries aktiviert.
(more…)