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 1tkGUZ-0022JK-6H for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Feb 2025 05:49:59 +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 1tkGUX-0070Fc-R6 for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Feb 2025 05:49:57 +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 1tkGUX-0070FU-Bf for pgsql-hackers@lists.postgresql.org; Tue, 18 Feb 2025 05:49:57 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tkGUV-001SVl-0e for pgsql-hackers@postgresql.org; Tue, 18 Feb 2025 05:49:56 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-21f61b01630so93632215ad.1 for ; Mon, 17 Feb 2025 21:49:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=j-davis-com.20230601.gappssmtp.com; s=20230601; t=1739857794; x=1740462594; darn=postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=lS/Qee9w9pjsw9QADZskt5j8s5RoiIpkpJ+uqEtiKNs=; b=c1e2VyUpdE725NzYRbVGmhPBonQ479P25XTEt65z+dQv50tj69o5wU+BCN5eocLEXj BKfuIGMiovtlQcNOxWHuu/+2VljtCyFsVaiVXQMCFKf9+ZC6/+mbe3XfcaR6B0T1ENnX OxJhiJcPHXnSuYSmd/KBbVe5tA3n0/ZD7WBt+NKd683fgHJD+s/3e7e/mEIMIyRNFBgu gDnseMW5e0smpkuAcIOTKWXYxk9OBW9HD45VZpExP7WrNaZc1/L4r7j6XQYEaNpNtlK4 ESv0vefLBW0JbWIglwL/d5epcT8fzIV1CvxKgdIbXnwvFzKWo18HUaS5Qoyu6HG4kMmR jpOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739857794; x=1740462594; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lS/Qee9w9pjsw9QADZskt5j8s5RoiIpkpJ+uqEtiKNs=; b=fzHeS2aFAkq0/L2TtWSLqNb+LvGrTP+qEy9wvC29DGKoQ9CoPfNN4TBMvxgJfDYTme A84MNfu7YaH3XPtjRZnXq8998yL29ZElmx/cOhAfqs6mbpK6vAez912e7ImZCt60C2fG zwGwYD7W8nilCuRZv+uOB7iP6xdpn0FPoPhFzoNYxe3LXVC3i7sUIv4ee42Q3R7KAc62 sExMzqLeACSM5L5Jf7TOlHa+jjg2i0lxOnOGXuvHhN+VWD76kGXmW8PJlNOE78EF9usi 4/xkueuycaPZ6P6O3y3O4poT3rS0y4lRq7s1XH2/2nrw+XmaQb996W9jpYIuVcr07xUP 0fCA== X-Forwarded-Encrypted: i=1; AJvYcCVfYqZ/RPX5G+XwyLXwBw+KQpaYGZ/9nRHgZsIW4T5zTjs0UY2d7+xdjTOhUdYZf7VTJGrVk4pGcScbZe/3@postgresql.org X-Gm-Message-State: AOJu0Yz7/gq7437uNx09ggiaMmyn4aPOgT8EyN0i92JVce/AJMZ6jWTP 1VsXUkLMNlArcwS7c6rEGNtZy3uC00DqCRAwUT3EW6nUlPVkL2lTZa0s6+2ysA== X-Gm-Gg: ASbGncul+2cXj+8cNauxfFaW4bRgURKG6LWCNPOMBbkSe4tqjyIMk2spTrHHRSSqsRN YE6USPCLVoGiNxPUM/3iXRVapDbWRtkVH0XjUxGpccmBPZKFdgiyqmEzQlQUgg9z6x4u2+yRBjJ Cu560tqnH0Exj9b7m9/dQOGXr5M557G3KPg3oVT5faJdkwExWvkKlD28yZjG3dS+7gvsnOKZKLX OvWuFa3cQoMkGzsh+GLjb34v+TQFzDCjXCtpDBEnmZA482I6PRQ9M2iyFfy17VXUkfh0oD9XkrQ FLz1pvU2Bj4bMSpoxD9x4pCmsk0cjW/43vqduVO/HhGxOrHOefWO09M6XQ== X-Google-Smtp-Source: AGHT+IH/L34vNu9leuQp1hK3ym0LE14WHki4jQf6mZN6kY9sHTyeo5bjfKYe8uFWJk54MbKT9NkB4Q== X-Received: by 2002:a05:6a00:3392:b0:730:9637:b2ff with SMTP id d2e1a72fcca58-73262200aaamr15992454b3a.7.1739857794048; Mon, 17 Feb 2025 21:49:54 -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 d2e1a72fcca58-73255f4c0d1sm7349723b3a.62.2025.02.17.21.49.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 21:49:53 -0800 (PST) Message-ID: Subject: Re: Reduce TupleHashEntryData struct size by half From: Jeff Davis To: David Rowley Cc: Heikki Linnakangas , pgsql-hackers@postgresql.org Date: Mon, 17 Feb 2025 21:49:51 -0800 In-Reply-To: References: <817d244237878cebdff0bc363718feaf49a1ea7d.camel@j-davis.com> <0f3e7407-fb19-42c0-ad10-46eace6c1399@iki.fi> <7c3224111d9edcc16e8e3c8242de5a82c4ee2a73.camel@j-davis.com> <7530bd8783b1a78d53a3c70383e38d8da0a5ffe5.camel@j-davis.com> <09b325921e50bc3a3217fb01d8eb512c89ee36f1.camel@j-davis.com> 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 Wed, 2025-02-12 at 17:01 -0800, Jeff Davis wrote: > In any case, it seems like we have agreement to switch to the Bump > context, so I'll do another round of tests to see if there are any > downsides, then clean it up and commit v7-0001. Results for v7-0001 (switch to Bump Allocator for table entries). Setup: SET work_mem=3D'10GB'; SET max_parallel_workers=3D0; SET max_parallel_workers_per_gather=3D0; =20 --=C2=A0T1: group size avg ~ 1.5 create table t1(i int8, j numeric); insert into t1 select random(1,10000000),sqrt(g) from generate_series(1,10000000) g; vacuum freeze analyze t1; checkpoint; -- T100: group size avg ~100 create table t100(i int8, j numeric); insert into t100 select random(1,100000),sqrt(g) from generate_series(1,10000000) g; vacuum freeze analyze t100; checkpoint; Q1: explain analyze select i, count(j) from THETABLE group by i; t1 t100 master: 776MB / 4085ms 14MB / 1375ms patch: 632MB / 4192ms 10MB / 1375ms=20 Q2: explain analyze select i, count(j), max(j), sum(j) from THETABLE group by i; t1 t100 master: 3280MB / 7817ms 54MB / 4194ms patch: 3048MB / 8103ms 54MB / 4492ms While it's a memory reduction in all cases, and a ~20% memory reduction for by-value types; there appears to be some slowdown for by-reference types -- 7% for Q2 when the group size is 100. I profiled it and it seems to be spending more time in advance_aggregates. Since I didn't change that code, the only explanation I have for that is that with everything in one memory context, the by-reference values end up near enough to the group key and pergroup state to benefit from caching effects. I'm not sure that explanation makes sense though, because even in the old code where they are both in the same memory context, why would we expect the transition values to be close to the grouping key or pergroup state? Regards, Jeff Davis