Incorrect accounting (n_tup_ins) of non-inserted rows

Поиск
Список
Период
Сортировка
От Ilya Matveychikov
Тема Incorrect accounting (n_tup_ins) of non-inserted rows
Дата
Msg-id CAKh5nabvJBwQaXAMJ833zzY6dDBv4UZJwddhKzEt7wCKh+g_BA@mail.gmail.com
обсуждение исходный текст
Ответы Re: Incorrect accounting (n_tup_ins) of non-inserted rows  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
Hello,

Seems that accounting of insertions with `n_tup_ins` not correct in
case of insertion errors cause by constraints checking (duplicate key
value violates unique constraint):

EXAMPLE:

postgres=# create table t(name text unique);
CREATE TABLE
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');
ERROR:  duplicate key value violates unique constraint "t_name_key"
DETAIL:  Key (name)=(a) already exists.
postgres=# SELECT n_tup_ins FROM pg_stat_user_tables WHERE relname='t';
 n_tup_ins
-----------
         3

 name
------
 a
 b

CODE REFERENCE (src/backend/postmaster/pgstat.c)

/* count attempted actions regardless of commit/abort */
tabstat->t_counts.t_tuples_inserted += trans->tuples_inserted;
tabstat->t_counts.t_tuples_updated += trans->tuples_updated;
tabstat->t_counts.t_tuples_deleted += trans->tuples_deleted;


So, is this behavior normal or probably needs to be fixed?

--
Ilya Matveychikov

В списке pgsql-bugs по дате отправления:

Предыдущее
От: Dmitriy Sarafannikov
Дата:
Сообщение: Re: Too many files in pg_replslot folder
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Incorrect accounting (n_tup_ins) of non-inserted rows