pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andres Freund <andres@anarazel.de>
To: Marco Nenciarini <marco.nenciarini@2ndquadrant.it>
Cc: Petr Jelinek <petr.jelinek@2ndquadrant.com>
Cc: Thomas Munro <thomas.munro@enterprisedb.com>
Cc: Simon Riggs <simon@2ndquadrant.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: [PATCH] Logical decoding of TRUNCATE
Date: Sun, 1 Apr 2018 13:01:07 -0700
Message-ID: <20180401200107.gjpehuqy63efechn@alap3.anarazel.de> (raw)
In-Reply-To: <372b6f96-8415-912a-de72-ec5f54ad677f@2ndquadrant.it>
References: <1cb9bd52-9e3a-21bf-0c0c-afa90f463629@2ndquadrant.com>
	<f6352c33-f3e3-0e35-dbd2-29949b9c2b59@2ndquadrant.com>
	<de2a9d73-1e25-797c-03f8-9faa57f75e85@2ndquadrant.it>
	<ffb116ef-a072-2b9b-dd92-e288dbfa0f6c@2ndquadrant.com>
	<0361327b-5d59-32b0-cb13-e844acf0f0d0@2ndquadrant.it>
	<31773cc5-3b29-1740-e7d2-dc48e80a06ce@2ndquadrant.com>
	<fde57e23-9828-8741-bb60-2b2d9e4ad55a@2ndquadrant.it>
	<CAEepm=0AP2-z05GCxz0yTvtG3uW+gdZkZqW1EY97Sdy_G6tA5w@mail.gmail.com>
	<8ef5c78a-1e98-dce5-82f7-bd0f6eba92e5@2ndquadrant.com>
	<372b6f96-8415-912a-de72-ec5f54ad677f@2ndquadrant.it>

On 2018-01-25 14:21:15 +0100, Marco Nenciarini wrote:
> + 	if (SessionReplicationRole != SESSION_REPLICATION_ROLE_REPLICA)
> + 	{
> + 
> + 		/*
> + 		 * Check foreign key references.  In CASCADE mode, this should be
> + 		 * unnecessary since we just pulled in all the references; but as a
> + 		 * cross-check, do it anyway if in an Assert-enabled build.
> + 		 */
>   #ifdef USE_ASSERT_CHECKING
>   		heap_truncate_check_FKs(rels, false);
> + #else
> + 		if (stmt->behavior == DROP_RESTRICT)
> + 			heap_truncate_check_FKs(rels, false);
>   #endif
> + 	}

That *can't* be right.

> + 		case REORDER_BUFFER_CHANGE_TRUNCATE:
> + 			appendStringInfoString(ctx->out, " TRUNCATE:");
> + 
> + 			if (change->data.truncate_msg.restart_seqs
> + 				|| change->data.truncate_msg.cascade)
> + 			{
> + 				if (change->data.truncate_msg.restart_seqs)
> + 					appendStringInfo(ctx->out, " restart_seqs");
> + 				if (change->data.truncate_msg.cascade)
> + 					appendStringInfo(ctx->out, " cascade");
> + 			}
> + 			else
> + 				appendStringInfoString(ctx->out, " (no-flags)");
> + 			break;
>   		default:
>   			Assert(false);
>   	}

I know this has been discussed in the thread already, but it really
strikes me as wrong to basically do some mini DDL replication feature
via per-command WAL records.
> ***************
> *** 111,116 **** CREATE PUBLICATION <replaceable class="parameter">name</replaceable>
> --- 111,121 ----
>             and so the default value for this option is
>             <literal>'insert, update, delete'</literal>.
>            </para>
> +          <para>
> +            <command>TRUNCATE</command> is treated as a form of
> +            <command>DELETE</command> for the purpose of deciding whether
> +            to publish, or not.
> +          </para>
>           </listitem>
>          </varlistentry>
>         </variablelist>

Why is this a good idea?


Hm, it seems logicaldecoding.sgml hasn't been updated?

> + void
> + ExecuteTruncateGuts(List *explicit_rels, List *relids, List *relids_logged,
> + 							DropBehavior behavior, bool restart_seqs)
> + {
> + 	List	   *rels = list_copy(explicit_rels);

Why is this copied?


> + 	 * Write a WAL record to allow this set of actions to be logically decoded.
> + 	 * We could optimize this away when !RelationIsLogicallyLogged(rel)
> + 	 * but that doesn't save much space or time.

What you're saying isn't that you're not logging anything, but that
you're allocating the header regardless? Because this certainly sounds
like you unconditionally log a WAL record.

> + 	 * Assemble an array of relids, then an array of seqrelids so we can write
> + 	 * a single WAL record for the whole action.
> + 	 */
> + 	logrelids = palloc(maxrelids * sizeof(Oid));
> + 	foreach (cell, relids_logged)
> + 	{
> + 		nrelids++;
> + 		if (nrelids > maxrelids)
> + 		{
> + 			maxrelids *= 2;
> + 			logrelids = repalloc(logrelids, maxrelids * sizeof(Oid));
> + 		}
> + 		logrelids[nrelids - 1] = lfirst_oid(cell);
> + 	}
> + 
> + 	foreach (cell, seq_relids_logged)
> + 	{
> + 		nseqrelids++;
> + 		if ((nrelids + nseqrelids) > maxrelids)
> + 		{
> + 			maxrelids *= 2;
> + 			logrelids = repalloc(logrelids, maxrelids * sizeof(Oid));
> + 		}
> + 		logrelids[nrelids + nseqrelids - 1] = lfirst_oid(cell);
> + 	}

I'm confused. Why do we need the resizing here, when we know the max
upfront?

> + /*
> +  * For truncate we list all truncated relids in an array, followed by all
> +  * sequence relids that need to be restarted, if any.
> +  * All rels are always within the same database, so we just list dbid once.
> +  */
> + typedef struct xl_heap_truncate
> + {
> + 	Oid			dbId;
> + 	uint32		nrelids;
> + 	uint32		nseqrelids;
> + 	uint8		flags;
> + 	Oid relids[FLEXIBLE_ARRAY_MEMBER];
> + } xl_heap_truncate;

Given that the space is used anyway due to padding, I'd just make flags
32bit.

Greetings,

Andres Freund




view thread (48+ messages)  latest in thread

Message-ID: <20180401200107.gjpehuqy63efechn@alap3.anarazel.de>
Permalink:  ../20180401200107.gjpehuqy63efechn@alap3.anarazel.de/
Also on:    postgresql.org/message-id/20180401200107.gjpehuqy63efechn@alap3.anarazel.de

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: andres@anarazel.de, marco.nenciarini@2ndquadrant.it, petr.jelinek@2ndquadrant.com, thomas.munro@enterprisedb.com, simon@2ndquadrant.com, pgsql-hackers@postgresql.org
  Subject: Re: [PATCH] Logical decoding of TRUNCATE
  In-Reply-To: <20180401200107.gjpehuqy63efechn@alap3.anarazel.de>
  References: <1cb9bd52-9e3a-21bf-0c0c-afa90f463629@2ndquadrant.com> <f6352c33-f3e3-0e35-dbd2-29949b9c2b59@2ndquadrant.com> <de2a9d73-1e25-797c-03f8-9faa57f75e85@2ndquadrant.it> <ffb116ef-a072-2b9b-dd92-e288dbfa0f6c@2ndquadrant.com> <0361327b-5d59-32b0-cb13-e844acf0f0d0@2ndquadrant.it> <31773cc5-3b29-1740-e7d2-dc48e80a06ce@2ndquadrant.com> <fde57e23-9828-8741-bb60-2b2d9e4ad55a@2ndquadrant.it> <CAEepm=0AP2-z05GCxz0yTvtG3uW+gdZkZqW1EY97Sdy_G6tA5w@mail.gmail.com> <8ef5c78a-1e98-dce5-82f7-bd0f6eba92e5@2ndquadrant.com> <372b6f96-8415-912a-de72-ec5f54ad677f@2ndquadrant.it> <20180401200107.gjpehuqy63efechn@alap3.anarazel.de>

* 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