Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 0A7D516FA505 for ; Mon, 9 Jul 2012 20:50:48 -0300 (ADT) Received: from mail-pb0-f46.google.com ([209.85.160.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SoNj5-0002hu-B3 for pgsql-performance@postgresql.org; Mon, 09 Jul 2012 23:50:47 +0000 Received: by pbbrp8 with SMTP id rp8so19996416pbb.19 for ; Mon, 09 Jul 2012 16:50:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding :x-gm-message-state; bh=o4Bnkeh3L02N/TSFHN+tSVM9FMETULWb4/HOafZtysk=; b=lfTXNsnNavn7DtJA6rt/gIeOghHGNFAWjOcj0mr3uscmN6BapPyqUcN+weMRETkwIv Uz4DNghRu98Z2lEQae06dixFPK8UDWKD7pV/Laj9Wpe3BAJ4kF8sR6N4L9JvDAiHzPyF yIT8dbK4XkXL8HTOWuXai49OyAMXE6KuhZ79HN10rjsvAICvLKyDheanZG98XGblv5QH Lol2pekdzEc/jVlltCtLWx9w3aa4UwnO+eimsnEtJmbuNNuYm8E1hKrFi66hNC1yKsUZ vSHQ9uwYFcVPQ8yUxjn1oAM6NmIFQQ5bOi7P71XP+VTZgmOybkd0YaT/TffulgbPoyxl z/1A== Received: by 10.66.72.163 with SMTP id e3mr47904550pav.42.1341877834414; Mon, 09 Jul 2012 16:50:34 -0700 (PDT) Received: from ayaki.localdomain (124-169-169-118.dyn.iinet.net.au. [124.169.169.118]) by mx.google.com with ESMTPS id rg9sm28600501pbc.67.2012.07.09.16.50.31 (version=SSLv3 cipher=OTHER); Mon, 09 Jul 2012 16:50:33 -0700 (PDT) Message-ID: <4FFB6E45.50708@ringerc.id.au> Date: Tue, 10 Jul 2012 07:50:29 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0 MIME-Version: 1.0 To: Misa Simic CC: Andrew Dunstan , "pgsql-performance@postgresql.org" Subject: Re: Paged Query References: <-6943177787207849568@unknownmsgid> In-Reply-To: <-6943177787207849568@unknownmsgid> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQn7nHEZXBxztWHgnyg/1clcdiZEm2ziPL8H6/IB4oubX+VJljopAqphtYlAKi8zF3UpTAnX X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/102 X-Sequence-Number: 47283 On 07/10/2012 06:24 AM, Misa Simic wrote: > Hi Andrew, > > Sure... We are sending data in Json to clients > > { > total:6784, > data:[50 rows for desired page] > } > > SELECT count(*) FROM table - without where, without joins used to have > bad performance... However, in real scenario we have never had the case > without joins and where... Join columns are always indexed, and we > always try to put indexes on columns what will mostly be used in where > in usual queries... When/if you do need a count of a single table without any filters, a common trick is to use table statistics to return an approximation. If your autovaccum is running regularly it's usually a very good approximation, too. Sounds like this hack may become unnecessary in 9.2 though. -- Craig Ringer