agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Adrian Klaver <adrian.klaver@aklaver.com>
To: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-sql@postgresql.org
Subject: Re: Schema for caching message-count in folders using triggers
Date: Thu, 05 Mar 2015 12:31:32 -0800
Message-ID: <54F8BD24.6070101@aklaver.com> (raw)
In-Reply-To: <VisenaEmail.a.dd389169d0fb6df0.14beb890fcb@tc7-visena>
References: <VisenaEmail.a.dd389169d0fb6df0.14beb890fcb@tc7-visena>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
On 03/05/2015 12:04 PM, Andreas Joseph Krogh wrote:
> På torsdag 05. mars 2015 kl. 20:59:28, skrev Adrian Klaver
> <adrian.klaver@aklaver.com <mailto:adrian.klaver@aklaver.com>>:
> >
> > The problem with this is locking (waiting for another TX to
> commit when
> > updating the same folder) and deadlock issues when trying to
> > simultaneously insert/delete/update messages in a folder.
> > Does anyone have any better ideas for safely caching the
> message-count
> > in each folder without locking and deadlock issues?
>
> How accurate does this have to be?
>
> Not exactly following what is folder?
> Is it a table that contains the messages?
>
> A top of the head idea would be to use sequences. Create a sequence for
> each folder starting at current count and then use nextval, setval to
> change the value:
>
> http://www.postgresql.org/docs/9.4/interactive/functions-sequence.html
>
> It is not transactional, so it would probably not be spot on, which is
> why I asked about accuracy earlier.
>
> Yes, 'folder' is a table which contains 'message':
>
> create tablefolder(
> idserial PRIMARY KEY,
> namevarchar not null unique,
> message_countinteger not null default0
> );
>
> create table message(
> idserial PRIMARY KEY,
> folder_idINTEGER NOT NULL REFERENCESfolder(id),
> messagevarchar not null
> );
>
> The count has to be exact, no estimate from EXPLAIN or such...
Well there goes my idea. Seems the way to go is partitioning:
http://www.postgresql.org/docs/9.4/static/ddl-partitioning.html
Break the data into smaller units
> --
> *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;
--
Adrian Klaver
adrian.klaver@aklaver.com
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
view thread (6+ messages) latest in thread
Message-ID: <54F8BD24.6070101@aklaver.com>
Permalink: ../54F8BD24.6070101@aklaver.com/
Also on: postgresql.org/message-id/54F8BD24.6070101@aklaver.com
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: adrian.klaver@aklaver.com, andreas@visena.com
Subject: Re: Schema for caching message-count in folders using triggers
In-Reply-To: <54F8BD24.6070101@aklaver.com>
* 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