|
PostgreSQL Source Code git master
|
#include "postgres.h"#include <limits.h>#include "common/hashfn.h"#include "lib/dshash.h"#include "storage/lwlock.h"#include "utils/dsa.h"
Go to the source code of this file.
Data Structures | |
| struct | dshash_table_item |
| struct | dshash_partition |
| struct | dshash_table_control |
| struct | dshash_table |
Macros | |
| #define | DSHASH_NUM_PARTITIONS_LOG2 7 |
| #define | DSHASH_NUM_PARTITIONS (1 << DSHASH_NUM_PARTITIONS_LOG2) |
| #define | DSHASH_MAGIC 0x75ff6a20 |
| #define | ENTRY_FROM_ITEM(item) ((char *)(item) + MAXALIGN(sizeof(dshash_table_item))) |
| #define | ITEM_FROM_ENTRY(entry) |
| #define | NUM_SPLITS(size_log2) (size_log2 - DSHASH_NUM_PARTITIONS_LOG2) |
| #define | NUM_BUCKETS(size_log2) (((size_t) 1) << (size_log2)) |
| #define | BUCKETS_PER_PARTITION(size_log2) (((size_t) 1) << NUM_SPLITS(size_log2)) |
| #define | MAX_COUNT_PER_PARTITION(hash_table) |
| #define | PARTITION_FOR_HASH(hash) (hash >> ((sizeof(dshash_hash) * CHAR_BIT) - DSHASH_NUM_PARTITIONS_LOG2)) |
| #define | BUCKET_INDEX_FOR_HASH_AND_SIZE(hash, size_log2) (hash >> ((sizeof(dshash_hash) * CHAR_BIT) - (size_log2))) |
| #define | BUCKET_INDEX_FOR_PARTITION(partition, size_log2) ((partition) << NUM_SPLITS(size_log2)) |
| #define | PARTITION_FOR_BUCKET_INDEX(bucket_idx, size_log2) ((bucket_idx) >> NUM_SPLITS(size_log2)) |
| #define | BUCKET_FOR_HASH(hash_table, hash) |
| #define | PARTITION_LOCK(hash_table, i) (&(hash_table)->control->partitions[(i)].lock) |
| #define | ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME(hash_table) |
Typedefs | |
| typedef struct dshash_partition | dshash_partition |
| typedef struct dshash_table_control | dshash_table_control |
Functions | |
| static void | delete_item (dshash_table *hash_table, dshash_table_item *item) |
| static void | resize (dshash_table *hash_table, size_t new_size_log2) |
| static void | ensure_valid_bucket_pointers (dshash_table *hash_table) |
| static dshash_table_item * | find_in_bucket (dshash_table *hash_table, const void *key, dsa_pointer item_pointer) |
| static void | insert_item_into_bucket (dshash_table *hash_table, dsa_pointer item_pointer, dshash_table_item *item, dsa_pointer *bucket) |
| static dshash_table_item * | insert_into_bucket (dshash_table *hash_table, const void *key, dsa_pointer *bucket) |
| static bool | delete_key_from_bucket (dshash_table *hash_table, const void *key, dsa_pointer *bucket_head) |
| static bool | delete_item_from_bucket (dshash_table *hash_table, dshash_table_item *item, dsa_pointer *bucket_head) |
| static dshash_hash | hash_key (dshash_table *hash_table, const void *key) |
| static bool | equal_keys (dshash_table *hash_table, const void *a, const void *b) |
| static void | copy_key (dshash_table *hash_table, void *dest, const void *src) |
| dshash_table * | dshash_create (dsa_area *area, const dshash_parameters *params, void *arg) |
| dshash_table * | dshash_attach (dsa_area *area, const dshash_parameters *params, dshash_table_handle handle, void *arg) |
| void | dshash_detach (dshash_table *hash_table) |
| void | dshash_destroy (dshash_table *hash_table) |
| dshash_table_handle | dshash_get_hash_table_handle (dshash_table *hash_table) |
| void * | dshash_find (dshash_table *hash_table, const void *key, bool exclusive) |
| void * | dshash_find_or_insert (dshash_table *hash_table, const void *key, bool *found) |
| bool | dshash_delete_key (dshash_table *hash_table, const void *key) |
| void | dshash_delete_entry (dshash_table *hash_table, void *entry) |
| void | dshash_release_lock (dshash_table *hash_table, void *entry) |
| int | dshash_memcmp (const void *a, const void *b, size_t size, void *arg) |
| dshash_hash | dshash_memhash (const void *v, size_t size, void *arg) |
| void | dshash_memcpy (void *dest, const void *src, size_t size, void *arg) |
| int | dshash_strcmp (const void *a, const void *b, size_t size, void *arg) |
| dshash_hash | dshash_strhash (const void *v, size_t size, void *arg) |
| void | dshash_strcpy (void *dest, const void *src, size_t size, void *arg) |
| void | dshash_seq_init (dshash_seq_status *status, dshash_table *hash_table, bool exclusive) |
| void * | dshash_seq_next (dshash_seq_status *status) |
| void | dshash_seq_term (dshash_seq_status *status) |
| void | dshash_delete_current (dshash_seq_status *status) |
| void | dshash_dump (dshash_table *hash_table) |
| #define ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME | ( | hash_table | ) |
| #define BUCKET_FOR_HASH | ( | hash_table, | |
| hash | |||
| ) |
| #define BUCKET_INDEX_FOR_HASH_AND_SIZE | ( | hash, | |
| size_log2 | |||
| ) | (hash >> ((sizeof(dshash_hash) * CHAR_BIT) - (size_log2))) |
| #define BUCKET_INDEX_FOR_PARTITION | ( | partition, | |
| size_log2 | |||
| ) | ((partition) << NUM_SPLITS(size_log2)) |
| #define BUCKETS_PER_PARTITION | ( | size_log2 | ) | (((size_t) 1) << NUM_SPLITS(size_log2)) |
| #define DSHASH_NUM_PARTITIONS (1 << DSHASH_NUM_PARTITIONS_LOG2) |
| #define ENTRY_FROM_ITEM | ( | item | ) | ((char *)(item) + MAXALIGN(sizeof(dshash_table_item))) |
| #define ITEM_FROM_ENTRY | ( | entry | ) |
| #define MAX_COUNT_PER_PARTITION | ( | hash_table | ) |
| #define NUM_BUCKETS | ( | size_log2 | ) | (((size_t) 1) << (size_log2)) |
| #define NUM_SPLITS | ( | size_log2 | ) | (size_log2 - DSHASH_NUM_PARTITIONS_LOG2) |
| #define PARTITION_FOR_BUCKET_INDEX | ( | bucket_idx, | |
| size_log2 | |||
| ) | ((bucket_idx) >> NUM_SPLITS(size_log2)) |
| #define PARTITION_FOR_HASH | ( | hash | ) | (hash >> ((sizeof(dshash_hash) * CHAR_BIT) - DSHASH_NUM_PARTITIONS_LOG2)) |
| #define PARTITION_LOCK | ( | hash_table, | |
| i | |||
| ) | (&(hash_table)->control->partitions[(i)].lock) |
| typedef struct dshash_partition dshash_partition |
| typedef struct dshash_table_control dshash_table_control |
|
inlinestatic |
Definition at line 1087 of file dshash.c.
References dshash_table::arg, dshash_parameters::copy_function, generate_unaccent_rules::dest, dshash_parameters::key_size, and dshash_table::params.
Referenced by insert_into_bucket().
|
static |
Definition at line 834 of file dshash.c.
References Assert(), BUCKET_FOR_HASH, dshash_table::control, dshash_partition::count, delete_item_from_bucket(), dshash_table_item::hash, hash(), LWLockHeldByMe(), PARTITION_FOR_HASH, PARTITION_LOCK, and dshash_table_control::partitions.
Referenced by dshash_delete_current(), and dshash_delete_entry().
|
static |
Definition at line 1037 of file dshash.c.
References dshash_table::area, dsa_free(), dsa_get_address(), DsaPointerIsValid, next, and dshash_table_item::next.
Referenced by delete_item().
|
static |
Definition at line 1008 of file dshash.c.
References dshash_table::area, dsa_free(), dsa_get_address(), DsaPointerIsValid, ENTRY_FROM_ITEM, equal_keys(), sort-test::key, next, and dshash_table_item::next.
Referenced by dshash_delete_key().
| dshash_table * dshash_attach | ( | dsa_area * | area, |
| const dshash_parameters * | params, | ||
| dshash_table_handle | handle, | ||
| void * | arg | ||
| ) |
Definition at line 272 of file dshash.c.
References dshash_table::area, dshash_table::arg, arg, Assert(), dshash_table::buckets, dshash_table::control, dsa_get_address(), DSHASH_MAGIC, dshash_table_control::magic, palloc(), dshash_table::params, and dshash_table::size_log2.
Referenced by GetNamedDSHash(), init_dsm_registry(), logicalrep_launcher_attach_dshmem(), pgstat_attach_shmem(), and SharedRecordTypmodRegistryAttach().
| dshash_table * dshash_create | ( | dsa_area * | area, |
| const dshash_parameters * | params, | ||
| void * | arg | ||
| ) |
Definition at line 208 of file dshash.c.
References dshash_table::area, dshash_table::arg, arg, dshash_table_control::buckets, dshash_table::buckets, dshash_table::control, DSA_ALLOC_NO_OOM, DSA_ALLOC_ZERO, dsa_allocate, dsa_allocate_extended(), dsa_free(), dsa_get_address(), DsaPointerIsValid, DSHASH_MAGIC, DSHASH_NUM_PARTITIONS, DSHASH_NUM_PARTITIONS_LOG2, ereport, errcode(), errdetail(), errmsg(), ERROR, dshash_table_control::handle, i, dshash_table_control::lwlock_tranche_id, LWLockInitialize(), dshash_table_control::magic, palloc(), dshash_table::params, dshash_table_control::partitions, partitions, dshash_table_control::size_log2, dshash_table::size_log2, and dshash_parameters::tranche_id.
Referenced by GetNamedDSHash(), init_dsm_registry(), logicalrep_launcher_attach_dshmem(), SharedRecordTypmodRegistryInit(), and StatsShmemInit().
| void dshash_delete_current | ( | dshash_seq_status * | status | ) |
Definition at line 759 of file dshash.c.
References Assert(), dshash_table::control, dshash_seq_status::curitem, delete_item(), DSHASH_MAGIC, dshash_seq_status::exclusive, dshash_table_item::hash, dshash_seq_status::hash_table, LW_EXCLUSIVE, LWLockHeldByMeInMode(), dshash_table_control::magic, PARTITION_FOR_HASH, PARTITION_LOCK, and PG_USED_FOR_ASSERTS_ONLY.
Referenced by pgstat_free_entry().
| void dshash_delete_entry | ( | dshash_table * | hash_table, |
| void * | entry | ||
| ) |
Definition at line 543 of file dshash.c.
References Assert(), dshash_table::control, delete_item(), DSHASH_MAGIC, dshash_table_item::hash, ITEM_FROM_ENTRY, LW_EXCLUSIVE, LWLockHeldByMeInMode(), LWLockRelease(), dshash_table_control::magic, PARTITION_FOR_HASH, and PARTITION_LOCK.
Referenced by pgstat_free_entry(), and pgstat_get_entry_ref().
| bool dshash_delete_key | ( | dshash_table * | hash_table, |
| const void * | key | ||
| ) |
Definition at line 505 of file dshash.c.
References Assert(), ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME, BUCKET_FOR_HASH, dshash_table::control, dshash_partition::count, delete_key_from_bucket(), DSHASH_MAGIC, ensure_valid_bucket_pointers(), hash(), hash_key(), sort-test::key, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), dshash_table_control::magic, PARTITION_FOR_HASH, PARTITION_LOCK, and dshash_table_control::partitions.
Referenced by ApplyLauncherForgetWorkerStartTime(), and find_or_make_matching_shared_tupledesc().
| void dshash_destroy | ( | dshash_table * | hash_table | ) |
Definition at line 325 of file dshash.c.
References dshash_table::area, Assert(), dshash_table_control::buckets, dshash_table::buckets, dshash_table::control, dsa_free(), dsa_get_address(), DsaPointerIsValid, DSHASH_MAGIC, ensure_valid_bucket_pointers(), dshash_table_control::handle, i, dshash_table_control::magic, dshash_table_item::next, NUM_BUCKETS, pfree(), and dshash_table::size_log2.
| void dshash_detach | ( | dshash_table * | hash_table | ) |
Definition at line 309 of file dshash.c.
References ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME, and pfree().
Referenced by pgstat_detach_shmem(), shared_record_typmod_registry_detach(), and StatsShmemInit().
| void dshash_dump | ( | dshash_table * | hash_table | ) |
Definition at line 780 of file dshash.c.
References dshash_table::area, Assert(), ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME, BUCKET_INDEX_FOR_PARTITION, dshash_table::buckets, dshash_table::control, dshash_partition::count, dsa_get_address(), DsaPointerIsValid, DSHASH_MAGIC, DSHASH_NUM_PARTITIONS, ensure_valid_bucket_pointers(), fprintf, i, j, LW_SHARED, LWLockAcquire(), LWLockHeldByMe(), LWLockRelease(), dshash_table_control::magic, dshash_table_item::next, PARTITION_LOCK, dshash_table_control::partitions, and dshash_table::size_log2.
| void * dshash_find | ( | dshash_table * | hash_table, |
| const void * | key, | ||
| bool | exclusive | ||
| ) |
Definition at line 392 of file dshash.c.
References Assert(), ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME, BUCKET_FOR_HASH, dshash_table::control, DSHASH_MAGIC, ensure_valid_bucket_pointers(), ENTRY_FROM_ITEM, find_in_bucket(), hash(), hash_key(), sort-test::key, LW_EXCLUSIVE, LW_SHARED, LWLockAcquire(), LWLockRelease(), dshash_table_control::magic, PARTITION_FOR_HASH, and PARTITION_LOCK.
Referenced by ApplyLauncherGetWorkerStartTime(), find_or_make_matching_shared_tupledesc(), get_val_in_hash(), lookup_rowtype_tupdesc_internal(), pgstat_drop_entry(), pgstat_get_entry_ref(), and pgstat_release_entry_ref().
| void * dshash_find_or_insert | ( | dshash_table * | hash_table, |
| const void * | key, | ||
| bool * | found | ||
| ) |
Definition at line 435 of file dshash.c.
References Assert(), ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME, BUCKET_FOR_HASH, dshash_table::control, dshash_partition::count, DSHASH_MAGIC, ensure_valid_bucket_pointers(), ENTRY_FROM_ITEM, find_in_bucket(), dshash_table_item::hash, hash(), hash_key(), insert_into_bucket(), sort-test::key, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), dshash_table_control::magic, MAX_COUNT_PER_PARTITION, PARTITION_FOR_HASH, PARTITION_LOCK, dshash_table_control::partitions, resize(), and dshash_table::size_log2.
Referenced by ApplyLauncherSetWorkerStartTime(), find_or_make_matching_shared_tupledesc(), GetNamedDSA(), GetNamedDSHash(), GetNamedDSMSegment(), pgstat_get_entry_ref(), pgstat_read_statsfile(), set_val_in_hash(), and SharedRecordTypmodRegistryInit().
| dshash_table_handle dshash_get_hash_table_handle | ( | dshash_table * | hash_table | ) |
Definition at line 369 of file dshash.c.
References Assert(), dshash_table::control, DSHASH_MAGIC, dshash_table_control::handle, and dshash_table_control::magic.
Referenced by GetNamedDSHash(), init_dsm_registry(), logicalrep_launcher_attach_dshmem(), SharedRecordTypmodRegistryInit(), and StatsShmemInit().
| int dshash_memcmp | ( | const void * | a, |
| const void * | b, | ||
| size_t | size, | ||
| void * | arg | ||
| ) |
| void dshash_memcpy | ( | void * | dest, |
| const void * | src, | ||
| size_t | size, | ||
| void * | arg | ||
| ) |
Definition at line 592 of file dshash.c.
References generate_unaccent_rules::dest.
| dshash_hash dshash_memhash | ( | const void * | v, |
| size_t | size, | ||
| void * | arg | ||
| ) |
| void dshash_release_lock | ( | dshash_table * | hash_table, |
| void * | entry | ||
| ) |
Definition at line 560 of file dshash.c.
References Assert(), dshash_table::control, DSHASH_MAGIC, dshash_table_item::hash, ITEM_FROM_ENTRY, LWLockRelease(), dshash_table_control::magic, PARTITION_FOR_HASH, and PARTITION_LOCK.
Referenced by ApplyLauncherGetWorkerStartTime(), ApplyLauncherSetWorkerStartTime(), find_or_make_matching_shared_tupledesc(), get_val_in_hash(), GetNamedDSA(), GetNamedDSHash(), GetNamedDSMSegment(), lookup_rowtype_tupdesc_internal(), pgstat_acquire_entry_ref(), pgstat_drop_entry_internal(), pgstat_get_entry_ref(), pgstat_read_statsfile(), pgstat_release_entry_ref(), set_val_in_hash(), and SharedRecordTypmodRegistryInit().
| void dshash_seq_init | ( | dshash_seq_status * | status, |
| dshash_table * | hash_table, | ||
| bool | exclusive | ||
| ) |
Definition at line 640 of file dshash.c.
References dshash_seq_status::curbucket, dshash_seq_status::curitem, dshash_seq_status::curpartition, dshash_seq_status::exclusive, dshash_seq_status::hash_table, InvalidDsaPointer, dshash_seq_status::nbuckets, and dshash_seq_status::pnextitem.
Referenced by pg_get_dsm_registry_allocations(), pgstat_build_snapshot(), pgstat_drop_database_and_contents(), pgstat_drop_matching_entries(), pgstat_reset_matching_entries(), and pgstat_write_statsfile().
| void * dshash_seq_next | ( | dshash_seq_status * | status | ) |
Definition at line 659 of file dshash.c.
References dshash_table::area, Assert(), ASSERT_NO_PARTITION_LOCKS_HELD_BY_ME, dshash_table::buckets, dshash_table::control, dshash_seq_status::curbucket, dshash_seq_status::curitem, dshash_seq_status::curpartition, dsa_get_address(), DsaPointerIsValid, ensure_valid_bucket_pointers(), ENTRY_FROM_ITEM, dshash_seq_status::exclusive, dshash_seq_status::hash_table, LW_EXCLUSIVE, LW_SHARED, LWLockAcquire(), LWLockHeldByMeInMode(), LWLockRelease(), dshash_seq_status::nbuckets, dshash_table_item::next, NUM_BUCKETS, PARTITION_FOR_BUCKET_INDEX, PARTITION_LOCK, dshash_seq_status::pnextitem, dshash_table_control::size_log2, and dshash_table::size_log2.
Referenced by pg_get_dsm_registry_allocations(), pgstat_build_snapshot(), pgstat_drop_database_and_contents(), pgstat_drop_matching_entries(), pgstat_reset_matching_entries(), and pgstat_write_statsfile().
| void dshash_seq_term | ( | dshash_seq_status * | status | ) |
Definition at line 749 of file dshash.c.
References dshash_seq_status::curpartition, dshash_seq_status::hash_table, LWLockRelease(), and PARTITION_LOCK.
Referenced by pg_get_dsm_registry_allocations(), pgstat_build_snapshot(), pgstat_drop_database_and_contents(), pgstat_drop_matching_entries(), pgstat_reset_matching_entries(), and pgstat_write_statsfile().
| int dshash_strcmp | ( | const void * | a, |
| const void * | b, | ||
| size_t | size, | ||
| void * | arg | ||
| ) |
| void dshash_strcpy | ( | void * | dest, |
| const void * | src, | ||
| size_t | size, | ||
| void * | arg | ||
| ) |
| dshash_hash dshash_strhash | ( | const void * | v, |
| size_t | size, | ||
| void * | arg | ||
| ) |
|
inlinestatic |
Definition at line 939 of file dshash.c.
References dshash_table::area, dshash_table_control::buckets, dshash_table::buckets, dshash_table::control, dsa_get_address(), dshash_table_control::size_log2, and dshash_table::size_log2.
Referenced by dshash_delete_key(), dshash_destroy(), dshash_dump(), dshash_find(), dshash_find_or_insert(), and dshash_seq_next().
|
inlinestatic |
Definition at line 1076 of file dshash.c.
References a, dshash_table::arg, b, dshash_parameters::compare_function, dshash_parameters::key_size, and dshash_table::params.
Referenced by delete_key_from_bucket(), and find_in_bucket().
|
inlinestatic |
Definition at line 953 of file dshash.c.
References dshash_table::area, dsa_get_address(), DsaPointerIsValid, ENTRY_FROM_ITEM, equal_keys(), sort-test::key, and dshash_table_item::next.
Referenced by dshash_find(), and dshash_find_or_insert().
|
inlinestatic |
Definition at line 1065 of file dshash.c.
References dshash_table::arg, dshash_parameters::hash_function, sort-test::key, dshash_parameters::key_size, and dshash_table::params.
Referenced by compute_tsvector_stats(), dshash_delete_key(), dshash_find(), and dshash_find_or_insert().
|
static |
Definition at line 988 of file dshash.c.
References dshash_table::area, copy_key(), dsa_allocate, dsa_get_address(), ENTRY_FROM_ITEM, dshash_parameters::entry_size, insert_item_into_bucket(), sort-test::key, MAXALIGN, and dshash_table::params.
Referenced by dshash_find_or_insert().
|
static |
Definition at line 972 of file dshash.c.
References dshash_table::area, Assert(), dsa_get_address(), and dshash_table_item::next.
Referenced by insert_into_bucket(), and resize().
|
static |
Definition at line 860 of file dshash.c.
References dshash_table::area, Assert(), BUCKET_INDEX_FOR_HASH_AND_SIZE, dshash_table_control::buckets, dshash_table::buckets, dshash_table::control, DSA_ALLOC_HUGE, DSA_ALLOC_ZERO, dsa_allocate_extended(), dsa_free(), dsa_get_address(), DsaPointerIsValid, DSHASH_NUM_PARTITIONS, dshash_table_item::hash, i, insert_item_into_bucket(), LW_EXCLUSIVE, LWLockAcquire(), LWLockHeldByMe(), LWLockRelease(), dshash_table_item::next, PARTITION_LOCK, and dshash_table_control::size_log2.
Referenced by dshash_find_or_insert().