Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W799n-0001oC-0N for pgsql-hackers@arkaria.postgresql.org; Sat, 25 Jan 2014 19:44:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W799l-0004oP-Go for pgsql-hackers@arkaria.postgresql.org; Sat, 25 Jan 2014 19:44:41 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W799j-0004oG-Hm for pgsql-hackers@postgresql.org; Sat, 25 Jan 2014 19:44:39 +0000 Received: from mail.gransy.com ([2001:1528:137::f1]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W799f-0006j2-7D for pgsql-hackers@postgresql.org; Sat, 25 Jan 2014 19:44:38 +0000 Received: from antispam.gransy.com (antispam.gransy.com [77.78.104.124]) by mail.gransy.com (Postfix) with ESMTP id 9C203508D3B for ; Sat, 25 Jan 2014 20:44:31 +0100 (CET) X-Virus-Scanned: G-Hosting.cz + Station.cz + Klenot.cz + Subreg.cz amavisd-new at antispam.gransy.com X-Spam-Flag: NO X-Spam-Score: 1.024 X-Spam-Level: * X-Spam-Status: No, score=1.024 tagged_above=0 required=5 tests=[ALL_TRUSTED=-1, NO_DNS_FOR_FROM=0.379, TO_NO_BRKTS_PCNT=1.645] autolearn=disabled Received: from mail.gransy.com ([82.208.29.194]) by antispam.gransy.com (antispam.gransy.com [77.78.104.124]) (amavisd-new, port 10024) with ESMTP id cpsX8hrBR67d for ; Sat, 25 Jan 2014 20:44:42 +0100 (CET) Received: from [192.168.1.227] (ip-78-45-139-138.net.upcbroadband.cz [78.45.139.138]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: tv@fuzzy.cz) by mail.gransy.com (Postfix) with ESMTPSA id 17141508D33 for ; Sat, 25 Jan 2014 20:44:31 +0100 (CET) Message-ID: <52E4141E.60609@fuzzy.cz> Date: Sat, 25 Jan 2014 20:44:30 +0100 From: Tomas Vondra User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 MIME-Version: 1.0 To: pgsql-hackers@postgresql.org Subject: Re: GIN improvements part2: fast scan References: <51BF0A90.2000503@vmware.com> <51C16235.3080308@vmware.com> <51C170A8.9060509@vmware.com> <51C4ACC5.2090707@vmware.com> <51D00FB6.9030008@vmware.com> <528533D9.3040501@vmware.com> <52E141BA.5000302@vmware.com> In-Reply-To: <52E141BA.5000302@vmware.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 23.1.2014 17:22, Heikki Linnakangas wrote: > I measured the time that query takes, and the number of pages hit, using > "explain (analyze, buffers true) ...". > > patches time (ms) buffers > --- > unpatched 650 1316 > patch 1 0.52 1316 > patches 1+2 0.50 1316 > patches 1+2+3 0.13 15 > > So, the second patch isn't doing much in this particular case. But it's > trivial, and I think it will make a difference in other queries where > you have the opportunity skip, but return a lot of tuples overall. > > In summary, these are fairly small patches, and useful on their, so I > think these should be committed now. But please take a look and see if > the logic in scanGetItem/keyGetItem looks correct to you. After this, I > think the main fast scan logic will go into keyGetItem. Hi, I've done some testing of the three patches today, and I've ran into an infinite loop caused by the third patch. I don't know why exactly it gets stuck, but with patches #1+#2 it works fine, and after applying #3 it runs infinitely. I can't point to a particular line / condition causing this, but this is wthat I see in 'perf top' 54.16% postgres [.] gingetbitmap 32.38% postgres [.] ginPostingListDecodeAllSegments 3.03% libc-2.17.so [.] 0x000000000007fb88 I've tracked it down to this loop in ginget.c:840 (I've added the logging for debugging / demonstration purposes): ===================================================================== elog(WARNING, "scanning entries"); elog(WARNING, "advacepast=(%u,%d)", BlockIdGetBlockNumber(&advancePast.ip_blkid), advancePast.ip_posid); while (entry->isFinished == FALSE && ginCompareItemPointers(&entry->curItem, &advancePast) <= 0) { elog(WARNING, "current=(%u,%d)", BlockIdGetBlockNumber(&entry->curItem.ip_blkid), entry->curItem.ip_posid); entryGetItem(ginstate, entry, advancePast); } elog(WARNING, "entries scanned"); ===================================================================== which is executed repeatedly, but the last invocation gets stuck and produces this output: WARNING: scanning entries WARNING: advacepast=(172058,0) LOG: entryLoadMoreItems, 172058/0, skip: 1 WARNING: getting item current=(171493,7) WARNING: getting item current=(116833,2) WARNING: getting item current=(116833,3) WARNING: getting item current=(116833,4) WARNING: getting item current=(116833,5) WARNING: getting item current=(116838,1) WARNING: getting item current=(116838,2) ... increasing sequence of block IDs ... WARNING: getting item current=(170743,5) WARNING: getting item current=(170746,4) WARNING: getting item current=(171493,7) LOG: entryLoadMoreItems, 172058/0, skip: 1 WARNING: getting item current=(116833,2) WARNING: getting item current=(116833,3) WARNING: getting item current=(116833,4) WARNING: getting item current=(116833,5) ... and repeat ===================================================================== Not sure what went wrong, though - I suspect it does not set the isFinished flag or something like that, but I don't know where/when should that happen. This is rather easy to reproduce - download the dump I already provided two weeks ago [http://www.fuzzy.cz/tmp/message-b.data.gz] and load it into a simple table: CREATE TABLE msgs (body tsvector); COPY msgs FROM '/tmp/message-b.data'; CREATE INDEX msgidx ON msgs USING gin(body); ANALYZE msgs; And then run this query: SELECT body FROM msgs WHERE body @@ plainto_tsquery('english','string | x') AND body @@ plainto_tsquery('english','versions | equivalent') AND body @@ plainto_tsquery('english','usually | contain'); It should run infinitely. I suspect it's not perfectly stable, i.e, the this query may work fine / another one will block. In that case try to run this [http://www.fuzzy.cz/tmp/random-queries.sql] - it's a file with 1000 generated queries, at least one of them should block (that's how I discovered the issue). regards Tomas -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers