Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iZu1f-0005U7-Nx for pgsql-general@arkaria.postgresql.org; Wed, 27 Nov 2019 09:54:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iZu1e-00079E-4X for pgsql-general@arkaria.postgresql.org; Wed, 27 Nov 2019 09:54:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iZu1d-000797-P0 for pgsql-general@lists.postgresql.org; Wed, 27 Nov 2019 09:54:21 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iZu1a-00011f-Np for pgsql-general@lists.postgresql.org; Wed, 27 Nov 2019 09:54:21 +0000 Received: by mail-wm1-x341.google.com with SMTP id g206so6363433wme.1 for ; Wed, 27 Nov 2019 01:54:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:mime-version:date:from:subject:thread-topic:to :content-transfer-encoding; bh=IN8/mnWFqETcYHk+0yNtP+xP5ihYoTvD53/1XoR4hd8=; b=pdyLR04moPlZ6PcQ6vCBvYlFDHmPG2Wjfwb3c9tVzCqTTpKvQGbpE/MyT3PTQMKNEO tcgz8SPbHE+/hA2MY+wt+j+1kTAjPofo5+s7QQJXwipFaHiH9C4cDrL+ESJmA5KLy/gp oHfppXMgOrKjwfypllYRQS9h/8WlSTZt5uN7Iv0ot2DaL9xoCLy6nAQTVT6FRzxIbwao EoGjiqLUS3R7NaE7TfSILjUrq1rqyckMMJhosDg/shMSZ06y5ZLH/XE1bHwSu5OWkNDC +9+DWuPl5Zehcap8wV4Mb0BPszlfQVcn82WGvBNpjPXQpTNEOx0+ZDekmaahnVWl4m0/ TbGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:mime-version:date:from:subject :thread-topic:to:content-transfer-encoding; bh=IN8/mnWFqETcYHk+0yNtP+xP5ihYoTvD53/1XoR4hd8=; b=rD4DRKPiLEB9KupDek6vqZtzNmCPZ9lYUy0rfRqq9b4bEK8lj9LmDxJcBetMfqD+sA U4R0caUn5kbVGna1yfJW2NFLLzo7hz8B2Nj0AaXe9ACJ3Ml5/kXYgAfXm1CCiQJExwDh TfbEMkYVLiQLLRg97bFSjHZhzITK5HYxT1Z1oD11E9ixSJNfsSH7UD4ob22XAuTFFzXe ygzRT03wFXQWdJ8AUgCyWrs0Zrlphg++vvYs7Tu6AP8rTbo2IFZDvQrDrdM+XhQ6day5 vnyOvcXx4KkfPZeODNHD9cf2/1zgsufPeThPhO4MMBVwxt1yMUkuPaVMCTHUyCFhpmmY FfeA== X-Gm-Message-State: APjAAAWg4CjWbL9320oZN6+9QmKqiKWCfq8QGOJkVN9byK3gagxpQNK+ MPuEvVT7FN4ck30hvc5cSPhYnRbvuow= X-Google-Smtp-Source: APXvYqw0dO27+uyyHoWmS+guCI4b8qPasgSiy8EHyiTD+QhAWmxaCEnLxzGhep3slMKEEAZYSsALJA== X-Received: by 2002:a05:600c:506:: with SMTP id i6mr3500360wmc.153.1574848457440; Wed, 27 Nov 2019 01:54:17 -0800 (PST) Received: from smtp.gmail.com ([193.105.219.210]) by smtp.gmail.com with ESMTPSA id m25sm5909457wmi.46.2019.11.27.01.54.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 27 Nov 2019 01:54:16 -0800 (PST) Message-ID: <5dde47c8.1c69fb81.9af8e.d5dd@mx.google.com> MIME-Version: 1.0 Date: Wed, 27 Nov 2019 11:54:13 +0200 From: Dmytro Zhluktenko Subject: RE: Re: Postgres Full Text Search Jsonb Array column does not search for first row Thread-Topic: RE: Re: Postgres Full Text Search Jsonb Array column does not search for first row To: Laurenz Albe , "pgsql-general@lists.postgresql.org" Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="utf-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk

Hello, thanks for h= elping!


explain (analyze, BUFFERS)

= SELECT *

FROM "cp"."Repro" x where cp.make_tsvect= or(x) @@ 'fir:*'::tsquery


outputs this query plan:

Bitmap Heap Scan on "Repro" x=C2= =A0 (cost=3D12.00..16.26 rows=3D1 width=3D72) (actual time=3D0.007..0.007 r= ows=3D0 loops=3D1)

=C2=A0 Recheck Cond: (cp.make_tsvector(x.*) @@ '''fir'':*'::tsquery)

=C2=A0 Buffers:= shared hit=3D2

=C2=A0 ->=C2=A0 Bitmap Index Scan on repro_fts_idx=C2=A0 (cost=3D0.00.= .12.00 rows=3D1 width=3D0) (actual time=3D0.005..0.005 rows=3D0 loops=3D1)<= o:p>

=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Index Cond: (cp.make_tsvector(x.*) @@ '''fir= '':*'::tsquery)

=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Buffers: shared hit=3D2

Planning Time: 0.070= ms

Execution = Time: 0.040 ms

 

&= nbsp;

Query runs fi= ne if uses seq scan. Seq Scan is not desired here since this is the query t= hat should run on huge amounts of data and it should find the first element= .

Obviously, i= f seq_scan is off, then query still does the same result.=


Also, if you add 100000 mor= e entries, it will still fail to find the first one using index.

=

 

BR, Dmytro.

 <= /o:p>

From: Laurenz Albe
Sent: 26 =D0=BB=D0=B8=D1=81=D1=82=D0=BE= =D0=BF=D0=B0=D0=B4=D0=B0 2019 =D1=80. 21:13
To: Dmytro Zhluktenko; pgsql-general@lists.postgresql.org
Subject:= Re: Postgres Full Text Search Jsonb Array column does not search for f= irst row

 

On Tue, 2019-11-26 at 13:37 +0200, Dmytro Zhluktenko wrote:

> Pgsql is unable to perform indexed full text search ont= o jsonb column containing an array when looking for the first row in the ta= ble.

>

> Any ideas w= hy this is happening?

>=C2=A0

> CREATE OR REPLACE FUNCTION cp.make_tsvector(in_t cp."Repro= ")

>=C2=A0 RETURNS tsvector

>=C2=A0 LANGUAGE plpgsql

>=C2=A0 IMM= UTABLE

>

> [...]

>=C2=A0

> CREATE INDEX= repro_fts_idx ON cp."Repro" USING gin (cp.make_tsvector(cp."= ;Repro".*)) WITH (fastupdate=3Doff, gin_pending_list_limit=3D'64');

>=C2=A0

> [...]

> 

> -- exp= lain analyze

> SELECT *

= >=C2=A0 FROM "cp"."Repro" x where cp.make_tsvector(x= ) @@ 'sup:*'::tsquery

 

One possibility is that there ar just too few rows in the tabl= e.

 

SET en= able_seqscan =3D off;

 

and then try again.

 <= /p>

If that is not the problm, please provide EXPLAIN (= ANALYZE, BUFFERS) output for

the query.

 

Yours,

Laurenz Albe

--

Cybertec | https://www.cybertec-postgresql.com

<= o:p> 

 

= =