<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Databases on PG Blog</title><link>https://pg-blogs.netlify.app/tags/databases/</link><description>Recent content in Databases on PG Blog</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Fri, 03 Jul 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://pg-blogs.netlify.app/tags/databases/index.xml" rel="self" type="application/rss+xml"/><item><title>Avoiding ORM Traps and the N+1 Problem in Java</title><link>https://pg-blogs.netlify.app/posts/8-avoiding-orm-traps-and-n-plus-1-in-java/</link><pubDate>Fri, 03 Jul 2026 00:00:00 +0000</pubDate><guid>https://pg-blogs.netlify.app/posts/8-avoiding-orm-traps-and-n-plus-1-in-java/</guid><description>&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;An ORM like JPA/Hibernate makes database access feel like working with plain objects. That is exactly the problem: a single innocent-looking loop can fire hundreds of SQL queries, and you won&amp;rsquo;t see it until production slows to a crawl.&lt;/p&gt;
&lt;p&gt;This post covers the ORM traps that bite Java teams most often — starting with the notorious &lt;strong&gt;N+1 query problem&lt;/strong&gt; — and the concrete techniques that fix them.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="the-n1-problem"&gt;The N+1 Problem&lt;/h2&gt;
&lt;p&gt;Consider loading authors and printing their books:&lt;/p&gt;</description></item><item><title>Avoiding ORM Traps and the N+1 Problem in Python</title><link>https://pg-blogs.netlify.app/posts/9-avoiding-orm-traps-and-n-plus-1-in-python/</link><pubDate>Fri, 03 Jul 2026 00:00:00 +0000</pubDate><guid>https://pg-blogs.netlify.app/posts/9-avoiding-orm-traps-and-n-plus-1-in-python/</guid><description>&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Python&amp;rsquo;s ORMs — SQLAlchemy and the Django ORM — are a joy to write and dangerously easy to make slow. A loop over a queryset that reads one related field can silently fire hundreds of queries. It looks fine in development and falls over on real data.&lt;/p&gt;
&lt;p&gt;This post covers the ORM traps Python teams hit most, starting with the &lt;strong&gt;N+1 query problem&lt;/strong&gt;, in both SQLAlchemy and Django.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id="the-n1-problem"&gt;The N+1 Problem&lt;/h2&gt;
&lt;p&gt;You load authors and print each author&amp;rsquo;s book count:&lt;/p&gt;</description></item><item><title>Database Indexing and Query Optimization for Java Developers</title><link>https://pg-blogs.netlify.app/posts/18-database-indexing-and-query-optimization-for-java/</link><pubDate>Fri, 03 Jul 2026 00:00:00 +0000</pubDate><guid>https://pg-blogs.netlify.app/posts/18-database-indexing-and-query-optimization-for-java/</guid><description>&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Fixing N+1 queries (see the &lt;a href="https://pg-blogs.netlify.app/posts/8-avoiding-orm-traps-and-n-plus-1-in-java/"&gt;previous post&lt;/a&gt;) gets your Hibernate app down to a handful of queries per request. The next bottleneck is what each of those queries costs once your tables have millions of rows — and that is almost always a question of indexing.&lt;/p&gt;
&lt;p&gt;An index turns &amp;ldquo;scan every row&amp;rdquo; into &amp;ldquo;look it up directly.&amp;rdquo; Get the index wrong — or skip it — and a query that took 2ms in development takes 4 seconds in production once real data volume shows up.&lt;/p&gt;</description></item><item><title>Database Indexing and Query Optimization for Python Developers</title><link>https://pg-blogs.netlify.app/posts/19-database-indexing-and-query-optimization-for-python/</link><pubDate>Fri, 03 Jul 2026 00:00:00 +0000</pubDate><guid>https://pg-blogs.netlify.app/posts/19-database-indexing-and-query-optimization-for-python/</guid><description>&lt;h2 id="introduction"&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Fixing N+1 queries with &lt;code&gt;select_related&lt;/code&gt;/&lt;code&gt;prefetch_related&lt;/code&gt; or &lt;code&gt;selectinload&lt;/code&gt; (see the &lt;a href="https://pg-blogs.netlify.app/posts/9-avoiding-orm-traps-and-n-plus-1-in-python/"&gt;previous post&lt;/a&gt;) gets you down to a small, sane number of queries per request. The next bottleneck is what each query costs once the table has millions of rows — and that is almost always about indexing.&lt;/p&gt;
&lt;p&gt;An index turns &amp;ldquo;scan every row&amp;rdquo; into &amp;ldquo;look it up directly.&amp;rdquo; Skip it, and a query that&amp;rsquo;s instant in development takes seconds once real data volume shows up in production.&lt;/p&gt;</description></item></channel></rss>