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 1riBOF-00FaLQ-Hh for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Mar 2024 10:54:19 +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 1riBOC-004MNG-V5 for pgsql-hackers@arkaria.postgresql.org; Thu, 07 Mar 2024 10:54:17 +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 1riBOC-004MN7-Ls for pgsql-hackers@lists.postgresql.org; Thu, 07 Mar 2024 10:54:17 +0000 Received: from m15.mail.163.com ([45.254.50.219]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1riBO5-003ITf-MV for pgsql-hackers@lists.postgresql.org; Thu, 07 Mar 2024 10:54:14 +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=QpfkyGRX60xCqe9DSwVytvAgo+Xf220NPS7fILakTxY=; b=caXWHTCiyYtA2+9hJ3E5MLYFPeJBYBanRSkVHNzFpqTjDHjjt1bebpCzTtaB5S UrDF8ZTpjK+8zB0Ruaey2oeqDGCUzillbjmh2bV9Jy7YShiOfpyW/E00nSXky/w3 ZcIqC92uMn7+wrDN/PE43LqIGx5U5wERe/pQw+aHGURTo= Received: from 8235eee8a2a0 (unknown [140.205.118.141]) by gzga-smtp-mta-g0-3 (Coremail) with SMTP id _____wDnj_TGnOllUe43Aw--.51826S3; Thu, 07 Mar 2024 18:53:59 +0800 (CST) References: <878r2zeqsp.fsf@163.com> <87r0gqcjno.fsf@163.com> <87le6xb5j9.fsf@163.com> <87bk7sbzaj.fsf@163.com> <701d2097-2c5b-41e2-8629-734e3c8ba613@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: Thu, 07 Mar 2024 18:42:31 +0800 In-reply-to: <701d2097-2c5b-41e2-8629-734e3c8ba613@postgrespro.ru> Message-ID: <87il1y9ut5.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID: _____wDnj_TGnOllUe43Aw--.51826S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7tF4fCw1UtF1rXr48AFWkJFb_yoW8tFyfpF Z3tr1Yya4DXFy0vrn3K3WxuryFqws5Jw15JrykJr1xC390kryIvrWIkFZ5Aay3ur95K3Wj qa1agry8Way5Z3DanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UjFAXUUUUU= X-Originating-IP: [140.205.118.141] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/1tbiVA2aU2VOBx9UTAAAs7 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrei Lepikhov writes: > On 5/3/2024 19:56, Andy Fan wrote: >> I think it is OK for a design review, for the implementaion side, the >> known issue includes: >> 1. Support grap such infromation from its parent for partitioned table >> if the child doesn't have such information. >> 2. builtin document and testing. >> Any feedback is welcome. > Thanks for your efforts. > I was confused when you showed the problem connected to clauses like > "Var op Const" and "Var op Param". hmm, then what is the soluation in your mind when you say the "ticky" in [1]? I am thinking we have some communication gap here. > As far as I know, the estimation logic of such clauses uses MCV and > number-distinct statistics. So, being out of MCV values, it becomes > totally insensitive to any internal skew in data and any data outside > the statistics boundaries. > Having studied the example you provided with the patch, I think it is > not a correct example: > Difference between var_eq_const and var_eq_non_const quite obvious: The response should be same as what I did in [2], let's see if we can make the gap between us smaller. > In the second routine, you don't have information about the const value > and can't use MCV for estimation. Also, you can't exclude MCV values > from the estimation. And it is just luck that you've got the right > answer. I think if you increased the weight of the unknown part, you > would get a bad result, too. > I would like to ask David why the var_eq_const estimator doesn't have an > option for estimation with a histogram. Having that would relieve a > problem with skewed data. Detecting the situation with incoming const > that is out of the covered area would allow us to fall back to ndistinct > estimation or something else. At least, histogram usage can be > restricted by the reltuples value and ratio between the total number of > MCV values and the total number of distinct values in the table. I think an example which show your algorithm is better would be pretty helpful for communication. [1] https://www.postgresql.org/message-id/15381eea-cbc3-4087-9d90-ab752292bd54%40postgrespro.ru [2] https://www.postgresql.org/message-id/87msra9vgo.fsf%40163.com -- Best Regards Andy Fan