Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5Vrk-0005DQ-Tt for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Dec 2022 17:48:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p5Vrj-0007Me-Q0 for pgsql-hackers@arkaria.postgresql.org; Wed, 14 Dec 2022 17:48:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5Vrj-0007M3-Fj for pgsql-hackers@lists.postgresql.org; Wed, 14 Dec 2022 17:48:23 +0000 Received: from mail-lj1-x22d.google.com ([2a00:1450:4864:20::22d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p5Vrg-0003eu-PE for pgsql-hackers@postgresql.org; Wed, 14 Dec 2022 17:48:23 +0000 Received: by mail-lj1-x22d.google.com with SMTP id f16so7367689ljc.8 for ; Wed, 14 Dec 2022 09:48:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=/fGQZrlDyP02O5FK3zbICwdCWL65D76rPreqyUZf93w=; b=X/9rN5MoLxMm4z0z9eNcalnBGfzY19JscsbiEHUhWLIy/kbMzMszn0TEASBYiHyaEQ LLKFWsvifJQMj0rKxkEN3yVfDzKNgefg8JMPD1VWW7sxRYtPlQX2/NU9LjeQ6WfI5xmj SOGktNeDXqquKx49qycbMONcq80luRqyHlldmZoLj/kgPSCXujZqoowt4XkdOevHJbGI yOMvlfGRCDsItRsoYeYMS2AnlSap5AXxFWeU2FTfGwhfHvE0e3XlKYBG9aELFe7OH1IH gWRcTuHU9GMxZEhy1AENCfWaACOHIRwqE2U31tRQaukNAOceN7K4TYYydEmMAexBfUNQ SKrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=/fGQZrlDyP02O5FK3zbICwdCWL65D76rPreqyUZf93w=; b=QcJpFPgLjXR6de7PKq4dJY7cBqkbILcBVXv2vLroLdCuiM/0R6kGhOFej45dLrrL0t TZZpNoeZGpWz/Uk9Yn3iVdH9e+rUSte1T6SPhalQNEE8kFeavgmxhAHmwV3xPHXnp9Ny oneqmUx9BXZ6E0SoSVCoQNoEZTiIS55N77dQjqAu19/dl8TqHXPmz0N00f9jDLNvdyKO A2OMQsjH+HhMN/yERnk1nicLitiihkZMUk+Pp3z/hGaVUT01wy6kbjc3es/ve70DO/or 6oiJFVyiHvcYLuJFF2orTjZ8s5qSGMm1JJK6JPnJALD7iZFwUS+q43ljWgb+DnqXhvcQ h9dg== X-Gm-Message-State: ANoB5plFECza9fn4r6UYC4nFk9PcYhMVDh6WTSg1QlmmeCwU1ksg2+8L CYtforFDUMW1jg9kv+I5NUd/hGgFUp5MJNH1WPc= X-Google-Smtp-Source: AA0mqf6qAI+zLcw8Y7di7oYEDNrcxKA87ntODyzTZzNKx6AE4TcQQ4KUsbfahFzCOxdAADVVbglWNghJRyR2+UFS7kU= X-Received: by 2002:a2e:b90a:0:b0:278:ec8b:4783 with SMTP id b10-20020a2eb90a000000b00278ec8b4783mr25392907ljb.91.1671040099973; Wed, 14 Dec 2022 09:48:19 -0800 (PST) MIME-Version: 1.0 References: <4b19419f-2e7c-a76b-c948-26d10af6693d@gmail.com> <20221207175824.apmc5clnj2fdjkaq@awork3.anarazel.de> <09c26df0-c5f9-eae0-5a6a-10fb00b0522e@gmail.com> <9f0a021e-40e1-0ae6-8086-a4457c99749e@gmail.com> <0ae83e69-bda0-0eb8-ef4a-d169292e3f66@gmail.com> <47f5faf0-6a6d-602a-5d5b-9449ca74c6ad@gmail.com> <20221214173552.sshklqvwezeo52h3@alap3.anarazel.de> In-Reply-To: <20221214173552.sshklqvwezeo52h3@alap3.anarazel.de> From: Robert Haas Date: Wed, 14 Dec 2022 12:48:08 -0500 Message-ID: Subject: Re: Minimal logical decoding on standbys To: Andres Freund Cc: "Drouvot, Bertrand" , Alvaro Herrera , Ibrar Ahmed , Amit Khandekar , fabriziomello@gmail.com, tushar , Rahila Syed , pgsql-hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Dec 14, 2022 at 12:35 PM Andres Freund wrote: > > typedef struct xl_heap_prune > > > > I think this is unsafe on alignment-picky machines. I think it will > > cause the offset numbers to be aligned at an odd address. > > heap_xlog_prune() doesn't copy the data into aligned memory, so I > > think this will result in a misaligned pointer being passed down to > > heap_page_prune_execute. > > I think the offset numbers are stored separately from the record, even > though it doesn't quite look like that in the above due to the way the > 'OFFSET NUMBERS' is embedded in the struct. As they're stored with the > block reference 0, the added boolean shouldn't make a difference > alignment wise? > > Or am I misunderstanding your point? Oh, you're right. So this is another case similar to xl_btree_reuse_page. In heap_xlog_prune(), we access the offset number data like this: redirected = (OffsetNumber *) XLogRecGetBlockData(record, 0, &datalen); end = (OffsetNumber *) ((char *) redirected + datalen); nowdead = redirected + (nredirected * 2); nowunused = nowdead + ndead; nunused = (end - nowunused); heap_page_prune_execute(buffer, redirected, nredirected, nowdead, ndead, nowunused, nunused); This is only safe if the return value of XLogRecGetBlockData is guaranteed to be properly aligned, and I think that there is no such guarantee in general. I think that it happens to come out properly aligned because both the main body of the record (xl_heap_prune) and the length of a block header (XLogRecordBlockHeader) happen to be sufficiently aligned. But we just recently had discussion about trying to make WAL records smaller by various means, and some of those proposals involved changing the length of XLogRecordBlockHeader. And the patch proposed here increases SizeOfHeapPrune by 1. So I think with the patch, the offset number array would become misaligned. No? -- Robert Haas EDB: http://www.enterprisedb.com