Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 5074BB5DBBF for ; Mon, 27 Jun 2011 20:01:02 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 62356-05 for ; Mon, 27 Jun 2011 23:00:55 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from nm30-vm0.bullet.mail.sp2.yahoo.com (nm30-vm0.bullet.mail.sp2.yahoo.com [98.139.91.238]) by mail.postgresql.org (Postfix) with SMTP id BB7D4B5D94C for ; Mon, 27 Jun 2011 20:00:54 -0300 (ADT) Received: from [98.139.91.69] by nm30.bullet.mail.sp2.yahoo.com with NNFMP; 27 Jun 2011 23:00:54 -0000 Received: from [98.139.91.35] by tm9.bullet.mail.sp2.yahoo.com with NNFMP; 27 Jun 2011 23:00:54 -0000 Received: from [127.0.0.1] by omp1035.mail.sp2.yahoo.com with NNFMP; 27 Jun 2011 23:00:54 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 150051.51178.bm@omp1035.mail.sp2.yahoo.com Received: (qmail 34359 invoked by uid 60001); 27 Jun 2011 23:00:53 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1309215653; bh=KVRxxLGePHeW9G5JGZfTMQNp6/tcjpvYqE5WwKg+Wcw=; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=5KFQhbqmWW4XJZec+mQL0dH3xMXGPyOODjKpKk7rJreCdSa3LvdhAQrJWDnGs63AKLNsXUHfqtciyF1VpGYZFrLJeQkKEtL5d8WXe54hZQzF7A+u/Ka1kTRLBx1HY1ZvFBMWytvO2kmPt1/YLKX/lV45PpY6yy48CZqNtdk/dvw= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=UItFeCmwp54g9Pil+wFgHAEI+K1a+g6mZInm5lT0rdFkNwblbM5NyMm2dA9p+5iC5oTZa5X/cMRsKAn5Pu8NzGWjKuZq7f5aMSxFikfitQJxCYPPWTcTUWN+pTWO2g8ET1Jm9+xPDL0zPXVFJC6+XFa7oR28JvVOQHnWwYgg+R8=; X-YMail-OSG: PLPjVjAVM1nqgvytTgFlDfisaoH9Xat10FxeKjfXbcbLayD HKHqtDdaSxdT86kcidTZMdLHEbW89btyn9N5i6JjMlQfd_wMGr5cnWaP.jm2 3QgjixqMvIc1eeIwWMhiLv85NyVwhMiI_.gbJJ4rTwZb6K74SdM9e7VLMfIy FlB2HtMM0iaDyb9CEUQrNumF3A5DT5JJvUISLjpnyFX8an9ZjvHXVtKnIfsS eSOvJgi9HCd4MDRwFh_eJnfnd72lhKyW7bybrSCsWgutV5578_mlCtGrhNXs nLsVPNvbMMhbwzmx41o73FGmr2IC53m7xrtKbj8.XgBxTUnd7r3IhvCrQ6sm libQcfgXEEKVACZiAUH_0RaK2QF05d2X0HZlkWKYv3wo0dmRtqzz6vRkfd3s HhT_g_6G3Q1kafA-- Received: from [88.203.16.8] by web112401.mail.gq1.yahoo.com via HTTP; Mon, 27 Jun 2011 16:00:53 PDT X-Mailer: YahooMailWebService/0.8.112.307740 References: <1309215572.70995.YahooMailNeo@web112411.mail.gq1.yahoo.com> Message-ID: <1309215653.11968.YahooMailNeo@web112401.mail.gq1.yahoo.com> Date: Mon, 27 Jun 2011 16:00:53 -0700 (PDT) From: Denis de Bernardy Reply-To: Denis de Bernardy Subject: Fw: Getting rid of a seq scan in query on a large table To: PG Performance In-Reply-To: <1309215572.70995.YahooMailNeo@web112411.mail.gq1.yahoo.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1254972455-1309215653=:11968" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.908 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/256 X-Sequence-Number: 44189 --0-1254972455-1309215653=:11968 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable =0A=0A=0A=0A----- Forwarded Message -----=0A>From: Denis de Bernardy =0A>To: Jens Hoffrichter =0A>S= ent: Tuesday, June 28, 2011 12:59 AM=0A>Subject: Re: [PERFORM] Getting rid = of a seq scan in query on a large table=0A>=0A>=0A>> Hash Cond: (posts.post= er_id =3D posters.poster_id)=0A>=0A>> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 -> =A0Seq Scan on posts =A0(cost=3D0.00..11862.12 rows=3D112312 width= =3D24) (actual time=3D0.019..60.092 rows=3D112312 loops=3D1)=0A>=0A>=0A>Unl= ess I am mistaking, you've very few poster ids in there (since the two rows= arguments are equal). The Postgres planner will identify this and just seq= scan the whole thing instead of bothering to randomly access the rows one = by one using the index. This looks like a case where you actually do not wa= nt it to use an index scan -- doing so will be slower.=0A>=0A>=0A>D=0A>=0A>= =0A>=0A>=0A>=0A>=0A>=0A>>________________________________=0A>>From: Jens Ho= ffrichter =0A>>To: pgsql-performance@postgresql= .org=0A>>Sent: Monday, June 27, 2011 2:46 PM=0A>>Subject: [PERFORM] Getting= rid of a seq scan in query on a large table=0A>>=0A>>=0A>>Hi everyone,=0A>= >=0A>>=0A>>I'm having trouble getting rid of a sequential scan on a table w= ith roughly 120k entries it. Creation of an index on that particular column= which triggers the sequential scan doesn't do anything, VACUUM and ANALYZE= has been done on the table.=0A>>=0A>>=0A>>The table in question has the fo= llowing definition:=0A>>=0A>>=0A>>=A0 =A0 =A0 =A0Column =A0 =A0 =A0 | =A0 = =A0 =A0 =A0 =A0 Type =A0 =A0 =A0 =A0 =A0 | =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0Modifiers=0A>>--------------------+-----------------= ---------+-----------------------------------------------------------------= -=0A>>=A0post_id =A0 =A0 =A0 =A0 =A0 =A0| bigint =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 | not null default nextval('posts_post_id_seq'::regclass)=0A>>= =A0forum_id =A0 =A0 =A0 =A0 =A0 | bigint =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 | not null=0A>>=A0threadlink =A0 =A0 =A0 =A0 | character varying(255) = =A0 | not null=0A>>=A0timestamp =A0 =A0 =A0 =A0 =A0| timestamp with time zo= ne | not null=0A>>=A0poster_id =A0 =A0 =A0 =A0 =A0| bigint =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 |=0A>>=A0thread_id =A0 =A0 =A0 =A0 =A0| bigint =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 | not null=0A>>=A0subject =A0 =A0 =A0 =A0 =A0 = =A0| text =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 | not null=0A>>=A0text = =A0 =A0 =A0 =A0 =A0 =A0 =A0 | text =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = | not null=0A>>=A0postername =A0 =A0 =A0 =A0 | character varying(255) =A0 |= =0A>>=A0internal_post_id =A0 | bigint =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 |= not null default nextval('posts_internal_post_id_seq'::regclass)=0A>>=A0in= ternal_thread_id | bigint =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 |=0A>>Indexes= :=0A>>=A0 =A0 "posts_pkey" PRIMARY KEY, btree (internal_post_id)=0A>>=A0 = =A0 "posts_forum_id_key" UNIQUE, btree (forum_id, post_id)=0A>>=A0 =A0 "idx= _internal_thread_id" btree (internal_thread_id)=0A>>=A0 =A0 "idx_posts_post= er_id" btree (poster_id)=0A>>Foreign-key constraints:=0A>>=A0 =A0 "posts_fo= rum_id_fkey" FOREIGN KEY (forum_id) REFERENCES forums(forum_id)=0A>>=A0 =A0= "posts_internal_thread_id_fkey" FOREIGN KEY (internal_thread_id) REFERENCE= S threads(internal_thread_id)=0A>>=A0 =A0 "posts_poster_id_fkey" FOREIGN KE= Y (poster_id) REFERENCES posters(poster_id)=0A>>=0A>>=0A>>The query is this= :=0A>>=0A>>=0A>>SELECT threads.internal_thread_id AS threads_internal_threa= d_id, threads.forum_id AS threads_forum_id, threads.thread_id AS threads_th= read_id, threads.title AS threads_title, threads.poster_id AS threads_poste= r_id, threads.postername AS threads_postername, threads.category AS threads= _category, threads.posttype AS threads_posttype =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 FROM threads JO= IN posts ON threads.internal_thread_id =3D posts.internal_thread_id JOIN po= sters ON posts.poster_id =3D posters.poster_id JOIN posters_groups AS poste= rs_groups_1 ON posters.poster_id =3D posters_groups_1.poster_id JOIN groups= ON groups.group_id =3D posters_groups_1.group_id WHERE groups.group_id =3D= 4 ORDER BY posts.timestamp DESC;=0A>>=0A>>=0A>>The query plan (with an exp= lain analyze) gives me the following:=0A>>=0A>>=0A>>=A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 QUERY PLAN=0A>>= ---------------------------------------------------------------------------= ---------------------------------------------------------------------------= ----------------=0A>>=A0Sort =A0(cost=3D13995.93..14006.63 rows=3D4279 widt= h=3D108) (actual time=3D79.927..79.947 rows=3D165 loops=3D1)=0A>>=A0 =A0Sor= t Key: posts."timestamp"=0A>>=A0 =A0Sort Method: =A0quicksort =A0Memory: 50= kB=0A>>=A0 =A0-> =A0Nested Loop =A0(cost=3D6.97..13737.84 rows=3D4279 width= =3D108) (actual time=3D0.605..79.693 rows=3D165 loops=3D1)=0A>>=A0 =A0 =A0 = =A0 =A0-> =A0Seq Scan on groups =A0(cost=3D0.00..1.05 rows=3D1 width=3D8) (= actual time=3D0.013..0.014 rows=3D1 loops=3D1)=0A>>=A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0Filter: (group_id =3D 4)=0A>>=A0 =A0 =A0 =A0 =A0-> =A0Nested Loop = =A0(cost=3D6.97..13694.00 rows=3D4279 width=3D116) (actual time=3D0.587..79= .616 rows=3D165 loops=3D1)=0A>>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-> =A0Hash Jo= in =A0(cost=3D6.97..12343.10 rows=3D4279 width=3D24) (actual time=3D0.568..= 78.230 rows=3D165 loops=3D1)=0A>>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0Hash Cond: (posts.poster_id =3D posters.poster_id)=0A>>=A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0-> =A0Seq Scan on posts =A0(cost=3D0.00..11862.1= 2 rows=3D112312 width=3D24) (actual time=3D0.019..60.092 rows=3D112312 loop= s=3D1)=0A>>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-> =A0Hash =A0(cost= =3D6.79..6.79 rows=3D14 width=3D24) (actual time=3D0.101..0.101 rows=3D14 l= oops=3D1)=0A>>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-> =A0= Hash Join =A0(cost=3D2.14..6.79 rows=3D14 width=3D24) (actual time=3D0.060.= .0.093 rows=3D14 loops=3D1)=0A>>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0Hash Cond: (posters.poster_id =3D posters_groups_1.= poster_id)=0A>>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0-> =A0Seq Scan on posters =A0(cost=3D0.00..3.83 rows=3D183 width=3D8= ) (actual time=3D0.006..0.023 rows=3D185 loops=3D1)=0A>>=A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-> =A0Hash =A0(cost=3D1.96.= .1.96 rows=3D14 width=3D16) (actual time=3D0.025..0.025 rows=3D14 loops=3D1= )=0A>>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0-> =A0Seq Scan on posters_groups posters_groups_1 =A0(cost=3D0.0= 0..1.96 rows=3D14 width=3D16) (actual time=3D0.016..0.021 rows=3D14 loops= =3D1)=0A>>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0Filter: (group_id =3D 4)=0A>>=A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0-> =A0Index Scan using threads_pkey on threads =A0(cost=3D0.00.= .0.30 rows=3D1 width=3D100) (actual time=3D0.006..0.007 rows=3D1 loops=3D16= 5)=0A>>=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Index Cond: (threads.inte= rnal_thread_id =3D posts.internal_thread_id)=0A>>=A0Total runtime: 80.137 m= s=0A>>(20 rows)=0A>>=0A>>=0A>>So the big time lost is in this line:=0A>>=0A= >>=0A>>Seq Scan on posts =A0(cost=3D0.00..11862.12 rows=3D112312 width=3D24= ) (actual time=3D0.019..60.092 rows=3D112312 loops=3D1)=0A>>=0A>>=0A>>which= I can understand why it slow ;)=0A>>=0A>>=0A>>But I haven't yet managed to= convert the Seq Scan into an Index Scan, and I'm not sure how to continue = there.=0A>>=0A>>=0A>>As I am not a big expert on psql optimization, any inp= ut would be greatly appreciated.=0A>>=0A>>=0A>>Best regards,=0A>>Jens=0A>>= =0A>>=0A>=0A> --0-1254972455-1309215653=:11968 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable

----- Forwarded Message -----
From: Denis de Bernardy <ddebernardy@y= ahoo.com>
To: Jens H= offrichter <jens.hoffrichter@gmail.com>
Sent: Tuesday, June 28, 2011 12:59 AM
Subject: Re: [PERFORM] Getting rid of= a seq scan in query on a large table

=0A
> Hash Cond: (posts.poster_id =3D posters.poster_id)
>                 &nb= sp;   ->  Seq Scan on posts  (cost=3D0.00..11862.12 rows= =3D112312 width=3D24) (actual time=3D0.019..60.092 rows=3D112312 loops=3D1)=

Unless I am mistaking, y= ou've very few poster ids in there (since the two rows arguments are equal)= . The Postgres planner will identify this and just seq scan the whole thing= instead of bothering to randomly access the rows one by one using the inde= x. This looks like a case where you actually do not want it to use an index= scan -- doing so will be slower.

D
<= div>



From:= Jens Hoffrichter <jens.hoffrichter@gmail.com>
To: pgsql-performance@postgresql.org
<= b>Sent: Monday, June 27, 2011 = 2:46 PM
Subject: [PERFOR= M] Getting rid of a seq scan in query on a large table

=0AHi everyone,

I'm having trouble g= etting rid of a sequential scan on a table with roughly 120k entries it. Cr= eation of an index on that particular column which triggers the sequential = scan doesn't do anything, VACUUM and ANALYZE has been done on the table.=0A

The table in question has the following definitio= n:

       Column   &= nbsp;   |           Type      =     |                 &n= bsp;          Modifiers
----------------= ----+--------------------------+-------------------------------------------= -----------------------
=0A
 post_id       &nb= sp;    | bigint               =     | not null default nextval('posts_post_id_seq'::regclass)
 forum_id           | bigint   &n= bsp;               | not null
=  threadlink         | character varying(255)  = ; | not null
=0A
 timestamp          = ;| timestamp with time zone | not null
 poster_id   &nb= sp;      | bigint             =       |
 thread_id        = ;  | bigint                 &n= bsp; | not null
 subject           =  | text                  =   | not null
=0A
 text         &nbs= p;     | text               &n= bsp;     | not null
 postername     &nbs= p;   | character varying(255)   |
 internal_post_i= d   | bigint                 &= nbsp; | not null default nextval('posts_internal_post_id_seq'::regclass)=0A
 internal_thread_id | bigint         &n= bsp;         |
Indexes:
  &nbs= p; "posts_pkey" PRIMARY KEY, btree (internal_post_id)
  &nbs= p; "posts_forum_id_key" UNIQUE, btree (forum_id, post_id)
=0A
&nbs= p;   "idx_internal_thread_id" btree (internal_thread_id)
&nb= sp;   "idx_posts_poster_id" btree (poster_id)
Foreign-key co= nstraints:
    "posts_forum_id_fkey" FOREIGN KEY (forum= _id) REFERENCES forums(forum_id)
=0A
    "posts_internal= _thread_id_fkey" FOREIGN KEY (internal_thread_id) REFERENCES threads(intern= al_thread_id)
    "posts_poster_id_fkey" FOREIGN KEY (p= oster_id) REFERENCES posters(poster_id)
=0A

T= he query is this:

SELECT threads.internal_thr= ead_id AS threads_internal_thread_id, threads.forum_id AS threads_forum_id,= threads.thread_id AS threads_thread_id, threads.title AS threads_title, th= reads.poster_id AS threads_poster_id, threads.postername AS threads_postern= ame, threads.category AS threads_category, threads.posttype AS threads_post= type                     =                      = ;                     &nb= sp;                     &= nbsp;                    =                     &nbs= p;                     &n= bsp;     FROM threads JOIN=0A posts ON threads.internal_thread_id= =3D posts.internal_thread_id JOIN posters ON posts.poster_id =3D posters.p= oster_id JOIN posters_groups AS posters_groups_1 ON posters.poster_id =3D p= osters_groups_1.poster_id JOIN groups ON groups.group_id =3D posters_groups= _1.group_id WHERE groups.group_id =3D 4 ORDER BY posts.timestamp DESC;=0A

The query plan (with an explain analyze) give= s me the following:

      &nbs= p;                     &n= bsp;                     =                      = ;       QUERY PLAN
-------------------------------= ---------------------------------------------------------------------------= ------------------------------------------------------------
=0A
&= nbsp;Sort  (cost=3D13995.93..14006.63 rows=3D4279 width=3D108) (actual= time=3D79.927..79.947 rows=3D165 loops=3D1)
   Sort Ke= y: posts."timestamp"
   Sort Method:  quicksort &n= bsp;Memory: 50kB
   ->  Nested Loop  (cost= =3D6.97..13737.84 rows=3D4279 width=3D108) (actual time=3D0.605..79.693 row= s=3D165 loops=3D1)
=0A
         -> &nb= sp;Seq Scan on groups  (cost=3D0.00..1.05 rows=3D1 width=3D8) (actual = time=3D0.013..0.014 rows=3D1 loops=3D1)
      &nbs= p;        Filter: (group_id =3D 4)
  &nb= sp;      ->  Nested Loop  (cost=3D6.97..13694.0= 0 rows=3D4279 width=3D116) (actual time=3D0.587..79.616 rows=3D165 loops=3D= 1)
=0A
               ->= ;  Hash Join  (cost=3D6.97..12343.10 rows=3D4279 width=3D24) (act= ual time=3D0.568..78.230 rows=3D165 loops=3D1)
    &nbs= p;                Hash Cond: (posts= .poster_id =3D posters.poster_id)
        &nb= sp;            ->  Seq Scan on posts =  (cost=3D0.00..11862.12 rows=3D112312 width=3D24) (actual time=3D0.019= ..60.092 rows=3D112312 loops=3D1)
=0A
        =              ->  Hash  (cos= t=3D6.79..6.79 rows=3D14 width=3D24) (actual time=3D0.101..0.101 rows=3D14 = loops=3D1)
               = ;            ->  Hash Join  (cos= t=3D2.14..6.79 rows=3D14 width=3D24) (actual time=3D0.060..0.093 rows=3D14 = loops=3D1)
=0A
              &n= bsp;                  Hash Con= d: (posters.poster_id =3D posters_groups_1.poster_id)
  &nbs= p;                     &n= bsp;        ->  Seq Scan on posters  (cost= =3D0.00..3.83 rows=3D183 width=3D8) (actual time=3D0.006..0.023 rows=3D185 = loops=3D1)
=0A
              &n= bsp;                  -> &n= bsp;Hash  (cost=3D1.96..1.96 rows=3D14 width=3D16) (actual time=3D0.02= 5..0.025 rows=3D14 loops=3D1)
          =                      = ;        ->  Seq Scan on posters_groups posters= _groups_1  (cost=3D0.00..1.96 rows=3D14 width=3D16) (actual time=3D0.0= 16..0.021 rows=3D14 loops=3D1)
=0A
        &nb= sp;                     &= nbsp;              Filter: (group_id =3D= 4)
               -> =  Index Scan using threads_pkey on threads  (cost=3D0.00..0.30 row= s=3D1 width=3D100) (actual time=3D0.006..0.007 rows=3D1 loops=3D165)
= =0A
                  &nbs= p;  Index Cond: (threads.internal_thread_id =3D posts.internal_thread_= id)
 Total runtime: 80.137 ms
(20 rows)

So the big time lost is in this line:
=0A
Seq Scan on posts  (cost=3D0.00..11862.12 rows=3D112312 wi= dth=3D24) (actual time=3D0.019..60.092 rows=3D112312 loops=3D1)
<= br>
which I can understand why it slow ;)

But I haven't yet managed to convert the Seq Scan into an Index Scan, and= I'm not sure how to continue there.
=0A

As I am no= t a big expert on psql optimization, any input would be greatly appreciated= .

Best regards,
Jens
=0A

<= br>


--0-1254972455-1309215653=:11968--