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 1nFP8m-0008Ed-Lz for pgsql-general@arkaria.postgresql.org; Wed, 02 Feb 2022 23:34:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nFP8k-0000Y0-Co for pgsql-general@arkaria.postgresql.org; Wed, 02 Feb 2022 23:34:18 +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 ) id 1nFP8j-0000WG-Mz for pgsql-general@lists.postgresql.org; Wed, 02 Feb 2022 23:34:18 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1nFP8a-0003k4-Vg for pgsql-general@lists.postgresql.org; Wed, 02 Feb 2022 23:34:16 +0000 Received: by mail-wr1-x433.google.com with SMTP id v13so1445590wrv.10 for ; Wed, 02 Feb 2022 15:34:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=dM6+NknNgOBe4+0EQ7+dbtbuH3fasZVM45P3jSbv2nk=; b=TyiE1L3ZacL/pRfbm92xXlI0DNWRPrz01ofoP5G2dNU62Let2Ob2EteFp2j3tyXBa8 Vzoy04ZsKmEDEGlW99bFgZjlHwMlP1GRqgkbixNT9TuZK5i0GnDZPdJPdpt9WLzsN79/ UUqgFIyT+gRgcFu1lQu3vgcrSNMZ1WyHc5X1+VfaFktChhHWi+8p4vm3eL1z8vF6jKsL DLmbONw12YEEbItjhc7o4JEknhIHC4dCV6ZhbX7M7tIYkXcncANV+h8+qAABOm7d22eg qHrDW8XNsTVnIiuFqiRZP6kPBndgpftLWGU3VagYfgPRwe7eiK5d9Z3/lmwYZpyzoFhX fPiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=dM6+NknNgOBe4+0EQ7+dbtbuH3fasZVM45P3jSbv2nk=; b=ZddC3JLhXJ2DmZvPexOPpI5sGms0eBy95OmOxAGiR2yTPMeOxzZDHJtMMp7xrcD1Bm e553052YjBUmzUNFoQN1vbWx9Ssqd3hM2GptwzP44AAjUagl/4SNfqtOsERPqqFoP9Gn P+oytEQu1tO3j9U2CuwWh2L00yLR45oxJy8laloKgzzlMkzvyT+UBuaEjOC94ik2TX48 msQazRlMDs4j8J+JrGGVmyjvnc0YZJyPdxJ8OkTEmXUbEQaLninH3pltrNiMBovo1W8r i3yM8/x5Zwe3uPWJugqha1Sls0X/RVoqW6zPv3Pmvp4yvHBSfKt+/Hfzs2+L0quOyyCF cX+A== X-Gm-Message-State: AOAM531Aks9hmYo/0qzatdhFYwEjf3TrD9VbManXIddKNIaLo582iSSU StJA4B+gTb7llb6h0XHo75bkqYtyvYiVdSxTw1n1cEH8pi6eqr5xBAkhcuP8ChnP3u8kYxEOl0w Q2KxfHAXAIMGuzXAaQo25Vzpim8h/dWZu/hDAJW0Bsv58O7wCQygGbtyoTuGPXr3QfRME/yIHas g6KnwtXFj8tk/zvzd1Nxz8UyxwjpzVLi+oKybXtqpDj05HpY1G9caA X-Google-Smtp-Source: ABdhPJyyXuAhzlhMB4k7wuuUcBOvDtnGvQES0935Pe48dALX0pGo6tM/mlvYed8dTInO2iMcdQjaTw== X-Received: by 2002:a05:6000:1861:: with SMTP id d1mr5263535wri.92.1643844847695; Wed, 02 Feb 2022 15:34:07 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id t4sm5836104wmj.10.2022.02.02.15.34.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Feb 2022 15:34:07 -0800 (PST) Message-ID: Date: Thu, 3 Feb 2022 00:34:02 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: increasing effective_cache_size slows down join queries by a factor of 4000x Content-Language: en-US To: Artyom Shaposhnikov , Michael Lewis Cc: pgsql-general@lists.postgresql.org References: From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/2/22 22:10, Artyom Shaposhnikov wrote: > the row estimate became ~1000x smaller with the stat in place, so it > looks like it grossly miscalculates the query plans without the stats > for large tables representing M:M relations. > Well, if the estimates are significantly off (and 3 orders of magnitude certainly qualifies), then all bets are off. There's no magical option that'd fix planning in such conditions. Ultimately, fixing the estimates (e.g. by creating extended statistics) is the right "fix" as it gives the optimizer the information needed to pick the right plan. > On Wed, Feb 2, 2022 at 11:47 AM Michael Lewis wrote: >> >> What does the row estimate look like on the scan of data table with that statistic in place? Anytime the stats give a mis-estimate this far off, I wouldn't expect that plans would be optimal except by luck. >> >> Index Scan using data_pkey on data t (cost=0.57..21427806.53 rows=58785023 width=131) (actual time=0.024..0.482 rows=854 loops=1) >> Index Cond: (id > 205284974) > It'd be interesting to see the plans without the LIMIT, as that makes the "actual" values low simply by terminating early. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company