Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WfzZ4-0000ck-4L for pgsql-performance@arkaria.postgresql.org; Thu, 01 May 2014 22:34:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WfzZ3-0004DI-Fo for pgsql-performance@arkaria.postgresql.org; Thu, 01 May 2014 22:34:49 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WfzZ1-0004D9-Ah for pgsql-performance@postgresql.org; Thu, 01 May 2014 22:34:47 +0000 Received: from smtp-out1.gransy.com ([77.78.126.51]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WfzYy-0006NB-At for pgsql-performance@postgresql.org; Thu, 01 May 2014 22:34:46 +0000 Received: from smtp-out.gransy.com (localhost [127.0.0.1]) by smtp-out1.gransy.com (Postfix) with ESMTP id 80D1A360044 for ; Fri, 2 May 2014 00:34:43 +0200 (CEST) Received: from smtp.gransy.com (smtp.simplia.cz [77.78.126.20]) by smtp-out1.gransy.com (Postfix) with ESMTP id 3E15D360005 for ; Fri, 2 May 2014 00:34:43 +0200 (CEST) Received: from [192.168.1.163] (ip-78-45-139-138.net.upcbroadband.cz [78.45.139.138]) (Authenticated sender: tv@fuzzy.cz) by smtp.gransy.com (Postfix) with ESMTPSA id 0375C19A04BA for ; Fri, 2 May 2014 00:34:42 +0200 (CEST) Message-ID: <5362CBFA.6060004@fuzzy.cz> Date: Fri, 02 May 2014 00:34:34 +0200 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Re: Optimize query for listing un-read messages References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 1.5.2014 23:58, Andreas Joseph Krogh wrote: > På torsdag 01. mai 2014 kl. 23:45:49, skrev Tomas Vondra >: > > On 1.5.2014 23:19, Andreas Joseph Krogh wrote: > > Just curious: > > Is such a JOIN index possible in other DBs, if so - which? > > Can other DBs do index on difference between two sets? > > Will PG ever have this, is it even possible? > > I'm not aware of such database, but maybe it's possible at least for > some cases. But I'd expect that to significantly depend on the schema. > And I'm not aware of any such effort in case of PostgreSQL, do don't > hold your breath. > > IMHO the problem with your schema is that while each 'read' message has > a matching row in message_property, 'undread' messages may or may not > have a matching row. Is there a particular reason for that? > > > > Yes. The point is that maintaining a message_property pair for all > messages for all users in the system imposes quite a > maintainance-headache. As the schema is now any new message is per > definition un-read, and when a user reads it then it gets an entry with > is_read=true in message_property. This table holds other properties too. > This way I'm avoiding having to book-keep so much when a new message > arrives and when a new user is created. A message in my system does not > necessarily have only one recipient, it might have one, many or none, > and might be visible to many. So how do you determine who's the recipient of a message? Or is that the case that everyone can read everything (which is why you're displaying them the unread messages, right)? I understand you're trying to solve this without storing a row for each possible message-person combination, but won't this eventually happen anyway (with is_read=true for all rows)? Tomas -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance