Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 28CE96353D4 for ; Tue, 6 Apr 2010 15:58:02 -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 98198-06-4 for ; Tue, 6 Apr 2010 18:57:47 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-gx0-f214.google.com (mail-gx0-f214.google.com [209.85.217.214]) by mail.postgresql.org (Postfix) with ESMTP id 9E3B6634BEE for ; Tue, 6 Apr 2010 15:46:00 -0300 (ADT) Received: by gxk6 with SMTP id 6so90031gxk.14 for ; Tue, 06 Apr 2010 11:45:59 -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 :content-transfer-encoding; bh=G71UHYvG1Njdl8GpAUxFoJ7kBLEDqfsc27IDTIUVlMY=; b=gSb6VtSxVtnA43pV+ycj8YEI21vvlPMdRqn+wfkuPgY116oDWsjqnDSX2V9pEAPR3z nO52u2RqHOs0QkLUZ9Rrz5BAu2s8231SHXk9CKMhsYnCOcPAL+Eea37FvEGzub4EG4If qwYCfMqjmmGnyRhW6up1FRbBD6orBUTAT6jrI= 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=b/C1B/hjjkIJyFu+lab8ghKrZmiba243s8moiLGYoA152uKs01Mh0eliSB9ZJe4aKs evpSSNqrM62XExzhdOzth2E6nBpBGsj5pRiZxu5ydfZkK+am0PMPlATtRJX2mBDnDJXx MFhtSrffsmmBgVpYnl7tcPlHbimRoFYAz8AsU= MIME-Version: 1.0 Received: by 10.151.108.2 with HTTP; Tue, 6 Apr 2010 11:45:59 -0700 (PDT) In-Reply-To: <201003311746.38192.luvar@plaintext.sk> References: <201003311746.38192.luvar@plaintext.sk> Date: Tue, 6 Apr 2010 12:45:59 -0600 Received: by 10.151.86.1 with SMTP id o1mr4851433ybl.279.1270579559525; Tue, 06 Apr 2010 11:45:59 -0700 (PDT) Message-ID: Subject: Re: Some question From: Scott Marlowe To: luvar@plaintext.sk Cc: pgsql-performance@postgresql.org 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.519 tagged_above=-10 required=5 tests=AWL=-0.779, BAYES_20=-0.74 X-Spam-Level: X-Archive-Number: 201004/57 X-Sequence-Number: 38307 2010/3/31 =C4=BDubom=C3=ADr Varga : > Hi, stright to my "problem": > If I try to select constant 1 from table with two rows, it will be someth= ing > like this: > > explain > SELECT * FROM t_route > =C2=A0 =C2=A0 =C2=A0 =C2=A0WHERE t_route.route_type_fk =3D (SELECT id FRO= M t_route_type WHERE type =3D 2) > =C2=A0 =C2=A0 =C2=A0 =C2=A0limit 4; > > "Limit =C2=A0(cost=3D1.02..1.91 rows=3D4 width=3D2640)" > " =C2=A0InitPlan" > " =C2=A0 =C2=A0-> =C2=A0Seq Scan on t_route_type =C2=A0(cost=3D0.00..1.02= rows=3D1 width=3D8)" > " =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Filter: ("type" =3D 2)" > " =C2=A0-> =C2=A0Seq Scan on t_route =C2=A0(cost=3D0.00..118115.25 rows= =3D535090 width=3D2640)" > " =C2=A0 =C2=A0 =C2=A0 =C2=A0Filter: (route_type_fk =3D $0)" > Looking at this it looks like you're using prepared queries, which can't make as good of a decision as regular queries because the values are opaque to the planner. Can you provide us with the output of explain analyze of that query?