Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dsSrl-0000Hi-8f for pgsql-performance@arkaria.postgresql.org; Thu, 14 Sep 2017 12:03:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dsSrk-0006B2-Se for pgsql-performance@arkaria.postgresql.org; Thu, 14 Sep 2017 12:03:32 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dsSrj-00069p-MU for pgsql-performance@postgresql.org; Thu, 14 Sep 2017 12:03:31 +0000 Received: from lb3-smtp-cloud7.xs4all.net ([194.109.24.31]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dsSrd-0006CT-41 for pgsql-performance@postgresql.org; Thu, 14 Sep 2017 12:03:30 +0000 Received: from webmail.xs4all.nl ([IPv6:2001:888:0:22:194:109:20:207]) by smtp-cloud7.xs4all.net with ESMTPA id sSrYdj0x9b2snsSrYdKlGP; Thu, 14 Sep 2017 14:03:21 +0200 Received: from mail.genj.nl ([77.242.116.162]) by webmail.xs4all.nl with HTTP (HTTP/1.1 POST); Thu, 14 Sep 2017 14:03:20 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Thu, 14 Sep 2017 14:03:20 +0200 From: vinny To: Subramaniam C Cc: pgsql-performance@postgresql.org Subject: Re: Store/Retrieve time series data from PostgreSQL In-Reply-To: References: Message-ID: <1eb896cf2a6bdc3fd7e1567c86ecafe9@xs4all.nl> X-Sender: vinny@xs4all.nl User-Agent: XS4ALL Webmail X-CMAE-Envelope: MS4wfPJ/EwmsH9HtVuzBlkMt9XEM928glAKEmc68Q7PtATwPqpJiWCwn2aTj0IxdMRT4GktZRel2cHHLeZ95rZqMIEqMRYX6Lek+lniUjD0LEOzxxibOBpd9 8QgHR+Y78DkwSjvUtcrtA4Ewox/vYK/4ixl3VvSdqwJYpkp0xutehtVLJbp/+PFOFeCdx2X9KDwV9MN5ZmvtR6Bak+GLeGQbpJ3mNuoAIKxdfEioKG8rJaEn uiAAQlgmb9EYbcW9GPo8SY/JgZG2iOJY8vfrJlsmYR4= 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 2017-09-14 13:51, Subramaniam C wrote: > Hi > > QUERY :- > > _select distinct on (health_timeseries.mobid) mobid, > health_timeseries.health, health_timeseries.hour from > health_timeseries where hour >=(1505211054000/(3600*1000))-1 and hour > <= 1505211054000/(3600*1000) ORDER BY health_timeseries.mobid DESC, > health_timeseries.hour DESC;_ > Did you run EXPLAIN on this query to see what it is actually doing? What you are doing how is selecting all rows from the last hour, sorting them by mobid and hour, and then DISTINCT filters out al duplicates. Sorting on mobid is therefor useless, DISTINCT still has to check all rows. Sorting on mobid and hour will take a long time if there is no index for it, so if you don't have an index on the mobid and hour together then you should probably try that. But, see what EXPLAIN tells you first. Regards, Vincent. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance