Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 97E65B5DC1A for ; Tue, 27 Sep 2011 12:00:15 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 29473-01 for ; Tue, 27 Sep 2011 15:00:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail-wy0-f174.google.com (mail-wy0-f174.google.com [74.125.82.174]) by mail.postgresql.org (Postfix) with ESMTP id A7AE8B5DBE3 for ; Tue, 27 Sep 2011 12:00:08 -0300 (ADT) Received: by wyg34 with SMTP id 34so7291413wyg.19 for ; Tue, 27 Sep 2011 08:00:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:in-reply-to:references:x-mailer :mime-version:content-type:content-transfer-encoding; bh=JXjH2GV2ptMikR6gUhoIOfZu3if8xc42ds35Gp95iPE=; b=EA55o5S1mNG/F0ZkqmU5jLj+HamzTdCbBXkuLJduYPlRS/zLSAA0CQdMlloFmPhwns onVqjygoSXi8ZgjQY2HesM7iIuRkSkh92SUGNnK9nfCcSuTgfLRV9LRLHtiyDuNtDUD1 Sw287cg4l46JgTIJxcmeUT+OeG2m4xvklE1j0= Received: by 10.227.204.14 with SMTP id fk14mr7065764wbb.88.1317135607610; Tue, 27 Sep 2011 08:00:07 -0700 (PDT) Received: from marco-dalibo (gev44-1-78-228-108-65.fbx.proxad.net. [78.228.108.65]) by mx.google.com with ESMTPS id o7sm36132545wbh.8.2011.09.27.08.00.05 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 27 Sep 2011 08:00:06 -0700 (PDT) Date: Tue, 27 Sep 2011 17:00:04 +0200 From: Marc Cousin To: pgsql-performance@postgresql.org Subject: Re: overzealous sorting? Message-ID: <20110927170004.784d7814@marco-dalibo> In-Reply-To: <201109271905.09573.anthony.shipman@symstream.com> References: <201109261628.15363.anthony.shipman@symstream.com> <201109271245.00979.anthony.shipman@symstream.com> <20110927105435.26d4e9c6@marco-dalibo> <201109271905.09573.anthony.shipman@symstream.com> X-Mailer: Claws Mail 3.7.10 (GTK+ 2.24.6; x86_64-unknown-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.889 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, T_TO_NO_BRKTS_FREEMAIL=0.01 X-Spam-Level: X-Archive-Number: 201109/396 X-Sequence-Number: 45172 Le Tue, 27 Sep 2011 19:05:09 +1000, anthony.shipman@symstream.com a =C3=A9crit : > On Tuesday 27 September 2011 18:54, Marc Cousin wrote: > > The thing is, the optimizer doesn't know if your data will be in > > cache when you will run your query=E2=80=A6 if you are sure most of your > > data is in the cache most of the time, you could try to tune > > random_page_cost (lower it) to reflect that data is cached. But if > > the win is small on this query, it may not be worth it. >=20 > What I really want is to just read a sequence of records in timestamp > order between two timestamps. The number of records to be read may be > in the millions totalling more than 1GB of data so I'm trying to read > them a slice at a time but I can't get PG to do just this. >=20 > If I use offset and limit to grab a slice of the records from a large=20 > timestamp range then PG will grab all of the records in the range, > sort them on disk and return just the slice I want. This is absurdly > slow.=20 >=20 > The query that I've shown is one of a sequence of queries with the > timestamp range progressing in steps of 1 hour through the timestamp > range. All I want PG to do is find the range in the index, find the > matching records in the table and return them. All of the planner's > cleverness just seems to get in the way. >=20 Maybe you should try using a cursor, if you don't know where you'll stop. This associated with a very low cursor_tuple_fraction will probably give you what you want (a fast start plan).