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 1rh0Ot-00963r-Kv for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Mar 2024 04:58:08 +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 1rh0Or-004DrU-TN for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Mar 2024 04:58:06 +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 1rh0Or-004DrM-Fq for pgsql-hackers@lists.postgresql.org; Mon, 04 Mar 2024 04:58:06 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rh0On-002k6B-6J for pgsql-hackers@postgresql.org; Mon, 04 Mar 2024 04:58:04 +0000 Received: from [172.30.8.38] (unknown [172.30.8.38]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id 36E6EE20E67; Mon, 4 Mar 2024 07:57:59 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1709528279; bh=f4NEHrD0chIiwKAZHpXteuzp9OISLiytQ9plTfE9/wo=; h=Message-ID:Date:User-Agent:Subject:To:References:From:In-Reply-To: From; b=bFAf3JQbM5dD6cFvVRwIy7iQY674yuSs/4TOICIp4sjZozcl0hH+Z0B6bMCySKwoj Ylrg0NttXTTQ0du/9Y5eVcxrSsrEkQbSOCvN6FfuX29mKz/CXca4lFaO3FsUn3OAoJ H513HVIgX2ia32TGBlCX1Qo4B5VgzKLXiqY1XThxTOLSJMO5eF3bHbom2kP8nyqXs5 Kz25AWQWeVoeojckAcX8PbUC94BPh/INp669geySoLMlVE7ezeSuNhVrfzz4BoKtV7 zipB5LLWB1vci1QIBsuIFt18Z+ughJ9HMX4/yZMibcGSR5s7lLRham1FZYnLDFFOkC 7/I5Fm3sNcuxQ== Message-ID: <15381eea-cbc3-4087-9d90-ab752292bd54@postgrespro.ru> Date: Mon, 4 Mar 2024 11:57:56 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: a wrong index choose when statistics is out of date Content-Language: en-US To: Andy Fan , PostgreSQL Hackers References: <878r2zeqsp.fsf@163.com> From: Andrei Lepikhov Organization: Postgres Professional In-Reply-To: <878r2zeqsp.fsf@163.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/3/2024 14:01, Andy Fan wrote: > 1. We can let the user define the column as the value is increased day by > day. the syntax may be: > > ALTER TABLE x_events ALTER COLUMN created_at ALWAYS_INCREASED. > > then when a query like 'create_at op const', the statistics module can > treat it as 'created_at = $1'. so the missing statistics doesn't make > difference. Then I think the above issue can be avoided. Let me write some words to support your efforts in that way. I also have some user cases where they periodically insert data in large chunks. These chunks contain 'always increased' values, and it causes trouble each time they start an analytic query over this new data before the analyze command. I have thought about that issue before but invented nothing special except a more aggressive analysis of such tables. Your trick can work, but it needs a new parameter in pg_type and a lot of additional code for such a rare case. I'm looking forward to the demo patch. -- regards, Andrei Lepikhov Postgres Professional