<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Performance on Prateek Sharma</title>
		<link>https://prateeksharma.me/tags/performance/</link>
		<description>Recent content in Performance on Prateek Sharma</description>
		<generator>Hugo</generator>
		<language>en-us</language>
		
		
		
		
			<lastBuildDate>Sun, 30 Aug 2026 00:00:00 +0000</lastBuildDate>
		
			<atom:link href="https://prateeksharma.me/tags/performance/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Composite index column order should match the query, not the schema</title>
				<link>https://prateeksharma.me/notes/index-column-order-should-match-the-filter/</link>
				<pubDate>Sun, 30 Aug 2026 00:00:00 +0000</pubDate>
				<guid>https://prateeksharma.me/notes/index-column-order-should-match-the-filter/</guid>
				<description>&lt;p&gt;In the &lt;a href=&#34;https://prateeksharma.me/projects/tts-study-assistant/&#34;&gt;TTS Study Assistant&lt;/a&gt;&#xA; notes table, queries&#xA;filter by &lt;code&gt;user_id&lt;/code&gt; always and &lt;code&gt;domain&lt;/code&gt; often, so the index is declared in that&#xA;order:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#e6edf3;background-color:#0d1117;-moz-tab-size:2;-o-tab-size:2;tab-size:2;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-sql&#34; data-lang=&#34;sql&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ff7b72&#34;&gt;CREATE&lt;/span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#ff7b72&#34;&gt;INDEX&lt;/span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;idx_uid_did&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#ff7b72&#34;&gt;ON&lt;/span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;notes(user_id,&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#ff7b72&#34;&gt;domain&lt;/span&gt;);&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;A composite index is only fully useful as a left-prefix: this index serves&#xA;&lt;code&gt;WHERE user_id = ?&lt;/code&gt; and &lt;code&gt;WHERE user_id = ? AND domain = ?&lt;/code&gt;, but not&#xA;&lt;code&gt;WHERE domain = ?&lt;/code&gt; alone. The rule of thumb is to order columns by how the&#xA;queries actually filter — most selective / most-always-present first — not by&#xA;declaration order in the table, and not alphabetically.&lt;/p&gt;</description>
			</item>
	</channel>
</rss>
