Re: [PERFORM] Optimize query for listing un-read messages

2014-05-02 Thread Andreas Joseph Krogh
På fredag 02. mai 2014 kl. 02:17:58, skrev Craig James cja...@emolecules.com mailto:cja...@emolecules.com: On Thu, May 1, 2014 at 4:26 AM, Andreas Joseph Kroghandr...@visena.com mailto:andr...@visena.com wrote: I have a schema where I have lots of messages and some users who might have read

Re: [PERFORM] Optimize query for listing un-read messages

2014-05-02 Thread Vitalii Tymchyshyn
What statistics do you have on the data? I suppose most messages are read by low number of users, mostly 0 or one. I can see two options to consider: 1) Use arrays to store information on which users have already read the message. You may need GIN/GIST index to search fast. 2) Introduce some kind