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 1rkJIA-00Bqu7-TJ for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Mar 2024 07:44:51 +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 1rkJI8-00EAB9-Ib for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Mar 2024 07:44:49 +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 1rkJI8-00EAB1-9o for pgsql-hackers@lists.postgresql.org; Wed, 13 Mar 2024 07:44:48 +0000 Received: from m16.mail.163.com ([220.197.31.2]) by magus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rkJI4-004G6z-TS for pgsql-hackers@lists.postgresql.org; Wed, 13 Mar 2024 07:44:47 +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=BQQsmprZn9iC8x8wkAXp0Yj3VUMqmX+7Sxcnha/Nipw=; b=NUYDfmh7GEZN8ilvW5JvQxmqQ0l3n+ACNk0bP7cs5Mt6JegWVzWJXfbq4Ka5RG w+1ttDnJC/zWoDtQxK0+m19nXBadgSOvnNU6TyyI6Y2MPUBv8cfybEePLC7n8b/X RCoAcBtxiFKqe8weEOQmTNMitN93o/ang13HvXhJBe5xk= Received: from 8235eee8a2a0 (unknown [140.205.118.69]) by gzga-smtp-mta-g1-2 (Coremail) with SMTP id _____wDnT+NkWfFlnrFgBg--.127S3; Wed, 13 Mar 2024 15:44:36 +0800 (CST) References: <878r2zeqsp.fsf@163.com> <87r0gqcjno.fsf@163.com> <87le6xb5j9.fsf@163.com> <87bk7sbzaj.fsf@163.com> <87msra9vgo.fsf@163.com> <87edcl9hlu.fsf@163.com> <877cicao6e.fsf@163.com> <056d02c9-c9c7-4384-8522-851259209a17@postgrespro.ru> User-agent: mu4e 1.10.7; emacs 29.1 From: Andy Fan To: Andrei Lepikhov Cc: David Rowley , PostgreSQL Hackers , pgsql-hackers@lists.postgresql.org Subject: Re: a wrong index choose when statistics is out of date Date: Wed, 13 Mar 2024 15:39:07 +0800 In-reply-to: <056d02c9-c9c7-4384-8522-851259209a17@postgrespro.ru> Message-ID: <87jzm68tjv.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID: _____wDnT+NkWfFlnrFgBg--.127S3 X-Coremail-Antispam: 1Uf129KBjvdXoWrtF17Gw1DKFy5uF4rArWDurg_yoWkWFc_ur 1kCrZFy34kAFsxKa15GwsrJr97K3yUuw1UKw17Gr12gFyYvF45Jrs7Gr9Iv343Gwsavrnx CrsxXr4qyw45ujkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7IUU8u45UUUUU== X-Originating-IP: [140.205.118.69] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/xtbBzwqgU2V4IMrD8gAAsw List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > > Having had the same problem for a long time, I've made an attempt and > invented a patch that probes an index to determine whether the estimated > constant is within statistics' scope. > I remember David's remark on the overhead problem, but I don't argue it > here. This patch is on the table to have one more solution sketch for > further discussion. I think the following code will be really horrendous on peformance aspect, think about the cases where we have thousands of tuples. + index_rescan(index_scan, scankeys, 1, NULL, 0); + while (index_getnext_tid(index_scan, ForwardScanDirection) != NULL) + { + ntuples++; + } + > Also, Andy, if you have a specific problem with index choosing, you can > try a tiny option that makes the index-picking technique less dependent > on the ordering of index lists [1]. thanks, index choosing issue already not the only issue I want to address now. You said the my patch was kind of lucky to work at [1], have you figure out an example to prove that? [1] https://www.postgresql.org/message-id/701d2097-2c5b-41e2-8629-734e3c8ba613%40postgrespro.ru -- Best Regards Andy Fan