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 1tDBCX-00GWms-Uq for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Nov 2024 23:30:38 +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 1tDBCV-008ZZF-Sh for pgsql-hackers@arkaria.postgresql.org; Mon, 18 Nov 2024 23:30:36 +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 1tDBCV-008ZZ7-GW for pgsql-hackers@lists.postgresql.org; Mon, 18 Nov 2024 23:30:36 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tDBCT-002eJu-3M for pgsql-hackers@postgresql.org; Mon, 18 Nov 2024 23:30:35 +0000 Received: from [192.168.1.110] (dsl-hkibng22-50ddb7-241.dhcp.inet.fi [80.221.183.241]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4XskPx5fK6z49Pv5; Tue, 19 Nov 2024 01:30:28 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1731972631; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xIAzAEPG8b6TA7Eez60+PZoqwKxk/3iU0TPJhpAGLZw=; b=SqGcixd/FLYEzBCHh0c+l3LQlmYIMey8x7DuT+ZqsVw08wjVoCwZk8vZ2u8KYUDTVuxUpd kE6EkfICyANzWj1AHkFGcxYwJQdpGDdzIKqF3IyhVe5uwdqCDyfAoDecBGRhIz7sQthuBM uYDysd2EK0P0uecbHHP/cE9iBRPHZt5wkwLHolfLkQuVtN1Sk98xr3IVv820oFedtmE3CV hYlgLcPk53q5DffmCtxf7H2IiWV3yuVp2uz96Ymez3vT3ALh9ucfn5+QPArs1XHs6pW9De RBEPPIzR7KUbZSUH3zImro5DAA/nFUe04xm45ILU1jA622aIPD26QaXIuH9Weg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1731972631; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xIAzAEPG8b6TA7Eez60+PZoqwKxk/3iU0TPJhpAGLZw=; b=Iaf+wI2TUjtjgZcL95JzUOc5T3/kzORPHvX/doshw7LD4fkKRR/KGnKfSEms4DA0Ib3v4I IzSYN2GGNKSRhkrEPD7PbL58qtaMfwgYLnv+VygGjpl6tue91PphrvV8JsBmcdKtl6GMQM AnZZOGAsXQ5WwOgS+huibYJTzJecF16iJQtKgFQF8usv/rpPv9O8TD5dFdTrZoG6E0eIYy bPDFzd4QH2IGTe6C3GEekSKFdDRuRyrhNoGk66ySda4DU5RsAHqbfudmr8UMxYJOg2wzax p1xLqWda7CCcVDEU9PCkylNVDYL8Sm87fRSbZbkZqwQtIvhdo48Avt+mzA34CQ== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1731972631; a=rsa-sha256; cv=none; b=np+BOfOMaOoK9HeTzvP7rwly1oeIvPvXcFcmADoeKlzBZnN43a1kS1jL3CHVBZVD9C4rEp rE67xhYl5upybyn4dueVO4ZA/5WxqS3tXflNGNsk8sjwY4aKHRBMSJ+ziOJlUsBJ97jOma OmAFl40VnWVgLGo4thRaUO1nlA0F3RM+2ZiUxvFZHH8yCXaS7OpUUqpKFhYd9SIKGLxAXR tdnrtFqx7G3xeZNT78yycpqJbPv2eH5lCn1FTAz9yUj9JViD+EsNaIxoSC/g3qHrZkkhnI naQnaCKzhl6+79JXqU4BlvlEUnTCXXGFxUbyRpTdb20aupdhhHSbk3PqnsuH7A== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi Message-ID: Date: Tue, 19 Nov 2024 01:30:28 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Reduce TupleHashEntryData struct size by half To: Jeff Davis , pgsql-hackers@postgresql.org References: <817d244237878cebdff0bc363718feaf49a1ea7d.camel@j-davis.com> <0f3e7407-fb19-42c0-ad10-46eace6c1399@iki.fi> <7c3224111d9edcc16e8e3c8242de5a82c4ee2a73.camel@j-davis.com> Content-Language: en-US From: Heikki Linnakangas In-Reply-To: <7c3224111d9edcc16e8e3c8242de5a82c4ee2a73.camel@j-davis.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 18/11/2024 22:22, Jeff Davis wrote: > On Mon, 2024-11-18 at 12:13 +0200, Heikki Linnakangas wrote: >> Hmm, it would seem more straightforward to store it in the beginning, >> i.e. have something like this: >> >> struct { >>       void *additional; >>       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. Sounds like a good idea. Needs some changes to the TupleTableSlotOps interface to avoid the memcpy I presume. >> Come to think of it, how important is it that we use MinimalTuple >> here >> at all? Some other representation could be faster to deal with in >> TupleHashTableMatch() anyway. > > What did you have in mind? That sounds like a good idea orthogonal to > reducing the bucket size. Queries that have a only a small number of groups might might benefit from storing a plain Datum/isnull array instead of a MinimalTuple. That would take more memory when you have a lot of groups though. > Alternatively, MinimalTuple is not very "minimal", and perhaps we can > just make it better. Yeah. It tries to be compatible with HeapTuple, but perhaps we should give up on that and pack it more tightly instead. >>> 0004: Removes the "status" field from TupleHashEntryData, using >>> firstTuple==NULL to mean "empty", otherwise "in use". Hack: need an >>> additional "special" pointer value to mean "input slot" now that >>> NULL >>> means "empty". >> >> +1 > > For the FIRSTTUPLE_INPUTSLOT marker, do you think it's cleaner to use > what I did: > > const static MinimalTuple FIRSTTUPLE_INPUTSLOT = (MinimalTuple) 0x1; > > or something like: > > static MinimalTupleData dummy = {0}; > const static MinimalTuple FIRSTTUPLE_INPUTSLOT = &dummy; > > ? I think I'd do "(MinimalTuple) 0x1" myself, but no strong opinion. -- Heikki Linnakangas Neon (https://neon.tech)