Fix various issues with ALTER TEXT SEARCH CONFIGURATION
authorMichael Paquier <michael@paquier.xyz>
Wed, 31 Jan 2024 04:15:21 +0000 (13:15 +0900)
committerMichael Paquier <michael@paquier.xyz>
Wed, 31 Jan 2024 04:15:21 +0000 (13:15 +0900)
commit3e91dba8b079c02dc5204108c7e797b402c75779
tree5e52c46515aa681b7bb90d3f01e766269ea0847c
parent6ee26c6a4bafabbd22a85f575d2446fd5ec6ad0d
Fix various issues with ALTER TEXT SEARCH CONFIGURATION

This commit addresses a set of issues when changing token type mappings
in a text search configuration when using duplicated token names:
- ADD MAPPING would fail on insertion because of a constraint failure
after inserting the same mapping.
- ALTER MAPPING with an "overridden" configuration failed with "tuple
already updated by self" when the token mappings are removed.
- DROP MAPPING failed with "tuple already updated by self", like
previously, but in a different code path.

The code is refactored so the token names (with their numbers) are
handled as a List with unique members rather than an array with numbers,
ensuring that no duplicates mess up with the catalog inserts, updates
and deletes.  The list is generated by getTokenTypes(), with the same
error handling as previously while duplicated tokens are discarded from
the list used to work on the catalogs.

Regression tests are expanded to cover much more ground for the cases
fixed by this commit, as there was no coverage for the code touched in
this commit.  A bit more is done regarding the fact that a token name
not supported by a configuration's parser should result in an error even
if IF EXISTS is used in a DROP MAPPING clause.  This is implied in the
code but there was no coverage for that, and it was very easy to miss.

These issues exist since at least their introduction in core with
140d4ebcb46e, so backpatch all the way down.

Reported-by: Alexander Lakhin
Author: Tender Wang, Michael Paquier
Discussion: https://postgr.es/m/18310-1eb233c5908189c8@postgresql.org
Backpatch-through: 12
src/backend/commands/tsearchcmds.c
src/test/regress/expected/tsdicts.out
src/test/regress/sql/tsdicts.sql
src/tools/pgindent/typedefs.list