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 1qvKYt-004ZCO-Q9 for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Oct 2023 16:47:23 +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 1qvKYr-009tes-RY for pgsql-hackers@arkaria.postgresql.org; Tue, 24 Oct 2023 16:47:22 +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 1qvKYr-009tei-Hr for pgsql-hackers@lists.postgresql.org; Tue, 24 Oct 2023 16:47:22 +0000 Received: from mail-il1-x135.google.com ([2607:f8b0:4864:20::135]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qvKYo-0026Gy-SE for pgsql-hackers@postgresql.org; Tue, 24 Oct 2023 16:47:21 +0000 Received: by mail-il1-x135.google.com with SMTP id e9e14a558f8ab-357c8dbac0eso10940845ab.2 for ; Tue, 24 Oct 2023 09:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698166037; x=1698770837; 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=7Q7zpJq7aDauheFMBVl0b2kpsFOHgQXt9MZk5OccF3E=; b=guTaaVGcu1BOAPWScfDWGSI+pkezQLu69saEooSpfgx9Q4gTGmPIZMbquBKUyDoJsq Tvh3KNoEeswRYYtKJMZuIIk9EK7sFtXefzZWRk0twTHIIJbC8++HmBpi8GjTVo33hK/e 64mx6LtaIOcYKhb51yRKOUwKB7nvP0aXhyA8B0iQ1sE/IAvPhtFJ0unCvWXyNX2EzwDj AaYZoS2l1VQjbg3bklv49Ty73DxViYtuZgAZC7L2Iiq+zsz7PiMcIIkNnLokM32n5cKv pBEJm20friIdl/dxVoXCiL31Yv7ugnz5zVPAqIyoSkaLa+e5WYeXGxzDFnyCl4//cS9G 7/Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698166037; x=1698770837; 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=7Q7zpJq7aDauheFMBVl0b2kpsFOHgQXt9MZk5OccF3E=; b=Znk9+G/m6UeQinZ7Rd1Qam2DHWR4mWwHSDxt6X5inuNSNqjVqGjTy9r5pcWtvIilH/ PikbQb+lm6+864p3JE5aA7cfS3EIJDCXsE6Knu62vKkETs70BqN8CvEggUoBVHA0Njyg mfqBAmmdM3/uI7uXCN2whLpCendnub7+JlRsJhiw7/5UPhPqZfLzj/NUTkjF8OvQRUzc XEl6Q1f7zFfmJuydf7NzYCEQs2/4yu/po1/obFjVVJTm0wXlVUuxKwR0FhHHuJBh69VS rva+5wPEYY4eNKxPc7K6QVVOMEDxAtka9qXL4t+hFra482vJsnks1npRt+MvK1ZQaAPB GjXg== X-Gm-Message-State: AOJu0YwKatP8u+sSw22nKj3kfjxU72WgRUcQCx9mQKRkyEFDrILbi8YR 3UMACWRSUaY1EyqOeJMJvDtoKmD5df4= X-Google-Smtp-Source: AGHT+IGjpy5wAV1KuPPwBjzz7A/bGfpUU8hGY5Wsw4l3CH4OlNrIjO0yH+Wxl0IIrr2Wo5+unk81cA== X-Received: by 2002:a05:6e02:1a6f:b0:34f:d1bc:c47c with SMTP id w15-20020a056e021a6f00b0034fd1bcc47cmr16765027ilv.22.1698166037524; Tue, 24 Oct 2023 09:47:17 -0700 (PDT) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id h15-20020a92c08f000000b00351287f213bsm3241703ile.14.2023.10.24.09.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 09:47:16 -0700 (PDT) Date: Tue, 24 Oct 2023 11:47:15 -0500 From: Nathan Bossart To: Jelte Fennema Cc: PostgreSQL-development Subject: Re: Add new for_each macros for iterating over a List that do not require ListCell pointer Message-ID: <20231024164715.GB871220@nathanxps13> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Oct 24, 2023 at 06:03:48PM +0200, Jelte Fennema wrote: > Many usages of the foreach macro in the Postgres codebase only use the > ListCell variable to then get its value. This adds macros that > simplify iteration code for that very common use case. Instead of > passing a ListCell you can pass a variable of the type of its > contents. This IMHO improves readability of the code by reducing the > total amount of code while also essentially forcing the use of useful > variable names. > > While this might seem like a small quality of life improvement, in > practice it turns out to be very nice to use. At Microsoft we have > been using macros very similar to these ones in the Citus codebase for > a long time now and we pretty much never use plain foreach anymore for > new code. This seems reasonable to me. > Finally, I guess there needs to be some bikeshedding on the naming. In > the Citus codebase we call them foreach_xyz instead of the > for_each_xyz naming pattern that is used in this patchset. I'm not > sure what the current stance is on if foreach should be written with > or without an underscore between for and each. Currently pg_list.h > uses both. I don't have a strong opinion on the matter, but if I had to choose, I guess I'd pick foreach_*() because these macros are most closely related to foreach(). BTW after applying your patches, initdb began failing with the following for me: TRAP: failed Assert("n >= 0 && n < list->length"), File: "list.c", Line: 770, PID: 902807 -- Nathan Bossart Amazon Web Services: https://aws.amazon.com