<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Aditya Bhawar</title>
    <description>The latest articles on DEV Community by Aditya Bhawar (@aditya_bhawar_dc332d1d5c7).</description>
    <link>https://dev.to/aditya_bhawar_dc332d1d5c7</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3690003%2Fde73decf-c947-44eb-ae8d-9d27a9c90fd7.gif</url>
      <title>DEV Community: Aditya Bhawar</title>
      <link>https://dev.to/aditya_bhawar_dc332d1d5c7</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aditya_bhawar_dc332d1d5c7"/>
    <language>en</language>
    <item>
      <title>🤯 What Actually Happens Inside a DBMS When You Run a SQL Query?</title>
      <dc:creator>Aditya Bhawar</dc:creator>
      <pubDate>Fri, 02 Jan 2026 13:30:21 +0000</pubDate>
      <link>https://dev.to/aditya_bhawar_dc332d1d5c7/what-actually-happens-inside-a-dbms-when-you-run-a-sql-query-3eee</link>
      <guid>https://dev.to/aditya_bhawar_dc332d1d5c7/what-actually-happens-inside-a-dbms-when-you-run-a-sql-query-3eee</guid>
      <description>&lt;p&gt;Hi, I’m Aditya Balaji Bhavar — a computer science student and developer who enjoys breaking down complex DBMS concepts into simple, practical, and slightly funny explanations.&lt;/p&gt;

&lt;h2&gt;
  
  
  🤯 What Actually Happens Inside a DBMS When You Run a SQL Query?
&lt;/h2&gt;

&lt;p&gt;You type a SQL query.&lt;br&gt;
You press &lt;strong&gt;Enter&lt;/strong&gt;.&lt;br&gt;
Results appear instantly.&lt;/p&gt;

&lt;p&gt;Looks simple… right?&lt;/p&gt;

&lt;p&gt;Behind the scenes, your DBMS is doing a &lt;strong&gt;full mental workout&lt;/strong&gt; while pretending everything is fine 😌&lt;br&gt;
Let’s walk through &lt;strong&gt;what really happens&lt;/strong&gt; — in a &lt;strong&gt;human + funny + developer-friendly way&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  1️⃣ You Write a SQL Query (The Innocent Beginning)
&lt;/h2&gt;

&lt;p&gt;You write something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;salary&lt;/span&gt;
&lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Employee&lt;/span&gt;
&lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;department&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'IT'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You’re basically saying:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Hey DBMS, can you please give me IT people and their salaries?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The DBMS nods politely.&lt;/p&gt;

&lt;p&gt;Internally:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“Ah yes… another SELECT query. Let’s see how bad this is.”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  2️⃣ Query Enters the DBMS (Judgment Day Begins)
&lt;/h2&gt;

&lt;p&gt;Your query enters the &lt;strong&gt;DBMS engine&lt;/strong&gt; and is immediately handed to the &lt;strong&gt;Query Processor&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;⚠️ Important truth:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The DBMS does &lt;strong&gt;NOT&lt;/strong&gt; touch your data yet.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First, it needs to decide:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Is this query even legal?&lt;/li&gt;
&lt;li&gt;Does this human know SQL?&lt;/li&gt;
&lt;li&gt;Should I proceed or scream error?&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3️⃣ Query Processing (The Brain of the DBMS 🧠)
&lt;/h2&gt;

&lt;p&gt;This is where most of the magic (and sass) happens.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 3.1 Parsing (Grammar Police 🚨)
&lt;/h3&gt;

&lt;p&gt;The &lt;strong&gt;Query Parser&lt;/strong&gt; checks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✔ Is the SQL syntax correct?&lt;/li&gt;
&lt;li&gt;✔ Do these tables exist?&lt;/li&gt;
&lt;li&gt;✔ Do these columns exist?&lt;/li&gt;
&lt;li&gt;✔ Does this user have permission?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example of instant rejection:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="n"&gt;SELEC&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Employee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Parser be like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;❌ “SELEC? Seriously? Come back when you can spell.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Query dies right here. No data harmed.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 3.2 Translation (SQL → DBMS Language)
&lt;/h3&gt;

&lt;p&gt;If your query passes the grammar test, the DBMS translates it into its &lt;strong&gt;own internal language&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Your SQL becomes something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;π(name, salary)
     |
σ(department = 'IT')
     |
Employee
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Translation meaning:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Okay, filter IT employees first, then show only name and salary.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now the DBMS understands &lt;strong&gt;what you want&lt;/strong&gt;, but not &lt;strong&gt;how to do it efficiently yet&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 3.3 Query Optimization (Big Brain Time 🧠🔥)
&lt;/h3&gt;

&lt;p&gt;This is the DBMS thinking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Should I read the whole table like an idiot…&lt;br&gt;
or use an index and finish early?”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Possible choices:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Read entire Employee table ❌&lt;/li&gt;
&lt;li&gt;Use index on &lt;code&gt;department&lt;/code&gt; ✔&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;strong&gt;Query Optimizer&lt;/strong&gt; compares multiple plans and chooses the &lt;strong&gt;least painful one&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;💡 Fun fact:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The optimizer doesn’t care how &lt;em&gt;pretty&lt;/em&gt; your SQL is — only how &lt;em&gt;cheap&lt;/em&gt; it is.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  🔹 3.4 Execution Plan (Battle Plan Ready ⚔️)
&lt;/h3&gt;

&lt;p&gt;After deciding the best strategy, the DBMS creates a &lt;strong&gt;Query Execution Plan (QEP)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Index Scan → Filter → Projection → Output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is basically:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Here’s the exact order. Don’t improvise.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Plan is sent to the &lt;strong&gt;Execution Engine&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  4️⃣ Query Execution (Touching Real Data 😬)
&lt;/h2&gt;

&lt;p&gt;Now — and only now — the DBMS starts touching actual data.&lt;/p&gt;




&lt;h3&gt;
  
  
  🔹 4.1 Storage Manager (Data Fetch Guy 💾)
&lt;/h3&gt;

&lt;p&gt;The Execution Engine says:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I need IT employees.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;strong&gt;Storage Manager&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Finds where the data lives on disk&lt;/li&gt;
&lt;li&gt;Loads required blocks into memory&lt;/li&gt;
&lt;li&gt;Uses indexes to avoid unnecessary work&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;DBMS hates disk I/O.&lt;br&gt;
Memory is fast. Disk is slow.&lt;br&gt;
Indexes = happiness ❤️&lt;/p&gt;


&lt;h3&gt;
  
  
  🔹 4.2 Transaction Manager (The Strict Watchman 👮)
&lt;/h3&gt;

&lt;p&gt;While data is being read:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ensures &lt;strong&gt;consistency&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Ensures &lt;strong&gt;isolation&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Manages locks if many users are querying&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Basically:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“No cheating. No half results. No chaos.”&lt;/p&gt;
&lt;/blockquote&gt;


&lt;h3&gt;
  
  
  🔹 4.3 Filtering &amp;amp; Processing (Final Cleanup 🧹)
&lt;/h3&gt;

&lt;p&gt;DBMS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Applies &lt;code&gt;WHERE department = 'IT'&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Picks only &lt;code&gt;name&lt;/code&gt; and &lt;code&gt;salary&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Sorts or groups if needed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything follows the execution plan &lt;strong&gt;step by step&lt;/strong&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  5️⃣ Results Returned (You Think It Was Easy 😎)
&lt;/h2&gt;

&lt;p&gt;Finally, DBMS hands you the result:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name   | salary
-------|--------
Amit   | 60000
Rohit  | 55000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You see numbers.&lt;br&gt;
DBMS just ran a marathon.&lt;/p&gt;


&lt;h2&gt;
  
  
  🔄 The Whole Journey (Simplified)
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Your SQL
   ↓
Parser (Grammar check)
   ↓
Translator (DBMS language)
   ↓
Optimizer (Big brain)
   ↓
Execution Plan
   ↓
Execution Engine
   ↓
Storage Manager
   ↓
Disk
   ↓
Results
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🏦 Real-Life Example: Bank App 💳
&lt;/h2&gt;

&lt;p&gt;Query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;balance&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;Account&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;acc_no&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;101&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Behind the scenes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parser approves&lt;/li&gt;
&lt;li&gt;Optimizer uses index on &lt;code&gt;acc_no&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;DBMS reads &lt;strong&gt;exactly one row&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Transaction manager ensures accuracy&lt;/li&gt;
&lt;li&gt;Balance returned instantly&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That “instant” result?&lt;br&gt;
Yeah… not magic. Just smart planning.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔑 Interview-Friendly Truths (Remember These)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Queries are &lt;strong&gt;never executed directly&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Optimizer decides the execution path&lt;/li&gt;
&lt;li&gt;Indexes save lives (and CPUs)&lt;/li&gt;
&lt;li&gt;DBMS works hard so you can look cool&lt;/li&gt;
&lt;li&gt;Writing better SQL = understanding internals&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎯 Final Thought
&lt;/h2&gt;

&lt;p&gt;Next time you run a SQL query, remember:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You asked politely.&lt;br&gt;
The DBMS judged you.&lt;br&gt;
Optimized your request.&lt;br&gt;
Ran a perfect plan.&lt;br&gt;
And still didn’t complain.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Respect your DBMS.&lt;br&gt;
And please… use indexes 😄&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
