|
PostgreSQL Source Code git master
|
#include "postgres.h"#include "common/hashfn.h"#include "common/string.h"#include "miscadmin.h"#include "nodes/queryjumble.h"#include "pg_plan_advice.h"#include "pg_stash_advice.h"#include "postmaster/bgworker.h"#include "storage/dsm_registry.h"#include "utils/guc.h"#include "utils/memutils.h"#include "lib/simplehash.h"
Go to the source code of this file.
Macros | |
| #define | SH_PREFIX pgsa_stash_name_table |
| #define | SH_ELEMENT_TYPE pgsa_stash_name |
| #define | SH_KEY_TYPE uint64 |
| #define | SH_KEY pgsa_stash_id |
| #define | SH_HASH_KEY(tb, key) hash_bytes((const unsigned char *) &(key), sizeof(uint64)) |
| #define | SH_EQUAL(tb, a, b) (a == b) |
| #define | SH_SCOPE extern |
| #define | SH_DEFINE |
Functions | |
| static char * | pgsa_advisor (PlannerGlobal *glob, Query *parse, const char *query_string, int cursorOptions, ExplainState *es) |
| static bool | pgsa_check_stash_name_guc (char **newval, void **extra, GucSource source) |
| static void | pgsa_init_shared_state (void *ptr, void *arg) |
| static bool | pgsa_is_identifier (char *str) |
| void | _PG_init (void) |
| void | pgsa_attach (void) |
| void | pgsa_check_lockout (void) |
| void | pgsa_check_stash_name (char *stash_name) |
| void | pgsa_create_stash (char *stash_name) |
| void | pgsa_clear_advice_string (char *stash_name, int64 queryId) |
| void | pgsa_drop_stash (char *stash_name) |
| void | pgsa_reset_all_stashes (void) |
| uint64 | pgsa_lookup_stash_id (char *stash_name) |
| void | pgsa_set_advice_string (char *stash_name, int64 queryId, char *advice_string) |
| void | pgsa_start_worker (void) |
| #define SH_DEFINE |
Definition at line 79 of file pg_stash_advice.c.
| #define SH_ELEMENT_TYPE pgsa_stash_name |
Definition at line 73 of file pg_stash_advice.c.
Definition at line 76 of file pg_stash_advice.c.
| #define SH_KEY pgsa_stash_id |
Definition at line 75 of file pg_stash_advice.c.
Definition at line 74 of file pg_stash_advice.c.
| #define SH_PREFIX pgsa_stash_name_table |
Definition at line 72 of file pg_stash_advice.c.
Definition at line 78 of file pg_stash_advice.c.
Definition at line 86 of file pg_stash_advice.c.
References DefineCustomBoolVariable(), DefineCustomIntVariable(), DefineCustomStringVariable(), EnableQueryId(), fb(), GUC_UNIT_S, load_external_function(), MarkGUCPrefixReserved(), pg_stash_advice_persist, pg_stash_advice_persist_interval, pg_stash_advice_stash_name, PGC_POSTMASTER, PGC_SIGHUP, PGC_USERSET, pgsa_advisor(), pgsa_check_stash_name_guc(), pgsa_start_worker(), and process_shared_preload_libraries_in_progress.
|
static |
Definition at line 150 of file pg_stash_advice.c.
References pgsa_entry::advice_string, DEBUG2, dsa_get_address(), dshash_find(), dshash_release_lock(), elog, fb(), InvalidDsaPointer, parse(), pg_atomic_unlocked_test_flag(), pg_stash_advice_stash_name, pgsa_attach(), pgsa_dsa_area, pgsa_entry_dshash, pgsa_lookup_stash_id(), pgsa_state, pstrdup(), pgsa_shared_state::stashes_ready, and unlikely.
Referenced by _PG_init().
Definition at line 221 of file pg_stash_advice.c.
References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, pgsa_shared_state::area, dsa_attach(), dsa_create, dsa_get_handle(), DSA_HANDLE_INVALID, dsa_pin(), dsa_pin_mapping(), pgsa_shared_state::dsa_tranche, dshash_attach(), dshash_create(), dshash_get_hash_table_handle(), DSHASH_HANDLE_INVALID, pgsa_shared_state::entry_hash, pgsa_shared_state::entry_tranche, fb(), GetNamedDSMSegment(), pgsa_shared_state::lock, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MemoryContextSwitchTo(), pg_stash_advice_mcxt, pgsa_dsa_area, pgsa_entry_dshash, pgsa_entry_dshash_parameters, pgsa_init_shared_state(), pgsa_stash_dshash, pgsa_stash_dshash_parameters, pgsa_state, pgsa_shared_state::stash_hash, pgsa_shared_state::stash_tranche, TopMemoryContext, and dshash_parameters::tranche_id.
Referenced by pg_create_advice_stash(), pg_drop_advice_stash(), pg_get_advice_stash_contents(), pg_get_advice_stashes(), pg_set_stashed_advice(), pg_start_stash_advice_worker(), pg_stash_advice_worker_main(), and pgsa_advisor().
Definition at line 325 of file pg_stash_advice.c.
References ereport, errcode(), errmsg, ERROR, fb(), pg_atomic_unlocked_test_flag(), PGSA_DUMP_FILE, pgsa_state, and pgsa_shared_state::stashes_ready.
Referenced by pg_create_advice_stash(), pg_drop_advice_stash(), and pg_set_stashed_advice().
Definition at line 340 of file pg_stash_advice.c.
References ereport, errcode(), errmsg, ERROR, fb(), NAMEDATALEN, pg_is_ascii(), and pgsa_is_identifier().
Referenced by pg_create_advice_stash(), pg_drop_advice_stash(), pg_get_advice_stash_contents(), and pg_set_stashed_advice().
Definition at line 380 of file pg_stash_advice.c.
References fb(), GUC_check_errcode(), GUC_check_errdetail, NAMEDATALEN, newval, pg_is_ascii(), and pgsa_is_identifier().
Referenced by _PG_init().
Definition at line 447 of file pg_stash_advice.c.
References pgsa_entry::advice_string, Assert, pgsa_shared_state::change_count, dsa_free(), dshash_delete_entry(), dshash_find(), ereport, errcode(), errmsg, ERROR, fb(), InvalidDsaPointer, pgsa_shared_state::lock, LWLockHeldByMe(), pg_atomic_add_fetch_u64(), pgsa_dsa_area, pgsa_entry_dshash, pgsa_lookup_stash_id(), and pgsa_state.
Referenced by pg_set_stashed_advice().
Definition at line 423 of file pg_stash_advice.c.
References Assert, pgsa_shared_state::change_count, dshash_find_or_insert, dshash_release_lock(), ereport, errcode(), errmsg, ERROR, fb(), pgsa_shared_state::lock, LW_EXCLUSIVE, LWLockHeldByMeInMode(), pgsa_shared_state::next_stash_id, pg_atomic_add_fetch_u64(), pgsa_stash_dshash, and pgsa_state.
Referenced by pg_create_advice_stash(), and pgsa_restore_stashes().
Definition at line 490 of file pg_stash_advice.c.
References pgsa_entry::advice_string, Assert, pgsa_shared_state::change_count, dsa_free(), dshash_delete_current(), dshash_delete_entry(), dshash_find(), dshash_seq_init(), dshash_seq_next(), dshash_seq_term(), ereport, errcode(), errmsg, ERROR, fb(), InvalidDsaPointer, pgsa_entry::key, pgsa_shared_state::lock, LW_EXCLUSIVE, LWLockHeldByMeInMode(), pg_atomic_add_fetch_u64(), pgsa_dsa_area, pgsa_entry_dshash, pgsa_stash_dshash, pgsa_entry_key::pgsa_stash_id, and pgsa_state.
Referenced by pg_drop_advice_stash().
Definition at line 568 of file pg_stash_advice.c.
References DSA_HANDLE_INVALID, DSHASH_HANDLE_INVALID, InvalidPid, LWLockInitialize(), LWLockNewTrancheId(), pg_atomic_init_flag(), pg_atomic_init_u64(), pg_atomic_test_set_flag(), pg_stash_advice_persist, and UINT64CONST.
Referenced by pgsa_attach().
Definition at line 605 of file pg_stash_advice.c.
References str.
Referenced by pgsa_check_stash_name(), and pgsa_check_stash_name_guc().
Definition at line 628 of file pg_stash_advice.c.
References dshash_find(), dshash_release_lock(), fb(), and pgsa_stash_dshash.
Referenced by pg_get_advice_stash_contents(), pgsa_advisor(), pgsa_clear_advice_string(), and pgsa_set_advice_string().
Definition at line 537 of file pg_stash_advice.c.
References pgsa_entry::advice_string, Assert, dsa_free(), dshash_delete_current(), dshash_seq_init(), dshash_seq_next(), dshash_seq_term(), fb(), InvalidDsaPointer, pgsa_shared_state::lock, LW_EXCLUSIVE, LWLockHeldByMeInMode(), pgsa_shared_state::next_stash_id, pgsa_dsa_area, pgsa_entry_dshash, pgsa_stash_dshash, pgsa_state, and UINT64CONST.
Referenced by pgsa_read_from_disk().
Definition at line 647 of file pg_stash_advice.c.
References pgsa_entry::advice_string, Assert, pgsa_shared_state::change_count, dsa_allocate, dsa_free(), dsa_get_address(), DsaPointerIsValid, dshash_find_or_insert_extended(), DSHASH_INSERT_NO_OOM, dshash_release_lock(), ereport, errcode(), errdetail(), errmsg, ERROR, fb(), InvalidDsaPointer, pgsa_shared_state::lock, LWLockHeldByMe(), pg_atomic_add_fetch_u64(), pgsa_dsa_area, pgsa_entry_dshash, pgsa_lookup_stash_id(), and pgsa_state.
Referenced by pg_set_stashed_advice(), and pgsa_restore_entries().
Definition at line 726 of file pg_stash_advice.c.
References BGW_DEFAULT_RESTART_INTERVAL, BackgroundWorker::bgw_flags, BackgroundWorker::bgw_function_name, BackgroundWorker::bgw_library_name, BackgroundWorker::bgw_name, BackgroundWorker::bgw_notify_pid, BackgroundWorker::bgw_restart_time, BackgroundWorker::bgw_start_time, BackgroundWorker::bgw_type, BGWH_STARTED, BGWORKER_SHMEM_ACCESS, BgWorkerStart_ConsistentState, ereport, errcode(), errhint(), errmsg, ERROR, fb(), MyProcPid, process_shared_preload_libraries_in_progress, RegisterBackgroundWorker(), RegisterDynamicBackgroundWorker(), and WaitForBackgroundWorkerStartup().
Referenced by _PG_init(), and pg_start_stash_advice_worker().
| PG_MODULE_MAGIC |
Definition at line 25 of file pg_stash_advice.c.
|
static |
Definition at line 58 of file pg_stash_advice.c.
Referenced by pgsa_attach().
Definition at line 48 of file pg_stash_advice.c.
Referenced by _PG_init(), and pgsa_init_shared_state().
| int pg_stash_advice_persist_interval = 30 |
Definition at line 49 of file pg_stash_advice.c.
Referenced by _PG_init(), and pg_stash_advice_worker_main().
|
static |
Definition at line 47 of file pg_stash_advice.c.
Referenced by _PG_init(), and pgsa_advisor().
| dsa_area* pgsa_dsa_area |
Definition at line 53 of file pg_stash_advice.c.
Referenced by pg_get_advice_stash_contents(), pgsa_advisor(), pgsa_attach(), pgsa_clear_advice_string(), pgsa_drop_stash(), pgsa_reset_all_stashes(), pgsa_set_advice_string(), and pgsa_write_entries().
| dshash_table* pgsa_entry_dshash |
Definition at line 55 of file pg_stash_advice.c.
Referenced by pg_create_advice_stash(), pg_drop_advice_stash(), pg_get_advice_stash_contents(), pg_get_advice_stashes(), pg_set_stashed_advice(), pg_start_stash_advice_worker(), pgsa_advisor(), pgsa_attach(), pgsa_clear_advice_string(), pgsa_drop_stash(), pgsa_read_from_disk(), pgsa_reset_all_stashes(), pgsa_set_advice_string(), pgsa_write_entries(), and pgsa_write_to_disk().
|
static |
Definition at line 37 of file pg_stash_advice.c.
Referenced by pgsa_attach().
| dshash_table* pgsa_stash_dshash |
Definition at line 54 of file pg_stash_advice.c.
Referenced by pg_get_advice_stash_contents(), pg_get_advice_stashes(), pgsa_attach(), pgsa_create_stash(), pgsa_drop_stash(), pgsa_lookup_stash_id(), pgsa_reset_all_stashes(), and pgsa_write_stashes().
|
static |
Definition at line 28 of file pg_stash_advice.c.
Referenced by pgsa_attach().
| pgsa_shared_state* pgsa_state |
Definition at line 52 of file pg_stash_advice.c.
Referenced by pg_create_advice_stash(), pg_drop_advice_stash(), pg_get_advice_stash_contents(), pg_get_advice_stashes(), pg_set_stashed_advice(), pg_start_stash_advice_worker(), pg_stash_advice_worker_main(), pgsa_advisor(), pgsa_attach(), pgsa_check_lockout(), pgsa_clear_advice_string(), pgsa_create_stash(), pgsa_detach_shmem(), pgsa_drop_stash(), pgsa_read_from_disk(), pgsa_reset_all_stashes(), pgsa_restore_entries(), pgsa_restore_stashes(), and pgsa_set_advice_string().