Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 887A963619C for ; Wed, 25 Mar 2009 00:47:23 -0300 (ADT) 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 14399-02 for ; Wed, 25 Mar 2009 00:47:19 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.245]) by mail.postgresql.org (Postfix) with ESMTP id 6EEAB635A92 for ; Wed, 25 Mar 2009 00:47:01 -0300 (ADT) Received: by an-out-0708.google.com with SMTP id c5so1877733anc.28 for ; Tue, 24 Mar 2009 20:47:00 -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:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=NXK3PfUDW6DNURh27DKRTPlYGd9CJnQ4jr3SkwQLDks=; b=uv09B9b2efBcBcE1lTNU29B/V3sULRi5qOBUp5PuY1UJ+v3qW6w2ZIoq3Yw+1tUzgg q7JfgZGOdIp05lnH+APBQ5Mm3IbrKcMZ91kNrvPuJZPptNiDM+Rb6c1XQ+ZJ4i3m+9/i Y4zwmRX94lDo+9fURR6q4VVD+XZxcdXuR1xBc= 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=pBM+7stR+xyvO+WaxHamYS17GEJpAMmglPyUMWOklWCEZwV2/CvML+vPQgYD3QzOoW XAhL4wPcz2P5zjLDFXxhlhE+McIM4TYN6US58jwuWZrynW/pzRri1zZ5DuyvMyOCwo7F mzoO5WGuRQAWx74Nhs8N4lwFXx4zY/hzXb4Q4= MIME-Version: 1.0 Received: by 10.100.131.16 with SMTP id e16mr8399670and.118.1237952820721; Tue, 24 Mar 2009 20:47:00 -0700 (PDT) In-Reply-To: References: <7fd310d10903231203r1bd37b8cn8baeadae83253f44@mail.gmail.com> <7fd310d10903241521v1cbf5d7aueca653e03ed98649@mail.gmail.com> Date: Tue, 24 Mar 2009 22:47:00 -0500 Message-ID: <7fd310d10903242047t1a7b7daw1d61c3de7f20b7c6@mail.gmail.com> Subject: Re: Help Me Understand Why I'm Getting a Bad Query Plan From: Bryan Murphy To: marcin mank Cc: 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=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/361 X-Sequence-Number: 33283 On Tue, Mar 24, 2009 at 10:04 PM, marcin mank wrote= : > There is one thing I don`t understand: > > =A0 =A0 =A0 =A0 =A0 =A0 =A0-> =A0Nested Loop =A0(cost=3D0.00..180564.28 r= ows=3D1806 > width=3D37) (actual time=3D0.192..60.214 rows=3D3174 loops=3D1) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-> =A0Index Scan using visitors_us= erid_index2 on > visitors v =A0(cost=3D0.00..2580.97 rows=3D1300 width=3D33) (actual > time=3D0.052..2.342 rows=3D897 loops=3D1) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Index Cond: (userid = =3D > 'fbe2537f21d94f519605612c0bf7c2c5'::bpchar) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-> =A0Index Scan using > itemexperiencelog__index__visitorid on itemexperiencelog l > (cost=3D0.00..134.04 rows=3D230 width=3D70) (actual time=3D0.013..0.040 r= ows=3D4 > loops=3D897) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Index Cond: (l.visitor= id =3D v.id) > > If it expects 1300 visitors with the userid, and for each of them to > have 230 entries in itemexperiencelog, how can it come up with 1806 > returned rows (and be about right!)? I'm not sure I follow what you're saying. One thing to keep in mind, due to a lapse in our judgement at the time, this itemexperiencelog table serves as both a current state table, and a log table. Therefore, it potentially has multiple redundant entries, but we typically only look at the most recent entry to figure out the state of the current item. We're in the process of re-factoring this now, as well as denormalizing some of the tables to eliminate unnecessary joins, but I keep running into these problems and need to understand what is going on so that I know we're fixing the correct things. Thanks, Bryan