Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id EAB53632D07 for ; Sat, 6 Feb 2010 07:46:32 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 67377-04 for ; Sat, 6 Feb 2010 11:46:22 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f220.google.com (mail-fx0-f220.google.com [209.85.220.220]) by mail.postgresql.org (Postfix) with ESMTP id 42DE7632C8A for ; Sat, 6 Feb 2010 07:46:22 -0400 (AST) Received: by fxm20 with SMTP id 20so14040fxm.21 for ; Sat, 06 Feb 2010 03:46:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=Bbn7o42VfYSl2mjaA6r2/zLwVbXbua+BfVuGyEiBnCU=; b=uETmMmwIaZs6mrhl9JyHH7WsZ36vJsdPsQJ81PyJHdsVosRbmKjcfkm5x7OBmN2i48 Y0i+MXERTf5EXKUVGXcev8b0TJzN1wiLY9CYUfoy01Bbs/CwiWWc2fwBjrEcOibtavMe K/xT2VG30ueFxiFyZ8cusLedPAEInIA4JZeig= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=dmih8Zs90GVNxEUeqIvuktDxY0+YmcLxRmVUtxtZa0QPt+yLUMsSNhtYrPCseU/7Hn FxW6Tfr9AlB/22N45SxEPNhjim7noF/+DfR8uB9gQ0A8YzqB3TKJNd60DpU0vA5BZpPS x7CdlOHWrmZMYcmu2K5pyRtIyqfeNxcon+KPo= MIME-Version: 1.0 Received: by 10.239.193.4 with SMTP id g4mr264218hbi.192.1265437861070; Fri, 05 Feb 2010 22:31:01 -0800 (PST) In-Reply-To: References: <603c8f071002031905w51dbea37y148284ea6546feda@mail.gmail.com> <2f4958ff1002040028j29e907c6l47e1f5efe83b667d@mail.gmail.com> <4B6BFE33.5080809@gmail.com> Date: Sat, 6 Feb 2010 01:31:01 -0500 Message-ID: <603c8f071002052231r4f456b6fx76f9497c4f8b8fd9@mail.gmail.com> Subject: Re: Slow query: table iteration (8.3) From: Robert Haas To: Glenn Maynard Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.555 tagged_above=-10 required=5 tests=BAYES_00=-2.599, DATE_IN_PAST_03_06=0.044 X-Spam-Level: X-Archive-Number: 201002/106 X-Sequence-Number: 37527 On Fri, Feb 5, 2010 at 8:35 PM, Glenn Maynard wrote: > On Fri, Feb 5, 2010 at 6:17 AM, Yeb Havinga wrote: >> and the cache is used between each row of test_users. The plan is with a >> parameter, that means the optimizer could not make use of an actual valu= e >> during planning. However, your test case is clever in the sense that the= re >> is an index on users and score and the sql function has an order by that >> matches the index, so the planner can avoid a sort by accessing the test >> table using the index. > > That's why the index exists. =A0The point is that the window function > doesn't use the index in this way, and (I think) does a complete index > scan. > > It's not just about avoiding a sort, but avoiding touching all of the > irrelevant data in the index and just index searching for each > user_id. =A0The window function appears to scan the entire index. =A0In > principle, it could skip all of the "rank() > 1" data with an index > search, which I'd expect to help many uses of rank(); I assume that's > just hard to implement. Yeah. The window function stuff is all pretty new, and I seem to recall some discussion around the fact that it's not all as well-optimized as it could be yet. Maybe someone will feel the urge to take a whack at that for 9.1. ...Robert