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 1p5lMz-0006qW-QV for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Dec 2022 10:21:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p5lMy-0008Nw-MO for pgsql-hackers@arkaria.postgresql.org; Thu, 15 Dec 2022 10:21:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p5lMy-0008N7-Ac for pgsql-hackers@lists.postgresql.org; Thu, 15 Dec 2022 10:21:40 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1p5lMv-0007Yk-12 for pgsql-hackers@postgresql.org; Thu, 15 Dec 2022 10:21:39 +0000 Received: by mail-wm1-x32c.google.com with SMTP id m5-20020a7bca45000000b003d2fbab35c6so1082687wml.4 for ; Thu, 15 Dec 2022 02:21:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=L1/X66Wzae2IQTfn8syeJ1obaVlkGtJ1WkyXKV1X5JI=; b=JqrPLMxsL0qfv1XBfLQ5SXa7me9F22JFw9iCRQ52IxES4sytkfy7WvdAyFrVl8dPs+ FzLeqPKjtRETbtyfHJvPmnSG8TjIvZIIdFLnT9Rv0clWN0SjAT8SmteKqD60TnDAFTXf NUfkUKkcPXEomj38si0aphuQh0aYPpthHHAC31Q0J7R4+uXSNXQlbBtEKOdxlBkuiboQ FF1H8696laQxSmMFFern781TujHQOiliWjO2RyA89vATmu4kh1oEwHmph2YazkXtGuHT HaEJv0WgLVZFq49w6b316xryQ08Se20bntMsZaZDQg5KGwY8+SPlTX122q20NF2GIN3V kJQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=L1/X66Wzae2IQTfn8syeJ1obaVlkGtJ1WkyXKV1X5JI=; b=SSL6UQ9Kq3Pfn7Eanwx7Oy+ALgYImeI9UYwEV8B1JEbjgcSX+skOMPsdn/o+tsUiPg 1Nc9AqRUYdIC4G27tAMmTEDqO9HNpyw07AeqruEnDSOQ2uGqBJMnIP03MrZYZm0x6jYA ViSiLMEZlumz+DXHjyH6SH1HXvuqiYnfYhJoZZaRgXM21ZDAr92lvtt5zkFdZKkdxZ6R RJkF/ZHdoGlfQXgh9T+uHreFQM/QWr+O0xCftqbdcyt5nfREB7Cd1LMUEZCehU6GA2GD 6nzv7ONRPNB1zNL97jNzO2YJSNTRxeG2qx9CKj84LRtPqtHWejE/qro0hrGa+eUiD6/3 jq7w== X-Gm-Message-State: ANoB5pme6svnQlHlGpQocZGQdm/qRhCBCLs9thuKb4BGzsQi2iO5UDfY xzfa5Wz1T6pUJl0sW4QVcPc= X-Google-Smtp-Source: AA0mqf7/kQDZZpw5nC1hHLrlRToyqPig1HoOVjYbDkOSMsghMi9qgS+kj1iKDZ1A42BIgWZLiMtQYA== X-Received: by 2002:a1c:6a01:0:b0:3cf:d365:1e86 with SMTP id f1-20020a1c6a01000000b003cfd3651e86mr28660513wmc.31.1671099695177; Thu, 15 Dec 2022 02:21:35 -0800 (PST) Received: from [192.168.12.242] ([54.239.6.185]) by smtp.gmail.com with ESMTPSA id n3-20020a7bcbc3000000b003cfd4e6400csm5815329wmi.19.2022.12.15.02.21.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 Dec 2022 02:21:34 -0800 (PST) Message-ID: Date: Thu, 15 Dec 2022 11:20:18 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: Minimal logical decoding on standbys Content-Language: en-US To: Robert Haas , Andres Freund Cc: Alvaro Herrera , Ibrar Ahmed , Amit Khandekar , fabriziomello@gmail.com, tushar , Rahila Syed , pgsql-hackers 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> From: "Drouvot, Bertrand" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On 12/14/22 6:48 PM, Robert Haas wrote: > 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, Why, could you please elaborate? It looks to me that here we are "just" accessing the members of the xl_heap_prune struct to get the numbers. Then, the actual data will be read later in heap_page_prune_execute() from the buffer/page based on the numbers we got from xl_heap_prune. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com