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 1iaKxP-0001aH-VK for pgsql-general@arkaria.postgresql.org; Thu, 28 Nov 2019 14:39:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iaKxO-00075l-2i for pgsql-general@arkaria.postgresql.org; Thu, 28 Nov 2019 14:39:46 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iaKxN-00074s-Kr for pgsql-general@lists.postgresql.org; Thu, 28 Nov 2019 14:39:45 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iaKxK-0000w2-JF for pgsql-general@lists.postgresql.org; Thu, 28 Nov 2019 14:39:44 +0000 Received: by mail-wr1-x441.google.com with SMTP id c14so6806768wrn.7 for ; Thu, 28 Nov 2019 06:39:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=UdwhH7w9dIrEoY3QiEvzHkyfyJ4upgWXQYyC5/OXaH0=; b=pfTc6wPa9oYOkOuOnoKMmaszYSLKQ3zkrZzX8tQPakIOi6hQyibYoTA0GQRiNvtgzY krwKlaml23278Ld/Ub1Y1HdNlmGLyZMN+WBrrYDWqgasLqxrn8Eg0I4efL3NWk7HaTDG b2/OBvm0OjHCxcThw0J56BGzk1o98aU7juJuCj4xBgnFaspf9WnijUkbmRc2sEt8XKUP buNzhG3cZXoel0v4fU/OBm2Co01zAornNPwnyPf6CkfYaNKC8xzuWym9J2Ar2znQA1v/ z/LUJiikhjprP/RA3vr0YH11Qp8Ts1cseoiZWXngz5IkBGEMWUVqwRgY8KAr5uepuupD 7pgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=UdwhH7w9dIrEoY3QiEvzHkyfyJ4upgWXQYyC5/OXaH0=; b=Yf/425fQ4bAwC1zRWh5POAUdbEZE3hh6nhav+MwtQ5QJEuhqsr5qzs/3FkWLcMlTJ5 DeqcaXvlD59TY57z6XDXy4Dmry9Y2GoHN4u9dhMIlZY/f3iirv0AJMxt6JGzU+1dhaWE d2yLmXdigco71dDBIT8JnfhtNbBS+gdQ8903BENSGVNl4mEOBxmbxr7DcmFCbMwKoD1g grsGRtubi9YWFiW4NaOD8m6o+zOv9SJ1iMlTSu87yG3uqMm7XDMWKuQpPLZMo79iKOtN l/Vt/xaHVE1Uff2iwSr0I4Jhsdd+x57q3DB3TxGsiA2HwYGKu6OsNT+piJ1Qfbdlcofj 6JZQ== X-Gm-Message-State: APjAAAXipJVf6R3htuTVfw/IOPb2OzL4Mninv5sTldi4EnblFDxhrnVP MfY/CSkYstAlhLssXZlSnF2anQ== X-Google-Smtp-Source: APXvYqxf90Bl2Tl/EHiRU4oRm7pG+vg7jitEshNrlFO/j/4lhR11c8Y4a/WQ8/nDpYiUcC8G5GxOtw== X-Received: by 2002:adf:e3d0:: with SMTP id k16mr6773745wrm.241.1574951981252; Thu, 28 Nov 2019 06:39:41 -0800 (PST) Received: from localhost.localdomain (217-149-168-19.nat.highway.telekom.at. [217.149.168.19]) by smtp.gmail.com with ESMTPSA id 72sm24096283wrl.73.2019.11.28.06.39.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2019 06:39:40 -0800 (PST) Message-ID: <1efa25ca941b0ad2d0628fe21b33ff91df714339.camel@cybertec.at> Subject: Re: Re: Postgres Full Text Search Jsonb Array column does not search for first row From: Laurenz Albe To: Dmytro Zhluktenko , "pgsql-general@lists.postgresql.org" Date: Thu, 28 Nov 2019 15:39:40 +0100 In-Reply-To: <5dde47c8.1c69fb81.9af8e.d5dd@mx.google.com> References: <5dde47c8.1c69fb81.9af8e.d5dd@mx.google.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.5 (3.32.5-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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