<?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 Stefan Litsche</title>
		<link>https://biosoft.de/tags/sql/</link>
		<description>Recent content in SQL on Stefan Litsche</description>
		<generator>Hugo</generator>
		<language>en-US</language>
		
		
		
		
			<lastBuildDate>Fri, 02 Jul 2021 10:26:00 +0100</lastBuildDate>
		
			<atom:link href="https://biosoft.de/tags/sql/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Sorting in Lakes</title>
				<link>https://biosoft.de/posts/sorting-in-lakes/</link>
				<pubDate>Fri, 02 Jul 2021 10:26:00 +0100</pubDate>
				<guid>https://biosoft.de/posts/sorting-in-lakes/</guid>
				<description>&lt;p&gt;In case we sort rows using SQL we need to distinguish between duplicate values&#xA;of unique rows and duplicate values due to duplicate rows.&lt;/p&gt;&#xA;&lt;p&gt;The nice thing about the &lt;a href=&#34;https://www.postgresql.org/docs/current/functions-window.html&#34;&gt;&lt;code&gt;row_number&lt;/code&gt;&lt;/a&gt; SQL function is that it provides you with&#xA;a unique number (per partition) which is often used as a mean to de-duplicate a&#xA;set.  The &lt;code&gt;rank&lt;/code&gt; function does not provide this property because duplicate&#xA;values share the same rank.&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;SELECT a,&#xA;    dense_rank() OVER (ORDER BY a),&#xA;    rank() OVER (ORDER BY a),&#xA;    row_number() OVER (ORDER BY a)&#xA;FROM (VALUES (1),(1),(2)) AS t(a);&#xA;&#xA; a | dense_rank | rank | row_number&#xA;---+------------+------+------------&#xA; 1 |          1 |    1 |          1&#xA; 1 |          1 |    1 |          2&#xA; 2 |          2 |    3 |          3&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;The problem occurs if you use it the wrong way.  Recently I spent a some time&#xA;debugging a weird behavior in a report.  The numbers changed during different&#xA;executions on an immutable data set &amp;mdash; which is not what you expect.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Analyze Extreme Distributions in Postgresql</title>
				<link>https://biosoft.de/posts/analyze-extreme-distributions-in-postgresql/</link>
				<pubDate>Thu, 30 Jul 2015 10:30:00 +0100</pubDate>
				<guid>https://biosoft.de/posts/analyze-extreme-distributions-in-postgresql/</guid>
				<description>&lt;p&gt;&#xA;&lt;img src=&#34;https://biosoft.de/extreme/load-spike.png&#34; alt=&#34;/extreme/load-spike.png&#34; title=&#34;/extreme/load-spike.png&#34; /&gt;&lt;/p&gt;&#xA;&lt;p&gt;&#xA;Recently my team and I observed in our PostgreSQL databases a sporadic increase&#xA;in the execution time of stored procedures (see the graph above). Often it&#xA;happened that an &lt;code&gt;analyze&lt;/code&gt; of the referenced table solved the issue. In our case,&#xA;fluctuations in our execution plan caused statement timeouts. This led to errors&#xA;in our applications.&lt;/p&gt;&#xA;&lt;p&gt;&#xA;We wanted to understand this behavior better. Which circumstances prompted more&#xA;frequent plan fluctuations? How exactly could we influence the system to be more&#xA;reliable? To find answers, we tested how different configurations of PostgreSQL&#xA;influenced the results of the query planner. This post shares the results of our&#xA;tests.&lt;/p&gt;</description>
			</item>
			<item>
				<title>NULL Werte in Order By Klausel</title>
				<link>https://biosoft.de/posts/null-werte-order-by/</link>
				<pubDate>Thu, 21 Jul 2011 16:21:00 +0000</pubDate>
				<guid>https://biosoft.de/posts/null-werte-order-by/</guid>
				<description>&lt;p&gt;Man möchte in einer nach einer Spalte sortieren die &lt;a href=&#34;http://de.wikipedia.org/wiki/Nullwert&#34;&gt;Null&#xA;Werte&lt;/a&gt; enthält.  Aber man braucht ein&#xA;sicheres Verhalten dafür, ob die &lt;code&gt;NULL&lt;/code&gt; Werte am Beginn oder am Ende eingefügt&#xA;werden.  Wie kann man das &lt;em&gt;standard konform&lt;/em&gt; und &lt;em&gt;backend unabhängig&lt;/em&gt; realisieren?&lt;/p&gt;&#xA;&lt;p&gt;Am einfachsten wäre es, wenn es ein zugesichertes Verhalten gibt.  Leider gibt&#xA;es das nicht.  Der Standard gibt nur vor, dass alle Nullmarken gleich behandelt&#xA;werden.  Der ISO Standard SQL/92 sagt dazu (Zitat C.Date, H.Darwin (1998) &lt;a href=&#34;http://www.amazon.de/SQL-Standard-mit-den-Erweiterungen/dp/3827313457&#34;&gt;SQL - Der Standard&lt;/a&gt;. Seite 278):&lt;/p&gt;</description>
			</item>
			<item>
				<title>Performance Strategien</title>
				<link>https://biosoft.de/posts/performance-strategien/</link>
				<pubDate>Thu, 02 Jun 2011 12:20:00 +0000</pubDate>
				<guid>https://biosoft.de/posts/performance-strategien/</guid>
				<description>&lt;p&gt;Gerade arbeite ich in einem Projekt, bei dem es um die Konvertierung von ca. 20&#xA;Mio Datensätzen geht.  Vorgegebene Technik ist PL/SQL.  Die allgemein bekannten grundlegenden Maßnahmen zur Optimierung - wie optimale Zugriffspfade, Indizierung, Vermindern der Resultsets, etc. - werden genutzt.&#xA;Was kann man darüber hinaus noch tun?&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;Vermeiden von I/O&lt;/li&gt;&#xA;&lt;li&gt;Parallelisierung&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Zugriffe im Hauptspeicher sind bekanntermaßen schneller aus I/O Operationen.  Darum können Nachschlage Listen, die im Hauptspeicher bspw. als Arrays oder Hashlisten umgesetzt sind, deutliche Zeit ersparen.&lt;/p&gt;</description>
			</item>
	</channel>
</rss>
