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 1sRfRB-00Havy-8g for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jul 2024 22:05:21 +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 1sRfR8-009LWx-4H for pgsql-hackers@arkaria.postgresql.org; Wed, 10 Jul 2024 22:05:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sRfR7-009LUE-QK for pgsql-hackers@lists.postgresql.org; Wed, 10 Jul 2024 22:05:17 +0000 Received: from mail-io1-xd32.google.com ([2607:f8b0:4864:20::d32]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sRfR5-001SKg-K8 for pgsql-hackers@postgresql.org; Wed, 10 Jul 2024 22:05:17 +0000 Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-7f9be1f6cdbso14327539f.1 for ; Wed, 10 Jul 2024 15:05:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720649113; x=1721253913; darn=postgresql.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=VQZm8DA430gQZekWy9L75aEW91TvjhbXa4O5sfdIVAA=; b=FBcz76Ntm3j6Bob/xDzdaDAPa06ZUlJ3QvQJ/yURXJF+ITm6Jsd8AGuoHcjN6M0cFV FDfnQp/DAAMm396PKlcM3yqE8A3axa/mTFKMSMwgnpDC3iOtAyD/mu/hZ6cFX0DjrQiO bh3WBhy9yCHx0+PogrJOTZxkJknR/a6xroXKrEqw/KkJXaMq42vTrPUJufi5D9gs1Alk lNeXv7ElLYJiFZdxG4gjUJe/3ph6K/vExIgd+RFFo3Qj22El/wCgxL656dqB7ovkz9Nz dTT++0NF5Qu8kXuzX8ieWrswxkSdU4cHmBmK5OcQfjk+8jgIwDrqP+hVOyF971Xt7QPA CJ4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720649113; x=1721253913; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=VQZm8DA430gQZekWy9L75aEW91TvjhbXa4O5sfdIVAA=; b=XRqoTYz2u7bG41iY8kHeVjqKodGhflUInD0RuD1k1qjkOw5AQrqHSO9NPnEUZVfHdf 8wmOicGjJvl38TvwY8zaf/rDOP4daD6EPRRSucqYQ8GV+LZI/wUzd1ySxfoD/Lw+d9KZ 9CDNQXtEZGO0g4EJ6O6xTQRPI+iquc1Sc/eOZyhQ1zXe3Yto23zWhLZANf9fg0M4WbKJ Cv1/K/Tfw5CFybD0fpBCJKhkJ2uNZzutJPAGgHasCY/dnhUNm6/H6RMPKcGzYPc14OL8 BARgRu8xWdmOQ0+naExur2knMnYTW4ihN6Iw+MfCbRt0OCb+KBBsdT4D5D0Zg/besHRE B1Tg== X-Gm-Message-State: AOJu0Yyn3YgKbmdLL/fNto1mGjGhDhLQSI8Yr48tyNE4TZE/ceBvH8/8 NL8T31yKwOMZ2PPlew0WV2iq+9fUji5Ip0BU1SpeQ+1oekt9qoyG9oLbJnl1 X-Google-Smtp-Source: AGHT+IEuMghnHNYTm0bn/BXteT0T+QWWpDIngkV2vXTDaDZlREE6TmW7y/GnTRb0B3FV1LzpNi3iRA== X-Received: by 2002:a05:6602:154d:b0:7f9:16da:ac79 with SMTP id ca18e2360f4ac-80003ca8a54mr1029192639f.16.1720649113573; Wed, 10 Jul 2024 15:05:13 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c0b1b0d427sm1470589173.64.2024.07.10.15.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jul 2024 15:05:13 -0700 (PDT) Date: Wed, 10 Jul 2024 17:05:11 -0500 From: Nathan Bossart To: Euler Taveira Cc: pgsql-hackers Subject: Re: improve performance of pg_dump with many sequences Message-ID: References: <20240503025140.GA1227404@nathanxps13> <0a0f4d52-ab75-4d69-abe8-5713bf70eee6@app.fastmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0a0f4d52-ab75-4d69-abe8-5713bf70eee6@app.fastmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jul 10, 2024 at 05:08:56PM -0300, Euler Taveira wrote: > Nice improvement. The numbers for a realistic scenario (10k sequences) are Thanks for taking a look! > You are changing internal representation from char to int64. Is the main goal to > validate catalog data? What if there is a new sequence data type whose > representation is not an integer? IIRC 0001 was primarily intended to reduce the amount of memory needed for the sorted table. Regarding a new sequence data type, I'm assuming we'll have much bigger fish to fry if we do that (e.g., pg_sequence uses int8 for the values), and I'd hope that adjusting this code wouldn't be too difficult, anyway. > This code path is adding zero byte to the last position of the fixed string. I > suggest that the zero byte is added to the position after the string length. I'm not following why that would be a better approach. strncpy() will add a NUL to the end of the string unless it doesn't fit in the buffer, in which case we'll add our own via "seqtype[sizeof(seqtype) - 1] = '\0'". Furthermore, the compiler can determine the position where the NUL should be placed, whereas placing it at the end of the copied string requires a runtime strlen(). > l = strlen(PQgetvalue(res, 0, 0)); > Assert(l < sizeof(seqtype)); > strncpy(seqtype, PQgetvalue(res, 0, 0), l); > seqtype[l] = '\0'; I think the strncpy() should really be limited to the size of the seqtype buffer. IMHO an Assert is not sufficient. > If you are not planning to apply 0003, make sure you fix collectSequences() to > avoid versions less than 10. Move this part to 0002. Yeah, no need to create the table if we aren't going to use it. > Since you apply a fix for pg_sequence_last_value function, you can simplify the > query in 0003. CASE is not required. Unfortunately, I think we have to keep this workaround since older minor releases of PostgreSQL don't have the fix. > patched (0001 and 0002): > real 0m0,290s > user 0m0,038s > sys 0m0,104s > > I'm not sure if 0003 is worth. Maybe if you have another table like you > suggested. What pg_dump command did you test here? Did you dump the sequence data, or was this --schema-only? -- nathan