Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pUD53-0001GU-7X for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Feb 2023 20:48:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pUD52-0004v8-0D for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Feb 2023 20:48:12 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pUD51-0004up-MI for pgsql-hackers@lists.postgresql.org; Mon, 20 Feb 2023 20:48:11 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pUD4v-0001Uc-R3 for pgsql-hackers@lists.postgresql.org; Mon, 20 Feb 2023 20:48:08 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 31KKm4pK3724864; Mon, 20 Feb 2023 15:48:04 -0500 From: Tom Lane To: David Rowley cc: Alexander Lakhin , Richard Guo , pgsql-hackers@lists.postgresql.org Subject: Re: Killing off removed rels properly In-reply-to: <3628050.1676916703@sss.pgh.pa.us> References: <229905.1676062220@sss.pgh.pa.us> <1343881.1676313553@sss.pgh.pa.us> <36bee393-b351-16ac-93b2-d46d83637e45@gmail.com> <3582657.1676910808@sss.pgh.pa.us> <3587195.1676912023@sss.pgh.pa.us> <3628050.1676916703@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 20 Feb 2023 13:11:43 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3724862.1676926084.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 20 Feb 2023 15:48:04 -0500 Message-ID: <3724863.1676926084@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > But while I'm looking at this, 3c569049b seems kind of broken on > its own terms. Why is it populating so little of the IndexOptInfo > for a partitioned index? I realize that we're not going to directly > plan anything using such an index, but not populating fields like > sortopfamily seems like it's at least leaving stuff on the table, > and at worst making faulty decisions. I fixed the other issues discussed in this thread, but along the way I grew even more concerned about 3c569049b, because I discovered that it's changed plans in more ways than what its commit message suggests. For example, given the setup CREATE TABLE pa_target (tid integer PRIMARY KEY) PARTITION BY LIST (tid); CREATE TABLE pa_targetp PARTITION OF pa_target DEFAULT; CREATE TABLE pa_source (sid integer); then I get this as of commit 3c569049b7^: # explain select * from pa_source s left join pa_target t on s.sid =3D t.t= id; QUERY PLAN = = --------------------------------------------------------------------------= --------------------- Nested Loop Left Join (cost=3D0.15..544.88 rows=3D32512 width=3D8) -> Seq Scan on pa_source s (cost=3D0.00..35.50 rows=3D2550 width=3D4) -> Index Only Scan using pa_targetp_pkey on pa_targetp t (cost=3D0.15= ..0.19 rows=3D1 width=3D4) Index Cond: (tid =3D s.sid) (4 rows) and this as of 3c569049b7 and later: # explain select * from pa_source s left join pa_target t on s.sid =3D t.t= id; QUERY PLAN = = --------------------------------------------------------------------------= -- Hash Left Join (cost=3D67.38..109.58 rows=3D2550 width=3D8) Hash Cond: (s.sid =3D t.tid) -> Seq Scan on pa_source s (cost=3D0.00..35.50 rows=3D2550 width=3D4) -> Hash (cost=3D35.50..35.50 rows=3D2550 width=3D4) -> Seq Scan on pa_targetp t (cost=3D0.00..35.50 rows=3D2550 wid= th=3D4) (5 rows) Now, I'm not unhappy about that change: it's clearly a win that we now realize we'll get at most one matching t row for each s row. What I'm unhappy about is that this means a partially-populated IndexOptInfo is being used for rowcount estimation and perhaps other things. That seems like sheer folly. Even if it manages to not dump core from trying to access a missing field, there's a significant risk of wrong answers, now or in the future. Why was it done like that? regards, tom lane