pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: boekewurm+postgres@gmail.com
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16818: progress reporting ALTER TABLE ADD UNIQUE
Date: Mon, 11 Jan 2021 18:13:13 -0300
Message-ID: <20210111211313.GA25789@alvherre.pgsql> (raw)
In-Reply-To: <16818-4313f4b1612e09d7@postgresql.org>

On 2021-Jan-11, PG Bug reporting form wrote:

> The progress reprorting for `ALTER TABLE test ADD UNIQUE (col)` is in
> `pg_stat_progress_create_index`. As it indeed creates an index, that is not
> too unexpected, but the `command` column of that view reports `CREATE
> INDEX`, and _that_ is somewhat unexpected. A reasonable expectation would be
> `ALTER TABLE ADD CONSTRAINT` or comparable. 

Hmm, seems a reasonable complaint.  Are there other command wordings
that would need to be handled?  I can't think of any (but I already
overlooked this one, evidently ...)

This seems fixed easily, in a way -- we'd need to set a distinct value
to the PROGRESS_CREATEIDX_COMMAND param when ALTER TABLE ADD; currently
possible values are in progress.h:

/* Commands of PROGRESS_CREATEIDX */
#define PROGRESS_CREATEIDX_COMMAND_CREATE		1
#define PROGRESS_CREATEIDX_COMMAND_CREATE_CONCURRENTLY	2
#define PROGRESS_CREATEIDX_COMMAND_REINDEX		3
#define PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY	4

The problem is that we'd need to change system_view.sql to recognize the
new value, and we can't change that on existing systems.  If we fail to
adjust that view definition, the column will show NULL when the command
is ALTER TABLE ADD.

Something like the attached patch, but I haven't tried to compile it
yet.  Probably need docs adjustments also.


(Also: I don't see we set
PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY anywhere ... an
oversight?)

-- 
Álvaro Herrera

Attachments:

alter-table-add-progress.patch (text/x-diff, 2.0K) download commit adce17b33253a42c7e60f17c50698facfa7bd729 Author: Alvaro Herrera <alvherre@alvh.no-ip.org> AuthorDate: Mon Jan 11 18:11:04 2021 -0300 CommitDate: Mon Jan 11 18:11:04 2021 -0300 First attempt at handling ALTER TABLE ADD in create index progress reporting diff --git a/src/backend/catalog/system_views.sql b/src/backend/catalog/system_views.sql index 5d89e77dbe..7892988570 100644 --- a/src/backend/catalog/system_views.sql +++ b/src/backend/catalog/system_views.sql @@ -1075,6 +1075,7 @@ CREATE VIEW pg_stat_progress_create_index AS WHEN 2 THEN 'CREATE INDEX CONCURRENTLY' WHEN 3 THEN 'REINDEX' WHEN 4 THEN 'REINDEX CONCURRENTLY' + WHEN 5 THEN 'ALTER TABLE ADD CONSTRAINT' END AS command, CASE S.param10 WHEN 0 THEN 'initializing' WHEN 1 THEN 'waiting for writers before build' diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 992f4813b4..0a72b10b0d 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -575,6 +575,8 @@ DefineIndex(Oid relationId, pgstat_progress_start_command(PROGRESS_COMMAND_CREATE_INDEX, relationId); pgstat_progress_update_param(PROGRESS_CREATEIDX_COMMAND, + is_alter_table ? + PROGRESS_CREATEIDX_COMMAND_ALTER_TABLE_ADD : concurrent ? PROGRESS_CREATEIDX_COMMAND_CREATE_CONCURRENTLY : PROGRESS_CREATEIDX_COMMAND_CREATE); diff --git a/src/include/commands/progress.h b/src/include/commands/progress.h index 95ec5d02e9..54e68a2ba0 100644 --- a/src/include/commands/progress.h +++ b/src/include/commands/progress.h @@ -109,6 +109,7 @@ #define PROGRESS_CREATEIDX_COMMAND_CREATE_CONCURRENTLY 2 #define PROGRESS_CREATEIDX_COMMAND_REINDEX 3 #define PROGRESS_CREATEIDX_COMMAND_REINDEX_CONCURRENTLY 4 +#define PROGRESS_CREATEIDX_COMMAND_ALTER_TABLE_ADD 5 /* Lock holder wait counts */ #define PROGRESS_WAITFOR_TOTAL 3

view thread (3+ messages)  latest in thread

Message-ID: <20210111211313.GA25789@alvherre.pgsql>
Permalink:  ../20210111211313.GA25789@alvherre.pgsql/
Also on:    postgresql.org/message-id/20210111211313.GA25789@alvherre.pgsql

 ·  · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: alvherre@alvh.no-ip.org, boekewurm+postgres@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16818: progress reporting ALTER TABLE ADD UNIQUE
  In-Reply-To: <20210111211313.GA25789@alvherre.pgsql>

* 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