<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SQL on Chen Kai Blog</title><link>https://www.chenk.top/en/tags/sql/</link><description>Recent content in SQL on Chen Kai Blog</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sun, 21 Apr 2024 09:00:00 +0000</lastBuildDate><atom:link href="https://www.chenk.top/en/tags/sql/index.xml" rel="self" type="application/rss+xml"/><item><title>Databases (3): Transactions and Concurrency — ACID, Isolation Levels, and Locking</title><link>https://www.chenk.top/en/databases/03-transactions-and-concurrency/</link><pubDate>Sun, 21 Apr 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/databases/03-transactions-and-concurrency/</guid><description>&lt;p>Every application that handles money, inventory, or any state that matters eventually hits a concurrency bug. Two users buy the last item in stock. A bank transfer debits one account but crashes before crediting the other. A report reads half-updated data and produces nonsense numbers. Transactions exist to prevent these failures, and understanding how they work is non-negotiable for anyone building production systems.&lt;/p>
&lt;hr>
&lt;h2 id="what-is-a-transaction" class="heading-anchor">What Is a Transaction?&lt;a href="#what-is-a-transaction" class="heading-link" aria-label="Permalink to this section" title="Copy link to this section">#&lt;/a>
&lt;/h2>&lt;p>A transaction is a group of operations that the database treats as a single unit. Either &lt;strong>all&lt;/strong> operations succeed, or &lt;strong>none&lt;/strong> of them do.&lt;/p></description></item><item><title>Databases (2): Indexing and Query Planning — How Databases Find Your Data</title><link>https://www.chenk.top/en/databases/02-indexing-and-query-planning/</link><pubDate>Fri, 19 Apr 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/databases/02-indexing-and-query-planning/</guid><description>&lt;p>A query that returns in 2 milliseconds on your laptop with 1,000 rows will take 45 seconds on a production database with 50 million rows — unless you have the right indexes. Indexes are the single most impactful performance tool in your database toolkit, and understanding how they work changes the way you think about every schema and every query you write.&lt;/p>
&lt;hr>
&lt;h2 id="the-fundamental-problem-finding-a-row" class="heading-anchor">The Fundamental Problem: Finding a Row&lt;a href="#the-fundamental-problem-finding-a-row" class="heading-link" aria-label="Permalink to this section" title="Copy link to this section">#&lt;/a>
&lt;/h2>&lt;p>Imagine a table with 10 million rows, stored on disk as a heap file. Each row sits somewhere in a sequence of 8 KB pages. When you run:&lt;/p></description></item><item><title>Databases (1): Data Models and SQL — Why Tables Won (For Now)</title><link>https://www.chenk.top/en/databases/01-data-models-and-sql/</link><pubDate>Wed, 17 Apr 2024 09:00:00 +0000</pubDate><guid>https://www.chenk.top/en/databases/01-data-models-and-sql/</guid><description>&lt;p>Every application you have ever used sits on top of a data model. Pick the wrong one and you spend the next three years fighting your own database instead of shipping features.&lt;/p>
&lt;p>For the past four decades, one model has dominated: the relational model. Flat tables, foreign keys, SQL. It is not glamorous. It is not trendy. But there is a reason almost every bank, airline, hospital, and e-commerce platform still runs on it — and understanding &lt;em>why&lt;/em> is the first step to understanding databases at all.&lt;/p></description></item></channel></rss>