Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aGwYx-00049E-GZ for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Jan 2016 22:28:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aGwYw-000081-Qe for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Jan 2016 22:28:14 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aGvBu-0006AE-QK for pgsql-bugs@postgresql.org; Wed, 06 Jan 2016 21:00:23 +0000 Received: from mail-ob0-x229.google.com ([2607:f8b0:4003:c01::229]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1aGvBq-0004mA-NE for pgsql-bugs@postgresql.org; Wed, 06 Jan 2016 21:00:21 +0000 Received: by mail-ob0-x229.google.com with SMTP id wp13so174624311obc.1 for ; Wed, 06 Jan 2016 13:00:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=salesintel.com; s=google; h=message-id:mime-version:to:cc:from:subject:date:importance :in-reply-to:references:content-type; bh=gzCKi4UrFp6/QhG+zMSiqjDc0PlCbJN+/kJtiRRRvTE=; b=Y7aSKQEZ8aqjYc3AyohjnDoaLtCDwAd43O9z5kYeAV+1kiMJUZadNoF1l+vkE9YzJY YIgkp2v2o/2JBGWkyJT2ym2F9DXTLL7rjx3q9CPRw6bUTV4lQ8TZxibZ4FozpwAaj518 KCmn2jUg9JOoNDZtc05WDp0oRQN2hUaZ30y44= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:mime-version:to:cc:from:subject:date :importance:in-reply-to:references:content-type; bh=gzCKi4UrFp6/QhG+zMSiqjDc0PlCbJN+/kJtiRRRvTE=; b=I5jEANzD1gluL8uKbDHRtsYSzbi7DiUyyKg6e0Bx5xW1onZaXaQSSfJ/GPm4A1fY9d M4nQd5pBN78KuIjuqU14zA5TF66Y00WsaJTmglyrNBjjIYmF6OAaNWECGkqPjNoxDIEa ++I34GNOawriXN098Wq+57+E5m3n5vnLpXsA4vCMYiZix476DE4xzCb+/UoYc/L+hech V4pNILKR+bs09PTCEEbNW04rRS/HrrG1ZkO0ECyLK0sDKIxW0y9yGM+zsAdM36Wvz/0r yh217PrOP6qm5X/UPmLu7n5m2ZBrv5OuH3MhS/R4KxJP/tg5sdIEjZAq6K3v48Nucuqf XmVQ== X-Gm-Message-State: ALoCoQkSgdygY3b2ZHc+6SZk+4y1Fhken7JznZF9TugQDTmgiSQuB98FmkuRGP0c9yZh40NYB0BUX0Ocz8pvBzzY7DrOv+jmdw== X-Received: by 10.182.19.234 with SMTP id i10mr70791626obe.67.1452114017668; Wed, 06 Jan 2016 13:00:17 -0800 (PST) Received: from ?IPv6:::ffff:192.168.1.7? (71-218-214-23.hlrn.qwest.net. [71.218.214.23]) by smtp.gmail.com with ESMTPSA id y9sm39471108obg.4.2016.01.06.13.00.15 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 06 Jan 2016 13:00:16 -0800 (PST) Message-ID: <568d8060.291cb60a.e8a06.ffff9d00@mx.google.com> MIME-Version: 1.0 To: Andres Freund Cc: Peter Geoghegan , pgsql-bugs From: Paul Subject: Re: BUG #13846: INSERT ON CONFLICT consumes sequencers onconflicts Date: Wed, 6 Jan 2016 14:00:14 -0700 Importance: normal X-Priority: 3 In-Reply-To: <20160106181946.GE7650@awork2.anarazel.de> References: <20160105150227.1117.51692@wrigleys.postgresql.org> <20160105161326.GD7650@awork2.anarazel.de> <20160106181946.GE7650@awork2.anarazel.de> Content-Type: multipart/alternative; boundary="_6AF939D6-7F6F-4CFF-834D-196AD44A0FC1_" X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --_6AF939D6-7F6F-4CFF-834D-196AD44A0FC1_ Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To be clear, the column defaulted to a sequencer is not at all involved in = determining conflicts, and therefore it should not matter if it is used in = a unique index, nor would there be any problems with a BEFORE trigger. Gaps aren=E2=80=99t any kind of issue, and it=E2=80=99s not about how popul= ar a related table is to the table upon which the UPSERT would be applied. For example, I might be receiving event data from a shop floor where everyt= hing is instrumented; tank levels, step counters, etc. There could be milli= ons of events over a relatively short period of time. I might have a field = in the event data which indicates the =E2=80=98class=E2=80=99 of device tha= t generated the event; ex: =E2=80=98pump=E2=80=99, =E2=80=98actuator=E2=80= =99, =E2=80=98regulator=E2=80=99, =E2=80=98thermometer=E2=80=99. There may = only be less than a few hundred classes of devices that rarely change. So I= have a table, with a surrogate SMALLINT key defaulted to a sequence, and a= =E2=80=98name=E2=80=99 column which is a device class name. As the raw event data is processed, I want to do an UPSERT into the device = class table, using only the class name to resolve conflicts, to get it=E2= =80=99s surrogate key, which is then used while inserting the related event= record linking that event record to the particular device class. Since de= vice classes are rarely added, it will be the common case that an actual IN= SERT is almost never performed. Using INSERT ON CONFLICT in this case, however, would mean the device class= table, which would only ever hold a few hundred records and would only req= uire a SMALLINT for its surrogate key, would have to have a BIGINT for no g= ood reason, which really isn=E2=80=99t a big deal. What IS the big deal is = that the event table would also require a BIGINT for the device class colum= n to relate the event to the device class. In most cases, there are many mo= re =E2=80=98organizing=E2=80=99 columns, similar to the device class in thi= s example, meaning BIGINTs would have to be used for no good reason within = event tables, which can hold vast volumes of data. This can have a real and= measurable impact on memory, network, and storage requirements, which even= tually map to dollars. This basic scenario is very common, and one that greatly benefits from UPSE= RT capability; i.e. linking event data to organizational data. It=E2=80=99s= much less common to have to UPSERT into some event table; i.e. the INSERT = part of UPSERTs is usually the path less taken. I used the example of a sho= p floor with device classes, but its the same issue for looking at orders b= y product hierarchies, commissions by territories, stars by classification,= web-page-hits by marketing campaigns=E2=80=A6. I could list hundreds of pr= ocesses within many problem domains that are of this same basic pattern. My only point is, there=E2=80=99s another great capability in Postgres, for= doing efficient concurrent UPSERTS, but that one of the most common and pr= ime use cases for it is going to cost more money from having to use 64bit n= umbers everywhere for no good reason. From: Andres Freund Sent: Wednesday, January 6, 2016 11:19 AM To: Paul Hester Cc: Peter Geoghegan; pgsql-bugs Subject: Re: [BUGS] BUG #13846: INSERT ON CONFLICT consumes sequencers onco= nflicts On 2016-01-05 22:04:41 -0700, Paul Hester wrote: > No peek-ahead necessary, when the sequenced column would not be used in t= he > conflict_target. UPSERTS to dimension tables in a star schema as part of = an > OLAP system are very handy, but typically the records in the dimension > tables use a surrogate key based on sequences for maintenance & performan= ce > reasons, and the 'natural' key/value is the only column that would be use= d > to detect a conflict. In this case, the 'normal' path would be the > conflict_action nearly all the time, and not the insert. If the typical > path was the INSERT, I'd bet the data would be from some event source, an= d > I guess in that case if there were a key column defaulted with a sequence= , > like an order#, it would have to be used to resolve conflicts. But it's > hard to imagine a case in a process flow where you wouldn't already know = if > the event existed or not, limiting the need for an UPSERT on event data. It'd be very fragile. You could only do that if the value isn't involved in any unique indexes, if there are no BEFORE triggers (since they need to see the value). > This limitation, of consuming sequencers used for defaults on columns not > necessary to resolve conflict, diminishes the viability for using Postges > UPSERTS for large data warehouses, is all I'm saying (or requires surroga= te > keys being 64 bit). Just caught me by surprise in comparison to other > RDBMSs offering some form of UPSERTs that would not consume a sequencer i= f > its values weren't required to resolve conflicts. If you use normal sequences you already need to cope with gaps in sequences. And ids needing to be 64bits if you're a longer lived business and it's for a a halfway "popular" table, isn't something new. So I don't think addressing this is worth adding code for, especially given the fragility of the situations where it'd be usable. --_6AF939D6-7F6F-4CFF-834D-196AD44A0FC1_ Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="utf-8"

To be clear, the column defaul= ted to a sequencer is not at all involved in determining conflicts,= and therefore it should not matter if it is used in a unique index, nor wo= uld there be any problems with a BEFORE trigger.

 

Gaps aren=E2=80=99t any kind of iss= ue, and it=E2=80=99s not about how popular a related table is to the table = upon which the UPSERT would be applied.

 =

For example, I might be receiving event data= from a shop floor where everything is instrumented; tank levels, step coun= ters, etc. There could be millions of events over a relatively short period= of time. I might have a field in the event data which indicates the =E2=80= =98class=E2=80=99 of device that generated the event; ex: =E2=80=98pump=E2= =80=99, =E2=80=98actuator=E2=80=99, =E2=80=98regulator=E2=80=99, =E2=80=98t= hermometer=E2=80=99. There may only be less than a few hundred classes of d= evices that rarely change. So I have a table, with a surrogate SMALLINT key= defaulted to a sequence, and a =E2=80=98name=E2=80=99 column which is a de= vice class name.

 

As the raw event data is processed, I want to do an UPSERT into the= device class table, using only the class name to resolve conflicts, to get= it=E2=80=99s surrogate key, which is then used while inserting the related= event record linking that event record to the particular device class.=C2= =A0 Since device classes are rarely added, it will be the common case that = an actual INSERT is almost never performed.

&n= bsp;

Using INSERT ON CONFLICT in this case, h= owever, would mean the device class table, which would only ever hold a few= hundred records and would only require a SMALLINT for its surrogate key, w= ould have to have a BIGINT for no good reason, which really isn=E2=80=99t a= big deal. What IS the big deal is that the event table would also require = a BIGINT for the device class column to relate the event to the device clas= s. In most cases, there are many more =E2=80=98organizing=E2=80=99 columns,= similar to the device class in this example, meaning BIGINTs would have to= be used for no good reason within event tables, which can hold vast volume= s of data. This can have a real and measurable impact on memory, network, a= nd storage requirements, which eventually map to dollars.

 

This basic scenario is ve= ry common, and one that greatly benefits from UPSERT capability; i.e. linki= ng event data to organizational data. It=E2=80=99s much less common to have= to UPSERT into some event table; i.e. the INSERT part of UPSERTs is usuall= y the path less taken. I used the example of a shop floor with device class= es, but its the same issue for looking at orders by product hierarchies, co= mmissions by territories, stars by classification, web-page-hits by marketi= ng campaigns=E2=80=A6. I could list hundreds of processes within many probl= em domains that are of this same basic pattern.

 

My only point is, there= =E2=80=99s another great capability in Postgres, for doing efficient concur= rent UPSERTS, but that one of the most common and prime use cases for it is= going to cost more money from having to use 64bit numbers everywhere for n= o good reason.

 

 

 


From:= Andres Freund
Sent: Wednesday, January 6, 2016 11:19 AM
To: Paul Hester
Cc: Peter Geoghegan; pgsql= -bugs
Subject: Re: [BUGS] BUG #13846: INSERT ON CONFLICT cons= umes sequencers onconflicts

 

On 2016-01-05 22:04:41 -0700, Paul Hester wrote:<= /p>

> No peek-ahead necessary, when the sequenced co= lumn would not be used in the

> conflict_target.= UPSERTS to dimension tables in a star schema as part of an

> OLAP system are very handy, but typically the records in the = dimension

> tables use a surrogate key based on = sequences for maintenance & performance

> re= asons, and the 'natural' key/value is the only column that would be used

> to detect a conflict. In this case, the 'normal'= path would be the

> conflict_action nearly all = the time, and not the insert. If the typical

> p= ath was the INSERT, I'd bet the data would be from some event source, and

> I guess in that case if there were a key column= defaulted with a sequence,

> like an order#, it= would have to be used to resolve conflicts. But it's

> hard to imagine a case in a process flow where you wouldn't already= know if

> the event existed or not, limiting th= e need for an UPSERT on event data.

 

It'd be very fragile. You could only do that if = the value isn't involved

in any unique indexes, if = there are no BEFORE triggers (since they need

to se= e the value).

 

> This limitation, of consuming sequencers used for defaults on col= umns not

> necessary to resolve conflict, dimini= shes the viability for using Postges

> UPSERTS f= or large data warehouses, is all I'm saying (or requires surrogate

> keys being 64 bit). Just caught me by surprise in comp= arison to other

> RDBMSs offering some form of U= PSERTs that would not consume a sequencer if

> i= ts values weren't required to resolve conflicts.

 

If you use normal sequences you alr= eady need to cope with gaps in

sequences. And ids n= eeding to be 64bits if you're a longer lived

busine= ss and it's for a a halfway "popular" table, isn't something new.=

 

&nb= sp;

So I don't think addressing this is worth= adding code for, especially

given the fragility of= the situations where it'd be usable.

 

= --_6AF939D6-7F6F-4CFF-834D-196AD44A0FC1_--