<?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 stingh711 on Medium]]></title>
        <description><![CDATA[Stories by stingh711 on Medium]]></description>
        <link>https://medium.com/@stingh711?source=rss-e8c0870140d4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*UICvnsDE-1LxX-eA.jpg</url>
            <title>Stories by stingh711 on Medium</title>
            <link>https://medium.com/@stingh711?source=rss-e8c0870140d4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 19:21:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stingh711/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 is great]]></title>
            <link>https://medium.com/@stingh711/postgresql-is-great-bccd36d7757b?source=rss-e8c0870140d4------2</link>
            <guid isPermaLink="false">https://medium.com/p/bccd36d7757b</guid>
            <dc:creator><![CDATA[stingh711]]></dc:creator>
            <pubDate>Thu, 18 Sep 2014 08:28:16 GMT</pubDate>
            <atom:updated>2014-09-18T08:28:16.619Z</atom:updated>
            <content:encoded><![CDATA[<p>Target: study postgresql’s feature and how to use them effective on PDMS’ dynamic form’s save and search.</p><p>Table schema is as following:</p><p>id | integer | not null default nextval(‘data_id_seq’::regclass) | plain | | patient_id | integer | | plain | | item_id | integer | | plain | | data_type | integer | | plain | | value | character varying |</p><p>Column value is used to save the value of dynamic form which has 5 types. They are string, integer, float, date and options. I use varchar here and want to convert it to the actual data type when doing query.</p><p>I added other three partial indexes base on different data types. Thanks to postgresql’s partial index.</p><p>“data_value_dict_index” btree ((value::integer)) WHERE data_type = 3 “data_value_integer_index” btree ((value::integer)) WHERE data_type = 2 “data_value_text_index” btree (value) WHERE data_type = 1</p><p>Then I inserted about 10000000 records into the table and run following SQL.</p><p>select distinct patient_id from data where data_type = 2 and item_id = 2 and value::int &gt; 500 limit 20; =&gt; 2.2s</p><p>(select distinct patient_id from data where data_type = 2 and item_id = 2 and value::int &gt; 700) intersect (select patient_id from data where data_type = 1 and item_id = 9 and value = ‘99&#39;); =&gt; 2.0s</p><p>The result is not bad. More importantly, postgresql has intersect which is very useful for PDMS. Its partial index is also great. Although I save value as string and convert it to other type in query, the indexes still work.</p><p>Then I adjusted the indexed by adding item_id column, the result turned out to be amazing.</p><p>select distinct patient_id from data where data_type = 2 and item_id = 2 and value::int &gt; 500 limit 20 =&gt; 118.640 ms</p><p>(select distinct patient_id from data where data_type = 2 and item_id = 2 and value::int &gt; 700) intersect (select patient_id from data where data_type = 1 and item_id = 9 and value = ‘99&#39;) =&gt; 143 ms</p><p>The indexes is now: “data_value_dict_index” btree (item_id, (value::integer)) WHERE data_type = 3 “data_value_integer_index” btree (item_id, (value::integer)) WHERE data_type = 2 “data_value_text_index” btree (item_id, value) WHERE data_type = 1</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bccd36d7757b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>