Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id BA4016329CA for ; Fri, 8 Jan 2010 15:01:31 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 84704-05 for ; Fri, 8 Jan 2010 19:01:18 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-fx0-f227.google.com (mail-fx0-f227.google.com [209.85.220.227]) by mail.postgresql.org (Postfix) with ESMTP id C9D626325DE for ; Fri, 8 Jan 2010 15:01:20 -0400 (AST) Received: by fxm27 with SMTP id 27so4989296fxm.3 for ; Fri, 08 Jan 2010 11:01:19 -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=mtIyOxhaqePvOm6GALPCYjJekKBPE6g+27Nngu/wac0=; b=D7A078AoKqfAbysIbYAgZ3c2RhSteglBqeH9J96KVmP/ud/ga1Fow9Slwq5JI903Ag vuyC8UUth6m6lLwSLD8G6oqpPTcEtcl6mIIahiNO1t4NTyueSTefssiJ/EkD/zhrKdxG 2giwNkMk2uot7AmgofXhYjj8qjzdif25sqkII= 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=h+bgxF3yuejEW6l1UkLfn5zhHMwd9RUptmEY/6f6FaW+Y34manPXDbYyj58bjlToEo VsyjhXNh1xWfCnkVLKbQCXAkJ8otzq2EDAsvbcDqlOt3uEYLOXUaUT/ZGMuJ21krSM+z +IObqe3GArjUJgsj7KAxgzm271/x/kTWRzjTM= MIME-Version: 1.0 Received: by 10.239.179.91 with SMTP id c27mr968379hbg.51.1262977278985; Fri, 08 Jan 2010 11:01:18 -0800 (PST) In-Reply-To: <9969.1262975223@sss.pgh.pa.us> References: <4B47722A.4010502@digsys.bg> <9969.1262975223@sss.pgh.pa.us> Date: Fri, 8 Jan 2010 14:01:18 -0500 Message-ID: <603c8f071001081101t5c7b26fci407edd8523a7f4a@mail.gmail.com> Subject: Re: Change query join order From: Robert Haas To: Tom Lane Cc: Kaloyan Iliev Iliev , 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.458 tagged_above=-10 required=5 tests=AWL=0.141, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201001/153 X-Sequence-Number: 37033 On Fri, Jan 8, 2010 at 1:27 PM, Tom Lane wrote: > Kaloyan Iliev Iliev writes: >> My question is why the planner didn't do the index scan first on ms_data >> to reduce the rows to ~ 11000 and the use the PK index on >> ms_commands_history. > > 11000 index probes aren't exactly free. =A0If they take more than about > 1msec apiece, the planner picked the right plan. The OP could try setting enable_hashjoin to false (just for testing, never for production) and do EXPLAIN ANALYZE again. That might generate the desired plan, and we could see which one is actually faster. If the other plan does turn out to be faster (and I agree with Tom that there is no guarantee of that), then one thing to check is whether seq_page_cost and random_page_cost are set too high. If the data is all cached, the default values of 4 and 1 are three orders of magnitude too large, and they should also be set to equal rather than unequal values. ...Robert