Every day, millions of conversations happen around the world — each language has its own rules so the listener can understand the speaker.

Databases are the same. They have their own "language" to talk with us: Query.

Also, have you ever had this happen? Your query runs fine every day, but one day it suddenly becomes much slower — and you have no idea why.

So when you send a query, how does the database process it?

👋 Hi there!

I'm Luân a.k.a Jarzt — a Software Engineer. Besides coding, gaming, and playing basketball, I also love writing — sharing cool stuff I've learned along the way. Connect with me on LinkedIn!


How Does a Database Read Your Query?

To understand your query, the database goes through 4 main steps:

  1. Parsing — Read and understand the query
  2. Binding — Link to real data
  3. Optimizer — Find the best way to run it
  4. Execution — Run and return results

Before we dive in, let's set up some sample data and a query on PostgreSQL so you can try it yourself.

Okay, let's see how the database works step by step!


1. Parsing