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 1tzm0I-006Tab-OC for pgsql-general@arkaria.postgresql.org; Wed, 02 Apr 2025 00:30:50 +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 1tzm0G-008NhK-K8 for pgsql-general@arkaria.postgresql.org; Wed, 02 Apr 2025 00:30:48 +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 1tzm0G-008NgJ-8y for pgsql-general@lists.postgresql.org; Wed, 02 Apr 2025 00:30:48 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tzm0B-002r8U-0v for pgsql-general@lists.postgresql.org; Wed, 02 Apr 2025 00:30:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 5320UdsN702948; Tue, 1 Apr 2025 20:30:39 -0400 From: Tom Lane To: Manikandan Swaminathan cc: pgsql-general@lists.postgresql.org Subject: Re: Postgres Query Plan using wrong index In-reply-to: References: Comments: In-reply-to Manikandan Swaminathan message dated "Tue, 01 Apr 2025 17:12:04 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <702946.1743553839.1@sss.pgh.pa.us> Date: Tue, 01 Apr 2025 20:30:39 -0400 Message-ID: <702947.1743553839@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Manikandan Swaminathan writes: > 4. When running the following query, I would expect the index "idx_col_b_a" > to be used: select min(col_b) from test_table where col_a > 4996. > I have a range-based filter on col_a, and am aggregating the result with > min(col_b). Both columns are covered by "idx_col_b_a". They may be covered, but sort order matters, and that index has the wrong sort order to help with this query. Try create index on test_table(col_b, col_a); regards, tom lane