Re: CPU hogged by concurrent SELECT..FOR UPDATE SKIP LOCKED - Mailing list pgsql-performance

From Michael Lewis
Subject Re: CPU hogged by concurrent SELECT..FOR UPDATE SKIP LOCKED
Date
Msg-id CAHOFxGpAS-HG1k5R=WxDN8G6kA97uq17=B8Hor_E0ZK_FB6DUw@mail.gmail.com
Whole thread Raw
In response to Re: CPU hogged by concurrent SELECT..FOR UPDATE SKIP LOCKED  (Jim Jarvie <jim@talentstack.to>)
Responses Re: CPU hogged by concurrent SELECT..FOR UPDATE SKIP LOCKED  (David Rowley <dgrowleyml@gmail.com>)
List pgsql-performance
On Thu, Aug 20, 2020 at 4:40 PM Jim Jarvie <jim@talentstack.to> wrote:

On 20-Aug.-2020 17:42, Michael Lewis wrote:

Can you share an explain analyze for the query that does the select for
update? I wouldn't assume that partition pruning is possible at all with
hash, and it would be interesting to see how it is finding those rows.

Well this got interesting  - the already moved error showed up:  Note, the actual process partitions are regular table partitions, these are not hashed.  Only the incoming and completed are hashed due to row counts at either end of the processing; in flight (where the issue shows up) is quite small:

[queuedb] # explain analyze select queueid,txobject,objectid,state from mq.queue where (state = 'tx_active' or state='tx_fail_retryable') and txobject = 'ticket' limit 250 for update skip locked;
ERROR:  40001: tuple to be locked was already moved to another partition due to concurrent update
LOCATION:  heapam_tuple_lock, heapam_handler.c:405
Time: 579.131 ms

That is super curious. I hope that someone will jump in with an explanation or theory on this.

I still wonder why the move between partitions is needed though if the work is either done (failed or successful) or not done... not started, retry needed or in progress... it doesn't matter. It needs to get picked up by the next process if it isn't already row locked.

pgsql-performance by date:

Previous
From: Jim Jarvie
Date:
Subject: Re: CPU hogged by concurrent SELECT..FOR UPDATE SKIP LOCKED
Next
From: David Rowley
Date:
Subject: Re: CPU hogged by concurrent SELECT..FOR UPDATE SKIP LOCKED