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.96) (envelope-from ) id 1vuYGI-00D4Qb-0m for pgsql-performance@arkaria.postgresql.org; Mon, 23 Feb 2026 15:54:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vuYGH-00E694-0F for pgsql-performance@arkaria.postgresql.org; Mon, 23 Feb 2026 15:54:17 +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.96) (envelope-from ) id 1vuYGG-00E68w-2W for pgsql-performance@lists.postgresql.org; Mon, 23 Feb 2026 15:54:16 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vuYGD-00000000orO-3t7i for pgsql-performance@postgresql.org; Mon, 23 Feb 2026 15:54:15 +0000 Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4836e3288cdso29949945e9.0 for ; Mon, 23 Feb 2026 07:54:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771862054; x=1772466854; darn=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=qiI7CID8eOMFfOS4UXnkuOI0crjZ25jj7teHRz8OHdo=; b=HHvozETBTVlxNPjuCh/n+TkUFJp3/EHh+9C/XRyOX7nD95IgbUcbmw1013FploFkFB n4Co1mvQk7LpA5bQwedj7/11bqU3gkIBoT4RHWeUJkN4zkPAbdzXiHIdqyuZTvDKQ/3w SgytJgfIdn91g+gxmxU8eR4jrJ2bxBITqjZ/BJxYby/kxVhtnPZBrgxxm1ZCXL+Ne7Zc rofxWAbmBliPZ0cdzykG2ScK0RHc/uVJcTO65RP9i4BJiLNVfgpRBbFMbFbQ9btGkv3K z6NTs2N0T5Om6JeiwFquxsBXm3CaQYMy9HOtKqpHTPBIpGzrxBHpyY8FpXsjxrXVN6/o i93w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771862054; x=1772466854; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qiI7CID8eOMFfOS4UXnkuOI0crjZ25jj7teHRz8OHdo=; b=Ks4YRVYDSPSW3UbsUQfd9W86UarZAjO8Owz14XvRWAoSwHV2in/PNCwJTNiQ2qv1lM 1xyJxsX7WRJ2+Pnlk0AkjWTbKltvnKS4EiRffK3x+j9SBqVk/1ZmgJdExxY2uv13IxD+ QiW2uP8SW9qVStt6blpP1eb+NpAX0XsIS8p55WkC12LLVlisTGhuXpIqeH0sJ5rp8A06 0g2PRdCjd37aW/gX0FcD2ulfpPbYy1MkMh3Vl+OV/a/m3+o/5PqTZ/S36W70Cogzh1al VIkidI+xQBG6iusbs83xcH0W+bjOnaLw+pMAi4+Aaa+lmuC+jAE5N46W2GO9AEg2/43U QMsg== X-Forwarded-Encrypted: i=1; AJvYcCV0bEoYQFL4oO8vNu7xLNrCfjDxjDgtmEFi83xHCrsca5ChFU6OwFZxotybS9mBOqDZEb2ecSpOkSWl6D8RRN6dQA==@postgresql.org X-Gm-Message-State: AOJu0YzAK78eC+JjJFt68REy8UhcOQSaKE3l3jo9DhUbCQ5s4Mn437wE WPC0qoFNx1Y4q8edsMKJ8CHqW2Vf8tO1xXIvSVyOM+MqHraLLBJ7hF/E X-Gm-Gg: AZuq6aLjO5+Gr+7AiuyF3WYE1LGwxOsvoo52+TYZgmRoB+rtGeLKS1So/DQmKd44g+t E6VC0iP777EU634rDLkbZu5l6q2jHsyZQ7EsBQJmnAH9NGKlS0A9Qn6Xj9qufw0u3g4dJoR6f/m HARjog1EVAybnOmY94kfYfk7wmejJE96QIs9h2D21JMaI5OxxFROTksDRb8ZATJlvSDYBRXUDyl 1mDWPKK38SljfSAX3KW4s8rxTLw6GSz0Nu01ih6Jf32dYB2M2GUkmlhmhS5Oj8Y7tG+UJJ9S3XW Fb11XWV78ImJLXBghM1B2/Q6h/fQ0gpe1wQjXf048+EZEEH7mRy0782oq+YNgqH+Zt5HySLkKIS BhkXxu+DIJXRuJTIA7cadTK8Je51kz/pDqhpaBVNvCR043fsOewHttmFz0oFFkXHeg7L8qdG3j0 U2SihBFtrm2jk4Q5v1YjN4kSfJdrnJklmkxaRJ1iQDVNYwtaUr5Cm2JVAI2So/Ya5jPIXf4xKvc Q== X-Received: by 2002:a05:600c:8b73:b0:483:7ea3:3de3 with SMTP id 5b1f17b1804b1-483a949236dmr131795205e9.2.1771862053299; Mon, 23 Feb 2026 07:54:13 -0800 (PST) Received: from [192.168.0.86] (84.123.225.106.dyn.user.ono.com. [84.123.225.106]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483a31f9af5sm254672575e9.12.2026.02.23.07.54.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Feb 2026 07:54:12 -0800 (PST) Message-ID: <64ddfe83-317c-4cf1-b04f-cb74d9f40629@gmail.com> Date: Mon, 23 Feb 2026 16:54:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: unstable query plan on pg 16,17,18 To: Laurenz Albe , Attila Soki , pgsql-performance@postgresql.org References: Content-Language: en-US From: Andrei Lepikhov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 23/2/26 10:41, Laurenz Albe wrote: > On Mon, 2026-02-23 at 10:37 +0100, Attila Soki wrote: >> When upgrading from PostgreSQL 14.4, I noticed that one of my somewhat complex >> analytical queries sometimes gets an inefficient plan under PostgreSQL 16, 17, and 18. >> Under 14.4, the query runs with a stable plan and completes in 19 to 22 seconds. >> In newer versions, the plan seems to be unstable, sometimes the query completes >> in 17 to 20 seconds, sometimes it runs for 5 to 18 minutes with the inefficient plan. >> This also happens even if the data is not significantly changed. > > This is very likely owing to a bad estimate. > > Could you turn on "track_io_timing" and send us the EXPLAIN (ANALYZE, BUFFERS) output > for both the good and the bad plan? Since PG16, the optimiser changed a lot. So, there are plenty of possibilities that might happen - table statistics update, for example. So, we need at least EXPLAIN ANALYSE for 'good' and 'bad' cases to begin a discussion. -- regards, Andrei Lepikhov, pgEdge