X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C528BD1B376 for ; Wed, 28 Jul 2004 13:54:10 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 47655-03 for ; Wed, 28 Jul 2004 16:53:41 +0000 (GMT) Received: from boutiquenumerique.com (gailleton-2-82-67-9-10.fbx.proxad.net [82.67.9.10]) by svr1.postgresql.org (Postfix) with ESMTP id 54C3DD1B495 for ; Wed, 28 Jul 2004 13:53:02 -0300 (ADT) Received: (qmail 8798 invoked from network); 28 Jul 2004 18:53:02 +0200 Received: from unknown (HELO musicbox) (192.168.0.2) by gailleton-2-82-67-9-10.fbx.proxad.net with SMTP; 28 Jul 2004 18:53:02 +0200 Date: Wed, 28 Jul 2004 18:53:12 +0200 To: pgsql-performance@postgresql.org Subject: Join performance References: <6EE64EF3AB31D5448D0007DD34EEB34101AF05@Herge.rcsinc.local> From: =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= Organization: =?iso-8859-15?Q?La_Boutique_Num=E9rique?= Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-15 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID: In-Reply-To: <6EE64EF3AB31D5448D0007DD34EEB34101AF05@Herge.rcsinc.local> User-Agent: Opera M2/7.50 (Linux, build 673) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200407/217 X-Sequence-Number: 7608 Hello, I'm building a kind of messaging/forum application with postgresql. There are users which will send each others messages, send messages to forums, etc. I would like to put the messages in folders, so each user has several folders (inbox, sent...), and forums are also folders. A message will appear in the sender's "sent" folder and the receiver's inbox, or receiving forum folder. There are two ways I can do this : - either by placing two folder fields (outbox_folder_id and receiving_folder_id) in the messages table, which can both point to a folder or be null. When a user sends a message to another user/folder, these fields are set appropriately. - or by having a messages table, and a link table linking messages to folders. I have built a test database with about 20000 messages in 2000 folders (10 messages per folder). Finding all the messages in a folder takes more than 600 times longer with the link table than with the single table approach (66 ms vs. 0.12 ms). Is this normal ? I have checked explain analyze and it uses indexes in all cases. The query plans look right to me.