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 1qnc0j-00BRNa-SF for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Oct 2023 09:48:13 +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 1qnc0i-003WPl-2z for pgsql-hackers@arkaria.postgresql.org; Tue, 03 Oct 2023 09:48:12 +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 1qnc0h-003WPN-O5 for pgsql-hackers@lists.postgresql.org; Tue, 03 Oct 2023 09:48:11 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qnc0f-007x88-Oy for pgsql-hackers@lists.postgresql.org; Tue, 03 Oct 2023 09:48:10 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-1dd830ed844so444468fac.2 for ; Tue, 03 Oct 2023 02:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696326489; x=1696931289; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=np/XDJ1yrwhQkiOlLmw2KZasDqKNOiscymrCXWo+x9c=; b=KzryKX/zudtOH+OyOq6bYJm9uhFH+JF2nOru14f713A4zP77JlVFsgdkcHK8xlLPfT VUm9IiDXbjMz6MCeRFhNTgA2DaGc2+34BKeNWqaieDsBAVceS/ToiBpoEIRv8xEHGaB+ h5VIa3wbmD8AD0gse32aReQJfx/dcsfSDkSLS613dx3+XhqnJokiSHWpoLHL8FUArF0h 1Fq5BsDpF9kGH0x01Ehaui+G6jbLl1mhRDHJEcDfXXbXnmx2Hlwl7Zuwu8JF9sBDvwj2 +0ffpIMZ+F6r4sO9ocAMtTHnTHvrtilLQZTb+YIjU58n/nn+v7H78YONb37Rqy4Yf9wy D/eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696326489; x=1696931289; h=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=np/XDJ1yrwhQkiOlLmw2KZasDqKNOiscymrCXWo+x9c=; b=c5mn6ZnZZdFZ2pvneaLzH07cuMF8779EpcAx8vV7HjW8afbDWoe1byz1fRHs1/oYvc MpB6Sou83SIJ8WOW7MDBsn/Dh/VNoxidkyLm7uR1FEX5EUMfdjXeObpLlVT4FiX5LqNJ AwQduzB70SoLkFwg805lwkr++zhwRImP/nxGT5T+H7UX6p3exOe6ibkrDoZtFpAkBLso eyNQPSDTFu1VDhDTA8EjNMNfl8SXpszM+JijA4cpkqxBZvddL535Ve1fUp5hGaHr2Lf/ DWww3yZ16LdYJFtxKyufTR3d2XBsfliGRLIW8V3CUdFWX+9jZaYTuYhnZSyOFkPDYW0x z9MQ== X-Gm-Message-State: AOJu0YxUaowlffkbW6UDtkj5LHn7XVpOhQEH1ABXf1cHN78gUIZ40baH 9AI6Itb7u7w+kVG813bfvvbSOANNYq+31kLGroQ= X-Google-Smtp-Source: AGHT+IFYwpmKzZ2xHaX6/ahI6TPs0Eqm6fEEN6I3WTVQFOVx2cy0jlRbd3LQblZiVMsOty5EAGPcpI0hgSxmAimKFzM= X-Received: by 2002:a05:6870:ea95:b0:1d6:56d8:a787 with SMTP id s21-20020a056870ea9500b001d656d8a787mr15410611oap.11.1696326488962; Tue, 03 Oct 2023 02:48:08 -0700 (PDT) MIME-Version: 1.0 References: <2656000.KRxA6XjA2N@peanuts2> <20230918215247.GA2661288@nathanxps13> <20230918215442.GB2661288@nathanxps13> <2575263.Lt9SDvczpP@peanuts2> In-Reply-To: <2575263.Lt9SDvczpP@peanuts2> From: vignesh C Date: Tue, 3 Oct 2023 15:17:57 +0530 Message-ID: Subject: Re: Improvements in pg_dump/pg_restore toc format and performances To: Pierre Ducroquet Cc: Nathan Bossart , pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 19 Sept 2023 at 15:46, Pierre Ducroquet wrote: > > On Monday, September 18, 2023 11:54:42 PM CEST Nathan Bossart wrote: > > On Mon, Sep 18, 2023 at 02:52:47PM -0700, Nathan Bossart wrote: > > > On Thu, Jul 27, 2023 at 10:51:11AM +0200, Pierre Ducroquet wrote: > > >> I ended up writing several patches that shaved some time for pg_restore > > >> -l, > > >> and reduced the toc.dat size. > > > > > > I've only just started taking a look at these patches, and I intend to do > > > a > > > more thorough review in the hopefully-not-too-distant future. > > > > Since cfbot is failing on some pg_upgrade and pg_dump tests, I've set this > > to waiting-on-author. > > Attached updated patches fix this regression, I'm sorry I missed that. Few comments: 1) These printf statements are not required: + /* write the list of am */ + printf("%d tableams to save\n", tableam_count); + WriteInt(AH, tableam_count); + for (i = 0 ; i < tableam_count ; i++) + { + printf("%d is %s\n", i, tableams[i]); + WriteStr(AH, tableams[i]); + } + + /* write the list of namespaces */ + printf("%d namespaces to save\n", namespace_count); + WriteInt(AH, namespace_count); + for (i = 0 ; i < namespace_count ; i++) + { + printf("%d is %s\n", i, namespaces[i]); + WriteStr(AH, namespaces[i]); + } + + /* write the list of owners */ + printf("%d owners to save\n", owner_count); 2) We generally use pg_malloc in client tools, we should change palloc to pg_malloc: + /* prepare dynamic arrays */ + tableams = palloc(sizeof(char*) * 1); + tableams[0] = NULL; + tableam_count = 0; + namespaces = palloc(sizeof(char*) * 1); + namespaces[0] = NULL; + namespace_count = 0; + owners = palloc(sizeof(char*) * 1); + owners[0] = NULL; + owner_count = 0; + tablespaces = palloc(sizeof(char*) * 1); 3) This similar code is repeated few times, will it be possible to do it in a common function: + if (namespace_count < 128) + { + te->namespace_idx = AH->ReadBytePtr(AH); + invalid_entry = 255; + } + else + { + te->namespace_idx = ReadInt(AH); + invalid_entry = -1; + } + if (te->namespace_idx == invalid_entry) + te->namespace = ""; + else + te->namespace = namespaces[te->namespace_idx]; 4) Can the initialization of tableam_count, namespace_count, owner_count and tablespace_count be done at declaration and these initialization code can be removed: + /* prepare dynamic arrays */ + tableams = palloc(sizeof(char*) * 1); + tableams[0] = NULL; + tableam_count = 0; + namespaces = palloc(sizeof(char*) * 1); + namespaces[0] = NULL; + namespace_count = 0; + owners = palloc(sizeof(char*) * 1); + owners[0] = NULL; + owner_count = 0; + tablespaces = palloc(sizeof(char*) * 1); + tablespaces[0] = NULL; + tablespace_count = 0; 4) There are some whitespace issues in the patch: Applying: move static strings to arrays at beginning .git/rebase-apply/patch:24: trailing whitespace. .git/rebase-apply/patch:128: trailing whitespace. .git/rebase-apply/patch:226: trailing whitespace. .git/rebase-apply/patch:232: trailing whitespace. warning: 4 lines add whitespace errors. Regards, Vignesh