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 1qY2a4-000d3u-Gk for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Aug 2023 10:56:20 +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 1qY2a3-005j2i-E2 for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Aug 2023 10:56:19 +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 1qY2a3-005j2a-3y for pgsql-hackers@lists.postgresql.org; Mon, 21 Aug 2023 10:56:18 +0000 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qY2Zz-0009mn-Ap for pgsql-hackers@lists.postgresql.org; Mon, 21 Aug 2023 10:56:18 +0000 Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-51d95aed33aso3983386a12.3 for ; Mon, 21 Aug 2023 03:56:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1692615374; x=1693220174; 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=9YEyRv3/HtPXGqm2lTZ0NguVs30f8t6O+CJ181I9Mdo=; b=aTWgn/nNC2tj/OijIaxlCtKOP2k6Kw4z2Z41Yb+f64DX3MzXKqffRXqmv9LZoMwuV6 KwjNBGIW5b10X8z0RZDruK3Dy9tMlo+WZgWO6Lo/r5YWAgs8Apd1VEyezkNjmnC7buuN SjXY4fgIMSAMuDPdcwDKaaj9Madv8C4B1iKIflm4Wfxf5l7D0jC61fI5jJy0GAPZ/+yn p6F15RI2RZO+SEiTgJFP236YOleSvuVJxkE3nOd8Obe5lAu13GmHX0reHnFcDg2DuV6s 7XpL5xeQlh0/saD1wq1rsDj9mDkMzEPw/ZRRH9U+kLDLdtclC772wEMT4VxaiC7Odg3W kemQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692615374; x=1693220174; 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=9YEyRv3/HtPXGqm2lTZ0NguVs30f8t6O+CJ181I9Mdo=; b=O2k5jaDU8aeGKANFyLu+ygYh+sSBMBD0Yu7ItjqVT1r/4ZTQ7D9uFEFfh1ieSetdrD kn/AXsEruUpTswyy64Srnkq2BUk44ParMQBSHIinEFKeTZZngYowdKTxN0RWX8vPoDSz WX1BhtEIfB5JilAWSgtIy2T81cOIYX2H9UF61jqjFN6AZYtA0Cwnnz/L8wtAXhiEAMDj FlqDaX1nZ3EXmchhjQpqjjw/CJWgXYKvb5AN7EvgkmEJkmD9XzHVI0bqdSW9mtjw/3lX tOwDyELxecfuKcFj+IqEvIrTs9vTBi+v5KaTUPyvN+TL12eqmHVoOf11/KLA5XVlhV79 yb9Q== X-Gm-Message-State: AOJu0YwSInW3Po6+NnPSodLLm2x9YXsbjTcqPj92h4SQKQwB+vPin6aQ w/K44BTweQ4rX2zz776KjxFIJQ== X-Google-Smtp-Source: AGHT+IF6P5i0K7n31KvCVkhzE5ZtEnoX3IDWdiGHwsP9ZK3BeMnDlFOhmg6udCSa8ZErV/Dh7lxWPA== X-Received: by 2002:aa7:d741:0:b0:522:ab06:7213 with SMTP id a1-20020aa7d741000000b00522ab067213mr4562397eds.27.1692615373687; Mon, 21 Aug 2023 03:56:13 -0700 (PDT) Received: from [10.137.0.17] (static-84-42-175-93.bb.vodafone.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id t26-20020aa7d4da000000b005233609e39dsm5775614edr.30.2023.08.21.03.56.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Aug 2023 03:56:13 -0700 (PDT) Message-ID: <8e629488-cb14-5f17-adb3-c02205ebacab@enterprisedb.com> Date: Mon, 21 Aug 2023 12:56:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: Wrong rows estimations with joins of CTEs slows queries by more than factor 500 Content-Language: en-US To: Jian Guo , Hans Buschmann , "pgsql-hackers@lists.postgresql.org" Cc: Zhenghua Lyu References: <4504e67078d648cdac3651b2960da6e7@nidsa.net> <46a7d950-7ca7-8ab9-76dd-f0bc7611c609@enterprisedb.com> From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 8/21/23 10:16, Jian Guo wrote: > Hi hackers, > > I found a new approach to fix this issue, which seems better, so I would > like to post another version of the patch here. The origin patch made > the assumption of the values of Vars from CTE must be unique, which > could be very wrong. This patch examines variables for Vars inside CTE, > which avoided the bad assumption, so the results could be much more > accurate. > No problem with posting a reworked patch to the same thread, but I'll repeat my suggestion to register this in the CF app [1]. The benefit is that people are more likely to notice the patch and also cfbot [2] will run regression tests. [1] https://commitfest.postgresql.org [2] http://cfbot.cputube.org/ -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company