From: Tom Lane <tgl@sss.pgh.pa.us>
To: Chao Li <li.evan.chao@gmail.com>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: Residual tsquery cleanups
Date: Mon, 17 Aug 2026 10:46:41 -0400
Message-ID: <753081.1786978001@sss.pgh.pa.us> (raw)
In-Reply-To: <033D6816-517B-47A0-BBEA-0DB37A2B5489@gmail.com>
References: <455079.1786897319@sss.pgh.pa.us>
<033D6816-517B-47A0-BBEA-0DB37A2B5489@gmail.com>
Chao Li <li.evan.chao@gmail.com> writes:
> Overall looks good to me. A few small comments:
> 1 - 0001
> ```
> + unsigned int dist = pq_getmsgint(buf, sizeof(int16));
> +
> + if (dist > MAXENTRYPOS)
> + elog(ERROR, "invalid tsquery: invalid phrase distance %d",
> + dist);
> ```
> Here, “dist” is an unsigned int, so maybe it would be better to use “%u” than “%d” to print it.
Hmm ... doesn't really matter, since pq_getmsgint's result is
guaranteed to be in 0..65535. But OK.
> 2 - 0002
> ···
> + <para>The length of a <type>tsquery</type>'s data (lexemes only)
> + must be less than 1 megabyte</para>
> ···
> Look like to me this is inaccurate, because in pushValue_internal(), the "if (distance > MAXSTRPOS)” check happens before adding a new element, 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
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 using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, li.evan.chao@gmail.com, pgsql-hackers@lists.postgresql.org
Subject: Re: Residual tsquery cleanups
In-Reply-To: <753081.1786978001@sss.pgh.pa.us>
* 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