Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UfZcB-0004pH-Im for pgsql-performance@arkaria.postgresql.org; Thu, 23 May 2013 17:47:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UfZcB-0007Jo-1x for pgsql-performance@arkaria.postgresql.org; Thu, 23 May 2013 17:47:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UfZc9-0007IK-9C for pgsql-performance@postgresql.org; Thu, 23 May 2013 17:47:45 +0000 Received: from cerberus.pinpointresearch.com ([66.7.238.130] helo=polaris.pinpointresearch.com) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UfZbz-0004Cd-BE for pgsql-performance@postgresql.org; Thu, 23 May 2013 17:47:44 +0000 Received: from [192.168.1.179] (betelgeuse.pinpointresearch.com [192.168.1.179]) by polaris.pinpointresearch.com (Postfix) with ESMTP id 72AA7E00EC82; Thu, 23 May 2013 10:47:34 -0700 (PDT) Message-ID: <519E563A.4010401@pinpointresearch.com> Date: Thu, 23 May 2013 10:47:38 -0700 From: Steve Crawford User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: Jonathan Morra CC: pgsql-performance@postgresql.org Subject: Re: Performance of complicated query References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -3.0 (---) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 05/23/2013 10:19 AM, Jonathan Morra wrote: > I am fairly new to squeezing performance out of Postgres, but I hope > this mailing list can help me. I have read the instructions found at > http://wiki.postgresql.org/wiki/Slow_Query_Questions and have tried to > abide by them the best that I can. I am running "PostgreSQL 9.1.7, > compiled by Visual C++ build 1500, 64-bit" on an x64 Windows 7 > Professional Service Pack 1 machine with 8 GB of RAM. I'm not sure under what constraints you are operating but you will find most people on the list will recommend running live systems on Linux/Unix for a variety of reasons. > CREATE TABLE reads > ... > ALTER TABLE reads > OWNER TO postgres; To avoid future grief you should set up a user (see CREATE ROLE...) for your database that is not the cluster superuser (postgres). I assume you set up a database (see CREATE DATABASE...) for your app. The base databases (postgres, template*) should be used for administrative purposes only. > > ... > Ultimately what I want to do is to find a sum of values for each > patient. The scenario is that each patient is assigned a device and > they get incremental values on their device. Since these values are > incremental if a patient never switches devices, the reported value > should be the last value for a patient. However, if a patient > switches devices then the reported value should be the sum of the last > value for each device that the patient was assigned. I'm afraid I'm a bit confused about what you are after due to switching between "sum" and "last". It sounds like a patient is issued a device which takes a number of readings. Do you want the sum of those readings for a given patient across all devices they have been issued, the sum of readings for a specific device, the most recent reading for a specific patient regardless of which device was in use for that reading, or the sum of the most recent readings on each device issued to a specific patient? Are you looking to generate a report across all patients/devices or lookup information on a specific patient or device? Cheers, Steve -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance