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 1tlsuH-002aA9-FW for pgsql-hackers@arkaria.postgresql.org; Sat, 22 Feb 2025 17:03:14 +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 1tlsuG-00E1P6-HW for pgsql-hackers@arkaria.postgresql.org; Sat, 22 Feb 2025 17:03:12 +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 1tlsuG-00E1Ox-3y for pgsql-hackers@lists.postgresql.org; Sat, 22 Feb 2025 17:03:12 +0000 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tlsuD-000BLj-1n for pgsql-hackers@postgresql.org; Sat, 22 Feb 2025 17:03:11 +0000 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-abb7a6ee2deso480199566b.0 for ; Sat, 22 Feb 2025 09:03:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1740243788; x=1740848588; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ABxwDG7kTN4XpYW8wyJ7k+4TNe+jE1wDaQ+GJQYL9/M=; b=DUu9VNzAAj27wum6dhVZCEF9tnPioFyctd+mUcwQ/jWjb08w2fBW+c5OId8AH4IGIY plDZx8OmFNM4r330aqkY29/zNhKDh9S8+aUPobii11AHGS6xP7IFk/ggiam5xDGVprAY ba+cs/ZOEkcXeaFMQOQN/CjM3WIMmlvrAOO2N7nfGe/3dEuL2PwUsQEYw+7dl0d29wdd gADE0HXqLqozCqBbGC4x6HErXFWsi1QckLrPIdXcicMdVStT61GGuUML552CSvE/sGb8 dI7TyYYeLr+W7+HDQ1LxNTNqhvk0ePfSoAxSVvUsJfYj0vJRZm1uTzR3JORuh3yQj8Tz eyRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740243788; x=1740848588; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ABxwDG7kTN4XpYW8wyJ7k+4TNe+jE1wDaQ+GJQYL9/M=; b=FgrElcV2HjUYLwRf7jwd3qTijnju82hMqHTwYL2H/VTIjcGSdTr5v466sNS/pz4zV9 mACWxsocEIlZICdVHvvPtc5GJA9N6mg+r8sWVHqwEA00MeJ5dj3W1pgr4OZ0ZeAbbJxz GzAdTO4RvK2XGJsZQj+J9QB6jDMBomcVw+D1RRHWqA2eJ9v1dsoxIdg3MXYC7SB/UXak q52GZQfs/WJPv1Scf2Ic0yFTgtbxUbEX5n4EFYn52+f98BdcqBDAsPG0T5ZO+VeeoswK Qbe7QC/TKYQQ6/7jZ68+H+YLHXrI+Xb1QeKjV/gpdiJFXvbdmwuKDxJS83UBLnWB5dmg d2Rg== X-Forwarded-Encrypted: i=1; AJvYcCWO5vnkJKpcqWDTt/H3tI5cRUex8opywasw4hwU47SO5Add/7lLLkfdXph7WPQFl+wqIdKonrfw0hC3LxNC@postgresql.org X-Gm-Message-State: AOJu0Yw4krcEJDuycRxsvScO6VT9Qmxmkz0UEo8mKQ+2QINDMqpnvMn6 HZoFuOd/2EqrX7gA+19PmY9tTab12A79ke+SeZxVYzvzeySbdvZlkdTBWjAKsrU9jQSGQgLEdMc u3pcTz6t5ffYbM+a69gC3T84VdOg= X-Gm-Gg: ASbGncsdDnJZUdtcmuGnaktp/7C8lQA6jgYyfNnm9nk7ICd5Z9Mz1vBrofvJBZlTdRJ EyYWk6tl5ywsB+KTRWclirkUUM1b9x300eInAoyP205ETYu6hlcqJ2A1Bdbtnia4QTWhE9s/4JR fsEhQLBsU= X-Google-Smtp-Source: AGHT+IGjVh3wxy9cnSMtFA8ptZkOut+dAOdTsrzgXRD9ex0/N+bR6ADJzIS+b4qKmIHHslVcqnNJ5F6kBWWxPvaqgH0= X-Received: by 2002:a17:907:3f92:b0:abb:e259:2a64 with SMTP id a640c23a62f3a-abc09b21c99mr732272266b.33.1740243788057; Sat, 22 Feb 2025 09:03:08 -0800 (PST) MIME-Version: 1.0 References: <54c35fb9-da3a-4754-ab8c-46ed0b612465@vondra.me> <684c70d7-180e-461d-9377-600c2db581ba@vondra.me> <74839af6-aadc-4f60-ae77-ae65f94bf607@gmail.com> In-Reply-To: <74839af6-aadc-4f60-ae77-ae65f94bf607@gmail.com> From: Tender Wang Date: Sun, 23 Feb 2025 01:02:56 +0800 X-Gm-Features: AWEUYZl3SZvwNNDGEQMZA3Li9EX99EztNEqAVXow8S1-MXczeWuE8KxyrzO27TE Message-ID: Subject: Re: generic plans and "initial" pruning To: Alexander Lakhin Cc: Amit Langote , Tomas Vondra , Robert Haas , Alvaro Herrera , Andres Freund , Daniel Gustafsson , David Rowley , PostgreSQL Hackers , Thom Brown , Tom Lane Content-Type: multipart/alternative; boundary="000000000000cf54c3062ebe140a" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000cf54c3062ebe140a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Alexander Lakhin =E4=BA=8E2025=E5=B9=B42=E6=9C=8822= =E6=97=A5=E5=91=A8=E5=85=AD 23:00=E5=86=99=E9=81=93=EF=BC=9A > Hello Amit, > > 21.02.2025 05:40, Amit Langote wrote: > > I pushed the final piece yesterday. > > > Please look at new error, produced by the following script, > starting from 525392d57: > CREATE TABLE t(id int) PARTITION BY RANGE (id); > CREATE INDEX idx on t(id); > CREATE TABLE tp_1 PARTITION OF t FOR VALUES FROM (10) TO (20); > CREATE TABLE tp_2 PARTITION OF t FOR VALUES FROM (20) TO (30) PARTITION B= Y > RANGE(id); > CREATE TABLE tp_2_1 PARTITION OF tp_2 FOR VALUES FROM (21) to (22); > CREATE TABLE tp_2_2 PARTITION OF tp_2 FOR VALUES FROM (22) to (23); > CREATE FUNCTION stable_one() RETURNS INT AS $$ BEGIN RETURN 1; END; $$ > LANGUAGE plpgsql STABLE; > > SELECT min(id) OVER (PARTITION BY id ORDER BY id) FROM t WHERE id >=3D > stable_one(); > > ERROR: XX000: trying to open a pruned relation > LOCATION: ExecGetRangeTableRelation, execUtils.c:830 > > This issue was discovered with SQLsmith. > The error message was added in commit 525392d57. In this case, the estate->es_unpruned_relids only includes 1, which is the offset of table t. In register_partpruneinfo(), we collect glob->prunableRelids; in this case, it contains 2,3,4,5. Then we will do: result->unprunableRelids =3D bms_difference(glob->allRelids, glob->prunableRelids); so the result->unprunableRelids only contains 1. But tp_2 is also partition table, and its partpruneinfo created by create_append_plan() is put into the head of global list. So we first process it in ExecDoInitialPruning(). Then error reports because we only contain 1 in estate->es_unpruned_relids. --=20 Thanks, Tender Wang --000000000000cf54c3062ebe140a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


Alexander Lakhi= n <exclusion@gmail.com> = =E4=BA=8E2025=E5=B9=B42=E6=9C=8822=E6=97=A5=E5=91=A8=E5=85=AD 23:00=E5=86= =99=E9=81=93=EF=BC=9A
=20 =20 =20
Hello Amit,

21.02.2025 05:40, Amit Langote wrote:
I pushed the final piece yesterday.

Please look at new error, produced by the following script,
starting from 525392d57:
CREATE TABLE t(id int) PARTITION BY RANGE (id);
CREATE INDEX idx on t(id);
CREATE TABLE tp_1 PARTITION OF t FOR VALUES FROM (10) TO (20);
CREATE TABLE tp_2 PARTITION OF t FOR VALUES FROM (20) TO (30) PARTITION BY RANGE(id);
CREATE TABLE tp_2_1 PARTITION OF tp_2 FOR VALUES FROM (21) to (22);
CREATE TABLE tp_2_2 PARTITION OF tp_2 FOR VALUES FROM (22) to (23);
CREATE FUNCTION stable_one() RETURNS INT AS $$ BEGIN RETURN 1; END; $$ LANGUAGE plpgsql STABLE;

SELECT min(id) OVER (PARTITION BY id ORDER BY id) FROM t WHERE id >=3D stable_one();

ERROR:=C2=A0 XX000: trying to open a pruned relation
LOCATION:=C2=A0 ExecGetRangeTableRelation, execUtils.c:830

This issue was discovered with SQLsmith.
The error message was added in commit=C2=A0 525392d57. In this = case, the=C2=A0estate->es_unpruned_relids only includes 1, which is the = offset of table t.
In=C2=A0register_partpruneinfo(), we collect g= lob->prunableRelids; in this case, it contains 2,3,4,5. Then we will do:=
result->unprunableRelids =3D bms_difference(glob->allRelid= s,
=C2=A0glob->prunableRelids);
so the result-&= gt;unprunableRelids only contains 1.

But tp_2 is a= lso partition table, and its partpruneinfo created by create_append_plan() = is put into the head of global list.=C2=A0
So we first process it= in=C2=A0ExecDoInitialPruning().=C2=A0 Then error reports because we only c= ontain 1 in=C2=A0estate->es_unpruned_relids.


--
Tha= nks,
Tender Wang
--000000000000cf54c3062ebe140a--