Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rmRk1-007tqC-95 for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Mar 2024 05:10:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rmRjz-009f6c-7V for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Mar 2024 05:10:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rmRjy-009f6U-Rc for pgsql-hackers@lists.postgresql.org; Tue, 19 Mar 2024 05:10:23 +0000 Received: from mail-lf1-x12b.google.com ([2a00:1450:4864:20::12b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rmRjr-005GGO-7M for pgsql-hackers@postgresql.org; Tue, 19 Mar 2024 05:10:22 +0000 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-513e8bf8228so407517e87.1 for ; Mon, 18 Mar 2024 22:10:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710825014; x=1711429814; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=aMGkPZdcCInhUxhk9YQQR5PXJaBT1NmubG89QbwWfEI=; b=HiLSbs1j0u5r3ukCamqEvzXvtgTMBTplRHV5vD9zUdLkCM536Gbgf2Wr7xyKR1tkxp ROI+Ebd9tRHKy/C+PgASRiAP2XVqPsXyaf3U7TF8uyGpeI6I3a//1RrVl3kQ268UM7t2 jkbaN+yNAG1T3z0x77q8tWpF0rJkH2TXj5/rCW03fnnVOhRXS8MygwX0JyVpTNmPa8Us 3Viq5DEYySKcunzS7u6f+K48ZHSPeXDMqldRpxhoKf1YezPvUIQgyvIdiWl2xoOY26Am vdlIQ8x0AJ9FgqO9eanUUNhSEmo3c+DLMwgQFEFE81VrenmqP9zhYGFxW9AvJOG5/4u2 PGqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710825014; x=1711429814; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aMGkPZdcCInhUxhk9YQQR5PXJaBT1NmubG89QbwWfEI=; b=kO9rDRAZxPjGfrJGjdwqx8Joy98IS/ww7CAWdIINacqmkVn21UckmvVR6IRu/FV311 tKv63p+6NedR0VUfM+VLg/wKQ3RVH3LC5QmxH5XdOall8Ywt5YQX6dkuLobMLgTg0v5d J1+452EBn8xw07VC4UCojctZJ0itJwqJpvK/iURBaGtHs7Xs6L+zwfZqUsn2z6PArJ8v lK1O6jpqTCXDCV2V0X111a1s1UWVAKdXM1fAP14isV35U0D9H4yG3xBiRmv3uVnF+ONv mJoPSwCP0uUhosOc9Z4rdxz9/z2VP0jfaYv5v1xQC0JD1dLUex8YCrB3DEMsmOhDImGl xLOg== X-Gm-Message-State: AOJu0YxNh8NUQ7sAL5rkC7bCRmExoxc7hCx7W99bKNyiEsKG+MtmH4T1 Doth3joPSq+8qyg2AbFGdY6qzmXt3nztLC4dvseasDwthHORCCoD0yBFZiAjIOqGgYVXyIfgMNn DfJLgYmgiIOJJM4BUeEFLv1EvFNU= X-Google-Smtp-Source: AGHT+IEYKDbxzPNfiuH4qQbTkHPLakUPAYcencXym23Gi61WIfsLeLRZCN6oiXXA5DkglHyJ40CPrikYcNVma5E09B0= X-Received: by 2002:ac2:5058:0:b0:514:b446:f5d9 with SMTP id a24-20020ac25058000000b00514b446f5d9mr717844lfm.3.1710825013726; Mon, 18 Mar 2024 22:10:13 -0700 (PDT) MIME-Version: 1.0 References: <20230603223824.o7iyochli2dwwi7k@alap3.anarazel.de> In-Reply-To: From: Masahiko Sawada Date: Tue, 19 Mar 2024 14:09:36 +0900 Message-ID: Subject: Re: New Table Access Methods for Multi and Single Inserts To: Bharath Rupireddy Cc: PostgreSQL-development , Andres Freund , Dilip Kumar , Luc Vlaming , Justin Pryzby , Jeff Davis , Michael Paquier , Matthias van de Meent Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Fri, Mar 8, 2024 at 7:37=E2=80=AFPM Bharath Rupireddy wrote: > > On Sat, Mar 2, 2024 at 12:02=E2=80=AFPM Bharath Rupireddy > wrote: > > > > On Mon, Jan 29, 2024 at 5:16=E2=80=AFPM Bharath Rupireddy > > wrote: > > > > > > > Please find the attached v9 patch set. > > > > I've had to rebase the patches due to commit 874d817, please find the > > attached v11 patch set. > > Rebase needed. Please see the v12 patch set. > I've not reviewed the patches in depth yet, but run performance tests for CREATE MATERIALIZED VIEW. The test scenarios is: -- setup create unlogged table test (c int); insert into test select generate_series(1, 10000000); -- run create materialized view test_mv as select * from test; Here are the results: * HEAD 3775.221 ms 3744.039 ms 3723.228 ms * v12 patch 6289.972 ms 5880.674 ms 7663.509 ms I can see performance regressions and the perf report says that CPU spent most time on extending the ResourceOwner's array while copying the buffer-heap tuple: - 52.26% 0.18% postgres postgres [.] intorel_receive 52.08% intorel_receive table_multi_insert_v2 (inlined) - heap_multi_insert_v2 - 51.53% ExecCopySlot (inlined) tts_buffer_heap_copyslot tts_buffer_heap_store_tuple (inlined) - IncrBufferRefCount - ResourceOwnerEnlarge ResourceOwnerAddToHash (inlined) Is there any reason why we copy a buffer-heap tuple to another buffer-heap tuple? Which results in that we increments the buffer refcount and register it to ResourceOwner for every tuples. I guess that the destination tuple slot is not necessarily a buffer-heap, and we could use VirtualTupleTableSlot instead. It would in turn require copying a heap tuple. I might be missing something but it improved the performance at least in my env. The change I made was: - dstslot =3D table_slot_create(state->rel, NULL); + //dstslot =3D table_slot_create(state->rel, NULL); + dstslot =3D MakeTupleTableSlot(RelationGetDescr(state->rel), + &TTSOpsVirtual); + And the execution times are: 1588.984 ms 1591.618 ms 1582.519 ms Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com