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 1uH2LU-00CHeR-E9 for pgsql-bugs@arkaria.postgresql.org; Mon, 19 May 2025 15:24:05 +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 1uH2LT-00GW7V-47 for pgsql-bugs@arkaria.postgresql.org; Mon, 19 May 2025 15:24:03 +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 1uH2LS-00GW7N-Qi for pgsql-bugs@lists.postgresql.org; Mon, 19 May 2025 15:24:02 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uH2LQ-002hW6-18 for pgsql-bugs@lists.postgresql.org; Mon, 19 May 2025 15:24:02 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-43ea40a6e98so47542825e9.1 for ; Mon, 19 May 2025 08:24:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec.at; s=google; t=1747668239; x=1748273039; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=QTD8b8+8Bxc77ysbTUvAFF6CBl3bme6+W4+i1Pp2QuA=; b=i7TWSx63PpcyavQYEMKfVsTGRQY1CAwYzSQWyotR0dy7r8M34wDS/3YWrDJJnsmTU/ as24JEhw5N4SKrFCVN1GX/m0yloy7wshqweVs5D//qIjKkjOyVuknxd3vcnPKfGmMMEw 2h+LIFDTly1O3W2UMImh5khdxPqEvcJQSOMV8RW1QXo++ZFGWS8cQjg7PGYOnuXOFWHa VreLd8DQiGrrCv/qsKv2XGmvUVzUZnzxwFK99vMr9qtqWTchWQkiPA4RBiIL351YhEma OS0nZO5l2VuvwgZ0U0on/oR6gnXlsZvcMGtmpVPV8AbIlriRtzrAb8fpCkrk1iF5vDTw EqSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747668239; x=1748273039; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=QTD8b8+8Bxc77ysbTUvAFF6CBl3bme6+W4+i1Pp2QuA=; b=qCTKViFr+5ZnpRhX6xM1I7NGtbRJJr5MDh9OBBUB4C5LK88KwCBUP9YDi/AfiFVaUw v8Mswx7uH1coE9jmFwVLT0ynKQgymX4tKboc3eJ0qqIh0NnERL2BZSHb3vuKgnBdIVN5 3XUHDwli8yfW2OcjwWQcVm0BPl0KZIOY5vCgA74Lw31uv6hjKEQ7bnGGCTW+3oSFUFSH sYu4aqtVd2IMMpiGXSDO9nyPvEBsv8KnwTsTwXDUPfP3ETb4lJ/IzvQmTXcBWbDhgEVa 3Z74KsrNLdcuECqYey0w4zDVTltgEnPVkGF7IOymk49Wjmec61gR4whG/AiYujpdAVOT Ph1A== X-Forwarded-Encrypted: i=1; AJvYcCXB/a+d5M8VZlYtW5LlKSgPgArIVXURQqaE41kvsBHgfaax4gqRvdrhB69cNJCObe1MpiIJfewIxOUX@lists.postgresql.org X-Gm-Message-State: AOJu0YxVIC+iiySK1bsCYM3g3iropd+RSkgEiPwCZqcccq3OrsjDdwgo UgCxBDbVxFHi5pg7Zd3A4oDTzYSlE+9/fqG/aF+S1hs+LUP93WrP0D1bg5b1FkHxmKLfdtlwZId jIOc8SVg= X-Gm-Gg: ASbGnct1GwObYFyDCS9wwFK52KxQJhoYveHiks2lAAHYMk40m4dYwwVOhj+UalHQL/T MVX23Rt4eLEf24OPxIs1i8MasMqmONHbvJrNQ1Jdu7Y8fdPbSGplAK891IfwChjecsacytZQubq Ik6fLxkz1f5SVE8ySOIoACYOrUo4BjvAzAKsnayZ5bu6xIeKVBzSXVMXrQKe4w/lvQbP3D3le1C RHyI9qmYPEwzxWuYvTXevsavIYFM96P/fwVDSwwyD1y/Quf4gGo49zl1dH5hYN/aqGWBb+vG663 /DyKg3q+32MoBaxV/IfxgQ/X5DSGdKfi5K0y0UVQ5q8GU4I+TPMJz5NsF7fl/7C0ZWWxUbktN3k XB8zV8w== X-Google-Smtp-Source: AGHT+IHMamZh4HlcHDNAZgofmdUMOwtjPgd8R+3ES/DPFyBm7A6TVr7QfniwbRFlA0DHkzIEx3nptg== X-Received: by 2002:a05:600c:8215:b0:441:b5cb:4f94 with SMTP id 5b1f17b1804b1-442fd606ba6mr125905985e9.5.1747668239167; Mon, 19 May 2025 08:23:59 -0700 (PDT) Received: from laurenz.albe-K4N0CV00F97414D ([2001:871:255:52d3:3ac8:61ab:b634:342]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-442f9053b4dsm170913435e9.4.2025.05.19.08.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 May 2025 08:23:58 -0700 (PDT) Message-ID: <4d33efcf76aa2a7d48c90c74e1889f4a571a787e.camel@cybertec.at> Subject: Re: BUG #18935: The optimiser's choice of sort doubles the execution time. From: Laurenz Albe To: xiaohongjun@stu.xidian.edu.cn, pgsql-bugs@lists.postgresql.org Date: Mon, 19 May 2025 17:23:58 +0200 In-Reply-To: <18935-afc77176f41fbecb@postgresql.org> References: <18935-afc77176f41fbecb@postgresql.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.1 (3.56.1-1.fc42) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2025-05-19 at 12:42 +0000, PG Bug reporting form wrote: > database4=3D# explain analyze SELECT t0.c0 FROM t0 INNER JOIN t1* ON > ((t1.c0)=3D(((t1.c0)-(((((t1.c0)*('(-795716537,-245904803]'::int4range)))= -(range_merge(t1.c0, > t0.c0))))))) GROUP BY t0.c0; > > [explicitly disabling sort leads to a faster execution plan] I see no bug here. The join condition is so complicated that the planner has a hard time estimating the number of result rows for the join. It guesses way to low, so the sort is expensive, and avoiding it is cheaper= . The optimizer cannot be perfect, particularly in the face of complicated expressions like that. Yours, Laurenz Albe