pgsql: Add helper functions for dshash tables with string keys.

Поиск
Список
Период
Сортировка
От Nathan Bossart
Тема pgsql: Add helper functions for dshash tables with string keys.
Дата
Msg-id E1reir1-000vD0-MQ@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Add helper functions for dshash tables with string keys.

Presently, string keys are not well-supported for dshash tables.
The dshash code always copies key_size bytes into new entries'
keys, and dshash.h only provides compare and hash functions that
forward to memcmp() and tag_hash(), both of which do not stop at
the first NUL.  This means that callers must pad string keys so
that the data beyond the first NUL does not adversely affect the
results of copying, comparing, and hashing the keys.

To better support string keys in dshash tables, this commit does
a couple things:

* A new copy_function field is added to the dshash_parameters
  struct.  This function pointer specifies how the key should be
  copied into new table entries.  For example, we only want to copy
  up to the first NUL byte for string keys.  A dshash_memcpy()
  helper function is provided and used for all existing in-tree
  dshash tables without string keys.

* A set of helper functions for string keys are provided.  These
  helper functions forward to strcmp(), strcpy(), and
  string_hash(), all of which ignore data beyond the first NUL.

This commit also adjusts the DSM registry's dshash table to use the
new helper functions for string keys.

Reviewed-by: Andy Fan
Discussion: https://postgr.es/m/20240119215941.GA1322079%40nathanxps13

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/42a1de3013eac394c3a170ce728f0280a62187bd

Modified Files
--------------
src/backend/lib/dshash.c                   | 58 +++++++++++++++++++++++++++++-
src/backend/replication/logical/launcher.c |  1 +
src/backend/storage/ipc/dsm_registry.c     |  9 +++--
src/backend/utils/activity/pgstat_shmem.c  |  1 +
src/backend/utils/cache/typcache.c         |  2 ++
src/include/lib/dshash.h                   | 19 +++++++++-
6 files changed, 83 insertions(+), 7 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: pgsql: Revise MERGE documentation
Следующее
От: Michael Paquier
Дата:
Сообщение: pgsql: Fix comment thinko in sequence.c