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 1w2cjO-000S4e-1y for pgsql-performance@arkaria.postgresql.org; Tue, 17 Mar 2026 22:17:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w2ciN-005kp2-1M for pgsql-performance@arkaria.postgresql.org; Tue, 17 Mar 2026 22:16:39 +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 1w2ciN-005kou-08 for pgsql-performance@lists.postgresql.org; Tue, 17 Mar 2026 22:16:39 +0000 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w2ciJ-00000000G7o-3PlI for pgsql-performance@lists.postgresql.org; Tue, 17 Mar 2026 22:16:38 +0000 Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-5a142464316so183204e87.1 for ; Tue, 17 Mar 2026 15:16:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773785795; x=1774390595; darn=lists.postgresql.org; h=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=yyQYKAlrA5iZMexoBVtAjJ7JBSS+Cns82oFf/hDYBiY=; b=i8vwGDGZ5CE/XSdg4RopG9LTJIyl9+VTm84zUHQLK/h/yWuHoAyKf52uEn3fyKpexA 1rHgwksXqFi/oH5XmS1FxBlh1Ah52bz/o/c6Ji0FmFBroe3aJC+daGQnT7RYrY/UtkA9 toLQSiSFeWRYzGrYTv4OgDiC9IWBqYwW3DgxxA46Xj2/ix+5a86ctrTPkTHc/da9aJYd fERrn7DJPGmuD1t4mmFI0irIJO39Kf/XUWCWG20haB+rmdw1X4X1QlZkTbOw5ocN1W4c PPtv6XGw3eYd5omoY+x0zS/u52dN3V+hNu1m3NkUWCXSOtI3vVx3Mi3+AO1lGbS5lKm3 Blrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773785795; x=1774390595; h=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=yyQYKAlrA5iZMexoBVtAjJ7JBSS+Cns82oFf/hDYBiY=; b=ewGcELmIh/1lPQzucsEqDhTuhf/jlxv8rn/2q/vCMsugOVyFNvpChGCn6g6pUfcxcp BfhjI3VwY5PvYF97cNATgkQnoWbrzmwzk4C0evKminYxk93KuQ4aqgeazH0/OYTqUuLW wcPIY8sQSpN871fkTGljVsk8m7CCt2Iz4C8Jg6iQ4bSmzOW8xh72gmcEqyU2CLsuPit5 gLEQ59Z/XduLoNrkCZYn/lQR9b2z0KPD7Jjr3adA7UTHhK4dx09CDJoy1WtE3v429tpN nVPUe3F3hGvstVO/6ktx548o9JYyJUuOyKdCd2paGm/XSeADIwZ5arLHze2tXSEXysDI xm6A== X-Forwarded-Encrypted: i=1; AJvYcCXzqhVtHKzAvnAbSovpoD9RI5NlwldtLKghZKBJRh40Vo07kH4dLt7Nq+iSHx6f4pyX3sDVbdxBia1hbDRHFUGqcA==@lists.postgresql.org X-Gm-Message-State: AOJu0YxEup9kL8kdMiNhSf6NLU8YmnlGV3pyBwrPD+in1adH+5x6ENJD ftx7xIGk/s861t9llcO5M/n3VUxeL+vDg9ih01EXafG+KPkzT7JY6pLBjaU8Qg== X-Gm-Gg: ATEYQzxkoNC9lpt9mLe8KQpGt4iWuOHEYBCKgeD/BR4lUeluv/gm4JNrOhOPzAhvGpe JN9G7Cf629fXATd7tPyPrQUJspPgxcFm9ScS7k3ERnSD6qZT+gjiwjHcYRdmCIuA+fzHfgmYiZD N99RPqTvpwU4f6xRWBfC6NKWfqFULEn/HwcHCMQlklhjx+eq1l0QmPMiruH7pgoWKMKeURB1XcC uraO8VcQ7/9WpIN0VPgnsGHb75oPgAi4TKWRfv7moSTSbuQC/rKOhwwo2j1Efi1vOFYY3b/ET6s pweE2CcuUNKJnBOLegOdX5kO9cU+P0mNTsieH/fRtejhXkjSaS+0bvk1GzQqc2XtzP2PB+P7P7K xaShOhJ2fEJ46CflZkwKX7Ks/FbAaRZE+npYTyyutbvMfnXHJodho2I89OOPmJ5oKGSv6NESFcw pOwC522spJO3W3Avug+HRud3HTaKiOqeO6Kxv1k7oZ X-Received: by 2002:ac2:5622:0:b0:5a1:2eb7:6dfe with SMTP id 2adb3069b0e04-5a2796b0a41mr290633e87.24.1773785794500; Tue, 17 Mar 2026 15:16:34 -0700 (PDT) Received: from [192.168.1.233] ([94.137.43.152]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5a279c2c152sm137698e87.23.2026.03.17.15.16.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Mar 2026 15:16:33 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------NI6XawikQRdcLILEurEe7w91" Message-ID: Date: Wed, 18 Mar 2026 04:16:30 +0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: postgres chooses objectively wrong index To: Merlin Moncure , pgsql-performance@lists.postgresql.org References: Content-Language: en-US From: Alexey Ermakov In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------NI6XawikQRdcLILEurEe7w91 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2026-03-18 03:01, Merlin Moncure wrote: > I've been maintaining an airflow style orchestrator in pl/pgsql, and > it's revealed a performance issue I just can't solve.  There is a > table, task, which may normally contain billions of rows, but only a > tiny portion is interesting for specific reasons—a common pattern in > task-type systems. > > ... > > I'm wondering if there are other tricks that might apply here, for > example, multi column index statistics...curious if anyone has > thoughts on that. > > Any suggestions? > > merlin > Hello. I think planner doesn't have information about distribution of *async.task_execution_state(task)* unless it's part of any full index. I would try to give that with extended statistics (postgresql 14+): create statistics (mcv) task_task_execution_state_stat on ((async.task_execution_state(task))) from async.task; analyze async.task; If that won't help - please show distribution from pg_stats_ext view for extended statistic above. -- Alexey Ermakov --------------NI6XawikQRdcLILEurEe7w91 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit
On 2026-03-18 03:01, Merlin Moncure wrote:
I've been maintaining an airflow style orchestrator in pl/pgsql, and it's revealed a performance issue I just can't solve.  There is a table, task, which may normally contain billions of rows, but only a tiny portion is interesting for specific reasons—a common pattern in task-type systems.

...

I'm wondering if there are other tricks that might apply here, for example, multi column index statistics...curious if anyone has thoughts on that.

Any suggestions?

merlin

Hello. I think planner doesn't have information about distribution of async.task_execution_state(task) unless it's part of any full index. I would try to give that with extended statistics (postgresql 14+):

create statistics (mcv) task_task_execution_state_stat on ((async.task_execution_state(task))) from async.task;
analyze async.task;

If that won't help - please show distribution from pg_stats_ext view for extended statistic above.


--
Alexey Ermakov

--------------NI6XawikQRdcLILEurEe7w91--