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 1ohsTl-0008AN-5G for pgsql-general@arkaria.postgresql.org; Mon, 10 Oct 2022 13:05:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ohsTk-0005GL-1l for pgsql-general@arkaria.postgresql.org; Mon, 10 Oct 2022 13:05:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ohsTj-0005GC-Ns for pgsql-general@lists.postgresql.org; Mon, 10 Oct 2022 13:05:55 +0000 Received: from bar-esg2.cablenet.com.cy ([109.110.244.74] helo=barracuda.cablenet.com.cy) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ohsTg-0004mv-Gm for pgsql-general@lists.postgresql.org; Mon, 10 Oct 2022 13:05:54 +0000 X-ASG-Debug-ID: 1665407148-17c036175887740001-cI9M9q Received: from mail0.cablenet.com.cy (mail.cablenet.com.cy [213.140.208.238]) by barracuda.cablenet.com.cy with ESMTP id ZoU3Sv1Y62GdIGmH (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 10 Oct 2022 16:05:48 +0300 (EEST) X-Barracuda-Envelope-From: kostas@methodosit.com.cy X-Barracuda-Effective-Source-IP: mail.cablenet.com.cy[213.140.208.238] X-Barracuda-Apparent-Source-IP: 213.140.208.238 Received: from localhost (localhost [127.0.0.1]) by mail0.cablenet.com.cy (Postfix) with ESMTP id B30695A40D2; Mon, 10 Oct 2022 16:05:47 +0300 (EEST) Received: from mail0.cablenet.com.cy ([127.0.0.1]) by localhost (mail0.cablenet.com.cy [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id b5g0jJCK0vWN; Mon, 10 Oct 2022 16:05:46 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by mail0.cablenet.com.cy (Postfix) with ESMTP id C143F5A2806; Mon, 10 Oct 2022 16:05:46 +0300 (EEST) X-Virus-Scanned: amavisd-new at mail0.cablenet.com.cy Received: from mail0.cablenet.com.cy ([127.0.0.1]) by localhost (mail0.cablenet.com.cy [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id ahULdHXWzZyt; Mon, 10 Oct 2022 16:05:45 +0300 (EEST) Received: from [192.168.98.4] (66.red-88-21-136.staticip.rima-tde.net [88.21.136.66]) by mail0.cablenet.com.cy (Postfix) with ESMTPSA id 64AA85A40CF; Mon, 10 Oct 2022 16:05:44 +0300 (EEST) Message-ID: <8da58bc7-a01a-0168-3d49-062258ac82ec@methodosit.com.cy> Date: Mon, 10 Oct 2022 16:05:42 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Subject: Re: Same query, same data different plan Content-Language: en-US X-ASG-Orig-Subj: Re: Same query, same data different plan To: Daevor The Devoted Cc: pgsql-general@lists.postgresql.org References: <20b3e283-3107-cd18-6e7f-90ed58e7ddf8@methodosit.com.cy> From: Kostas Papadopoulos In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Barracuda-Connect: mail.cablenet.com.cy[213.140.208.238] X-Barracuda-Start-Time: 1665407148 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://172.30.36.5:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cablenet.com.cy X-Barracuda-Scan-Msg-Size: 868 X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.101322 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, Yes, I ran ANALYZE in both databases. Kostas On 10/10/2022 16:03, Daevor The Devoted wrote: > Hi > > Is the table stats up to date on both? > > https://www.postgresql.org/docs/current/planner-stats.html > > Best regards, > Na-iem Dollie > > On Mon, Oct 10, 2022 at 2:56 PM Kostas Papadopoulos < > kostas@methodosit.com.cy> wrote: > >> >> I have two identical databases running in the same instance of Postgresql. >> Ran >> analyze on both. Running the same query I'm getting different plans, one >> x10 slower. >> Although I have solved my problem by re-writing the query, I want to >> understand why >> this is happening. If the configuration, Postgresql version, schema and >> data are the >> same, what other factors is the planner considering? >> >> -- >> >> Kostas Papadopoulos >> KE MethodosIT >> >> >> >> >