Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TIwFn-00060J-Ny for pgsql-sql@postgresql.org; Tue, 02 Oct 2012 06:46:51 +0000 Received: from plane.gmane.org ([80.91.229.3]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TIwFl-0005AO-Iw for pgsql-sql@postgresql.org; Tue, 02 Oct 2012 06:46:51 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1TIwFX-0002WK-2O for pgsql-sql@postgresql.org; Tue, 02 Oct 2012 08:46:35 +0200 Received: from 217.110.94.121 ([217.110.94.121]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 02 Oct 2012 08:46:35 +0200 Received: from spam_eater by 217.110.94.121 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 02 Oct 2012 08:46:35 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Thomas Kellerer Subject: Re: [noob] How to optimize this double pivot query? Date: Tue, 02 Oct 2012 08:46:11 +0200 Lines: 24 Message-ID: References: <001201cda03a$49a686d0$dcf39470$@yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 217.110.94.121 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.23) Gecko/20090812 Thunderbird/2.0.0.23 Mnenhy/0.7.6.666 In-Reply-To: X-Pg-Spam-Score: -2.9 (--) X-Archive-Number: 201210/8 X-Sequence-Number: 36879 Robert Buck, 02.10.2012 03:13: > So as you can probably glean, the tables store performance metric > data. The reason I chose to use k-v is simply to avoid having to > create an additional column every time a new metric type come along. > So those were the two options I thought of, straight k-v and column > for every value type. > > Are there other better options worth considering that you could point > me towards that supports storing metrics viz. with an unbounded > number of metric types in my case? > Have a look at the hstore module. It's exactly meant for that scenario with the added benefit that you can index on that column and looking up key names and their values is blazingly fast then. That combined with the tablefunc module (which let's you do pivot queries) might make your queries substantially more readable (and maybe faster as well). Regards Thomas