agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-sql@postgresql.org
Subject: Help with effective query for listing flags in use by messages in a folder
Date: Mon, 16 Mar 2015 22:59:28 +0100 (CET)
Message-ID: <VisenaEmail.48.cde120f823a3ddaf.14c249024eb@tc7-visena> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

Hi all.   On PG-9.3 (no JSONB),   For an IMAP-like system; I'm trying to figure 
out an effective way to query for "what flags are in use in a folder". A flag 
is considered used when one or more messages in that folder has the value=true. 
  The schema is like this: create table message( folder_id integer not NULL, 
is_seenboolean NOT NULL default false, is_replied boolean not null default false
,is_forwarded boolean not null default false, is_deleted boolean not null 
default false, is_draft boolean not null default false, is_flagged boolean not 
null default false);   I need the "flags" to be in the message-table for other 
queries to be as efficient as possible (no JOIN'ing), the system contains 
millions of messages.   create index message_folder_id_deleted_idx ON message(
folder_id) where is_deleted = TRUE; create index message_folder_id_forwarded_idx
ON message(folder_id) where is_forwarded = TRUE; create index 
message_folder_id_replied_idxON message(folder_id) where is_replied = TRUE; 
create indexmessage_folder_id_seen_idx ON message(folder_id) where is_seen = 
TRUE; create index message_folder_id_flagged_idx ON message(folder_id) where 
is_flagged= TRUE; create index message_folder_id_draft_idx ON message(folder_id)
whereis_draft = TRUE; select 'is_deleted' from (select * from message where 
folder_id= 3 AND is_deleted limit 1) as q UNION select 'is_forwarded' from (
select* from message where folder_id = 3 AND is_forwarded limit 1) as q UNION 
select'isreplied' from (select * from message where folder_id = 3 AND is_replied
limit1) as q UNION select 'is_seen' from (select * from message where folder_id 
=3 AND is_seen limit 1) as q UNION select 'is_flagged' from (select * from 
message wherefolder_id = 3 AND is_flagged limit 1) as q UNION select 'is_draft' 
from(select * from message where folder_id = 3 AND is_draft limit 1) as q ;   
Are there better ways to do this?   Thanks.   -- Andreas Joseph Krogh CTO / 
Partner - Visena AS Mobile: +47 909 56 963 andreas@visena.com 
<mailto:andreas@visena.com> www.visena.com <https://www.visena.com;  
<https://www.visena.com;

Message-ID: <VisenaEmail.48.cde120f823a3ddaf.14c249024eb@tc7-visena>
Permalink:  ../VisenaEmail.48.cde120f823a3ddaf.14c249024eb@tc7-visena/
Also on:    postgresql.org/message-id/VisenaEmail.48.cde120f823a3ddaf.14c249024eb@tc7-visena

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: andreas@visena.com
  Subject: Re: Help with effective query for listing flags in use by messages in a folder
  In-Reply-To: <VisenaEmail.48.cde120f823a3ddaf.14c249024eb@tc7-visena>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox