pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Dmytro Zhluktenko <d1mnewz@gmail.com>
To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Re: Postgres Full Text Search Jsonb Array column does not search for first row
Date: Thu, 28 Nov 2019 15:39:40 +0100
Message-ID: <1efa25ca941b0ad2d0628fe21b33ff91df714339.camel@cybertec.at> (raw)
In-Reply-To: <5dde47c8.1c69fb81.9af8e.d5dd@mx.google.com>
References: <5dde47c8.1c69fb81.9af8e.d5dd@mx.google.com>

On Wed, 2019-11-27 at 11:54 +0200, Dmytro Zhluktenko wrote:
> explain (analyze, BUFFERS)
> SELECT *
> FROM "cp"."Repro" x where cp.make_tsvector(x) @@ 'fir:*'::tsquery
> 
> outputs this query plan:
> Bitmap Heap Scan on "Repro" x  (cost=12.00..16.26 rows=1 width=72) (actual time=0.007..0.007 rows=0 loops=1)
>   Recheck Cond: (cp.make_tsvector(x.*) @@ '''fir'':*'::tsquery)
>   Buffers: shared hit=2
>   ->  Bitmap Index Scan on repro_fts_idx  (cost=0.00..12.00 rows=1 width=0) (actual time=0.005..0.005 rows=0 loops=1)
>         Index Cond: (cp.make_tsvector(x.*) @@ '''fir'':*'::tsquery)
>         Buffers: shared hit=2
> Planning Time: 0.070 ms
> Execution Time: 0.040 ms
> 
> Query runs fine if uses seq scan. Seq Scan is not desired here since this is the query that should run on huge amounts of data and it should find the first element.
> Obviously, if seq_scan is off, then query still does the same result.
> 
> Also, if you add 100000 more entries, it will still fail to find the first one using index.

I cannot quite follow.

We have seen that the query can use the index by setting "enable_seqscan = off",
but that PostgreSQL prefers to use a sequential scan because the table is small.

If the table were bigger, PostgreSQL would prefer the index scan.

Are your concerns hypothetical or real?
If real, can you show EXPLAIN (ANALYZE, BUFFERS) output of a query
execution where PostgreSQL chooses a sequential scan, but you think
it shouldn't?

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






view thread (5+ messages)  latest in thread

Message-ID: <1efa25ca941b0ad2d0628fe21b33ff91df714339.camel@cybertec.at>
Permalink:  ../1efa25ca941b0ad2d0628fe21b33ff91df714339.camel@cybertec.at/
Also on:    postgresql.org/message-id/1efa25ca941b0ad2d0628fe21b33ff91df714339.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at, d1mnewz@gmail.com
  Subject: Re: Postgres Full Text Search Jsonb Array column does not search for first row
  In-Reply-To: <1efa25ca941b0ad2d0628fe21b33ff91df714339.camel@cybertec.at>
  References: <5dde47c8.1c69fb81.9af8e.d5dd@mx.google.com> <1efa25ca941b0ad2d0628fe21b33ff91df714339.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox