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.96) (envelope-from ) id 1w7LSb-005Cje-25 for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Mar 2026 22:51:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w7LSY-006xSn-0Q for pgsql-hackers@arkaria.postgresql.org; Mon, 30 Mar 2026 22:51:50 +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.96) (envelope-from ) id 1w7LSX-006xSa-2h for pgsql-hackers@lists.postgresql.org; Mon, 30 Mar 2026 22:51:50 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w7LSW-00000001sVf-1L6y for pgsql-hackers@lists.postgresql.org; Mon, 30 Mar 2026 22:51:49 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-4873ce69ba9so15630985e9.2 for ; Mon, 30 Mar 2026 15:51:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774911107; cv=none; d=google.com; s=arc-20240605; b=bpXcuLMe5rUG1OkTuVSUkHalUbRnh0pQt/YAn7mThcg5fivK2c/r8ELmRSsmLS8Svi Isw4g+Elg1A0YTPpHMz81PAfZyaQ5UksTGyqtOZ4ESKSTdlR2+Do5VzNGf0xfIH36xl3 yF75vnbpihMLRlAf3MrzVpYNuNZjeFWe/m6LkgOVrUPlgwzLQzS09FoxfIOwsujkSMCT 9pfQUGYnkkNhagQWlaDdTvN2+KTgStcVKfObBkIf9zmPQ9tzOZ+JiAalSz6C1T1jNDoQ FOQFkzim2H3Fz/3bw/nUJMeQV3P8GNhB8xz4qT+QQiIzPqW57uyezGkimm6ld9jlWe+C 9FvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=L5yqxtXkwrjJaaIOPoRxYQCzXSwiX7fmM92niOqH4LE=; fh=C6kBPjKA9Ljr9Jq0FaojZ9NrR3NpxNQjRbMTb8nlgaU=; b=UMjvQNB20Irwy+KFC41mLQnNYnIiF3gSl01IYeOCytUwljY5kPslYyqV/3o2jtCmTQ 3GXBUJWACZ8x20Q+tPexM7Psgm/2o5ZP/nYZ4MlNUQHsxMFEoI47payHLkvkEwXjo8es CQyhiYex2eSHl+LJ9JGMn2qpnPPBJw/3f6wgTYfqH6MblkbrB36fjxh6ETb8sfY1QmL7 poU6qENjSv1GY5O+SBtGzSsv7ghrDPMvYf6X8v4nPIW/MtNsm2inmvIduduhGxRfY6Oz oM4C4MhKgecyUFz9DKta8S/fqqOjvnIK0iTpRszAHKiXOMCsDOs0BOmq/ykpNFLWDhBM 8Meg==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774911107; x=1775515907; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=L5yqxtXkwrjJaaIOPoRxYQCzXSwiX7fmM92niOqH4LE=; b=r3wUPu0BJ7wlcySxwZtvRDBIei/cABYKC4IR1TaFXsYDSc91ApR2GPWfWsL7w5a6oL 8c50KAlYKEoFjMBskFzS6PT1fbSQ2f85Hb3bD0BDinyPXSt34oOa2wZMg3vn8OYxws3E eVc/AyrbK8JxwO1rM5GDhFnZJVQQHAt6RxRblC+C0gFv7TOVLUB+qqYZL0DnahQUnJFA KweN/t+IWFNIkJ5ulH/gqxgZTX8UMrNdaZhI9/RsWYU2+dFEUkOyrXAvjAd9wBy9DYU+ P29gRVFXzaiTRaKCBFFyK+xGxlR4emhtwKKoDe7sXaxprqqgLWyGLesfERL2AfM2AgNx OZ7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774911107; x=1775515907; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=L5yqxtXkwrjJaaIOPoRxYQCzXSwiX7fmM92niOqH4LE=; b=D1I8SRY71NvEnz8sLBPJ1V/8Hq/pUVsZLafnodOU7uwgMdhrup1d4KqqpCB9EkmlO1 Hn2+LLFTFlWp4fk+LkAILjcQAbj/+FXw4CVaxlGW+Txq/QxpxxS6HY3Y5S1FaLflj2eR aW0LcLoU225yXIRq8pkdW4jngeFPR6wSfJ4OjTu7E6u+znN1ucO4Uldemx/I9S3P3LCZ q+KWIi+OwVM1KG8JwZdceOyLocb14JFkIU/EeOaKl0Ci7zU6tt141xfmCFRXxT032YDZ 1SFuboVI1yzKTnYZX+MAy8XzYP8wGU9K7U80XMbOLP8P3Rij6aORpAOETPLkknMx5L8Z 4g1g== X-Forwarded-Encrypted: i=1; AJvYcCUdiwfdC2jxPPZE0Or6kE0a7g2FsrOzrWwdMQ40b5ebZGk2KMPW8d8JFnrupR95heZnH0O+TlUnn7+Q4qsk@lists.postgresql.org X-Gm-Message-State: AOJu0YxYJ+esO3L8j6v5lBKOCkxQR8swhj7FW3ICXOx6frqgO5DgVlQ8 BBkuE0scRPtnGZ/03RGiQUKDZ8nz22Jjhlav0tDZ7Kp3azpf7yiN6asu4HNGGWPIMDQ7LZehAtD ue/ZTb0uPct/Ii3hJYlOu9KsccsxkGHw= X-Gm-Gg: ATEYQzzO1/DTvLgXDx6pf56y43jUBJeS/ZSZ35Dznr4FpFWgAnzHJYXdHtbu5uiIwPg +zHsaGnMrByq7MUqXXWWt2OB0JtlWWNgwHHLORNOz2bKVGr9uPdUNYRpflCM/Ao2TXbn5Uhx7g3 sDkHmX/I3YtXmYkxOycknT4afAlhhpHhIJ8AxduFLPiYubW0cYr0thEJClXjzv7c9f2m56KrOwm McPEzzGoYBW27u1ehTq5PUbf4s53LqKG0C+isSLsOzNuHAZiwycXtPmMzJN6UH8euwD7ao5owO1 GIFj7Gyz+Esc42rX2XbjeYzG1p4k6VrbzUXkM6iYGXbYZNFI+zYPTqA/RFtYaxXQ7j5JTDMjZQ= = X-Received: by 2002:a05:6000:2f8a:b0:43b:4a2c:ff4 with SMTP id ffacd0b85a97d-43b9ea4a54emr23467400f8f.33.1774911106661; Mon, 30 Mar 2026 15:51:46 -0700 (PDT) MIME-Version: 1.0 References: <2005009.1774880253@sss.pgh.pa.us> In-Reply-To: <2005009.1774880253@sss.pgh.pa.us> From: David Rowley Date: Tue, 31 Mar 2026 11:51:35 +1300 X-Gm-Features: AQROBzD3_n90P06mJCC1mxvfRIwXrmSAam4PILt44m4WefajcnX7dPanzfg84L4 Message-ID: Subject: Re: scale parallel_tuple_cost by tuple width To: Tom Lane Cc: Andrew Dunstan , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 31 Mar 2026 at 03:17, Tom Lane wrote: > > Andrew Dunstan writes: > > While investigating a performance issue, I found that it was extremely > > difficult to get a parallel plan in some cases due to the fixed > > parallel_tuple_cost. But this cost is not really fixed - it's going to > > be larger for larger tuples. So this proposal adjusts the cost used > > according to how large we expect the results to be. > > Unfortunately, I'm afraid that this is going to produce mostly > "garbage in, garbage out" estimates, because our opinion of how wide > tuples-in-flight are is pretty shaky. (See get_expr_width and > particularly get_typavgwidth, and note that we only have good > statistics-based numbers for plain Vars not function outputs.) > I agree that it could be useful to have some kind of adjustment here, > but I fear that linear scaling is putting way too much faith in the > quality of the data. (I suspect you're saying this because of the "Benchmark 2" in the text file, which contains aggregates which return a varlena type, of which we won't estimate the width very well for...) Sure, it's certainly true that there are cases where we don't get the width estimate right, but that's not stopped us using them before. So why is this case so much more critical? We now also have GROUP BY before join abilities in the planner, which I suspect must also be putting trust into the very same thing. Also, varlena-returning Aggrefs aren't going to be the Gather/GatherMerge targetlist, so why avoid making improvements in this area because we're not great at one of the things that could be in the targetlist? For the patch and the analysis: This reminds me of [1], where some reverse-engineering of costs from query run-times was done, which ended up figuring out what we set APPEND_CPU_COST_MULTIPLIER to. To get that for this case would require various tests with different tuple widths and ensuring that the costs scale linearly with the run-time of the query with the patched version. Of course, the test query would have to have perfect width estimates, but that could be easy enough to do by populating a text typed GROUP BY column and populating that with all the same width of text for each of the tests before increasing the width for the next test, using a fixed-width aggregate each time, e.g count(*). The "#define PARALLEL_TUPLE_COST_REF_WIDTH 100" does seem to be quite a round number. It would be good to know how close this is to reality. Ideally, it would be good to see results from an Apple M chip and recent x86. In my experience, these produce very different performance results, so it might be nice to find a value that is somewhere in the middle of what we get from those machines. I suspect having the GROUP BY column with text widths from 8 to 1024, increasing in powers of two would be enough data points. David [1] https://postgr.es/m/CAKJS1f9UXdk6ZYyqbJnjFO9a9hyHKGW7B=ZRh-rxy9qxfPA5Gw@mail.gmail.com