<?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 Jorge Solórzano on Medium]]></title>
        <description><![CDATA[Stories by Jorge Solórzano on Medium]]></description>
        <link>https://medium.com/@jorsol?source=rss-e8ecaa2d816b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*Bie0daHHgN7oOEXsIpMQnQ.jpeg</url>
            <title>Stories by Jorge Solórzano on Medium</title>
            <link>https://medium.com/@jorsol?source=rss-e8ecaa2d816b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 05:15:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jorsol/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[PostgreSQL 10 features: Parallel Queries]]></title>
            <link>https://medium.com/@jorsol/postgresql-10-features-parallel-queries-10a92c012d53?source=rss-e8ecaa2d816b------2</link>
            <guid isPermaLink="false">https://medium.com/p/10a92c012d53</guid>
            <category><![CDATA[new-features]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[parallel-processing]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Jorge Solórzano]]></dc:creator>
            <pubDate>Fri, 08 Sep 2017 17:07:01 GMT</pubDate>
            <atom:updated>2018-06-08T17:10:30.395Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*3p8rVqSQGxRaNYdcFSchjg.jpeg" /><figcaption>Parallel PostgreSQL queries: better throughput</figcaption></figure><p>This is the second story of the series “PostgreSQL 10 features”, you can read the first story “<a href="https://medium.com/@jorsol/postgresql-10-features-hash-indexes-484f319db281">Hash indexes</a>” if you missed it.</p><p>We are approaching to the final release of PostgreSQL 10, now I will talk about “Parallel Queries”, like the Hash indexes in the previous post, Parallel Queries it’s not an entirely new feature, but in PostgreSQL 10 there is an Improved Query Parallelism.</p><p>With 9.6, PostgreSQL introduces initial support for parallel execution of large queries. But it’s not enabled by default and only covers parallel execution of sequential scans, joins and aggregates.</p><p>In PostgreSQL 10 we will have:</p><ul><li>Support parallel B-tree index scans.</li><li>Support parallel bitmap heap scans.</li><li>Allow merge joins to be performed in parallel.</li><li>Allow non-correlated subqueries to be run in parallel.</li><li>Increase parallel query usage in procedural language functions.</li></ul><p>All of this is translated to Substantial performance improvements, especially in the area of scalability on multi-CPU-socket servers.</p><p>Yeah! our beloved Database is better and better with each release. We need to thanks Robert Haas and other PostgreSQL Hackers, for their hard work. It has been a long and awaited feature, but we are finally there.</p><p>Some people coming from other RDBMS could say: “WHAT!!! the X commercial database system has supported parallel queries since many years ago”; and yes it’s true, but these commercial databases heavily invest in development and the license to use them costs lots of money, and with PostgreSQL you get a pretty advanced feature set, comparable and sometimes better than the commercial counterpart, at zero cost, free/gratis, so I invite you to give a <a href="https://www.postgresql.org/about/donate/">donation to the project</a> to support the hackers that make this possible.</p><p>I will not make this post long since Robert Haas himself write a nice <a href="https://rhaas.blogspot.com/2017/03/parallel-query-v2.html">post about this improvements</a>.</p><p>Remember to tune properly to your environment, by default <a href="https://www.postgresql.org/docs/10/static/runtime-config-resource.html#guc-max-parallel-workers-per-gather"><strong>max_parallel_workers_per_gather</strong></a> is set to <strong><em>2</em></strong>, on multi cpu-core-sockets servers, you might want to increase this value, but be aware that parallel queries may consume very substantially more resources than non-parallel queries.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=10a92c012d53" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PostgreSQL 10 features: Hash indexes]]></title>
            <link>https://medium.com/@jorsol/postgresql-10-features-hash-indexes-484f319db281?source=rss-e8ecaa2d816b------2</link>
            <guid isPermaLink="false">https://medium.com/p/484f319db281</guid>
            <category><![CDATA[new-features]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Jorge Solórzano]]></dc:creator>
            <pubDate>Fri, 18 Aug 2017 05:00:59 GMT</pubDate>
            <atom:updated>2017-09-08T17:11:06.709Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*c6F-0b21XXkIg78ukkSK5w.png" /></figure><p>PostgreSQL 10 it’s coming soon, so I will write some small posts about new features in this amazing release of the most advanced open source database.</p><p>This are not a deep dive into the features, just a general overview of the new features coming in the new version.</p><p>PostgreSQL provides several index types: B-tree, Hash, GiST, SP-GiST, GIN and BRIN. In this post, I would like to talk about <strong>Hash indexes</strong> in PostgreSQL, this is not an entirely new feature, in fact PostgreSQL support Hash indexes since very ancient versions of PostgreSQL, from what I can tell, they can be older than PostgreSQL 7.2 (February 2002), so what’s the “new” with this?</p><p>In older versions and even in the current PostgreSQL 9.6, Hash indexes have not received much love, in fact they have a big fat warning in the docs:</p><p>From PostgreSQL 7.2:</p><blockquote><strong>Note:</strong> Because of the limited utility of hash indexes, a B-tree index should generally be preferred over a hash index. We do not have sufficient evidence that hash indexes are actually faster than B-trees even for = comparisons. Moreover, hash indexes require coarser locks.</blockquote><p>From PostgreSQL 7.3:</p><blockquote><strong>Note:</strong> Testing has shown PostgreSQL’s hash indexes to be similar or slower than B-tree indexes, and the index size and build time for hash indexes is much worse. Hash indexes also suffer poor performance under high concurrency. For these reasons, hash index use is discouraged.</blockquote><p>From PostgreSQL 8.1 and the first sign of hope and a more alarming warning that are not WAL-logged (not crash-safe):</p><blockquote><strong>Note:</strong> Testing has shown PostgreSQL’s hash indexes to perform no better than B-tree indexes, and the index size and build time for hash indexes is much worse. Furthermore, hash index operations are not presently WAL-logged, so hash indexes may need to be rebuilt with REINDEX after a database crash. For these reasons, hash index use is presently discouraged.</blockquote><blockquote>While the problems with hash indexes may be fixed eventually…</blockquote><p>From PostgreSQL 9.0 this changed from a <strong>Note</strong> to a <strong>Caution</strong>, since they are not WAL-logged, they cannot be replicated, which means data loss in queries:</p><blockquote><strong>Caution</strong>: Hash index operations are not presently WAL-logged, so hash indexes might need to be rebuilt with REINDEX after a database crash if there were unwritten changes. Also, changes to hash indexes are not replicated over streaming or file-based replication after the initial base backup, so they give wrong answers to queries that subsequently use them. For these reasons, hash index use is presently discouraged.</blockquote><p>Well since PostgreSQL 10, there is no more warning!</p><p>But please note: if you are currently using Hash indexes, even with all this warning signs, you must rebuild hash indexes when you upgrade (pg_upgrade specifically) from any previous major PostgreSQL version. This is required since in PostgreSQL 10 major improvements necessitated this requirement.</p><p>Now in PostgreSQL 10 Hash indexes are WAL-logged, this means that are crash-safe and can be replicated.</p><p>The performance has been improved too, require less locks, and meta-information is cached for faster lookups.</p><p>Wait, wait, you may ask, what so special about hash index? They essentially works only for = (equals) comparison, and B-Tree indexes already do that and a lot more.</p><p>The primary and most important improvement against B-Tree indexes is SPACE, the structure used for a hash is flat compared to a tree, so the gain in space can be significant, and they do pretty fast lookups.</p><p>If your data is pretty singular, where you need fast = lookups with less space, then Hash indexes can provide a good alternative to B-Tree.</p><p>Let’s suppose that you have a system, and you want to integrate <a href="https://haveibeenpwned.com/Passwords">Troy Hunt password SHA1 hashes</a> to check that a user don’t use a pwned password, then you download the massive file of 306 million SHA1 pwned passwords list and import it to PostgreSQL (yes, you use PostgreSQL right?) then how do you query a record? you convert the user input into SHA1 and search the row in PostgreSQL massive table (or little table depending who are you speaking). You query this table with a =, for every change of password the user wish to do, if the password is pwned, you reject that password change and force the user to choose another one.</p><p><em>Please note: It’s 2017, you should not, I repeat, NOT store a plain SHA1 user password (and if you are still using MD5, you seriously have problems), it’s not secure, please use something stronger like bcrypt or </em><a href="https://en.wikipedia.org/wiki/PBKDF2"><em>PBKDF2</em></a><em>.</em></p><p>Here is where Hash indexes start to shine, a simple table with 2 columns a serial and a text column, and 319,894,674 records, the table size is 23 GB, the serial column is the primary key (no good reason, just added to it) and the size of the PK 6852 MB.</p><p>A query without index in the sha1 column, the execution time is 4 minutes (thanks to the parallel workers).</p><p>The size of the B-Tree index: 20 GB. The size of the Hash index: 8192 MB (8 GB) more than a half than B-Tree :-) and the execution time is roughly the same as b-tree.</p><p>Another advantage of smaller indexes are that they can fit best in memory and less reads of disk, “Buffers: shared hit=2” vs “Buffers: shared hit=6”.</p><p>Here basically ends my first post of new features of PostgreSQL 10, next I will write about the i<a href="https://medium.com/@jorsol/postgresql-10-features-parallel-queries-10a92c012d53">mprovements in Parallel queries</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=484f319db281" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>