Ask ChatGPT: MariaDB Performance Tuning: Tips and Tricks

This is the next in the series of posts exploring ChatGPT and its insights about MariaDB. The series began with ChatGPT, OpenAI and MariaDB Foundation, followed by Ask ChatGPT – Getting Started with MariaDB: A Comprehensive Guide for Beginners.

This week’s topic, suggested by ChatGPT itself, was “MariaDB Performance Tuning”. So how did it do?

MariaDB is undoubtedly one of the most popular open-source database management systems available today, with a strong focus on performance and ease of use. Whether you are a developer, database administrator, or an IT professional, ensuring that your MariaDB installation performs efficiently is crucial.

Ask ChatGPT – Getting Started with MariaDB: A Comprehensive Guide for Beginners

This is the next in a series of posts on our explorations with ChatGPT that started with ChatGPT, OpenAI and MariaDB Foundation. Here, we asked ChatGPT to generate a blog post, and Chief Innovation Officer Daniel Black reviewed the results.

“Getting Started with MariaDB: A Comprehensive Guide for Beginners” is the question we asked ChatGPT. What we got is below. Rather than a blog on what you could have done yourself, I’ll look through the answer below and see how accurate it is, what could be better/worse, and assume this is some reflection on the references that the engine was trained on.

ChatGPT, OpenAI and MariaDB Foundation

When everybody and their grandmother are talking about ChatGPT, you know something is happening – something with significance outside the usual IT bubble. As the first in a series of blog entries, let me reflect upon what AI means for users of MariaDB Server – or, at least, what implications we at the MariaDB Foundation can see at this point in time.

The AI revolution is inevitable …

Pundits say that lawyers or programmers won’t be replaced by AI – but they will be replaced by lawyers or programmers that use AI. I would agree.

Writing User-Defined Functions in Rust

One of the most straightforward ways to add functionality to MariaDB or MySQL server instances is by creating a user-defined function (UDF). These are compiled functions loaded from dynamic binaries that can be much more performant and flexible than what can be written in SQL, providing the same capabilities as builtin functions.

These UDFs are typically written in C or C++, but a library is now available that makes it easy to write them in Rust. This blog discusses some of the reasoning for writing this library, followed by a very basic usage example that doesn’t require any experience with the language.

This one trick can make MariaDB 30x faster!

Yes, it is a bit of a click-bait title, but in this case running one SQL command did improve a community user’s performance by that much. It could help you too.

The story

A community user posted in a couple of places that when migrating a large WordPress installation to MariaDB that they were seeing a certain query performing terribly. The query was taking 1.5 seconds to execute and it was clear from the explain plan that the optimizer was not making an ideal decision about the join order.

The query was generated by WordPress so it would not be easy to force an index, or rewrite the query.

MariaDB & K8s: How to replicate MariaDB in K8s

In the previous blog we have seen how to create a statefulset MariaDB application. Also, we learned how replication works in MariaDB in this blog. Now, we will try to create a replicated statefulset application. As good references for creating this blog, I would like to give credit to the Kubernetes documentation as well as an example from Alibaba Cloud.

Configure replication

To replicate a MariaDB application we are going to create a statefulset that will consist of a single init container and one application container.

A mirror manager system to simplify the distribution of MariaDB binaries and packages

The MariaDB Foundation relies on public mirrors to distribute binaries and packages to the world. An overview of the full list can be seen at https://mirmon.mariadb.org. If you would like to volunteer to become a mirror, take a look at https://mariadb.com/kb/en/mirror-sites-for-mariadb/.

Our download page already automatically suggests one of those mirrors for you to download our binaries. Same goes for the repository configuration tool; see https://mariadb.org/download.

The purpose of this blog post is to present you a new system that we have been testing since December 2021 and that we believe is now ready for public adoption.

MariaDB replication using containers

In this blog we are going to demonstrate how to replicate a MariaDB database that runs in a Docker container (let’s call it primary) to one or more MariaDB servers that run in a Docker container (let’s call them replicas) using binary logging, a method that creates binary log files and an index that contains the record of all changes to the database (both data and structure). You can find an overview of how replication works here and you can find how to setup replication here. An example can be found in this GitHub script.