pgsql: Speed up tail processing when hashing aligned C strings

2024-03-30 Thread John Naylor
Speed up tail processing when hashing aligned C strings

After encountering the NUL terminator, the word-at-a-time loop exits
and we must hash the remaining bytes. Previously we calculated the
terminator's position and re-loaded the remaining bytes from the input
string. We already have all the data we need in a register, so let's
just mask off the bytes we need and hash them immediately. The mask can
be cheaply computed without knowing the terminator's position. We still
need that position for the length calculation, but the CPU can now
do that in parallel with other work, shortening the dependency chain.

Ants Aasma and John Naylor

Discussion: 
https://postgr.es/m/CANwKhkP7pCiW_5fAswLhs71-JKGEz1c1%2BPC0a_w1fwY4iGMqUA%40mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/07f0f6abfc7f6c55cede528d9689dedecefc734a

Modified Files
--
src/include/common/hashfn_unstable.h | 44 
1 file changed, 34 insertions(+), 10 deletions(-)



pgsql: Custom reloptions for table AM

2024-03-30 Thread Alexander Korotkov
Custom reloptions for table AM

Let table AM define custom reloptions for its tables.  This allows to
specify AM-specific parameters by WITH clause when creating a table.

The code may use some parts from prior work by Hao Wu.

Discussion: 
https://postgr.es/m/CAPpHfdurb9ycV8udYqM%3Do0sPS66PJ4RCBM1g-bBpvzUfogY0EA%40mail.gmail.com
Discussion: 
https://postgr.es/m/AMUA1wBBBxfc3tKRLLdU64rb.1.1683276279979.Hmail.wuhao%40hashdata.cn
Reviewed-by: Reviewed-by: Pavel Borisov, Matthias van de Meent

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/c95c25f9af4bc77f2f66a587735c50da08c12b37

Modified Files
--
src/backend/access/common/reloptions.c   |  6 ++--
src/backend/access/heap/heapam_handler.c | 12 +++
src/backend/access/table/tableamapi.c| 25 +++
src/backend/commands/tablecmds.c | 55 +++-
src/backend/postmaster/autovacuum.c  |  4 ++-
src/backend/utils/cache/relcache.c   |  6 +++-
src/include/access/reloptions.h  |  2 ++
src/include/access/tableam.h | 43 +
8 files changed, 126 insertions(+), 27 deletions(-)



pgsql: Generalize relation analyze in table AM interface

2024-03-30 Thread Alexander Korotkov
Generalize relation analyze in table AM interface

Currently, there is just one algorithm for sampling tuples from a table written
in acquire_sample_rows().  Custom table AM can just redefine the way to get the
next block/tuple by implementing scan_analyze_next_block() and
scan_analyze_next_tuple() API functions.

This approach doesn't seem general enough.  For instance, it's unclear how to
sample this way index-organized tables.  This commit allows table AM to
encapsulate the whole sampling algorithm (currently implemented in
acquire_sample_rows()) into the relation_analyze() API function.

Discussion: 
https://postgr.es/m/CAPpHfdurb9ycV8udYqM%3Do0sPS66PJ4RCBM1g-bBpvzUfogY0EA%40mail.gmail.com
Reviewed-by: Pavel Borisov, Matthias van de Meent

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/27bc1772fc814946918a5ac8ccb9b5c5ad0380aa

Modified Files
--
src/backend/access/heap/heapam_handler.c |  29 ++---
src/backend/access/table/tableamapi.c|   2 -
src/backend/commands/analyze.c   |  54 
src/include/access/heapam.h  |   9 +++
src/include/access/tableam.h | 106 +++
src/include/commands/vacuum.h|  19 ++
src/include/foreign/fdwapi.h |   6 +-
7 files changed, 100 insertions(+), 125 deletions(-)



pgsql: Let table AM insertion methods control index insertion

2024-03-30 Thread Alexander Korotkov
Let table AM insertion methods control index insertion

Previously, the executor did index insert unconditionally after calling
table AM interface methods tuple_insert() and multi_insert().  This commit
introduces the new parameter insert_indexes for these two methods.  Setting
'*insert_indexes' to true saves the current logic.  Setting it to false
indicates that table AM cares about index inserts itself and doesn't want the
caller to do that.

Discussion: 
https://postgr.es/m/CAPpHfdurb9ycV8udYqM%3Do0sPS66PJ4RCBM1g-bBpvzUfogY0EA%40mail.gmail.com
Reviewed-by: Pavel Borisov, Matthias van de Meent, Mark Dilger

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/b1484a3f1910bfd0e254afe40085dfc3351bda8c

Modified Files
--
src/backend/access/heap/heapam.c |  4 +++-
src/backend/access/heap/heapam_handler.c |  4 +++-
src/backend/access/table/tableam.c   |  6 --
src/backend/catalog/indexing.c   |  4 +++-
src/backend/commands/copyfrom.c  | 13 +
src/backend/commands/createas.c  |  4 +++-
src/backend/commands/matview.c   |  4 +++-
src/backend/commands/tablecmds.c |  6 +-
src/backend/executor/execReplication.c   |  6 --
src/backend/executor/nodeModifyTable.c   |  6 --
src/include/access/heapam.h  |  2 +-
src/include/access/tableam.h | 25 ++---
12 files changed, 60 insertions(+), 24 deletions(-)



pgsql: Add pg_basetype() function to extract a domain's base type.

2024-03-30 Thread Tom Lane
Add pg_basetype() function to extract a domain's base type.

This SQL-callable function behaves much like our internal utility
function getBaseType(), except it returns NULL rather than failing for
an invalid type OID.  (That behavior is modeled on our experience with
other catalog-inquiry functions such as the ACL checking functions.)
The key advantage over doing a join to pg_type is that it will loop
as needed to find the bottom base type of a nest of domains.

Steve Chavez, reviewed by jian he and others

Discussion: 
https://postgr.es/m/CAGRrpzZSX8j=MQcbCSEisFA=ic=k3bknvfnfjav1divjxfh...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/b154d8a6d0e52e5f6b09739639fdf55fa88bc6b8

Modified Files
--
doc/src/sgml/func.sgml   | 24 +++
src/backend/utils/adt/misc.c | 45 
src/include/catalog/catversion.h |  2 +-
src/include/catalog/pg_proc.dat  |  3 +++
src/test/regress/expected/domain.out | 25 
src/test/regress/sql/domain.sql  | 12 ++
6 files changed, 110 insertions(+), 1 deletion(-)



pgsql: Stabilize postgres_fdw test

2024-03-30 Thread Alvaro Herrera
Stabilize postgres_fdw test

The test fails when RESET statement_timeout takes longer than 10ms.
Avoid the problem by using SET LOCAL instead.

Overall, this test is not ideal: 10ms could be shorter than the time to
have sent the query to the "remote" server, so it's possible that on
some machines this test doesn't actually witness a remote query being
cancelled.  We may want to improve on this someday by using some other
testing technique, but for now it's better than nothing.  I verified
manually that one round of remote cancellation occurs when this runs on
my machine.

Discussion: 
https://postgr.es/m/CAGECzQRsdWnj=yaapcna8d7e1adbxrpbymybqrmpuijr2mp...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/ecf741cfae0603d1df269d8b799455bbcaef86e7

Modified Files
--
contrib/postgres_fdw/expected/postgres_fdw.out | 5 +++--
contrib/postgres_fdw/sql/postgres_fdw.sql  | 5 +++--
2 files changed, 6 insertions(+), 4 deletions(-)



pgsql: doc: Improve "Partition Maintenance" section

2024-03-30 Thread Alvaro Herrera
doc: Improve "Partition Maintenance" section

This adds some reference links and clarifies the wording a bit.

Author: Robert Treat 
Reviewed-by: Ashutosh Bapat 
Discussion: 
https://postgr.es/m/CABV9wwNGn-pweak6_pvL5PJ1mivDNPKfg0Tck_1oTUETv5Y=d...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/056c565742742e2eafe681c0a3ee7710503a556b

Modified Files
--
doc/src/sgml/ddl.sgml | 72 +--
1 file changed, 36 insertions(+), 36 deletions(-)



pgsql: Add support for MERGE ... WHEN NOT MATCHED BY SOURCE.

2024-03-30 Thread Dean Rasheed
Add support for MERGE ... WHEN NOT MATCHED BY SOURCE.

This allows MERGE commands to include WHEN NOT MATCHED BY SOURCE
actions, which operate on rows that exist in the target relation, but
not in the data source. These actions can execute UPDATE, DELETE, or
DO NOTHING sub-commands.

This is in contrast to already-supported WHEN NOT MATCHED actions,
which operate on rows that exist in the data source, but not in the
target relation. To make this distinction clearer, such actions may
now be written as WHEN NOT MATCHED BY TARGET.

Writing WHEN NOT MATCHED without specifying BY SOURCE or BY TARGET is
equivalent to writing WHEN NOT MATCHED BY TARGET.

Dean Rasheed, reviewed by Alvaro Herrera, Ted Yu and Vik Fearing.

Discussion: 
https://postgr.es/m/CAEZATCWqnKGc57Y_JanUBHQXNKcXd7r=0r4nezuvwp+syrk...@mail.gmail.com

Branch
--
master

Details
---
https://git.postgresql.org/pg/commitdiff/0294df2f1f842dfb0eed79007b21016f486a3c6c

Modified Files
--
doc/src/sgml/mvcc.sgml|  12 +-
doc/src/sgml/ref/merge.sgml   | 100 +--
src/backend/executor/execMain.c   |   6 +-
src/backend/executor/execPartition.c  |  21 +-
src/backend/executor/nodeModifyTable.c| 387 --
src/backend/nodes/nodeFuncs.c |   3 +
src/backend/optimizer/plan/createplan.c   |   8 +-
src/backend/optimizer/plan/planner.c  |  22 ++
src/backend/optimizer/plan/setrefs.c  |  20 +-
src/backend/optimizer/prep/prepjointree.c |  51 +++-
src/backend/optimizer/prep/preptlist.c|  26 +-
src/backend/optimizer/util/pathnode.c |   5 +-
src/backend/parser/gram.y |  62 +++--
src/backend/parser/parse_merge.c  |  56 ++--
src/backend/utils/adt/ruleutils.c |  41 ++-
src/bin/psql/tab-complete.c   |  30 +-
src/include/catalog/catversion.h  |   2 +-
src/include/nodes/execnodes.h |  15 +-
src/include/nodes/parsenodes.h|   7 +-
src/include/nodes/pathnodes.h |   2 +
src/include/nodes/plannodes.h |   2 +
src/include/nodes/primnodes.h |  10 +-
src/include/optimizer/pathnode.h  |   3 +-
src/include/parser/kwlist.h   |   2 +
src/test/isolation/expected/merge-update.out  |  88 --
src/test/isolation/specs/merge-update.spec|  10 +-
src/test/regress/expected/merge.out   | 299 +++-
src/test/regress/expected/rules.out   |  32 +++
src/test/regress/expected/updatable_views.out |  90 ++
src/test/regress/sql/merge.sql| 122 ++--
src/test/regress/sql/rules.sql|  19 ++
src/test/regress/sql/updatable_views.sql  |  32 +++
src/tools/pgindent/typedefs.list  |   1 +
33 files changed, 1226 insertions(+), 360 deletions(-)