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 1rh6it-009dg9-Ih for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Mar 2024 11:43:12 +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 1rh6ir-006zHw-Pp for pgsql-hackers@arkaria.postgresql.org; Mon, 04 Mar 2024 11:43:10 +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 1rh6ir-006zHn-GZ for pgsql-hackers@lists.postgresql.org; Mon, 04 Mar 2024 11:43:09 +0000 Received: from m15.mail.163.com ([45.254.50.220]) by makus.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rh6im-002n44-3C for pgsql-hackers@lists.postgresql.org; Mon, 04 Mar 2024 11:43:07 +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=c6imyfWI4z+iSa0qdL8cMQbNhpympfX4eXMORFIn/WM=; b=b4wzXAIKiHYceibYkPSMj4kD2YeH3pI6Of54JiSfn56EKOpx1k4iKg7mTWMeFD /G2GeP7xuomHYjaMULBFBXVF3fVP+10A8OUhMOrWEOUsK2VNXFumRD03mEoK2F2f VXraQwk6PB1PNPYw+/gNfIZ26L4MBszxLewbTYtCjtuB0= Received: from 8235eee8a2a0 (unknown [140.205.118.91]) by gzga-smtp-mta-g0-5 (Coremail) with SMTP id _____wDn1zfCs+VlCzcrAQ--.33519S3; Mon, 04 Mar 2024 19:42:58 +0800 (CST) References: <878r2zeqsp.fsf@163.com> <15381eea-cbc3-4087-9d90-ab752292bd54@postgrespro.ru> User-agent: mu4e 1.10.7; emacs 29.1 From: Andy Fan To: Andrei Lepikhov Cc: PostgreSQL Hackers , pgsql-hackers@lists.postgresql.org Subject: Re: a wrong index choose when statistics is out of date Date: Mon, 04 Mar 2024 19:37:54 +0800 In-reply-to: <15381eea-cbc3-4087-9d90-ab752292bd54@postgrespro.ru> Message-ID: <87msrecjel.fsf@163.com> MIME-Version: 1.0 Content-Type: text/plain X-CM-TRANSID: _____wDn1zfCs+VlCzcrAQ--.33519S3 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cr45uF1kuryxGr45AF4xZwb_yoW8XF1xpF WFgry5Janrt3WI9rZ7Cw48Xw1Fg395G34UKF98Wr1kZws8JryIkr48KF4UJFWSk348Z3Wa vrWkX3srCayruaDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRKFAJUUUUU= X-Originating-IP: [140.205.118.91] X-CM-SenderInfo: x2klx3xlid0iqsrtqiywtou0bp/1tbiQBSXU2VOBux61gAAs9 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Andrei Lepikhov writes: > 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. I have to say we run into a exactly same sistuation and use the same trick to solve the problem, and we know no matter how aggressive it is, the problem may still happen. > 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. Maybe my word "auto_increased" is too like a type, but actually what I want to is adding a new attribute for pg_attribute which ties with one column in one relation. When we figure out a selective on this *column*, we do such trick. This probably doesn't need much code. -- Best Regards Andy Fan