Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 27CFC14D4831 for ; Fri, 13 Jan 2012 15:22:11 -0400 (AST) Received: from smtp.01.com ([199.36.142.181]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RlmUM-0007EY-En for pgsql-performance@postgresql.org; Fri, 13 Jan 2012 19:08:36 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id ECC433F479F for ; Fri, 13 Jan 2012 13:08:20 -0600 (CST) X-Virus-Scanned: amavisd-new at smtp-out-1.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-1.01.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id H2EKI-PXvVP9 for ; Fri, 13 Jan 2012 13:08:20 -0600 (CST) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp-out-1.01.com (Postfix) with ESMTP id CC1F93F495B for ; Fri, 13 Jan 2012 13:08:20 -0600 (CST) Received: from Sidney-Stratton.local (70-36-197-35.dsl.dynamic.sonic.net [70.36.197.35]) by smtp-out-1.01.com (Postfix) with ESMTPSA id 6D4583F479F for ; Fri, 13 Jan 2012 13:08:19 -0600 (CST) Message-ID: <4F108122.3040400@agliodbs.com> Date: Fri, 13 Jan 2012 11:08:18 -0800 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.24) Gecko/20111103 Lightning/1.0b2 Thunderbird/3.1.16 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Discovering the most searched values for a field References: <4F10733B.3000704@gmail.com> In-Reply-To: <4F10733B.3000704@gmail.com> X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201201/46 X-Sequence-Number: 46059 On 1/13/12 10:08 AM, alexandre - aldeia digital wrote: > Hi, > > Is there a simple way (or a tool) to discover the most searched values > in a field from a table ? > > In the pg_stats, I can see the most common values generated by ANALYZE, > but I want to know how many queries are using this values. With this > information and the other statistics, I want to create partial indexes > or use table partitioning to create some benchmarks to speed up the > database access. No simple + fast way. The way to do this is: 1) log all queries 2) load query log into a database 3) filter to queries which only run against that table 4) analyze queries for values against that column. For (4), we've had the best luck with generating explain plans in XML and then digesting the XML to look for filter conditions. Finding column matches by regex was a lot less successful. -- Josh Berkus PostgreSQL Experts Inc. http://pgexperts.com