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 1sTtx2-003bmT-4l for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jul 2024 01:59:28 +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 1sTtwy-005YFX-V8 for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Jul 2024 01:59:24 +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 1sTtwy-005YFO-K4 for pgsql-hackers@lists.postgresql.org; Wed, 17 Jul 2024 01:59:24 +0000 Received: from mail-yb1-xb32.google.com ([2607:f8b0:4864:20::b32]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sTtwr-002Qo3-M4 for pgsql-hackers@postgresql.org; Wed, 17 Jul 2024 01:59:23 +0000 Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-e026a2238d8so6162563276.0 for ; Tue, 16 Jul 2024 18:59:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1721181557; x=1721786357; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=8K5XDUTbrN19J18lhvC6ynyKLHEhlwPbP4jtoAhkD/I=; b=I7F9lR5AmzWygPKu/g8cvSUbQWbW3izs6n4KbaWXvoZL10SqLlhIXiwZRzv8Hz+h3m zLT+1CQUGTZ7ULe1DEt1WiKWWmeeEit1JMgsz81qtyKk0y43Fo9YUcMueDeSt/d9lIkp 7Z2TmkPYMEG0fcoPxMtJEFkfJSgNI7GNhy2Kt2QSKdK76OyBuSUNoCDKo9urupjaOM5/ lAfnYpc4l2UP8Id6CfGcHoIGZH/DQreZoMKPNc1B/zY6SBerREUyw9M0rWaFb5b4CI2B jo+0vq5ZH1lmmY4gz1fVVD4NP9YasM2TE35Z4lI25dUNO/syBBofAJSxnJjt6+jKqcmA 3eRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721181557; x=1721786357; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8K5XDUTbrN19J18lhvC6ynyKLHEhlwPbP4jtoAhkD/I=; b=syUQCsqhaAejN+BDi/7w9sUEycoE6QRpkcR+U49fMusrTs4Yks0C2HDkKVvSOeFNbb 2KcHrO6GF1cyR9CrO2jai/veFx38tkkwA7BUCShZ9CDHnvccVTP1ccw5W07Pn6Rbsa1U Pk9Gl8ufjy9+wC6o1pJFV5KY3b54pCqYO5Lxj7vY8DLyf6a8zSxgVQGCpPtZpYpB7aUw R+cf0h1K++JKgjzBv61zu8qaVfN2R7311onZcf1DZXF81Q/hOdUJiG0i+GWX+sStXrh3 wSe/kQBmZssuX2B9rp8Qvw6YfLguhu5ifB0CZbjPCCjAZzdvoFC2wtXPWpvCd8WKZvxC xeSA== X-Forwarded-Encrypted: i=1; AJvYcCUxQZVu7e/1X6ipAcourGSjBWKKkm7aacQajCnr6e1NRySD6h6hFCiIOMsTncUgetKf4H4cTxZbBh2prnTVz8mBLERM2e9U+JDzJXIM X-Gm-Message-State: AOJu0YwFS8U3yCIAddDUfhtLF50pKews8pB/VLcine54YH1qFPwRyspJ NIw4i25hCFGoy0IwFQcFuUizhm+SpPPqRYiDq39iamvipc5xe4J9YwyASYzNNfAC23VVIF7H7OC pTLhvIipTyJnVrC+lGAw4rn49NNs= X-Google-Smtp-Source: AGHT+IGOFfasGfKLLlCp0epfI9qgxJGUXZ8lLH8bJwMcf1e+xQWpIMHATEkhNbZ9ApQNAZjEMqx0sgcyILP8Mi/KeCs= X-Received: by 2002:a05:6902:1b02:b0:e02:b466:e59c with SMTP id 3f1490d57ef6-e05ed54157emr423242276.0.1721181556704; Tue, 16 Jul 2024 18:59:16 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Guo Date: Wed, 17 Jul 2024 09:59:05 +0800 Message-ID: Subject: Re: Possible incorrect row estimation for Gather paths To: Anthonin Bonnefoy Cc: Rafia Sabih , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I can reproduce this problem with the query below. explain (costs on) select * from tenk1 order by twenty; QUERY PLAN ---------------------------------------------------------------------------= ------ Gather Merge (cost=3D772.11..830.93 rows=3D5882 width=3D244) Workers Planned: 1 -> Sort (cost=3D772.10..786.80 rows=3D5882 width=3D244) Sort Key: twenty -> Parallel Seq Scan on tenk1 (cost=3D0.00..403.82 rows=3D5882 w= idth=3D244) (5 rows) On Tue, Jul 16, 2024 at 3:56=E2=80=AFPM Anthonin Bonnefoy wrote: > The initial goal was to use the source tuples if available and avoid > possible rounding errors. Though I realise that the difference would > be minimal. For example, 200K tuples and 3 workers would yield > int(int(200000 / 2.4) * 2.4)=3D199999. That is probably not worth the > additional complexity, I've updated the patch to just use > gather_rows_estimate. I wonder if the changes in create_ordered_paths should also be reduced to 'total_groups =3D gather_rows_estimate(path);'. > I've also realised from the comments in optimizer.h that > nodes/pathnodes.h should not be included there and fixed it. I think perhaps it's better to declare gather_rows_estimate() in cost.h rather than optimizer.h. (BTW, I wonder if compute_gather_rows() would be a better name?) I noticed another issue in generate_useful_gather_paths() -- *rowsp would have a random value if override_rows is true and we use incremental sort for gather merge. I think we should fix this too. Thanks Richard