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 1tD8GZ-00GALg-T6 for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Nov 2024 20:22:36 +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 1tD8GX-007P3L-OB for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Nov 2024 20:22:34 +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 1tD8GX-007P38-9b for pgsql-hackers@lists.postgresql.org; Mon, 18 Nov 2024 20:22:34 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tD8GV-002Zpn-7h for pgsql-hackers@postgresql.org; Mon, 18 Nov 2024 20:22:32 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-2120f9ec28eso11338575ad.1 for ; Mon, 18 Nov 2024 12:22:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1731961350; x=1732566150; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=JtDJv59HDl6wTp+ichO5TDhkhLgmXhSEPajDklzMGqY=; b=SvT3CMo8Kr4b8gIMqU/OqEt1rBkfHt83H5PiVA2eiS2SuvKrzFTncyXciINWVD5cFZ dMQETRuIyOVLjkvhU98TqIUoNYzsP59x4cTGUZa6aQE4Rca3bsYFivmH57YDhdtuzfNu SPlBww+RiPGA05NXtqtpGgAW2LywNSye42i6SHb9EfA5pG5yz+hdtiUmrGSoIlAIqgZN eQUUML9jGYp384Euds0cYyNn5STTCN+bgZv0FECIi8s4m3qEamvBmbd1IUAoz0almMpK e3HTdp33eZLY8cMBwFw52/1F8dbXQSmDUwyNXkZ0sh0GrvOEZ8eM4IRp2XU+PcU2PwsN 08tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731961350; x=1732566150; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=JtDJv59HDl6wTp+ichO5TDhkhLgmXhSEPajDklzMGqY=; b=QyNWBbWJxg6xj54t4TcE1KyWeoNfzHqQidBtH80CC6x7n2NIKc/qtitOIid10hUkAD we9sBbcNYFQEkXuFImkbQAJtQRZJIzgtl5CX502UJSgIlzrJZS82krwRon7CEUryXCfz SJBhMmptHJ1N67WKLkKOEnjDAqg8MQH977g8d9v6NmNp8lU7NwibcUB1ibQYlaBVmz6H 3/wz+cgwIJOvzkpiXYKWWyptXwRRpQ1pSGwNI9cjINSiormjvBNEYltPChbU3JKx7Ov2 wdYMLkvtuKO/842kBpCAJpVtf6e2mjSbLTO+bd1BhR+FUsNHaMXzmUbeXqiQ8Vm5Ri4d 9m3Q== X-Forwarded-Encrypted: i=1; AJvYcCUoVGQJPqgrWvtoSix2FtYu3XA0p89JQj3wBgPa1sLMHQ78f1vn4QOaMhpy4G5HvtuAh7fzKl3QLzOQOI5p@postgresql.org X-Gm-Message-State: AOJu0YyI60QBGzr6OkPzzScgklWpM6fN1H7IuZ9M3FJLSeMfBk5vuxHY Uues54qe5RkaS/C/JSqRRqMFudiAF2EiCH6N+GS1O8MJxerqX9lHLHNYTzg2eQ== X-Google-Smtp-Source: AGHT+IFc5U65uxILoFJ4nuC6QOq9JkSkw1zTr8AQBDawQM5PiJkQoJNNkLr4zMxeAiWYSzbDdZPeSw== X-Received: by 2002:a17:903:18b:b0:205:5d71:561e with SMTP id d9443c01a7336-2124d0ee076mr8089065ad.26.1731961350076; Mon, 18 Nov 2024 12:22:30 -0800 (PST) Received: from jeff-laptop.lan (c-76-102-242-158.hsd1.ca.comcast.net. [76.102.242.158]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0ebbee5sm60875305ad.24.2024.11.18.12.22.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2024 12:22:29 -0800 (PST) Message-ID: <7c3224111d9edcc16e8e3c8242de5a82c4ee2a73.camel@j-davis.com> Subject: Re: Reduce TupleHashEntryData struct size by half From: Jeff Davis To: Heikki Linnakangas , pgsql-hackers@postgresql.org Date: Mon, 18 Nov 2024 12:22:28 -0800 In-Reply-To: <0f3e7407-fb19-42c0-ad10-46eace6c1399@iki.fi> References: <817d244237878cebdff0bc363718feaf49a1ea7d.camel@j-davis.com> <0f3e7407-fb19-42c0-ad10-46eace6c1399@iki.fi> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2024-11-18 at 12:13 +0200, Heikki Linnakangas wrote: > Seems pretty uncontroversial. You removed the typedef for struct=20 > TupleHashEntryData, which is a bit unusual for our usual source > style.=20 > Was there a reason for that? If it's private to a file and I don't intend to use it a lot, I do it to cut down typedefs.list bloat. I'll go ahead and add the typedef back to match the style, though. >=20 > Hmm, it would seem more straightforward to store it in the beginning, > i.e. have something like this: >=20 > struct { > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 void *additional; > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 MinimalTupleData mtup; > } ; That was my first approach, but it requires an additional memcpy, because ExecCopySlotMinimalTuple() does it's own palloc. I used repalloc() because it will often have space at the end of the chunk anyway, and not need to memcpy(). Maybe that's not significant but it did seem detectable in some perf tests. But perhaps we can go further and get rid of the "additional" pointer and inline the pergroup data and the grouping key tuple into the same palloc chunk? That would cut out a palloc and the 8 wasted bytes on the pointer. > Come to think of it, how important is it that we use MinimalTuple > here=20 > at all? Some other representation could be faster to deal with in=20 > TupleHashTableMatch() anyway. What did you have in mind? That sounds like a good idea orthogonal to reducing the bucket size. Alternatively, MinimalTuple is not very "minimal", and perhaps we can just make it better. >=20 > > 0004: Removes the "status" field from TupleHashEntryData, using > > firstTuple=3D=3DNULL to mean "empty", otherwise "in use". Hack: need an > > additional "special" pointer value to mean "input slot" now that > > NULL > > means "empty". >=20 > +1 For the FIRSTTUPLE_INPUTSLOT marker, do you think it's cleaner to use what I did: const static MinimalTuple FIRSTTUPLE_INPUTSLOT =3D (MinimalTuple) 0x1; or something like: static MinimalTupleData dummy =3D {0}; const static MinimalTuple FIRSTTUPLE_INPUTSLOT =3D &dummy; ? >=20 > On architectures with non-strict alignment, it doesn't matter as a=20 > simple load/store instruction is the fastest option anyway. My intuition is that the cost of dereferencing that pointer (to memory which is not expected to be in cache) is going to be way higher than the cost of a couple extra instructions to do the unaligned access. Regards, Jeff Davis