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 1rM2XN-002JbO-2K for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Jan 2024 09:00:13 +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 1rM2XL-0083M1-Pp for pgsql-hackers@arkaria.postgresql.org; Sat, 06 Jan 2024 09:00:11 +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 1rM2XL-0083Ls-E5 for pgsql-hackers@lists.postgresql.org; Sat, 06 Jan 2024 09:00:11 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rM2XG-0008tz-G6 for pgsql-hackers@lists.postgresql.org; Sat, 06 Jan 2024 09:00:10 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-50e8ca6c76dso321101e87.3 for ; Sat, 06 Jan 2024 01:00:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704531604; x=1705136404; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=hApyfeJcGmntN9JiViOuZuflecfeCF6BABRFILK3CQk=; b=gVQ4c4jj8ucJ+8EfvtTU8+OAim1+20FB1YDEYjupMf4HyPCC+8tcnZSxsvYH30V9xH 7W4MH9EyYP30ia0y2tm5t7RSNow2Bu9qr3f8GEHu0FjwYkVANSuLSv/ezBy6oA4dxfkK 0Nr8aHrxxvGkgtER5Xr9lKlZcv8Z6zRNAjQTdpGb59D18IYiUak0M0+6mtui4ah0OFC5 2AMIkeBxWf8JwAz6yo5bhyyXAKZlaCTtw7vmVFjPPKA5Wpky/Tis566bk3VIxByLLyjU FZGPWEoJed+Afy6jVHbliaRgrlX/o456yg7eJ0UJ+abl13zQsgObeZ8TpxjyKW8YSS0C p8Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704531604; x=1705136404; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hApyfeJcGmntN9JiViOuZuflecfeCF6BABRFILK3CQk=; b=oF/B+LTEotqGqBYEAHx7M1yvMtlxMEXs9v2eWeF5YG+9ppYEZ60TOerzUGXJT9w0C+ NRBxFyHCi2Z3PApvPbW4HZI0PQd9fTdwFSbxmh/TFUPR1ayYtlsEIgU38z78lO63yPFi fZF6qJBZoQ29r2+cad04Gb/2pNOEjvK4kZidk3ajuMs5c0sTUhb9Fn8EGnq/ByfFXW7+ 6u9vHKSMB+vd9pR49akEw0vzxozqpmJdDBrsyhf0isE36QpEjHK/dvCooj6PHbNFXxtJ Tknxq66qoxF0CGtfTi6YUw958z92Lr5hqTxBAztqD0X/dSkO0jiJyv3x587PIr8LN5iK plwA== X-Gm-Message-State: AOJu0YzFRU0RDZMRyLdhdwEj9nPv9iwPmR79fAv3RtZ+C+j5tjR82CIJ FjJ7a5CZ+G6YIxc9W6Bz3zo= X-Google-Smtp-Source: AGHT+IFngIbZ9q6iF55TCf4iqqqaA8u+tf8Oa8e5TQf1S+q2hE8MSDG5gHBUQhe3mtLotO9HUbOzPQ== X-Received: by 2002:a05:6512:1105:b0:50e:59cf:e548 with SMTP id l5-20020a056512110500b0050e59cfe548mr258281lfg.94.1704531603508; Sat, 06 Jan 2024 01:00:03 -0800 (PST) Received: from [1.0.0.7] ([91.185.77.50]) by smtp.gmail.com with ESMTPSA id b2-20020ac25622000000b0050e6bf65b2asm473782lff.288.2024.01.06.01.00.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Jan 2024 01:00:02 -0800 (PST) Message-ID: <608a4886-6c60-0f9e-97d5-591256bd4150@gmail.com> Date: Sat, 6 Jan 2024 12:00:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: Wrong rows estimations with joins of CTEs slows queries by more than factor 500 Content-Language: en-US To: Tom Lane , Richard Guo Cc: Jian Guo , Tomas Vondra , Hans Buschmann , "pgsql-hackers@lists.postgresql.org" , Zhenghua Lyu References: <4504e67078d648cdac3651b2960da6e7@nidsa.net> <46a7d950-7ca7-8ab9-76dd-f0bc7611c609@enterprisedb.com> <891440.1699483495@sss.pgh.pa.us> <414317.1700158568@sss.pgh.pa.us> <482957.1700192299@sss.pgh.pa.us> <754093.1700250120@sss.pgh.pa.us> From: Alexander Lakhin In-Reply-To: <754093.1700250120@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello Tom and Richard, 17.11.2023 22:42, Tom Lane wrote: > OK. I pushed the patch after a bit more review: we can simplify > things some more by using the subroot->parse querytree for all > tests. After the previous refactoring, it wasn't buying us anything > to do some initial tests with the raw querytree. (The original > idea of that, I believe, was to avoid doing find_base_rel if we > could; but now that's not helpful.) Please look at the following query: CREATE TABLE t(i int); INSERT INTO t VALUES (1); VACUUM ANALYZE t; WITH ir AS (INSERT INTO t VALUES (2) RETURNING i) SELECT * FROM ir WHERE i = 2; which produces ERROR:  no relation entry for relid 1 starting from f7816aec2. Best regards, Alexander