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 1rhNXK-00B95F-VV for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Mar 2024 05:40:23 +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 1rhNXI-00DggK-Fc for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Mar 2024 05:40:20 +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 1rhNXI-00DggC-5w for pgsql-hackers@lists.postgresql.org; Tue, 05 Mar 2024 05:40:20 +0000 Received: from m15.mail.163.com ([45.254.50.220]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rhNXD-002qAT-VR for pgsql-hackers@postgresql.org; Tue, 05 Mar 2024 05:40:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version: Content-Type; bh=CJi5N9h5QCgMa6lUa5KOCrY6jDV7cw4J+gslEWUs1SQ=; b=IFS7fO5YBXnsXXSAqeieVw77yuxSVvxPnXvJ2uyZ+YPtyeHQoSGxu3Zq7h4kGI FnqDRHMdCWaqM/Thokj45h7S04Hsn7zzk09S3Z3MkK/hfgtmH42sEpzMLMYbvPey rSjMvcOxzVkUJ4fYw6r/X96ajUOM0ETqmBwK3kcujYjOw= Received: from 8235eee8a2a0 (unknown [140.205.118.82]) by gzga-smtp-mta-g0-2 (Coremail) with SMTP id _____wDnb3A6sOZlAXe3AQ--.21142S3; Tue, 05 Mar 2024 13:40:11 +0800 (CST) References: <878r2zeqsp.fsf@163.com> <87r0gqcjno.fsf@163.com> User-agent: mu4e 1.10.7; emacs 29.1 From: Andy Fan To: David Rowley Cc: PostgreSQL Hackers Subject: Re: a wrong index choose when statistics is out of date Date: Tue, 05 Mar 2024 13:24:29 +0800 In-reply-to: Message-ID: <87le6xb5j9.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID: _____wDnb3A6sOZlAXe3AQ--.21142S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxXryfuFyfXF48tw4fuw4kZwb_yoW5Gw4DpF W5Ka43A3ykt3WxJr1xAr40qF4fArWDKr43Jr98W34jka4DXa4IvFn5Ka1Y9r9ruryq9w12 vF4qqr1vg3ZYvaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRKFAJUUUUU= X-Originating-IP: [140.205.118.82] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/1tbiQBSYU2VOBveb4gAAs8 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > On Tue, 5 Mar 2024 at 00:37, Andy Fan wrote: >> >> David Rowley writes: >> > I don't think it would be right to fudge the costs in any way, but I >> > think the risk factor for IndexPaths could take into account the >> > number of unmatched index clauses and increment the risk factor, or >> > "certainty_factor" as it is currently in my brain-based design. That >> > way add_path() would be more likely to prefer the index that matches >> > the most conditions. >> >> This is somehow similar with my proposal at [1]? What do you think >> about the treat 'col op const' as 'col op $1' for the marked column? >> This could just resolve a subset of questions in your mind, but the >> method looks have a solid reason. > > Do you mean this? Yes, it is not cautious enough to say "similar" too quick. After reading your opinion again, I think what you are trying to do is adding one more dimension to Path compared with the existing cost and pathkey information and it would take effects on add_path stage. That is impressive, and I'm pretty willing to do more testing once the v1 is done. I just noted you have expressed your idea about my proposal 1, > We should do anything like add column options in the meantime. Those > are hard to remove once added. I will try it very soon. and I'm a bit of upset no one care about my proposal 2 which is the AI method, I see many companies want to introduce AI to planner even I don't seen any impressive success, but this user case looks like a candidate. >> + /* >> + * To make the planner more robust to handle some inaccurate statistics >> + * issue, we will add a extra cost to qpquals so that the less qpquals >> + * the lower cost it has. >> + */ >> + cpu_run_cost += 0.01 * list_length(qpquals); > > I don't think it's a good idea to add cost penalties like you proposed > there. This is what I meant by "I don't think it would be right to > fudge the costs in any way". > > If you modify the costs to add some small penalty so that the planner > is more likely to favour some other plan, what happens if we then > decide the other plan has some issue and we want to penalise that for > some other reason? Adding the 2nd penalty might result in the original > plan choice again. Which one should be penalised more? I think the > uncertainty needs to be tracked separately. > > Fudging the costs like this is also unlikely to play nicely with > add_path's use of STD_FUZZ_FACTOR. There'd be an incentive to do > things like total_cost *= STD_FUZZ_FACTOR; to ensure we get a large > enough penalty. I agree and I just misunderstood your proposal yesterday. -- Best Regards Andy Fan