pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Matt Magoffin <postgresql.org@msqr.us>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Duplicate key violation on upsert
Date: Wed, 25 Mar 2020 21:28:02 -0700
Message-ID: <4372965a-188b-592c-8f08-92065f90efb7@aklaver.com> (raw)
In-Reply-To: <65AECD9A-CE13-4FCB-9158-23BE62BB65DD@msqr.us>
References: <0E4E069D-40B1-46C1-9BA0-5A5E737F753B@msqr.us>
	<604644e7-6881-3fdb-8767-897fc40559ac@aklaver.com>
	<03EC7E36-EA7F-452A-B0A9-2F0FBB73E914@msqr.us>
	<00a020ca-f2db-2dd7-2aa6-e3ef78e7ba68@aklaver.com>
	<C6A3AA75-38FA-4A8E-9FBD-A9121AE4EE91@msqr.us>
	<a7aecaad-5bb5-3daf-95e8-2c815039f66c@aklaver.com>
	<162ae0d1-be71-f200-2b58-80b4b955fea8@aklaver.com>
	<EB9192B4-9EAC-4376-BC8B-5D9CEF56F5FE@msqr.us>
	<80cdd870-e46c-147a-d063-03acfb30c892@aklaver.com>
	<DDC9F7A4-4145-4DDD-BBC4-06D931DA7BE0@msqr.us>
	<ff653668-3fad-da5c-b26a-addd2ea0f87e@aklaver.com>
	<65AECD9A-CE13-4FCB-9158-23BE62BB65DD@msqr.us>

On 3/25/20 5:23 PM, Matt Magoffin wrote:
> 
>> On 23/03/2020, at 1:10 PM, Adrian Klaver <adrian.klaver@aklaver.com 
>> <mailto:adrian.klaver@aklaver.com>> wrote:
>>
>> So the query is in the function solardatum.store_datum()?
>>
>> If so what is it doing?
> 
> Yes. This function first performs the INSERT INTO the 
> solardatum.da_datum table that we’re discussing here; then it inserts 
> into two different tables. If it helps, the actual SQL is available here:
> 
> https://github.com/SolarNetwork/solarnetwork-central/blob/4fa585929a5526187ade0e842c809837647c6a41/s...

I told see anything wrong at first glance, but is getting late here. I 
will take another look in the morning.

> 
>> And could you capture the values and pass them to a RAISE NOTICE?
> 
> It would take me some time to get that change deployed. If I was able 
> to, what information do you think would be helpful here, e.g. that 
> jdata_a is NULL or not, or something else?

The values for (node_id, ts, source_id, jdata_a) as they compromise the 
UNIQUE values for da_datum_pkey and da_datum_x_acc_idx.

> 
> The duplicate key violation occurs infrequently, and it does seem 
> appropriate to drop the UNIQUE constraint on the da_datum_x_acc_idx 
> given uniqueness is really only wanted on (node_id, ts, source_id). As 
> long as I can confirm that query performance doesn’t decrease, I’d like 
> to recreate the index without UNIQUE. Then I’m hoping this problem, 
> whatever the cause, goes away.
> 
> — m@


-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (15+ messages)  latest in thread

Message-ID: <4372965a-188b-592c-8f08-92065f90efb7@aklaver.com>
Permalink:  ../4372965a-188b-592c-8f08-92065f90efb7@aklaver.com/
Also on:    postgresql.org/message-id/4372965a-188b-592c-8f08-92065f90efb7@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: adrian.klaver@aklaver.com, postgresql.org@msqr.us
  Subject: Re: Duplicate key violation on upsert
  In-Reply-To: <4372965a-188b-592c-8f08-92065f90efb7@aklaver.com>
  References: <0E4E069D-40B1-46C1-9BA0-5A5E737F753B@msqr.us> <604644e7-6881-3fdb-8767-897fc40559ac@aklaver.com> <03EC7E36-EA7F-452A-B0A9-2F0FBB73E914@msqr.us> <00a020ca-f2db-2dd7-2aa6-e3ef78e7ba68@aklaver.com> <C6A3AA75-38FA-4A8E-9FBD-A9121AE4EE91@msqr.us> <a7aecaad-5bb5-3daf-95e8-2c815039f66c@aklaver.com> <162ae0d1-be71-f200-2b58-80b4b955fea8@aklaver.com> <EB9192B4-9EAC-4376-BC8B-5D9CEF56F5FE@msqr.us> <80cdd870-e46c-147a-d063-03acfb30c892@aklaver.com> <DDC9F7A4-4145-4DDD-BBC4-06D931DA7BE0@msqr.us> <ff653668-3fad-da5c-b26a-addd2ea0f87e@aklaver.com> <65AECD9A-CE13-4FCB-9158-23BE62BB65DD@msqr.us> <4372965a-188b-592c-8f08-92065f90efb7@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 DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox