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.96) (envelope-from ) id 1wV4nM-001fQq-2N for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Jun 2026 09:55:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wV4nL-005wdi-2C for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Jun 2026 09:55:23 +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.96) (envelope-from ) id 1wV4nL-005wda-0q for pgsql-hackers@lists.postgresql.org; Thu, 04 Jun 2026 09:55:23 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wV4nJ-000000013J1-1txR for pgsql-hackers@lists.postgresql.org; Thu, 04 Jun 2026 09:55:22 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-490b1bbcf3aso3961615e9.1 for ; Thu, 04 Jun 2026 02:55:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780566918; cv=none; d=google.com; s=arc-20240605; b=IsiUNSAT9b4UCpAGtAXv+sOC8iniP6A4xFYRHqElEWzQTy0GqM/UXXyrn4wkHAvvb8 tHAlcjOP82+DDBbq+ymuN9Dqo8V1Ea61khspqHFCX4fZxh0hk5v/ke2pG/D9nVr7rIEK r4cLvrQsAssyTdq+iNELlYfAsAtFZJp7PVA13kj0Ndlqw+VY0m8nUnYh7pdayfIlamFf QCz7I0AaMV0kFOLiVX3CGGT4tqELtv3Swif1NpF0C8vpQRmcoMZ2PFxgY9vYarhXOEbf nBzw6noruf+8BWiNBBiO2z+10nLnM0VIHhi1TBGh9HFzJwLN+vPxJ2rGI5Qru8c80Yqm i6Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=bKKDtdP7qobmAYP/SLabmWp8pGjLp48puOqs7irQFpQ=; fh=n+CrnPhBQpytWOqkK07OjyokYLgVHKry+pAXl2y8TIk=; b=bV2Q+xnAwjkKVFKHCDtxHyLiJwBEV3qJ7YH9RYHP6YG1HghemG2Fcnn+rXm0MOxtdu //Nlo0yvTPtXF4lFRzlEkHWVnCfxYo/bm43ImAcKS5PaKYYgSDNbZNh9S3kkLCqnm5oq ef0l6YbwmNPxY94TBNhkzqmzJM805yYJQx40psoDGNqxRqQasGaI13SYQbIDYFO9o+ef Z81jJo2lOSRZptiSuYaX2ulc0juxGqXT6pdyZ+iMJylI+TlclLhxeeV25Sessu0AffO9 rBUwteldzGbanSS6fq0MgiXkje4ASbdJYCFWK/ZN7rpw/LeeWH8cfIp8SBhtZZiehu8O bPVw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780566918; x=1781171718; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=bKKDtdP7qobmAYP/SLabmWp8pGjLp48puOqs7irQFpQ=; b=LL4RxdQgImzNFvCs9K7j7vE8WdG5enjmS3ptTo/sj0QfBZFVMUoFNpyUf0bv0BesvK YMcK+szuTdmVWWr+4he4m3orPng3EcwTOIkDiOQbgsovfZP4scPSirYo4UBk9QAW68+l jVw6qmnL90LsRLUcmv3Qx2Iua8HoBoquQKHkP8wH/7p1s8iITFDiHbrINxE2wUCad7Qk pn8gT8BforSq4qh+5Yg4Tv0XrfIKi33/Qq25n+Jbh2pBFt2fVl6Jn2PZByizqtLkCZTB vRgTNvicWe5rhk4ePIlilRdwAWajT9Y4+TR5odRSlnwqcKgmMPRNgMEanDx/TCgCeE1P +FKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780566918; x=1781171718; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=bKKDtdP7qobmAYP/SLabmWp8pGjLp48puOqs7irQFpQ=; b=es1x8mXUrzAOTHvhb7RRqpD6ymiwltJNj4mDtgisack6Oxqe2fpHDRLSotxj2W+QoV LpHxhtW5VgoGiyrWaW6TAdoGzA0p2HQC4dPTd9M+qYQAGsDr7aFBelH1A4Dfw+wuafq5 DleGokspdrQN+WjlsKANLoveot+k45jLgq5QXLMKahrhDC63vT/9qlXuxGJZwYcsNwN5 KyAlbru6jhxU+WM8qAhyB1iu084hPORKb94yluWBjwwei2xdXyYXUAjQXOqHXpt9N8gi PlyynIPhnJBT8/qP7ktgqqo529D5czB9mzRfw6L5iBwAc1Mhx5bwpxLWRfEZ6DRZddHW +gxw== X-Gm-Message-State: AOJu0YzKSq9RBjAse7RC0Lx3RlMbpAOodQ2nYrTy+t64T/lRmUuF48XH eiSQMdgPgdM79VmeTkrpjVFMbUgHfTO6/Xtczr46sYO4RvLLitgMD9Q+ic9Rxr7aX3YkGLp1i5T vnRO36NZWRt01irCNRzqv+bMRWqZ+ebc= X-Gm-Gg: Acq92OGjbStNyPYFIHo7K5zSRpOCsJWMijW0FFiARtGXqdiui2WD+1eK+ASmjD99pH7 ZBnLjUlJpN8afsHG1HfYSkpMdyKxx4/rZYhRrQXTJb488oUXE3iZna23TK/KnCFbPvg3UhtgRUK y2fZTVV7WRsx7UEANJrzsqiRQT4oroCV3CK9bziWK50B+SfT32zGjZtrCjylZPY9nulf3r+cecU UpIvsPpKuvzn1PA5yGnBBjNRaVBu9DHHT6W8rfrdGcfWlwV28WEmPSQOd5kQlaHcsr2PlyzpeTZ 2JKkvHLrt1gX7Btz5/gI2uP0+KuSMRCukyI55TiHI0e5XEAnJLmwSAMs0fcVfnO/5JLAa7GG00d QlS99Dh5z3VHQK7RUIpH6eK0vZmtr5/m0Dh551Gm7d35aiK/VWQHT7YRdP5feKw== X-Received: by 2002:a05:600c:3596:b0:490:44eb:c1ea with SMTP id 5b1f17b1804b1-490b5edd71amr128587885e9.24.1780566917926; Thu, 04 Jun 2026 02:55:17 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ashutosh Bapat Date: Thu, 4 Jun 2026 15:25:05 +0530 X-Gm-Features: AVHnY4JIN4gxMwO8nWQXeXQyDwWhC82RqKpRkYYGAvgjX7RujuVa_Ac0U-gABS0 Message-ID: Subject: Re: GRAPH_TABLE: lateral reference with label disjunction fails with "plan should not reference subplan's variable" To: Ewan Young Cc: PostgreSQL Hackers , peter@eisentraut.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Ewan, Thanks for trying out SQL/PGQ and the report. On Thu, Jun 4, 2026 at 1:58=E2=80=AFPM Ewan Young w= rote: > > Hi hackers, > > While testing with master I ran into an internal error in the > SQL/PGQ code (commit 2f094e7ac69). A lateral reference into a > GRAPH_TABLE clause whose graph pattern contains a label disjunction > resolving to more than one element table fails at plan time: > > CREATE TABLE v1 (id int); > CREATE TABLE v2 (id int); > CREATE TABLE x (a int); > CREATE PROPERTY GRAPH g > VERTEX TABLES (v1 KEY (id) LABEL l1, v2 KEY (id) LABEL l2); > > SELECT 1 FROM x, > GRAPH_TABLE (g MATCH (s IS l1|l2 WHERE s.id =3D x.a) COLUMNS (s.id)= ); > ERROR: plan should not reference subplan's variable > > The same pattern with a single label works fine, as does a label > disjunction without the lateral reference. Reproduces on any build of > master and 19beta1; the equivalent hand-written query (LATERAL over a > UNION ALL) plans fine. > > The cause is in rewriteGraphTable.c. replace_property_refs_mutator() > increments varlevelsup of lateral references by one, assuming the path > query will directly become the GRAPH_TABLE's subquery. That holds for > a single path query, but when the disjunction produces several path > queries, generate_union_from_pathqueries() wraps them in subquery RTEs > of a new UNION query, one level deeper, and nothing compensates for > that. The planner then attributes the parameters to the wrong query > level, which finalize_plan() detects. > > The attached patch increments the level of outer references in each > path query once more at the point where they are wrapped in the UNION > query, using IncrementVarSublevelsUp(). With the fix, the query above > returns the same results as the hand-written UNION ALL equivalent. > > make check passes with the patch applied. This bug is the same as the one being discussed in [1]. Let's continue the discussion there. [1] http://postgr.es/m/tencent_43D9888041FA4FDE498C7BF1@qq.com --=20 Best Wishes, Ashutosh Bapat