Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aGsOK-0000HW-Qr for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Jan 2016 18:01:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aGsOJ-0005Oq-Pz for pgsql-bugs@arkaria.postgresql.org; Wed, 06 Jan 2016 18:00:59 +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 1aGVOM-0004aL-If for pgsql-bugs@postgresql.org; Tue, 05 Jan 2016 17:27:30 +0000 Received: from mail-oi0-x230.google.com ([2607:f8b0:4003:c06::230]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1aGVOJ-0004LA-3Z for pgsql-bugs@postgresql.org; Tue, 05 Jan 2016 17:27:28 +0000 Received: by mail-oi0-x230.google.com with SMTP id l9so250406076oia.2 for ; Tue, 05 Jan 2016 09:27:26 -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=agoZqgscJYg6g9Zp8WjKOt3r9cfGUXsos50Wsx9M/Lg=; b=i6Ll2Zioviklk+PGYSWXHa8ZySI/4vMP+DWHLRp0ejOqRYrWgIEeu9FZgrMsLApRbU PvMO2i7NTP0GFsC3LjGnCtdgkRykxAgWMVs2UQjGBgENB3KxpgUOgY8kkFvtcWeSm6/4 8T0FFYpUO84v/9oN5Jz/qAKHn0Q8wCpicJv6M= 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=agoZqgscJYg6g9Zp8WjKOt3r9cfGUXsos50Wsx9M/Lg=; b=EVlM0sXCI8PFVmehQI4PqjQAQMb+/4lQX8P7TlQk42vmNOlW0diiifiaJ0ZpFLy08E cLLO7yvE8xxovAE3noYPSAHMcZwCLWrIHcZznNVhePb/ZLnXyL//uZgZlGXI3188xKTD tAZ9S1q+CLSQ0gIW8SaHRENYP3yjXLUadSi70BDwJz927KNI8mJ9VHVvaISAs85+n/zN pmmv8LHtLXHMNBmm4B4r6YLLw19X15/+5DCFYvJhQDTooGVkakDv9zDbzIUFbA4fRyWU wODp5+nuJhXX9dlyi3Xy6KXPbi5qamm/Fir38jrWrN/aPRX3BJwtpOKLCtbuy2ggMW8F 5jRw== X-Gm-Message-State: ALoCoQkHey7DeUIbmYIaYH/MW8+HhEhENOunKLCrXD5MZn9FRb7J1XtY8UqbzHsfrYwl7n5QSORI4H3GPTeKESfYPQFocm9vUQ== X-Received: by 10.202.90.132 with SMTP id o126mr56673981oib.17.1452014845764; Tue, 05 Jan 2016 09:27:25 -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 a65sm7799253oih.14.2016.01.05.09.27.23 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 05 Jan 2016 09:27:24 -0800 (PST) Message-ID: <568bfcfc.44e3ca0a.c02a8.ffffbdec@mx.google.com> MIME-Version: 1.0 To: Andres Freund Cc: "pgsql-bugs@postgresql.org" From: Paul Subject: Re: BUG #13846: INSERT ON CONFLICT consumes sequencers onconflicts Date: Tue, 5 Jan 2016 10:27:22 -0700 Importance: normal X-Priority: 3 In-Reply-To: <20160105161326.GD7650@awork2.anarazel.de> References: <20160105150227.1117.51692@wrigleys.postgresql.org> <20160105161326.GD7650@awork2.anarazel.de> Content-Type: multipart/alternative; boundary="_2B744780-1ECB-428B-B2ED-06A12FAD7B07_" 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 --_2B744780-1ECB-428B-B2ED-06A12FAD7B07_ Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If none of the columns with defaults are used to detect conflicts, why must= they be evaluated before conflict detection in order to reliably detect a = conflict? Lots of systems categorize information into =E2=80=98organizational=E2=80= =99 data that may be hierarchical in nature and fairly static, in relation = to the other =E2=80=98operational=E2=80=99 kind of data, which is usually g= enerated from events; those events being organized by the former for batchi= ng and reporting purposes, etc. It is often the case UPSERTS are most usefu= l when deriving the organizational data from the operational data, meaning = a very typical usage of an UPSERT would have many more updates than inserts= , in direct correlation to the number of events being processed. Its not un= reasonable over a relatively short period of time (within the overall lifet= ime of a particular system) to process billions of events, meaning SERIAL t= yped columns used as surrogate keys to the natural keys of organizational d= ata could exhaust their sequencers for no good reason, and SMALLSERIAL just= wouldn=E2=80=99t be usable, BIGSERIAL could work, but they=E2=80=99re, uhm= .. BIG. There should be a way to not evaluate defaulted columns not used in the con= flict_target, so that SERIAL typed columns not used for conflict detection = don=E2=80=99t unnecessary exhaust their sequencers=E2=80=A6. (I think that = was like a quadruple-negative sentence there=E2=80=A6, sorry about that) Regards, Paul From: Andres Freund Sent: Tuesday, January 5, 2016 9:13 AM To: paul@salesintel.com Cc: pgsql-bugs@postgresql.org Subject: Re: [BUGS] BUG #13846: INSERT ON CONFLICT consumes sequencers onco= nflicts On 2016-01-05 15:02:27 +0000, paul@salesintel.com wrote: > The following bug has been logged on the website: >=20 > Bug reference: 13846 > Logged by: Paul Hester > Email address: paul@salesintel.com > PostgreSQL version: 9.5rc1 > Operating system: Windows 10 Pro > Description: =20 >=20 > When using an INSERT statement with an ON CONFLICT clause, if there is a > conflict, and the table being inserted into has a column defaulted to > nextval('seq'), the sequencer 'seq' is always incremented. This can quick= ly > and artificially consume all values of the sequencer; it behaves as if > conflict detection happens after inserts are attempted, rather than befor= e. Yes. That's by design. You can't reliably do conflict detection before evaluating column default values. Andres Freund --_2B744780-1ECB-428B-B2ED-06A12FAD7B07_ Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="utf-8"

If none of the columns with defaults= are used to detect conflicts, why must they be evaluated before conflict d= etection in order to reliably detect a conflict?

 

Lots of systems categorize informat= ion into =E2=80=98organizational=E2=80=99 data that may be hierarchical in = nature and fairly static, in relation to the other =E2=80=98operational=E2= =80=99 kind of data, which is usually generated from events; those events b= eing organized by the former for batching and reporting purposes, etc. It i= s often the case UPSERTS are most useful when deriving the organizational d= ata from the operational data, meaning a very typical usage of an UPSERT wo= uld have many more updates than inserts, in direct correlation to the numbe= r of events being processed. Its not unreasonable over a relatively short p= eriod of time (within the overall lifetime of a particular system) to proce= ss billions of events, meaning SERIAL typed columns used as surrogate keys = to the natural keys of organizational data could exhaust their sequencers f= or no good reason, and SMALLSERIAL just wouldn=E2=80=99t be usable, BIGSERI= AL could work, but they=E2=80=99re, uhm.. BIG.

 

There should be a way to n= ot evaluate defaulted columns not used in the conflict_target, so that SERI= AL typed columns not used for conflict detection don=E2=80=99t unnecessary = exhaust their sequencers=E2=80=A6. (I think that was like a quadruple-negat= ive sentence there=E2=80=A6, sorry about that)

 

Regards,

Paul=

From: Andres Freund
Sent: Tuesday, January 5, 2016 9:13 AM
To: paul@salesintel.com
Cc: pgsql-bugs@postgresql.org
Subject: = Re: [BUGS] BUG #13846: INSERT ON CONFLICT consumes sequencers onconflic= ts

 

On 2016-01-05 15:02:27 +0000, paul@salesintel.com wrote:

> The following bug has been logged on the website:

>

> Bug reference:=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 13846

> Logged by:=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Paul Hester

> Email address:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 paul@salesintel.co= m

> PostgreSQL version: 9.5rc1

> Operating system:=C2=A0=C2=A0 Windows 10 Pro

> Description:=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0

>

> When using an INSERT sta= tement with an ON CONFLICT clause, if there is a

&g= t; conflict, and the table being inserted into has a column defaulted to

> nextval('seq'), the sequencer 'seq' is always in= cremented. This can quickly

> and artificially c= onsume all values of the sequencer; it behaves as if

> conflict detection happens after inserts are attempted, rather than = before.

 

Y= es. That's by design. You can't reliably do conflict detection before

evaluating column default values.

 

Andres Freund

 

= --_2B744780-1ECB-428B-B2ED-06A12FAD7B07_--