Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id EC720633E4D for ; Mon, 29 Mar 2010 16:56:25 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 42678-05-3 for ; Mon, 29 Mar 2010 19:56:02 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f225.google.com (mail-fx0-f225.google.com [209.85.220.225]) by mail.postgresql.org (Postfix) with ESMTP id 80CC7633BFF for ; Mon, 29 Mar 2010 16:55:48 -0300 (ADT) Received: by fxm25 with SMTP id 25so164736fxm.3 for ; Mon, 29 Mar 2010 12:55:47 -0700 (PDT) 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:received:message-id:subject:from:to:cc:content-type; bh=Rgh6/2nkXgcR7GCJlHhUh0anrq645ew8rs0dUepdEMo=; b=OR9p9yFFWjHCuijuFjrSwtabdrtmQBu9nkDwDztpg2+zjg2kgeRhIeDR3oNQCFX2XE vGNun8A18JD+1RbIR9ovraXiF4WimcUka8dCbUjvIWK5vzf8oDQ+rPJZ+QHaRTEVaboV sEtU9oi+RbnH0swHcS3KR0m3pVWeSWBpjMWbo= 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; b=lwqoMLmGb4H+UTuXY7kf/qVqxR4s0gmrvY8re/egwUVOZTS4pZjaBYhgp95rbvVBYI 0XB8h7PtvFkdOUJxcB3gzcrUmcBc6e71/+Od39AhIgdHAqrB/lsWk/yoIiEHviqBKIIK MVF1Q88DmdUVzHQ2YXzlSTqqRLPHYyAQiYWqI= MIME-Version: 1.0 Received: by 10.239.161.83 with HTTP; Mon, 29 Mar 2010 12:55:46 -0700 (PDT) In-Reply-To: References: <603c8f071003291102g778afc2fvda0fc281454526c9@mail.gmail.com> Date: Mon, 29 Mar 2010 15:55:46 -0400 Received: by 10.239.188.6 with SMTP id n6mr528505hbh.133.1269892546968; Mon, 29 Mar 2010 12:55:46 -0700 (PDT) Message-ID: <603c8f071003291255x151746dif0e33d18124c8bd2@mail.gmail.com> Subject: Re: experiments in query optimization From: Robert Haas To: Faheem Mitha Cc: pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.482 tagged_above=-10 required=5 tests=AWL=0.117, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201003/378 X-Sequence-Number: 38203 On Mon, Mar 29, 2010 at 2:31 PM, Faheem Mitha wrote: >> It's not really too clear to me from reading this what specific >> questions you're trying to answer. > > Quote from opt.{tex/pdf}, Section 1: > > "If I have to I can use Section~\ref{ped_hybrid} and > Section~\ref{tped_hybrid}, but I am left wondering why I get the performance > I do out of the earlier versions. Specifically, why is > Section~\ref{ped_bigjoin} so much slower than Section~\ref{ped_trunc}, and > why does the memory usage in Section~\ref{ped_phenoout} blow up relative to > Section~\ref{ped_bigjoin} and Section~\ref{ped_trunc}?" Here and in the document, you refer to section numbers for the "hybrid" version but I don't see where you define what the "hybrid" version actually is. And the differences between your queries are not real clear either - first you say you took out pheno and sex because they weren't necessary, but then you decide to put them back. I don't know what that means. If they're not necessary, leave them out. >> One random thought: WHERE row_number() = 1 is not too efficient. >> Try using LIMIT or DISTINCT ON instead. > > Possibly. However, the CTE that uses > > WHERE row_number() = 1 > > doesn't dominate the runtime or memory usage, so I'm not too concerned > about it. Hmm, you might be right. >> If you're concerned about memory usage, try reducing work_mem; you've >> probably got it set to something huge. > > work_mem = 1 GB (see diag.{tex/pdf}). > > The point isn't that I'm using so much memory. Again, my question is, why > are these changes affecting memory usage so drastically? Well each sort or hash can use an amount of memory that is limited from above by work_mem. So if you write the query in a way that involves more sorts or hashes, each one can add up to 1GB to your memory usage, plus overhead. However, it doesn't look like any of your queries including 30 sorts or hashes, so I'm thinking that the RSS number probably also includes some of the shared memory that has been mapped into each backend's address space. RSS is not a terribly reliable number when dealing with shared memory; it's hard to say what that really means. >> You might need to create some indices, too. > > Ok. To what purpose? This query picks up everything from the tables and the > planner does table scans, so conventional wisdom and indeed my experience, > says that indexes are not going to be so useful. Well, a hash join is not usually the first thing that pops to mind when dealing with a table that has 825 million rows (geno). I don't know if a nested loop with inner-indexscan would be faster, but it would almost certainly use less memory. ...Robert