<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by SaniulMallik on Medium]]></title>
        <description><![CDATA[Stories by SaniulMallik on Medium]]></description>
        <link>https://medium.com/@saniulhaquemallik?source=rss-1b77bd229f11------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wUZTMYIN5BIchmed-amzVA.jpeg</url>
            <title>Stories by SaniulMallik on Medium</title>
            <link>https://medium.com/@saniulhaquemallik?source=rss-1b77bd229f11------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 03:54:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saniulhaquemallik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[AI Hallucinations, RAG, and the Hybrid Future]]></title>
            <link>https://medium.com/@saniulhaquemallik/ai-hallucinations-rag-and-the-hybrid-future-18efb0d08a30?source=rss-1b77bd229f11------2</link>
            <guid isPermaLink="false">https://medium.com/p/18efb0d08a30</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[rags]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[llm-finetuning]]></category>
            <dc:creator><![CDATA[SaniulMallik]]></dc:creator>
            <pubDate>Sat, 24 Jan 2026 22:34:10 GMT</pubDate>
            <atom:updated>2026-01-24T22:34:10.854Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TAxddlJh2IiYA_NXmv_Osw.png" /></figure><p>Just a thought.</p><p>Earlier, we were excited just because we could <em>talk</em> to AI. That alone felt revolutionary.<br>But in 2026, that’s no longer special. That’s the baseline.</p><p>Now the real concern is much more practical:<br>Is it giving the correct answer, or just sounding confident?</p><p>Because in real products, sounding right is not enough. It has to <em>be</em> right.</p><blockquote><strong>1. The Problem: AI Hallucinations</strong></blockquote><p>You and I, and every LLM user out there, will have experienced this situation at some point. You’re going to ask that LLM a question that is super specific about your business, and it comes back with a beautifully formed, crystal-clear answer that turns out to be just plain wrong.</p><p>This is referred to as an “AI hallucination.”</p><p>The frightening part is not that it’s wrong. The frightening part is how convincing it is. There is absolutely no hesitation, no ‘I’m not sure,’ just sheer confidence.”</p><p><strong>Key Reasons for Hallucinations</strong></p><ul><li>When you ask an AI a question, it isn’t looking up a fact in a database. Instead, it is calculating which word is statistically most likely to come next based on the patterns it learned during training. <br>Think of it like a super-advanced version of the autocomplete on your phone — it’s designed to be fluent and convincing, not necessarily truthful. <br>It uses <strong>“Next-Word Prediction”. </strong>AI models are trained to predict the next token in a sequence. If a model doesn’t know the answer to a question, it will still try to finish the sentence. Because it has been trained on billions of pages of human text, it knows exactly what a “correct-sounding” answer looks like, even if the facts inside it are made up.</li><li><strong>Training Data Gap — Outdated Information — leads to a knowledge cutoff. — </strong>If you ask about events that happened after they were trained, they may guess based on older patterns. So if your system requires a specific business topic. <br>For Example, imagine you are building a recommendation model that suggests:<br><em>“Users may like this movie…”</em></li></ul><p>Your model is trained on what users <em>watched in the past</em>. But:</p><p>New movies are released every week — &gt; User preferences change -&gt; Trends shift</p><p>If your model isn’t updated with fresh data, it will keep recommending based on outdated behavior. It’s not wrong because it’s “bad”, it’s wrong because it’s <em>stuck in the past</em>.</p><blockquote><strong>2. Solution: ……………</strong></blockquote><blockquote>While we haven’t “solved” hallucinations yet,</blockquote><blockquote>But several techniques help:</blockquote><p><strong><em>First</em></strong><em>, let&#39;s discuss </em><strong><em>RAG (Retrieval-Augmented Generation). </em></strong>It Provides an <em>Open-Book Exam. </em>Before answering, the AI searches a specific, trusted library of documents you provide. It uses the keywords from the users input and then uses that information to craft its response.</p><p>It allows the AI to access information that happened five minutes ago. By connecting the model to live feeds. <br>It can also provide <strong>citations</strong>. It doesn’t just say “The sky is blue”; it says “According to [Document A], the sky is blue.” This makes the AI auditable and builds user trust.</p><p>Now, in RAG, there are some drawbacks if it is poorly designed, such as poor indexing or retrieval strategies. It can slow down your system. Can face problem on later business implementation.</p><p>The AI is still a visitor in your data. It comes in, reads a few documents, answers, and leaves. It gives the model access to knowledge, but it doesn’t change how the model thinks.</p><p>It does not make your AI trained in your domain.</p><blockquote><strong>3. Evolution: The Hybrid Future</strong></blockquote><p>In hybrid mode, you train the model with relevant data based on the particular business, and the best part is that the V<strong><em>ector DB</em></strong> is your <strong><em>Goldmine.</em></strong></p><p>If you are having the log of your <strong>RAG</strong> interaction, like user questions, retrieved context, and final response to the user, their feedback, etc.</p><p>To train the model,</p><p>Collect the quality logs — &gt; Keep only good or correct answers — &gt; Fine-Tune a Private Small Language Model.</p><pre>User Query<br>   ↓<br>Fine-Tuned SLM  → understands your business logic<br>   ↓<br>  RAG           → injects real-time knowledge<br>   ↓<br>Final Answer</pre><p>Now your model is well aware of how to act, as it has context, domain-based knowledge and was trained from previous interactions.</p><pre>You can fine-tune if :<br>  1. You repeat the same instructions often. or<br>  2. You need your model to be a beast on a fixed domain. or<br>  3. You want to lower your token amount or want a faster response.<br><br></pre><blockquote><strong>RAG vs Hybrid: The Real Cost Difference (In Tokens &amp; Money)</strong></blockquote><p>Now lets talk about the cost — tokens.</p><p><em>token = latency + money</em></p><p><em>Suppose your RAG system is taking 5k tokens for a complete response cycle.</em></p><pre>System Instructions        → 500 tokens  <br>User Query                 → 100 tokens  <br>Retrieved Context          → 4,000 tokens  <br>Model Answer               → 400 tokens  <br>-----------------------------------<br>Total ≈ 5,000 tokens per request<br><br>5000 token * 10k request per day. -&gt; 50 million token/day</pre><p>But if we are querying our trained SLM — <br>We will save on fewer system instructions, RAG cntext and also consider losing tokens for bad responses.</p><p>So, in the HYBRID model came the request cost breakdown,</p><pre>System Instructions       → 200 tokens  <br>User Query                → 100 tokens  <br>RAG Context (the very current docs that arenot used in the last training)  → 800 tokens  <br>Model Answer              → 300 tokens  <br>-----------------------------------<br>Total ≈ 1,400 tokens per request<br><br>1400 token * 10k requests per day -&gt; 14 million token/day</pre><p>“But a hybrid needs an initial training cost and periodic retraining to keep up with evolving business knowledge. Additionally, if you want to <strong>upgrade your base model</strong>, you will need to <strong>fine-tune the new model again</strong> using your existing dataset or logs to maintain consistency and domain expertise.</p><p>Process Visuals —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*olGSceUe3NEIRNb-vWNqNg.png" /></figure><p><em>RAG = access to information<br>SLM = your AI’s brain<br>Hybrid = brain + real-time memory</em></p><blockquote>And the best part is: <strong>you don’t have to stick to a single model</strong>. If you want, you can let users pick the model for each query — OpenAI, Gemini, Claude, or any fine-tuned SLM you have. The same Vector DB / RAG knowledge base continues to provide context, so every model has access to the same up-to-date facts.</blockquote><p><strong>🩶 <em>Thanks for reading<br></em></strong>Would love to hear your thoughts in the comments 👇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=18efb0d08a30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Looping update_or_create(): The Definitive Guide to Django's Idempotent Bulk Upsert]]></title>
            <link>https://medium.com/@saniulhaquemallik/stop-looping-update-or-create-the-definitive-guide-to-djangos-idempotent-bulk-upsert-5e9815864273?source=rss-1b77bd229f11------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e9815864273</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[django-orm]]></category>
            <category><![CDATA[django]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[SaniulMallik]]></dc:creator>
            <pubDate>Thu, 27 Nov 2025 05:02:39 GMT</pubDate>
            <atom:updated>2025-11-27T05:02:39.316Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GZ3DVQMtIugWXSBD0LysTw.png" /></figure><p>Alright, let’s begin with a simple but powerful idea: I<strong>dempotency</strong>.</p><p>In programming, an operation is idempotent when it can be run multiple times without changing the result.</p><p>An <strong>idempotent upsert (Update or insert) </strong>is a database operation that can be executed multiple times while guaranteeing the <strong>same final state</strong> of the database as if it had been executed only once.</p><p><strong>This makes it clear that re-running the operation with the same input data does not create unintended side effects such as—</strong></p><ul><li><strong>Duplicate records</strong></li><li><strong>Incorrect modifications</strong></li></ul><p>So if you’re building a feature or a background job that needs to <strong>sync </strong>large datasets from APIs, CRON jobs, or external sources, where —</p><ul><li>Some are already existing, and some are new.</li></ul><p>Now, if you’ve worked with Django for a while, it comes with a feature update_or_create</p><pre>for item in items:<br>    Product.objects.update_or_create(<br>        external_id=item[&#39;product_id&#39;],<br>        defaults={&#39;name&#39;: item[&#39;name&#39;], &#39;price&#39;: item[&#39;price&#39;]}<br>    )</pre><p>It <em>feels</em> idempotent — update if it exists, create if not.</p><p>But the reality is, under the hood, it’s doing a lot more work than it should.</p><p>Each call runs two queries:</p><h3>Step 1: The SELECT query</h3><p>For every loop iteration, Django first checks if the record already exists.<br> If external_id is a unique field, it’ll do something like:</p><pre>SELECT &quot;id&quot;, &quot;external_id&quot;, &quot;name&quot;, &quot;price&quot;<br>FROM &quot;products&quot;<br>WHERE &quot;external_id&quot; = &#39;SN-P5GC&#39;<br>LIMIT 1;</pre><ul><li>If the row exists → proceed to UPDATE.</li><li>If it doesn’t → proceed to INSERT.</li></ul><h3>Step 2: The UPDATE or INSERT query</h3><p>If the SELECT query returns a row, Django executes an UPDATE to modify it:</p><pre>UPDATE &quot;products&quot;<br>SET &quot;name&quot; = &#39;Sony PlayStation 5&#39;,<br>    &quot;price&quot; = 449.99<br>WHERE &quot;external_id&quot; = &#39;SN-P5GC&#39;;</pre><p>If the SELECT query finds <em>no matching row</em>, Django creates a new one instead:</p><pre>INSERT INTO &quot;products&quot; (&quot;external_id&quot;, &quot;name&quot;, &quot;price&quot;)<br>VALUES (&#39;SN-P5GC&#39;, &#39;Sony PlayStation 5&#39;, 449.99);</pre><p>So the total cost of creating or updating one product is 2 queries.</p><p>Now imagine this running for a batch of 3,000 items = 6000 database hits.</p><p>Which is so inefficient that we devs used to do this filtering part by ourselves in batches.</p><p>For example, we can use batching of 1000 items and search in the database with product IDs reference and update in bulk for returned objects. If the data is not there for a product ID, then create it in bulk.</p><pre>for batch in split(items, 1000):<br>    existing = fetch products where id in batch.ids<br>    to_update = products in batch that exist; to_create = those not exist<br>    bulk_update(to_update)<br>    try bulk_create(to_create, ignore_conflicts=True)<br>    except IntegrityError: save each to_create individually inside atomic()<br></pre><p>Fewer queries? Yes.<br>Fun? Absolutely not.</p><p>It solved the efficiency issue, but at the cost of readability and maintainability.</p><p>We reduced queries and improved speed significantly…<br>But deep down, we all wanted a real ORM-native, one-query upsert — without the emotional damage.</p><h3>🎉 The Django 4.1 Way: One Query to Rule Them All</h3><p>Instead of doing this dance 10,000 times, Django 4.1+ can now handle everything in <strong>one single upsert query</strong> using bulk_create(update_conflicts=True)</p><p><strong>How this works:<br></strong>During a bulk insert, if any row violates a unique/index rule, don’t crash — update the existing row instead.</p><pre>Product.objects.bulk_create(<br>    [<br>        Product(external_id=&#39;SN-P5GC&#39;, name=&#39;Sony PlayStation 5&#39;, price=449.99),<br>        Product(external_id=&#39;SN-XBX-X&#39;, name=&#39;Xbox Series X&#39;, price=499.00),<br>        Product(external_id=&#39;SN-SW-O2&#39;, name=&#39;Nintendo Switch OLED&#39;, price=299.50),<br>    ],<br>    update_conflicts=True,<br>    update_fields=[&#39;name&#39;, &#39;price&#39;],<br>    unique_fields=[&#39;external_id&#39;]<br>)</pre><p>Django converts this into a single SQL query:</p><pre>INSERT INTO &quot;products&quot; (&quot;external_id&quot;, &quot;name&quot;, &quot;price&quot;)<br>VALUES <br>    (&#39;SN-P5GC&#39;, &#39;Sony PlayStation 5&#39;, 449.99),<br>    (&#39;SN-XBX-X&#39;, &#39;Xbox Series X&#39;, 499.00),<br>    (&#39;SN-SW-O2&#39;, &#39;Nintendo Switch OLED&#39;, 299.50)<br>ON CONFLICT (&quot;external_id&quot;) DO UPDATE<br>SET &quot;name&quot; = EXCLUDED.&quot;name&quot;,<br>    &quot;price&quot; = EXCLUDED.&quot;price&quot;;</pre><h3>✅ What just happened?</h3><ul><li>PS5 already existed → <strong>updated</strong></li><li>Xbox, Switch maybe new → <strong>inserted</strong></li><li>3 products or 3k products → still <strong>1 query</strong></li><li>Same input repeated → same DB truth maintained (<strong>idempotent</strong>)</li><li>Database stops screaming, developers stop crying 🖤</li></ul><p>Less queries = less latency = less planning overhead = more happiness.</p><h3>Final Thoughts</h3><p>With bulk_create(update_conflicts=True), Django finally gives us the <strong>one-query, fully idempotent upsert</strong> we always wanted. No loops, no double queries, no messy batching — just clean, fast, reliable syncing.</p><p>Insert new rows, update existing ones, all in one shot.</p><p>No loops. No query flood. Just clean, lightning-fast syncing ⚡</p><p><strong>🩶 <em>Thanks for reading </em><br></strong>What do you think about bulk upsert vs update_or_create() loops?<br>Would love to hear your thoughts in the comments 👇🩶</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e9815864273" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adding One Column, Burning Gigabytes: How SQL Server Handles Schema Changes]]></title>
            <link>https://medium.com/@saniulhaquemallik/adding-one-column-burning-gigabytes-how-sql-server-handles-schema-changes-511ebcf73dfc?source=rss-1b77bd229f11------2</link>
            <guid isPermaLink="false">https://medium.com/p/511ebcf73dfc</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[sql-server]]></category>
            <category><![CDATA[django]]></category>
            <dc:creator><![CDATA[SaniulMallik]]></dc:creator>
            <pubDate>Sun, 02 Nov 2025 02:35:11 GMT</pubDate>
            <atom:updated>2025-11-02T21:20:09.330Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>A few months ago, when developing a new feature, I was faced with a weird database migration problem. <strong>The problem occurred when I tried to add a new column</strong> to an existing table using the command ALTER TABLE</blockquote><p>This was an operation that should have been instantaneous, but seemed to take considerably longer than it should.</p><p>Then I came to know how <strong>SQL Server manages memory and storage</strong> when schema changes are made — especially what happens when a table structure is modified or when we do a <strong>Django migration</strong> that triggers an ALTER TABLE</p><p>Before figuring out why adding a column can feel so heavy, let’s peek behind the curtain and see what SQL Server is really doing under the hood.</p><p><strong><em>How SQL Server Manages Memory (Pages, Buffers, and Caches)</em></strong></p><p>When we think of a database, it’s easy to imagine data being written straight to disk.</p><p>In reality, though, most operations happen <strong>in memory</strong> first.</p><p>SQL Server uses a complex memory management system built on a few key concepts: <strong>pages, buffers, </strong>and<strong> caches</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*qY55h5gKQHIVDrPem20-CQ.jpeg" /><figcaption>Image Source: <a href="https://www.researchgate.net/figure/Conceptual-diagram-of-the-SQL-Server-Cache-and-Buffer-Pool_fig1_392358763">https://www.researchgate.net/figure/Conceptual-diagram-of-the-SQL-Server-Cache-and-Buffer-Pool_fig1_392358763</a></figcaption></figure><blockquote><strong><em>Pages — The Building Blocks</em></strong></blockquote><p>SQL Server breaks its data into fixed-size chunks known as <strong>pages</strong>, each <strong>8 KB</strong> in size. Every row in a table is contained within one of these pages, and each page is assigned to a data file.</p><p>When a query runs, SQL doesn’t fetch data directly from disk — it first loads the necessary pages into <strong>RAM</strong>.</p><p>— -</p><blockquote><strong><em>Buffer Pool — Where the Action Happens</em></strong></blockquote><p>The <strong>Buffer Pool</strong> is a large memory region where SQL Server keeps frequently used pages.</p><p>When data is read from disk, it’s copied into the buffer pool.</p><p>If the same data is needed again, SQL simply reads it from memory instead of hitting the disk — drastically reducing I/O time.</p><blockquote>Every page in memory carries a “dirty” flag.<br>A <strong>“clean” page</strong> means:<br> The data in memory is <strong>exactly the same</strong> as what’s stored on disk.<br>A <strong>“dirty” page</strong> means:<br> The data in memory <strong>has been changed</strong> but <strong>not yet written</strong> back to disk.</blockquote><p>When data changes, the page is marked as dirty but isn’t immediately written to disk.</p><p>The dirty pages are written back to disk in batches by a background process called the <strong>Checkpoint</strong>, which balances consistency with performance.</p><p>— -</p><blockquote><strong><em>Memory Clerks and Caches — The Managers of SQL Memory</em></strong></blockquote><p>SQL Server does not treat its memory as a single shared pool — it divides it into specialised areas called <strong>Memory Clerks</strong>, each responsible for performing specific functions inside the engine.</p><p>Think of them as mini memory managers that keep different parts of SQL organized:</p><p>You can view all active memory clerks to see a detailed breakdown of how different components of SQL Server are consuming memory.</p><pre>SELECT type, SUM(pages_kb) AS memory_used_kb<br>FROM sys.dm_os_memory_clerks<br>GROUP BY type<br>ORDER BY memory_used_kb DESC;</pre><blockquote><strong><em>Plan Cache</em></strong></blockquote><p>When SQL executes a query, it first compiles it into an <strong>execution plan</strong> — a map of how to fetch or modify data efficiently.</p><p>Compilation is CPU-expensive; hence, SQL stores these plans in memory for reuse.</p><p>If the same query runs again — for instance, when running similar migrations in Django — SQL retrieves the cached plan instead of recompiling from scratch.</p><blockquote><strong><em>Data Cache</em></strong></blockquote><p>The <strong>Data Cache</strong> (part of the Buffer Pool) holds recently accessed data pages.</p><p>If you query a table multiple times, those pages remain cached, and SQL can serve the results directly from memory without needing to read from disk again.</p><p>Together, these caches save huge amounts of CPU and I/O overhead — which is why your database usually feels fast, until a migration comes along.</p><blockquote><strong><em>What Happens When You Add a New Column</em></strong></blockquote><p>Now, let’s get to the main mystery — why a simple ALTER TABLE ADD COLUMN can suddenly spike disk usage and take minutes to complete.</p><p>The internal process depends on <strong>whether the column has a default value</strong> or not.</p><p><em>Case 1: Adding a Column </em><strong><em>Without</em></strong><em> a Default Value</em></p><p>When you add a nullable column, for instance:</p><pre>ALTER TABLE users ADD bio VARCHAR(256) NULL;</pre><p>SQL Server does not rewrite existing rows.</p><p>It only <strong>updates the table’s metadata </strong>— specifically, the system catalogs that describe the table’s structure.</p><p>Since the column allows NULL, SQL doesn’t need to touch the actual data pages.</p><p>Every row simply <strong>implicitly </strong>has a NULL for that column.</p><p>This is a fast operation, typically in milliseconds, regardless of how large the table is.</p><p>— -</p><p><em>Case 2: Adding a Column </em><strong><em>With</em></strong><em> a Default Value</em></p><p>Now consider this:</p><pre>ALTER TABLE users ADD is_active BIT NOT NULL DEFAULT 1;</pre><p>This is a completely different story.</p><p>Because this column is <strong>non-nullable</strong> and has a <strong>default value</strong>, SQL Server needs to <strong>ensure that</strong> <strong>every existing row</strong> in the table gets that value.</p><p>So, what happens internally:</p><p>1. SQL reads affected data pages into the <strong>Buffer Pool</strong>.</p><p>2. It updates all rows in memory to include the new column and its default value.</p><p>3. These modified pages are marked <strong>dirty</strong>.</p><p>4. SQL eventually writes them back to disk.</p><p>For large tables — millions of rows — this means:</p><p>— High I/O operations</p><p>— Increased memory pressure in the buffer pool</p><p>— Potential log growth (since every update is logged)</p><p>— Long-duration locks that may block other queries</p><p>That’s why such migrations can take minutes (or hours) and temporarily slow down your entire database.</p><p>— -</p><blockquote><strong><em>How Django Migrations Trigger This</em></strong></blockquote><p>When Django runs a migration that adds a new field, it translates your model change into an ALTER TABLE statement.</p><p>If the field has a default or is non-nullable, Django includes that in the SQL command — which causes SQL Server to rewrite every existing row.</p><p>For example:</p><pre>class User(models.Model):<br>  name = models.CharField(max_length=100)<br>  is_active = models.BooleanField(default=True)</pre><p>will trigger something like:</p><pre>ALTER TABLE users ADD is_active BIT NOT NULL DEFAULT 1;</pre><blockquote><strong><em>The fix?</em></strong></blockquote><p>If possible, <strong>add nullable fields first</strong>, then run an UPDATE in batches, and finally <strong>set the column as non-nullable</strong> in a later migration.</p><p>That avoids massive rewrites and minimises lock contention.</p><p>— -</p><blockquote><strong><em>Takeaways</em></strong></blockquote><p>— Adding a column <strong>without</strong> <strong>a default</strong> is instant (<strong>metadata-only change</strong>).</p><p>— Adding a <strong>non-nullable</strong> column <strong>with a default value</strong> forces a t<strong>able rewrite</strong> — every row must be updated.</p><p>— SQL Server uses <strong>memory clerks</strong>, <strong>buffers</strong>, and <strong>caches</strong> to manage these operations efficiently, but large migrations still push the limits on systems.</p><p>For large tables, consider breaking migrations into steps.</p><blockquote><strong><em>Not all schema changes are lightweight.</em></strong></blockquote><p>Under the hood, SQL is doing far more than just “adding a field.”</p><p>It’s managing memory allocations, rewriting pages, marking them dirty, and coordinating between disk and buffer pool — all to keep your data safe and consistent.</p><p>So next time your ALTER TABLE takes forever, remember — it’s not SQL being slow.</p><p>It’s SQL being cautious.</p><blockquote><strong>Thanks for reading </strong><em>🩶</em></blockquote><p>I’d love to hear your experience with heavy migrations or schema changes — share your story in the comments, and let’s learn together</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=511ebcf73dfc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>