Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wvyc0-001f5c-0n for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Aug 2026 14:46:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wvybw-00BIbX-0b for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Aug 2026 14:46:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wvybv-00BIbP-2s for pgsql-hackers@lists.postgresql.org; Mon, 17 Aug 2026 14:46:49 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wvybt-00000001EMn-3vdC for pgsql-hackers@lists.postgresql.org; Mon, 17 Aug 2026 14:46:48 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 67HEkfNI753082; Mon, 17 Aug 2026 10:46:41 -0400 From: Tom Lane To: Chao Li cc: pgsql-hackers@lists.postgresql.org Subject: Re: Residual tsquery cleanups In-reply-to: <033D6816-517B-47A0-BBEA-0DB37A2B5489@gmail.com> References: <455079.1786897319@sss.pgh.pa.us> <033D6816-517B-47A0-BBEA-0DB37A2B5489@gmail.com> Comments: In-reply-to Chao Li message dated "Mon, 17 Aug 2026 10:39:31 +0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <753080.1786978001.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 17 Aug 2026 10:46:41 -0400 Message-ID: <753081.1786978001@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Chao Li writes: > Overall looks good to me. A few small comments: > 1 - 0001 > ``` > + unsigned int dist =3D pq_getmsgint(buf, sizeof(int16)); > + > + if (dist > MAXENTRYPOS) > + elog(ERROR, "invalid tsquery: invalid phrase distance %d", > + dist); > ``` > Here, =E2=80=9Cdist=E2=80=9D is an unsigned int, so maybe it would be be= tter to use =E2=80=9C%u=E2=80=9D than =E2=80=9C%d=E2=80=9D to print it. Hmm ... doesn't really matter, since pq_getmsgint's result is guaranteed to be in 0..65535. But OK. > 2 - 0002 > =C2=B7=C2=B7=C2=B7 > + The length of a tsquery's data (lexemes only) > + must be less than 1 megabyte > =C2=B7=C2=B7=C2=B7 > Look like to me this is inaccurate, because in pushValue_internal(), the= "if (distance > MAXSTRPOS)=E2=80=9D check happens before adding a new ele= ment, thus distance may exceed MAXSTRPOS after the element is added. True, it can be up to one lexeme more. But I didn't think it was worth trying to go into that much detail. As a comparison point, the corresponding bullet for tsvector doesn't explain how to calculate the space used for lexeme positions. I think the main takeaway here is just that there *is* a limit of this type. People who really want to know the exact details can consult the source code. regards, tom lane