Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 77564B5DBC2 for ; Thu, 3 Nov 2011 11:28:40 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 75017-05 for ; Thu, 3 Nov 2011 14:28:33 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from smtp.peak6.com (smtp.peak6.com [38.98.137.6]) by mail.postgresql.org (Postfix) with ESMTP id ED127B5DBCA for ; Thu, 3 Nov 2011 11:28:32 -0300 (ADT) X-AuditID: 0a64cb1e-b7c21ae0000074d4-da-4eb2a50b4981 Message-ID: <4EB2A50F.8080009@peak6.com> Date: Thu, 3 Nov 2011 09:28:31 -0500 From: Shaun Thomas Reply-To: Organization: Peak6 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: Scott Marlowe CC: CS DBA , "pgsql-performance@postgresql.org" Subject: Re: Poor performance on a simple join References: <4EB1A63E.80101@consistentstate.com> <4EB1BBD8.3040307@consistentstate.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed content-transfer-encoding: 7bit X-Originating-IP: [10.10.220.61] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrDIsWRmVeSWpSXmKPExsXCxcQrpsu9dJOfwZ4P2haLFu1htrg+8xyz xbJP5xkdmD3+3HjJ7rFz1l12jwv7prEHMEc1MNok5uXllySWpCqkpBYn2yoFuDp6mykElyTm pSQWpSi4ZBYn5yRm5qYWKSlkptgqGSkpFOQkJqfmpuaV2ColFhSk5qUo2XEpYAAboLLMPIXU vOT8lMy8dFslz2B/XQsLU0tdQyW7eARI6GbJ2PBgH1vBK8GK12+nMjUwLuPrYuTgkBAwkdi/ 07aLkRPIFJO4cG89G0iYV0BDYua3FJAwi4CKxNyXO9hAbDYBNYmFu28ygthCArIS+1edYwWx +QWEJfZ9aGIGsUUFQiSeTXgOVs8rIChxcuYTFhBbREBb4tGb62C9zAIFEhfaethBVgkLWEjs /xfRxcgFNPIho8SavsNgMzkFAiUevZrNDFFvK3FhznUWCFteYvvbOcwQN8hJ3Gl4zgbxiYLE 9eX+ExiFZiHZPAtJ9ywk3QsYmVcxiheXJSZnZJoWFOeWFBjqFaQmZpvp5aWWbGIExXHKabkd jNOXKh5iFOBgVOLhFSrf6CfEmlhWXJl7iFGCg1lJhHf94k1+QrwpiZVVqUX58UWlOanFhxi1 gUE2kVmKOzkfmGLySuKNDQyUxHmnTl3nJySQDkwB2ampBalFMNVMHJxSDYyii866XXKJvdwT r/Tr5Ly3U4Qqueuv5+X+ZfS37q5dP6Gp7kQ1X1/y0srvjiIznR6uWcgcE/1YOCFbWFul4d3a nEQh9T8FXEUO166kec/sSz747+/ipIluXrq7ilWnd5Xx3kqOiN9gePjY3y1bbjIKdR04dGmr qolGa9Tid+7z9dcnOd0q/a7EUpyRaKjFXFScCACxWTOp7wIAAA== X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-3.101 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-1.201 X-Spam-Level: X-Archive-Number: 201111/42 X-Sequence-Number: 45553 On 11/02/2011 09:04 PM, Scott Marlowe wrote: > Take a look here: > http://tech.jonathangardner.net/wiki/PostgreSQL/Materialized_Views Not sure materialized views are the approach I would take here. We actually see a lot of these kinds of queries with giant result sets, here. If they actually need all 12k rows for every execution (not likely, but possible) and 300ms is just too darn slow for that, there's always client-side caching. We have a couple queries that we need to keep cached at all times. Stock quotes and positions, for example, have to be available in sub-ms time thanks to the level of parallelism involved. One query in particular effectively grabs the entire set of current positions and every optimization in the book brings its execution time down to about two seconds. We can't have thousands of clients executing that all the time, so it gets shoved into a local memcached on each webserver. But if he's getting back 12k rows even *after* specifying a contact ID, a materialized view is still going to return 12k rows, and still has to perform at least an index scan unless he creates an MV for each contact ID (eww). This doesn't really look like fact-table territory either. I think the real question is: Why isn't 300ms fast enough? Is it because the client executes this repeatedly? If so, what changes often enough it must fetch all 12k rows every single time? Would implementing a timestamp and only grabbing newer rows work better? Is it because of several connections each running it in parallel? Why not cache a local copy and refresh periodically? Do they actually need all 12k rows every time? maybe some limit and offset clauses are in order. There's very little a human can do with 12k results. An automated tool shouldn't be grabbing them either, unless they're actually changing with every execution. If they're not, the tool really wants items since the last change, or it's doing too much work. If it were a report, 300ms is nothing compared to most reporting queries which can run for several minutes. I think we're missing a lot of details here. -- Shaun Thomas OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604 312-676-8870 sthomas@peak6.com ______________________________________________ See http://www.peak6.com/email-disclaimer/ for terms and conditions related to this email