Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bVk4m-00077w-UF for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Aug 2016 18:42:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bVk4m-00082a-Fe for pgsql-hackers@arkaria.postgresql.org; Fri, 05 Aug 2016 18:42:32 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bVk3P-00060e-Tj for pgsql-hackers@postgresql.org; Fri, 05 Aug 2016 18:41:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bVk3N-0008BI-LN for pgsql-hackers@postgresql.org; Fri, 05 Aug 2016 18:41:06 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u75IewiZ011563; Fri, 5 Aug 2016 14:40:58 -0400 From: Tom Lane To: Thomas Munro cc: Andreas Seltenreich , Pg Hackers , Oleg Bartunov , Teodor Sigaev Subject: Re: [sqlsmith] FailedAssertion("!(k == indices_count)", File: "tsvector_op.c", Line: 511) In-reply-to: References: <87invhoj6e.fsf@credativ.de> <20000.1470260376@sss.pgh.pa.us> Comments: In-reply-to Thomas Munro message dated "Thu, 04 Aug 2016 09:53:16 +1200" Date: Fri, 05 Aug 2016 14:40:58 -0400 Message-ID: <11562.1470422458@sss.pgh.pa.us> X-Pg-Spam-Score: -3.1 (---) 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 Thomas Munro writes: > The assertion in tsvector_delete_by_indices fails because its counting > algorithm doesn't expect indices_to_delete to contain multiple > references to the same index. Maybe that could be fixed by > uniquifying in tsvector_delete_arr before calling it, but since > tsvector_delete_by_indices already qsorts its input, it should be able > to handle duplicates cheaply. I poked at this and realized that that's not sufficient. If there are duplicates in indices_to_delete, then the initial estimate tsout->size = tsv->size - indices_count; is wrong because indices_count is an overestimate of how many lexemes will be removed. And because the calculation "dataout = STRPTR(tsout)" depends on tsout->size, we can't just wait till later to get it right. We could possibly initialize tsout->size = tsv->size (the maximum possible value), thereby ensuring that the WordEntry array doesn't overlap the dataout area; compute the correct tsout->size in the loop; and then memmove the data area into place to collapse out wasted space. But I think it might be simpler and better-performant just to de-dup the indices_to_delete array after qsort'ing it; that would certainly win for the case of indices_count == 1. The other problems I noted with failure to delete items seem to stem from the fact that tsvector_delete_arr relies on tsvector_bsearch to find items, but the input tsvector is not sorted (never mind de'duped) by array_to_tsvector. This seems like simple brain fade in array_to_tsvector, as AFAICS that's a required property of tsvectors. regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers