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 1rAtML-008big-4l for pgsql-general@arkaria.postgresql.org; Wed, 06 Dec 2023 14:58:45 +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 1rAtMJ-00AGT1-PD for pgsql-general@arkaria.postgresql.org; Wed, 06 Dec 2023 14:58:43 +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 1rAtMJ-00AGSt-Ea for pgsql-general@lists.postgresql.org; Wed, 06 Dec 2023 14:58:43 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rAtMG-00963a-6J for pgsql-general@lists.postgresql.org; Wed, 06 Dec 2023 14:58:42 +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 3B6EwcZI1099788; Wed, 6 Dec 2023 09:58:38 -0500 From: Tom Lane To: balasubramanian c r cc: pgsql-general Subject: Re: GIN INdex is not used with && operator for a text array index In-reply-to: References: Comments: In-reply-to balasubramanian c r message dated "Wed, 06 Dec 2023 20:02:52 +0530" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1099786.1701874718.1@sss.pgh.pa.us> Date: Wed, 06 Dec 2023 09:58:38 -0500 Message-ID: <1099787.1701874718@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk balasubramanian c r writes: > when Operator '@>' is used the index is used and the execution time is 60ms. Yeah ... note that it's predicted to return just one row, and that guess is correct: > Bitmap Heap Scan on public.address18 (cost=261.25..262.52 rows=1 width=4) > (actual time=58.992..58.994 rows=1 loops=1) > when Operator '&&' is used the index is used and the execution time is 60ms. > It is performing sequential scan which is not expected. I do not see why you expect that. This case retrieves many more rows than the other one, both in the planner's estimate and in reality: > Seq Scan on public.address18 (cost=0.00..77215.11 rows=247741 width=4) > (actual time=0.063..1880.467 rows=247741 loops=1) An indexscan is not necessarily better than a seqscan for such cases... > When i disable the sequential scan the execution time is increased > significantly. ... so, indeed, the planner was correct to use a seqscan. > Not expecting this behavior currently. Your expectation is faulty. regards, tom lane