Re: Index over only uncommon values in table

From: David Johnston <polobo(at)yahoo(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Index over only uncommon values in table
Date: 2013-06-18 22:00:22
Message-ID: 1371592822309-5759765.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Steven Schlansker-3 wrote
> The code may get changed multiple times in the same day, if I am
> busy hacking on it.

On the production table???

The other thought-line is just use a (primary key, version) index and make
use LIMIT / OFFSET with an ORDER BY on the PK and the filter on version
AFTER the initial rows are selected.

UPDATE tbl SET ....
FROM (
WITH possible_set AS ( SELECT pkid, version FROM tbl ORDER BY pkid DESC
LIMIT 5000 OFFSET 10000 )
SELECT pkid FROM possible_set WHERE version <> 'CURRENT_VERSION'
) src
tbl.pkid = src.pkid
;

DESC pkid means that newer records are prioritized over older ones.

Probably want a table to keep track of which ranges have already been
reserved and/or updated then client can connect and reserve a range and
perform an update. Concurrency and failure modes would need attention. You
can also keep track on entire ranges and identify which version all the
records are at and select ranges based upon how far behind the current
version they are (or whatever priority algorithm you desire - including
manual tweaks).

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Index-over-only-uncommon-values-in-table-tp5759735p5759765.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message 高健 2013-06-19 01:35:16 Re: I want to make an example of using parameterized path
Previous Message Steven Schlansker 2013-06-18 21:36:22 Re: Index over only uncommon values in table