postgresql/src/backend/commands
Tom Lane b3817f5f77 Improve hash_create()'s API for some added robustness.
Invent a new flag bit HASH_STRINGS to specify C-string hashing, which
was formerly the default; and add assertions insisting that exactly
one of the bits HASH_STRINGS, HASH_BLOBS, and HASH_FUNCTION be set.
This is in hopes of preventing recurrences of the type of oversight
fixed in commit a1b8aa1e4 (i.e., mistakenly omitting HASH_BLOBS).

Also, when HASH_STRINGS is specified, insist that the keysize be
more than 8 bytes.  This is a heuristic, but it should catch
accidental use of HASH_STRINGS for integer or pointer keys.
(Nearly all existing use-cases set the keysize to NAMEDATALEN or
more, so there's little reason to think this restriction should
be problematic.)

Tweak hash_create() to insist that the HASH_ELEM flag be set, and
remove the defaults it had for keysize and entrysize.  Since those
defaults were undocumented and basically useless, no callers
omitted HASH_ELEM anyway.

Also, remove memset's zeroing the HASHCTL parameter struct from
those callers that had one.  This has never been really necessary,
and while it wasn't a bad coding convention it was confusing that
some callers did it and some did not.  We might as well save a few
cycles by standardizing on "not".

Also improve the documentation for hash_create().

In passing, improve reinit.c's usage of a hash table by storing
the key as a binary Oid rather than a string; and, since that's
a temporary hash table, allocate it in CurrentMemoryContext for
neatness.

Discussion: https://postgr.es/m/590625.1607878171@sss.pgh.pa.us
2020-12-15 11:38:53 -05:00
..
Makefile Split copy.c into four files. 2020-11-23 10:50:50 +02:00
aggregatecmds.c Move catalog index declarations 2020-11-07 12:26:24 +01:00
alter.c Initial pgindent and pgperltidy run for v13. 2020-05-14 13:06:50 -04:00
amcmds.c Unify drop-by-OID functions 2020-06-09 09:39:46 +02:00
analyze.c snapshot scalability: Don't compute global horizons while building snapshots. 2020-08-12 16:03:49 -07:00
async.c Improve hash_create()'s API for some added robustness. 2020-12-15 11:38:53 -05:00
cluster.c Refactor CLUSTER and REINDEX grammar to use DefElem for option lists 2020-12-03 10:13:21 +09:00
collationcmds.c Use "true" not "TRUE" in one ICU function call. 2020-11-16 15:16:39 -05:00
comment.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
constraint.c Fix bogus CALLED_AS_TRIGGER() defenses. 2020-04-03 11:24:56 -04:00
conversioncmds.c Remove utils/acl.h from catalog/objectaddress.h 2020-03-10 10:27:00 +01:00
copy.c Split copy.c into four files. 2020-11-23 10:50:50 +02:00
copyfrom.c Split copy.c into four files. 2020-11-23 10:50:50 +02:00
copyfromparse.c Remove leftover comments, left behind by removal of WITH OIDS. 2020-11-30 10:26:43 +02:00
copyto.c Split copy.c into four files. 2020-11-23 10:50:50 +02:00
createas.c Remove INSERT privilege check at table creation of CTAS and matview 2020-11-21 19:45:30 +09:00
dbcommands.c Initial pgindent and pgperltidy run for v13. 2020-05-14 13:06:50 -04:00
define.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
discard.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
dropcmds.c Remove utils/acl.h from catalog/objectaddress.h 2020-03-10 10:27:00 +01:00
event_trigger.c Don't use custom OID symbols in pg_type.dat, either. 2020-10-29 13:33:38 -04:00
explain.c Fix broken XML formatting in EXPLAIN output for incremental sorts. 2020-10-23 11:32:33 -04:00
extension.c Make contrib modules' installation scripts more secure. 2020-08-10 10:44:42 -04:00
foreigncmds.c Unify drop-by-OID functions 2020-06-09 09:39:46 +02:00
functioncmds.c Support for OUT parameters in procedures 2020-10-05 09:21:43 +02:00
indexcmds.c Refactor CLUSTER and REINDEX grammar to use DefElem for option lists 2020-12-03 10:13:21 +09:00
lockcmds.c Fix cases of discarding result from list API functions 2020-11-11 08:03:51 +01:00
matview.c pg_stat_statements: track number of rows processed by REFRESH MATERIALIZED VIEW. 2020-11-12 11:26:55 +09:00
opclasscmds.c Message fixes and style improvements 2020-09-14 06:42:30 +02:00
operatorcmds.c Remove support for postfix (right-unary) operators. 2020-09-17 19:38:05 -04:00
policy.c Revise RelationBuildRowSecurity() to avoid memory leaks. 2020-09-26 16:04:06 -04:00
portalcmds.c In security-restricted operations, block enqueue of at-commit user code. 2020-11-09 07:32:09 -08:00
prepare.c Improve hash_create()'s API for some added robustness. 2020-12-15 11:38:53 -05:00
proclang.c Switch to multi-inserts when registering dependencies for many code paths 2020-09-05 21:33:53 +09:00
publicationcmds.c Unify drop-by-OID functions 2020-06-09 09:39:46 +02:00
schemacmds.c Unify drop-by-OID functions 2020-06-09 09:39:46 +02:00
seclabel.c Grammar object type refactoring 2020-06-13 09:19:30 +02:00
sequence.c Improve hash_create()'s API for some added robustness. 2020-12-15 11:38:53 -05:00
statscmds.c Replace remaining StrNCpy() by strlcpy() 2020-08-10 23:20:37 +02:00
subscriptioncmds.c Add support for streaming to built-in logical replication. 2020-09-03 07:54:07 +05:30
tablecmds.c Change get_constraint_index() to use pg_constraint.conindid 2020-12-09 15:41:45 +01:00
tablespace.c Fix temporary tablespaces for shared filesets some more. 2020-07-03 17:01:34 -04:00
trigger.c Provide the OR REPLACE option for CREATE TRIGGER. 2020-11-14 17:05:34 -05:00
tsearchcmds.c Switch to multi-inserts when registering dependencies for many code paths 2020-09-05 21:33:53 +09:00
typecmds.c Allow ALTER TYPE to update an existing type's typsubscript value. 2020-12-11 18:58:21 -05:00
user.c Improve error messages around REPLICATION and BYPASSRLS properties. 2020-11-03 15:49:05 -05:00
vacuum.c Avoid using tuple from syscache for update of pg_database.datfrozenxid 2020-12-08 12:13:19 +09:00
variable.c Update copyrights for 2020 2020-01-01 12:21:45 -05:00
view.c Restructure ALTER TABLE execution to fix assorted bugs. 2020-01-15 18:49:24 -05:00