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 1qlPWc-002fow-C1 for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Sep 2023 08:04:02 +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 1qlPWa-001MRP-W1 for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Sep 2023 08:04:00 +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 1qlPWa-001MQw-Jc for pgsql-hackers@lists.postgresql.org; Wed, 27 Sep 2023 08:04:00 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qlPWW-006t8G-F3 for pgsql-hackers@postgresql.org; Wed, 27 Sep 2023 08:03:59 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-5042bfb4fe9so16538170e87.1 for ; Wed, 27 Sep 2023 01:03:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695801834; x=1696406634; darn=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=+b0qDEHzGJtXT0jtkPogwAKYNeb8k5ZGz1aF4Sm9eXo=; b=BBQ3i9DDAbaka4dXXE6Ks/jbFxulEWv37chTTOPlavHOmf/E4SMmexremaR7pCFM4T UKzWtY8STh+0kFNAHtqAOKaloJYMruxS0EldGmWXouSrPEk9kEWfABGHggPEo7eNFq+w mPvmyEV1Cj0ARwWCZmUzijzDuiPgmhH/iRzngczg4Hst+e+iW/3zXph/Mgfn7uvf19yV MyCe//Ey8ykd9UAUsMHTQypFLTtEutOG7tippb7vixzeB0xOr5nh1HHcSQktbsG7A1OH DQVeRThgLi04KlxETgOZeXsLA1s/1OXBm8Hi3kHpx3072ZSkuNTwBGbTv08YSaY13y/i uOAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695801834; x=1696406634; h=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=+b0qDEHzGJtXT0jtkPogwAKYNeb8k5ZGz1aF4Sm9eXo=; b=jrj43GhWunDS15rhSOVHBPamA7LYLLQHa7KlvMucxrk/NwbU8KEa1IHnJUK5gEHpb+ mO0OXCNCm7S9sl+7iy5L4K6RVk25WLrn2Ap+2tyISG8OHcKDtYKmfdpc/kb7It+JiMIP PXyJUwy4gkGVvxkXrI6KGmpVQDsHHYTi6igZ4i//iNYV3mKYdI4NthW4lwYp87pa296s MsL1iQ6f4ruljMFu0w1utWM3+zDHyiCsH19gkUiQYoA3e4xaArWvnD2806jYqXyjIZ0U EOCSUz4Mg4Y2XJc5uZuA4Pvik2wVrQ7KrkNIzSnD8lVDjnnI+0yjL0bgkc2YPxhm6gJ2 4pKA== X-Gm-Message-State: AOJu0YzrteKF6wGtDdJeWp4hmfBuBPG+4I+eOcJ+1tVzhQY/F9oDoSuw qHnAMmdeqn2colJ9T2IDOOEKTjY7kP6T3x0G4oEYthK5oG0= X-Google-Smtp-Source: AGHT+IFO0GlcGuDNRwoUhI8n76lHIAPD8471ZUEPZZP674VZYFz5s3c3Q3uZnmDD00oB6UfGKA5A1A8O/Bd9rvseId4= X-Received: by 2002:ac2:59c5:0:b0:503:19d8:8dc3 with SMTP id x5-20020ac259c5000000b0050319d88dc3mr880278lfn.31.1695801834352; Wed, 27 Sep 2023 01:03:54 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Wed, 27 Sep 2023 21:03:43 +1300 Message-ID: Subject: Re: make add_paths_to_append_rel aware of startup cost To: Andy Fan Cc: pgsql-hackers , Zhang Mingli Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 18 Sept 2023 at 22:55, Andy Fan wrote: > Here is an updated version to show what's in my mind. My current thoughts on this are that the fractional cost part adds quite a bit more complexity than the minimalistic approach of just also considering the cheapest startup path. There's also quite a bit I don't like about the extra code you've added: 1. RelOptInfo.tuple_fraction is not given a default value in locations where we do makeNode(RelOptInfo); 2. This is very poorly documented and badly named. Also seems to have a typo "stopper" + /* Like order by, group by, distinct and so. */ + bool has_stoper_op; With that, nobody has a hope of knowing if some new operation should set that value to true or false. I think it needs to define the meaning, which I think (very roughly) is "does the query require any additional upper-planner operations which could require having to read more tuples from the final join relation than the number of tuples which are read from the final upper rel." 3. get_fractional_path_cost() goes to the trouble of setting total_rows then does not use it. 4. I don't see why it's ok to take the total_rows from the first Path in the list in get_cheapest_fractional_path_ext(). What if another Path has some other value? But overall, I'm more inclined to just go with the more simple "add a cheap unordered startup append path if considering cheap startup plans" version. I see your latest patch does both. So, I'd suggest two patches as I do see the merit in keeping this simple and cheap. If we can get the first part in and you still find cases where you're not getting the most appropriate startup plan based on the tuple fraction, then we can reconsider what extra complexity we should endure in the code based on the example query where we've demonstrated the planner is not choosing the best startup path appropriate to the given tuple fraction. David