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 1tzvsm-008mm0-3I for pgsql-performance@arkaria.postgresql.org; Wed, 02 Apr 2025 11:03:44 +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 1tzvsk-00CRXf-RE for pgsql-performance@arkaria.postgresql.org; Wed, 02 Apr 2025 11:03:42 +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 1tzvsk-00CRXV-Gl for pgsql-performance@lists.postgresql.org; Wed, 02 Apr 2025 11:03:42 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tzvsi-002XAS-2W for pgsql-performance@lists.postgresql.org; Wed, 02 Apr 2025 11:03:41 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-39c1ef4ae3aso389897f8f.1 for ; Wed, 02 Apr 2025 04:03:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1743591819; x=1744196619; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=Xc9aKdxwUyq1v3t6JPN7iVJQ/psOGAUxaExS/qI5t2c=; b=C0uWdAlPwDICKI3tAKf2sTI5I7Ha9jLTQ4qkIH+7Vw1Ma5mNOevTNcURJSMltRtzPV iK2mPfzUARSNjWtqFXFVFYAfu3L9pXxCFMGDq/VerYBSdmK9RnoTzohLhISbeMTt4DAU wghfSXizTiYdm4o/QjmLiUzQBFESxLczuU2W3L1HEkJnS9rZAJ6/I9Tr3rvbTTdX514A pymO9hD92Rpi1M09maQpMroxXiqPCBPg0CmqtFjKWGefrwTFPaAR2heQPOz1fg8zT4Tb MCmEBoZIcB+2xbLp1v2mV3mUodVwf4FuI1uPX2p2KPJ2dHJHCvz61A8psZjsAp1EeVpU xq7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743591819; x=1744196619; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Xc9aKdxwUyq1v3t6JPN7iVJQ/psOGAUxaExS/qI5t2c=; b=PzSLcQeKVirO5lvqruF5RzwV26BEt87Bnmw9c1BmsKV8lj7htku0uFg2dLyYmRbaOB sAEorKug0mmDoHg0xoeKwVZDf5M2USy2bNcAoguPSLqX03iSrwHyAXWYFauWaSWVcKjs eVF/JC4V6JcUwuFmcc7R2WZGNSppPzteRRHHD1LMlkMaNL5gfxxj5CoNpy+oohiaB8Mm lw+voDRFtGnYTaCnHlEgv3zFMp/vA+5RL2sV/BkCKgkGgXmFhc9+61sF4vODKBTzYnpZ BsNljo8wLJuBt+ey1q3tk0w8Xo1b9CIB5WhWKCdcNDVaLky3s5eMEC6U6NDbZ1dsIsgo CdkQ== X-Forwarded-Encrypted: i=1; AJvYcCW5XP8fYhc1eOuo/VVzquA2J1GYjMgV0B4STgV5aSUw3Mx0RtVOSbRm3B7G1yTZI26Fac3theIY4SeAarrausA9RA==@lists.postgresql.org X-Gm-Message-State: AOJu0Yx/YEYVsZFitSMOpcPBt0pooEsZmhbATSjhvLkMbtGk/yyYQLpb x8CayhG/nmrKg3KHgeFdAZogFf1VvlO2STgtKsfZOuBK++HxtVQuk7Z5OLvxUDg= X-Gm-Gg: ASbGncuUwer03ljVGOQvHQNjTgQozcEhiHzn7srJqXI9Pu/t9gK1Ult9S+OVLGPmPIh Ig8w90cMZ/PiiTXwlAwLYA9gR5w10x+T80N9X27Qefv7qBNBT2gGd/gRUNKjFVGam/Kudd/617M tcatMOCyt7i4h24Qip97Q6kb6b5oegGkJWsuwK1WQbzleO33wV4ryfsS605gEGh6KHeKGOawWQB E02e13dY3L0xukNNvLIi4qtpZm4vPVaBK++fioG7rEVqfHOLsLQG3CS86CA3Z/oV7aV2eqLOWC4 Sj+h8OEGo1CCd37ysOFHRaGqLDuviGXX2VgKzSVdF7eaBI+E7L4vF/TkJz/eOXPXKdW3wInIKST OCfs= X-Google-Smtp-Source: AGHT+IHykK9rt2watzOV/eHXY+ajTfsqMSYUzddynqs/FPGgbC5AFqMtYG3OaIfD7FAMjGw7OWdcqg== X-Received: by 2002:a5d:6d82:0:b0:39c:1efb:f7c4 with SMTP id ffacd0b85a97d-39c2a396975mr1543150f8f.25.1743591818559; Wed, 02 Apr 2025 04:03:38 -0700 (PDT) Received: from [192.168.0.89] (84.123.232.230.dyn.user.ono.com. [84.123.232.230]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39c0b65873bsm16440970f8f.8.2025.04.02.04.03.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Apr 2025 04:03:38 -0700 (PDT) Message-ID: Date: Wed, 2 Apr 2025 13:03:37 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: partition table optimizer join cost misestimation To: James Pang , pgsql-performance@lists.postgresql.org References: Content-Language: en-AU From: Andrei Lepikhov In-Reply-To: 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 On 4/2/25 12:18, James Pang wrote: > Hi, >    Postgresq v14.8, we found optimizer doest not take "merge append" > cost into sql plan total cost and then make a bad sql plan. attached > please find details. I suppose there is a different type of issue. MegeJoin sometimes doesn't need to scan the whole inner or outer side (see the MergeScanSelCache structure and how it is used in the cost estimation routine). So, the cost can be less because the optimizer predicted that only a small part of the Append will be scanned and used some sort of interpolation between startup cost and total cost. But to be sure, could you send the results of EXPLAIN ANALYZE VERBOSE? If you also send the data to reproduce the case, we may find the source of the problem more precisely. -- regards, Andrei Lepikhov