X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 724BA5391D for ; Tue, 26 Apr 2005 18:02:15 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 16132-09 for ; Tue, 26 Apr 2005 21:02:11 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.204]) by svr1.postgresql.org (Postfix) with ESMTP id 1BD985346C for ; Tue, 26 Apr 2005 18:02:10 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id 68so80057wri for ; Tue, 26 Apr 2005 14:02:12 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=uVAfJHNiXSjosT7VE2vfbrHF8sc8k7PetpdJwGMwN0XuAId34LA1z1A75kzE2LVh3PobA1RshxaNLfTYsmHe7yigkDPR8gx1WH4vOM2YsqPHOvyENnA7VwL4P2sDBhx9yTFdIt6yUQsvxgodvkAm4BmJMo5pYSKlpJRMojp2C0g= Received: by 10.54.79.8 with SMTP id c8mr109573wrb; Tue, 26 Apr 2005 14:02:12 -0700 (PDT) Received: by 10.54.22.6 with HTTP; Tue, 26 Apr 2005 14:02:12 -0700 (PDT) Message-ID: Date: Tue, 26 Apr 2005 16:02:12 -0500 From: Matthew Nuzum Reply-To: newz@bearfruit.org To: pgsql-performance@postgresql.org Subject: Re: speed up query with max() and odd estimates In-Reply-To: <20050426204853.GA29424@uio.no> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <20050426204853.GA29424@uio.no> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.323 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200504/707 X-Sequence-Number: 12104 On 4/26/05, Steinar H. Gunderson wrote: > On Tue, Apr 26, 2005 at 03:16:57PM -0500, Matthew Nuzum wrote: > > Seq Scan on usage_access (cost=3D0.00..1183396.40 rows=3D12713851 > > width=3D116) (actual time=3D481796.22..481839.43 rows=3D3343 loops=3D1) >=20 > That's a gross misestimation -- four orders of magnitude off! >=20 > Have you considering doing this in two steps, first getting out whatever > comes from the subquery and then doing the query? Have you ANALYZEd recen= tly? > Do you have an index on atime? >=20 Yes, there is an index on atime. I'll re-analyze but I'm pretty certain that runs nightly. Regarding two steps, are you suggesting: begin; select * into temp_table...; select * from temp_table...; drop temp_table; rollback; I have not tried that but will. BTW, I created an index on clients just for the heck of it and there was no improvement. (actually, a slight degradation) --=20 Matthew Nuzum www.bearfruit.org