pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14027: n_tup_ins increments regardless of insertion success
4+ messages / 4 participants
[nested] [flat]

* BUG #14027: n_tup_ins increments regardless of insertion success
@ 2016-03-16 21:59  matvejchikov@gmail.com
  0 siblings, 1 reply; 4+ messages in thread

From: matvejchikov@gmail.com @ 2016-03-16 21:59 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      14027
Logged by:          Ilya Matveychikov
Email address:      matvejchikov@gmail.com
PostgreSQL version: 9.5.1
Operating system:   Linux
Description:        

postgres=# create table t (name text unique);
postgres=# select n_tup_ins from pg_stat_user_tables where relname='t';
 n_tup_ins 
-----------
         0
postgres=# insert into t (name) values ('a');
INSERT 0 1
postgres=# select n_tup_ins from pg_stat_user_tables where relname='t';
 n_tup_ins 
-----------
         1
postgres=# insert into t (name) values ('b');
INSERT 0 1
postgres=# select n_tup_ins from pg_stat_user_tables where relname='t';
 n_tup_ins 
-----------
         2
postgres=# insert into t (name) values ('a');
ОШИБКА:  повторяющееся значение ключа нарушает ограничение уникальности
"t_name_key"
ПОДРОБНОСТИ:  Ключ "(name)=(a)" уже существует.
postgres=# select n_tup_ins from pg_stat_user_tables where relname='t';
 n_tup_ins 
-----------
         3



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #14027: n_tup_ins increments regardless of insertion success
@ 2016-03-18 22:08  Vik Fearing <vik@2ndquadrant.fr>
  parent: matvejchikov@gmail.com
  0 siblings, 1 reply; 4+ messages in thread

From: Vik Fearing @ 2016-03-18 22:08 UTC (permalink / raw)
  To: matvejchikov@gmail.com; pgsql-bugs

On 03/16/2016 11:59 PM, matvejchikov@gmail.com wrote:
> The following bug has been logged on the website:
> 
> Bug reference:      14027
> Logged by:          Ilya Matveychikov
> Email address:      matvejchikov@gmail.com
> PostgreSQL version: 9.5.1
> Operating system:   Linux
> Description:        
> 
> postgres=# create table t (name text unique);
> postgres=# select n_tup_ins from pg_stat_user_tables where relname='t';
>  n_tup_ins 
> -----------
>          0
> postgres=# insert into t (name) values ('a');
> INSERT 0 1
> postgres=# select n_tup_ins from pg_stat_user_tables where relname='t';
>  n_tup_ins 
> -----------
>          1
> postgres=# insert into t (name) values ('b');
> INSERT 0 1
> postgres=# select n_tup_ins from pg_stat_user_tables where relname='t';
>  n_tup_ins 
> -----------
>          2
> postgres=# insert into t (name) values ('a');
> ОШИБКА:  повторяющееся значение ключа нарушает ограничение уникальности
> "t_name_key"
> ПОДРОБНОСТИ:  Ключ "(name)=(a)" уже существует.
> postgres=# select n_tup_ins from pg_stat_user_tables where relname='t';
>  n_tup_ins 
> -----------
>          3

This is not a bug, there are three rows inserted into the table, you
just can't see the third.

Try this:

create extension pageinspect;
select * from heap_page_items(get_raw_page('t', 0));

and you will see the three rows.
-- 
Vik Fearing                                          +33 6 46 75 15 36
http://2ndQuadrant.fr     PostgreSQL : Expertise, Formation et Support


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #14027: n_tup_ins increments regardless of insertion success
@ 2016-03-19 01:08  David G. Johnston <david.g.johnston@gmail.com>
  parent: Vik Fearing <vik@2ndquadrant.fr>
  0 siblings, 1 reply; 4+ messages in thread

From: David G. Johnston @ 2016-03-19 01:08 UTC (permalink / raw)
  To: Vik Fearing <vik@2ndquadrant.fr>; +Cc: pgsql-bugs

On Fri, Mar 18, 2016 at 3:08 PM, Vik Fearing <vik@2ndquadrant.fr> wrote:

> On 03/16/2016 11:59 PM, matvejchikov@gmail.com wrote:
> > The following bug has been logged on the website:
> >
> > Bug reference:      14027
> > Logged by:          Ilya Matveychikov
> > Email address:      matvejchikov@gmail.com
> > PostgreSQL version: 9.5.1
> > Operating system:   Linux
> > Description:
> >
> > postgres=# create table t (name text unique);
> > postgres=# select n_tup_ins from pg_stat_user_tables where relname='t';
> >  n_tup_ins
> > -----------
> >          0
> > postgres=# insert into t (name) values ('a');
> > INSERT 0 1
> > postgres=# select n_tup_ins from pg_stat_user_tables where relname='t';
> >  n_tup_ins
> > -----------
> >          1
> > postgres=# insert into t (name) values ('b');
> > INSERT 0 1
> > postgres=# select n_tup_ins from pg_stat_user_tables where relname='t';
> >  n_tup_ins
> > -----------
> >          2
> > postgres=# insert into t (name) values ('a');
> > ОШИБКА:  повторяющееся значение ключа нарушает ограничение уникальности
> > "t_name_key"
> > ПОДРОБНОСТИ:  Ключ "(name)=(a)" уже существует.
> > postgres=# select n_tup_ins from pg_stat_user_tables where relname='t';
> >  n_tup_ins
> > -----------
> >          3
>
> This is not a bug, there are three rows inserted into the table, you
> just can't see the third.
>
> Try this:
>
> create extension pageinspect;
> select * from heap_page_items(get_raw_page('t', 0));
>
> and you will see the three rows.
>

​To help explain why - consider that PostgreSQL is basically optimistic in
its behavior.  It writes out data expecting that the various constraints
are going to succeed and that the transaction as a whole will be
committed.  If at any point the written data is deemed to be invalid it is
marked as have been (for practical purposes) "deleted"​

​just as if you had done an SQL DELETE on a valid record.  Its just that in
this instance the data in question was never visible outside of its
transaction.  It is, however, physically present and thus eligible for
vacuum and contributes to the statistics of the database.

David J.

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #14027: n_tup_ins increments regardless of insertion success
@ 2016-03-19 10:16  Ilya Matveychikov <matvejchikov@gmail.com>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Ilya Matveychikov @ 2016-03-19 10:16 UTC (permalink / raw)
  To: David G. Johnston <david.g.johnston@gmail.com>; +Cc: Vik Fearing <vik@2ndquadrant.fr>; pgsql-bugs

2016-03-19 4:08 GMT+03:00 David G. Johnston <david.g.johnston@gmail.com>:

> To help explain why - consider that PostgreSQL is basically optimistic in
> its behavior.  It writes out data expecting that the various constraints are
> going to succeed and that the transaction as a whole will be committed.  If
> at any point the written data is deemed to be invalid it is marked as have
> been (for practical purposes) "deleted"
>
> just as if you had done an SQL DELETE on a valid record.  Its just that in
> this instance the data in question was never visible outside of its
> transaction.  It is, however, physically present and thus eligible for
> vacuum and contributes to the statistics of the database.

David, thanks for the explanation. Now that's clear to me.


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2016-03-19 10:16 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-03-16 21:59 BUG #14027: n_tup_ins increments regardless of insertion success matvejchikov@gmail.com
2016-03-18 22:08 ` Vik Fearing <vik@2ndquadrant.fr>
2016-03-19 01:08   ` David G. Johnston <david.g.johnston@gmail.com>
2016-03-19 10:16     ` Ilya Matveychikov <matvejchikov@gmail.com>

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