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 1mua3E-0004Ij-LH for pgsql-bugs@arkaria.postgresql.org; Tue, 07 Dec 2021 12:58:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mua3D-0005bF-E4 for pgsql-bugs@arkaria.postgresql.org; Tue, 07 Dec 2021 12:58:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1mua3D-0005b6-5V for pgsql-bugs@lists.postgresql.org; Tue, 07 Dec 2021 12:58:31 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1mua3A-0008Nf-KH for pgsql-bugs@lists.postgresql.org; Tue, 07 Dec 2021 12:58:30 +0000 Received: by mail-wr1-x42e.google.com with SMTP id t18so5386402wrg.11 for ; Tue, 07 Dec 2021 04:58:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Z6jYlKHvVvgx7/Ub0Sm8XkWFYrQGbJWkKwqqWLjve68=; b=evjyMN4fOEwxkPhFUbo3vkWjIrle0mwXJEXSIiFbCrdWOOyYQXzvYZS0SILxS+C9Yf 04SN1YjBhls+i6+Ns9mIIFnH+EX3tG4jhOW+YF/jAK7Yk44I5kz/hKXcnada6EYQvJQu ZZ9oW/xS83s/mWSdUwi+aQyYBqE2oMwTbRPzjL0Kv4F3x7l6qxZ57uv0A0UsgmdTc66r 9D4GbVuNxLDtM3Es7do2lCiwdIrndimPy8xkrByv0W01njlTJNFcbPVTRSlcHwScD2EU OSK/mhTKRV1mxJ5THPCgC+wvCmyd2chx8Ex7ACG8RKt78u1eF7cHmFO43gdtIECvg4gG eMnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Z6jYlKHvVvgx7/Ub0Sm8XkWFYrQGbJWkKwqqWLjve68=; b=GpPtKmtZ/1Ykq+LpDBdKn937SsRFCcX6T51V3UGqLVPtWKiJslKpuV4rPwq0d8g8nk GpnfT/BMwL2Wkq2Lmo5HC0AkXoBYPlVcPiDP9xEtP6dtXshWFzmN8K/i7F7VtJ8xFOF8 pXLwYTUuk51uC9KHPvUlfrkGlzGUwyX0IJ0FSu/F3JLeDKGyjrrhAuWLgwOaB4RSe2rv hjiB9fQDH9Wp+QsG6v75ONlSa0phMnasbYP5yWgiJ+o4cJr97J/fxRlpWKlZt6r0n9qs t7W7mWpXMvIAhmS4I3r1OsBtlRjiGtNxSe1A60/skTqekHlyXqTii/v3eS4EzQGwBvSe p6tg== X-Gm-Message-State: AOAM532o2JrQnc6Smc+tHOSWq8bN5olcIiUHN6mH3Yyf3OH6ULiFCRZ4 kEYnTGlgAt+8lAw0K0Lq60o= X-Google-Smtp-Source: ABdhPJxBIdbbyER8VOTJU9Nbdwwsl7xCLsOXQnPZoycksONRzZPsm+sZQmZophTisd0VYbB1UGaZuQ== X-Received: by 2002:a5d:6dca:: with SMTP id d10mr51920398wrz.491.1638881906234; Tue, 07 Dec 2021 04:58:26 -0800 (PST) Received: from localhost (dslb-178-012-041-031.178.012.pools.vodafone-ip.de. [178.12.41.31]) by smtp.gmail.com with ESMTPSA id b11sm2500789wmj.35.2021.12.07.04.58.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Dec 2021 04:58:25 -0800 (PST) Date: Tue, 7 Dec 2021 13:59:25 +0100 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Tom Lane Cc: 253540651@qq.com, pgsql-bugs@lists.postgresql.org, Peter Eisentraut Subject: Re: BUG #17318: ERROR: AddressSanitizer: SEGV on unknown address in optimizer Message-ID: <20211207125925.jps4l6tr7htd6h3z@localhost> References: <17318-2eb65a3a611d2368@postgresql.org> <3048015.1638802600@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3048015.1638802600@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Mon, Dec 06, 2021 at 09:56:40AM -0500, Tom Lane wrote: > PG Bug reporting form writes: > > WITH RECURSIVE x ( x ) AS ( SELECT 1 UNION ALL SELECT x FROM LATERAL ( ( > > SELECT * FROM ( ( SELECT 4 AS x ) UNION ALL ( SELECT 5 AS x ) ) AS x WHERE x > > BETWEEN 1 AND 2 AND x < ( SELECT 3 GROUP BY DISTINCT ROLLUP ( x , x ) , > > ROLLUP ( x , x ) ) ) UNION ALL ( SELECT ( SELECT x LIMIT 1 ) FROM x OFFSET 0 > > LIMIT 5 ) ) AS x GROUP BY ROLLUP ( ( x , x , x ) , ( ( SELECT TRIM ( > > TRAILING ' ' FROM SUBSTRING ( VERSION ( ) FROM '^[^0-9]*' ) ) WHERE ( x IS > > NOT NULL ) ) , x ) ) ) CYCLE x SET BOOLEAN USING VALUES SELECT FROM x GROUP > > BY DISTINCT CUBE ( x , x , x ) ; > > I simplified this to > > WITH RECURSIVE x ( x ) AS > ( SELECT 1 > UNION ALL > SELECT x FROM > ( > SELECT 4 AS x > UNION ALL > SELECT x FROM x > ) AS x > ) > CYCLE x SET b USING v > SELECT * FROM x > ; > > and now I'm not sure whether to consider this an optimizer bug > or failure to detect an unsupported case. Our SELECT ref page > says > > Both the SEARCH and the CYCLE clause are only valid for recursive WITH > queries. The with_query must be a UNION (or UNION ALL) of two SELECT > (or equivalent) commands (no nested UNIONs). > > This WITH query sure looks like nested UNIONs to me, so either > that restriction is stated incorrectly, or it's being enforced > inadequately. If the former, we have an optimizer problem. Looking through the original thread [1] it seems "nested UNIONs" means constructions like "foo UNION bar UNION baz", which is indeed handled in parse_cte. The existing restrictions probably have to be extended to cover cases like here as well. [1]: https://www.postgresql.org/message-id/flat/db80ceee-6f97-9b4a-8ee8-3ba0c58e5be2%402ndquadrant.com