Michael Paquier [Sat, 20 Feb 2021 01:25:14 +0000 (10:25 +0900)]     doc: Mention that partitions_{done,total} is 0 for REINDEX progress reports
  REINDEX has recently gained support for partitions, so it can be
 confusing to see those fields not being set.  Making useful reports for
 for such relations is more complicated than it looks with the current
 set of columns available in pg_stat_progress_create_index, and this
 touches equally REINDEX DATABASE/SYSTEM/SCHEMA.  This commit documents
 that those two columns are not touched during a REINDEX.  
Reported-by: Justin Pryzby Discussion: https://postgr.es/m/
20210216064214.GI28165@telsasoft.com  
  Michael Paquier [Sat, 20 Feb 2021 01:17:10 +0000 (10:17 +0900)]     Fix inconsistent configure data for --with-ssl
  This inconsistency was showing up after an autoreconf.  
Reported-by: Antonin Houska Reviewed-by: Tom Lane Discussion: https://postgr.es/m/47255.
1613716807@antos  
  Fujii Masao [Fri, 19 Feb 2021 13:01:25 +0000 (22:01 +0900)]     Fix psql's ON_ERROR_ROLLBACK so that it handles COMMIT AND CHAIN.
  When ON_ERROR_ROLLBACK is enabled, psql releases a temporary savepoint
 if it's idle in a valid transaction block after executing a query. But psql
 doesn't do that after RELEASE or ROLLBACK is executed because a temporary
 savepoint has already been destroyed in that case. 
 This commit changes psql's ON_ERROR_ROLLBACK so that it doesn't release
 a temporary savepoint also when COMMIT AND CHAIN is executed. A temporary
 savepoint doesn't need to be released in that case because
 COMMIT AND CHAIN also destroys any savepoints defined within the transaction
 to commit. Otherwise psql tries to release the savepoint that
 COMMIT AND CHAIN has already destroyed and cause an error
 "ERROR:  savepoint "pg_psql_temporary_savepoint" does not exist". 
 Back-patch to v12 where transaction chaining was added.  
Reported-by: Arthur Nascimento Author: Arthur Nascimento 
Reviewed-by: Fujii Masao, Vik Fearing Discussion: https://postgr.es/m/16867-
3475744069228158@postgresql.org  
  Fujii Masao [Fri, 19 Feb 2021 12:57:52 +0000 (21:57 +0900)]     Fix bug in COMMIT AND CHAIN command.
  This commit fixes COMMIT AND CHAIN command so that it starts new transaction
 immediately even if savepoints are defined within the transaction to commit.
 Previously COMMIT AND CHAIN command did not in that case because
 commit 
280a408b48 forgot to make CommitTransactionCommand() handle
 a transaction chaining when the transaction state was TBLOCK_SUBCOMMIT. 
 Also this commit adds the regression test for COMMIT AND CHAIN command
 when savepoints are defined. 
 Back-patch to v12 where transaction chaining was added.  
Reported-by: Arthur Nascimento Author: Fujii Masao 
Reviewed-by: Arthur Nascimento, Vik Fearing Discussion: https://postgr.es/m/16867-
3475744069228158@postgresql.org  
  Peter Eisentraut [Fri, 19 Feb 2021 06:57:42 +0000 (07:57 +0100)]     Update snowball
 
 Update to snowball tag v2.1.0.  Major changes are new stemmers for
 Armenian, Serbian, and Yiddish.
 
 
    Peter Geoghegan [Fri, 19 Feb 2021 05:16:33 +0000 (21:16 -0800)]     Add nbtree README section on page recycling.
 
 Consolidate discussion of how VACUUM places pages in the FSM for
 recycling by adding a new section that comes after discussion of page
 deletion.  This structure reflects the fact that page recycling is
 explicitly decoupled from page deletion in Lanin & Shasha's paper.  Page
 recycling in nbtree is an implementation of what the paper calls "the
 drain technique".
 
 This decoupling is an important concept for nbtree VACUUM.  Searchers
 have to detect and recover from concurrent page deletions, but they will
 never have to reason about concurrent page recycling.  Recycling can
 almost always be thought of as a low level garbage collection operation
 that asynchronously frees the physical space that backs a logical tree
 node.  Almost all code need only concern itself with logical tree nodes.
 (Note that "logical tree node" is not currently a term of art in the
 nbtree code -- this all works implicitly.)
 
 This is preparation for an upcoming patch that teaches nbtree VACUUM to
 remember the details of pages that it deletes on the fly, in local
 memory.  This enables the same VACUUM operation to consider placing its
 own deleted pages in the FSM later on, when it reaches the end of
 btvacuumscan().
 
 
    Tom Lane [Fri, 19 Feb 2021 03:38:55 +0000 (22:38 -0500)]     Fix another ancient bug in parsing of BRE-mode regular expressions.
  While poking at the regex code, I happened to notice that the bug
 squashed in commit 
afcc8772e had a sibling: next() failed to return
 a specific value associated with the '}' token for a "\{m,n\}"
 quantifier when parsing in basic RE mode.  Again, this could result
 in treating the quantifier as non-greedy, which it never should be in
 basic mode.  For that to happen, the last character before "\}" that
 sets "nextvalue" would have to set it to zero, or it'd have to have
 accidentally been zero from the start.  The failure can be provoked
 repeatably with, for example, a bound ending in digit "0". 
 Like the previous patch, back-patch all the way.  
  Fujii Masao [Thu, 18 Feb 2021 14:22:23 +0000 (23:22 +0900)]     Fix "invalid spinlock number: 0" error in pg_stat_wal_receiver.
  Commit 
2c8dd05d6c added the atomic variable writtenUpto into
 walreceiver's shared memory information. It's initialized only
 when walreceiver started up but could be read via pg_stat_wal_receiver
 view anytime, i.e., even before it's initialized. In the server built
 with --disable-atomics and --disable-spinlocks, this uninitialized
 atomic variable read could cause "invalid spinlock number: 0" error. 
 This commit changed writtenUpto so that it's initialized at
 the postmaster startup, to avoid the uninitialized variable read
 via pg_stat_wal_receiver and fix the error. 
 Also this commit moved the read of writtenUpto after the release
 of spinlock protecting walreceiver's shared variables. This is
 necessary to prevent new spinlock from being taken by atomic
 variable read while holding another spinlock, and to shorten
 the spinlock duration. This change leads writtenUpto not to be
 consistent with the other walreceiver's shared variables protected
 by a spinlock. But this is OK because writtenUpto should not be
 used for data integrity checks. 
 Back-patch to v13 where commit 
2c8dd05d6c introduced the bug. 
 Author: Fujii Masao 
Reviewed-by: Michael Paquier, Thomas Munro, Andres Freund Discussion: https://postgr.es/m/
7ef8708c-5b6b-edd3-2cf2-
7783f1c7c175@oss.nttdata.com  
  Peter Eisentraut [Thu, 18 Feb 2021 07:27:05 +0000 (08:27 +0100)]     Add tests for bytea LIKE operator
  Add test coverage for the following operations, which were previously
 not tested at all: 
 bytea LIKE bytea (bytealike)
 bytea NOT LIKE bytea (byteanlike)
 ESCAPE clause for the above (like_escape_bytea) 
 also 
 name NOT ILIKE text (nameicnlike) 
 Discussion: https://www.postgresql.org/message-id/flat/
4d13563a-2c8d-fd91-20d5-
e71b7a4eaa87%40enterprisedb.com  
  Peter Eisentraut [Thu, 18 Feb 2021 06:59:10 +0000 (07:59 +0100)]     Allow specifying CRL directory
  Add another method to specify CRLs, hashed directory method, for both
 server and client side.  This offers a means for server or libpq to
 load only CRLs that are required to verify a certificate.  The CRL
 directory is specifed by separate GUC variables or connection options
 ssl_crl_dir and sslcrldir, alongside the existing ssl_crl_file and
 sslcrl, so both methods can be used at the same time. 
 Author: Kyotaro Horiguchi <horikyota.ntt@gmail.com>
 Discussion: https://www.postgresql.org/message-id/flat/
20200731.173911.
904649928639357911.horikyota.ntt@gmail.com  
  Peter Geoghegan [Thu, 18 Feb 2021 05:13:15 +0000 (21:13 -0800)]     nbtree README: move VACUUM linear scan section.
 
 Discuss VACUUM's linear scan after discussion of tuple deletion by
 VACUUM, but before discussion of page deletion by VACUUM.  This
 progression is a lot more natural.
 
 Also tweak the wording a little.  It seems unnecessary to talk about how
 it worked prior to PostgreSQL 8.2.
 
 
    Tomas Vondra [Wed, 17 Feb 2021 23:02:00 +0000 (00:02 +0100)]     Fix tuple routing to initialize batching only for inserts
  A cross-partition update on a partitioned table is implemented as a
 delete followed by an insert. With foreign partitions, this was however
 causing issues, because the FDW and core may disagree on when to enable
 batching.  postgres_fdw was only allowing batching for plain inserts
 (CMD_INSERT) while core was trying to batch the insert component of the
 cross-partition update.  Fix by restricting core to apply batching only
 to plain CMD_INSERT queries. 
 It's possible to allow batching for cross-partition updates, but that
 will require more extensive changes, so better to leave that for a
 separate patch. 
 Author: Amit Langote 
Reviewed-by: Tomas Vondra, Takayuki Tsunakawa Discussion: https://postgr.es/m/
20200628151002.7x5laxwpgvkyiu3q@development  
  Tomas Vondra [Wed, 17 Feb 2021 23:01:21 +0000 (00:01 +0100)]     Fix pointer type in ExecForeignBatchInsert SGML docs
  Reported-by: Ian Barwick Discussion: https://postgr.es/m/
20200628151002.7x5laxwpgvkyiu3q@development  
  Tom Lane [Wed, 17 Feb 2021 17:24:12 +0000 (12:24 -0500)]     Make some minor improvements in the regex code.
  Push some hopefully-uncontroversial bits extracted from an upcoming
 patch series, to remove non-relevant clutter from the main patches. 
 In compact(), return immediately after setting REG_ASSERT error;
 continuing the loop would just lead to assertion failure below.
 (Ask me how I know.) 
 In parseqatom(), remove assertion that moresubs() did its job.
 When moresubs actually did its job, this is redundant with that
 function's final assert; but when it failed on OOM, this is an
 assertion crash.  We could avoid the crash by adding a NOERR()
 check before the assertion, but it seems better to subtract code
 than add it.  (Note that there's a NOERR exit a few lines further
 down, and nothing else between here and there requires moresubs
 to have succeeded.  So we don't really need an extra error exit.)
 This is a live bug in assert-enabled builds, but given the very
 low likelihood of OOM in moresub's tiny allocation, I don't think
 it's worth back-patching. 
 On the other hand, it seems worthwhile to add an assertion that
 our intended v->subs[subno] target is still null by the time we
 are ready to insert into it, since there's a recursion in between. 
 In pg_regexec, ensure we fflush any debug output on the way out,
 and try to make MDEBUG messages more uniform and helpful.  (In
 particular, ensure that all of them are prefixed with the subre's
 id number, so one can match up entry and exit reports.) 
 Add some test cases in test_regex to improve coverage of lookahead
 and lookbehind constraints.  Adding these now is mainly to establish
 that this is indeed the existing behavior. 
 Discussion: https://postgr.es/m/
1340281.
1613018383@sss.pgh.pa.us  
  Peter Eisentraut [Wed, 17 Feb 2021 16:53:18 +0000 (17:53 +0100)]     Routine usage information schema tables
  Several information schema views track dependencies between
 functions/procedures and objects used by them.  These had not been
 implemented so far because PostgreSQL doesn't track objects used in a
 function body.  However, formally, these also show dependencies used
 in parameter default expressions, which PostgreSQL does support and
 track.  So for the sake of completeness, we might as well add these.
 If dependency tracking for function bodies is ever implemented, these
 views will automatically work correctly.  
Reviewed-by: Erik Rijkers <er@xs4all.nl> Discussion: https://www.postgresql.org/message-id/flat/
ac80fc74-e387-8950-9a31-
2560778fc1e3%40enterprisedb.com  
  Magnus Hagander [Wed, 17 Feb 2021 12:53:26 +0000 (13:53 +0100)]     Fix typo
  Author: Daniel Gustafsson <daniel@yesql.se>
 Discussion: https://postgr.es/m/
0CF087FC-BEAD-4010-8BB9-
3CDD74DC9060@yesql.se  
  Peter Eisentraut [Wed, 17 Feb 2021 10:24:46 +0000 (11:24 +0100)]     Use errmsg_internal for debug messages
 
 An inconsistent set of debug-level messages was not using
 errmsg_internal(), thus uselessly exposing the messages to translation
 work.  Fix those.
 
 
    Michael Paquier [Wed, 17 Feb 2021 02:50:58 +0000 (11:50 +0900)]     Add psql completion for [ NO ] DEPENDS ON EXTENSION
 
 ALTER INDEX was able to handle that already.  This adds tab completion
 for all the remaining commands that support this grammar:
 - ALTER FUNCTION
 - ALTER PROCEDURE
 - ALTER ROUTINE
 - ALTER TRIGGER
 - ALTER MATERIALIZED VIEW
 
 Author: Ian Lawrence Barwick
 Discussion: https://postgr.es/m/CAB8KJ=iypYudXuMOAMOP4BpkaYbXxk=a2cdJppX0e9mJXWtuig@mail.gmail.com
 
 
    Tom Lane [Tue, 16 Feb 2021 17:07:14 +0000 (12:07 -0500)]     Convert tsginidx.c's GIN indexing logic to fully ternary operation.
  Commit 
2f2007fbb did this partially, but there were two remaining
 warts.  checkcondition_gin handled some uncertain cases by setting
 the out-of-band recheck flag, some by returning TS_MAYBE, and some
 by doing both.  Meanwhile, TS_execute arbitrarily converted a
 TS_MAYBE result to TS_YES.  Thus, if checkcondition_gin chose to
 only return TS_MAYBE, the outcome would be TS_YES with no recheck
 flag, potentially resulting in wrong query outputs. 
 The case where this'd happen is if there were GIN_MAYBE entries
 in the indexscan results passed to gin_tsquery_[tri]consistent,
 which so far as I can see would only happen if the tidbitmap used
 to accumulate indexscan results grew large enough to become lossy. 
 I initially thought of fixing this by ensuring we always set the
 recheck flag as well as returning TS_MAYBE in uncertain cases.
 But that errs in the other direction, potentially forcing rechecks
 of rows that provably match the query (since the recheck flag
 remains set even if TS_execute later finds that the answer must be
 TS_YES).  Instead, let's get rid of the out-of-band recheck flag
 altogether and rely on returning TS_MAYBE.  This requires exporting
 a version of TS_execute that will actually return the full ternary
 result of the evaluation ... but we likely should have done that
 to start with. 
 Unfortunately it doesn't seem practical to add a regression test case
 that covers this: the amount of data needed to cause the GIN bitmap to
 become lossy results in a longer runtime than I think we want to have
 in the tests.  (I'm wondering about allowing smaller work_mem settings
 to ameliorate that, but it'd be a matter for a separate patch.) 
 Per bug #16865 from Dimitri Nüscheler.  Back-patch to v13 where
 the faulty commit came in. 
 Discussion: https://postgr.es/m/16865-
4ffdc3e682e6d75b@postgresql.org  
  Amit Kapila [Tue, 16 Feb 2021 01:56:50 +0000 (07:26 +0530)]     Remove the unnecessary PrepareWrite in pgoutput.
  This issue exists from the inception of this code (PG-10) but got exposed
 by the recent commit 
ce0fdbfe97 where we are using origins in tablesync
 workers. The problem was that we were sometimes sending the prepare_write
 ('w') message but then the actual message was not being sent and on the
 subscriber side, we always expect a message after prepare_write message
 which led to this bug. 
 I refrained from backpatching this because there is no way in the core
 code to hit this prior to commit 
ce0fdbfe97 and we haven't received any
 complaints so far.  
Reported-by: Erik Rijkers Author: Amit Kapila and Vignesh C 
Tested-by: Erik Rijkers Discussion: https://postgr.es/m/
1295168140.139428.
1613133237154@webmailclassic.xs4all.nl  
  Andres Freund [Tue, 16 Feb 2021 01:12:12 +0000 (17:12 -0800)]     Fix heap_page_prune() parameter order confusion introduced in 
dc7420c2c92. 
 Both luckily and unluckily the passed values meant the same for all
 types. Luckily because that meant my confusion caused no harm,
 unluckily because otherwise the compiler might have warned... 
 In passing, synchronize parameter names between definition and
 declaration.  
Reported-By: Peter Geoghegan <pg@bowt.ie> Author: Andres Freund <andres@anarazel.de>
 Discussion: https://postgr.es/m/CAH2-Wz=L=nBoepQdH9b5Qd0nMvepFT2CnT6sjWvvpOXa=K8HVQ@mail.gmail.com  
  Andres Freund [Tue, 16 Feb 2021 00:57:47 +0000 (16:57 -0800)]     Remove backwards compat ugliness in snapbuild.c.
  In 
955a684e040 we fixed a bug in initial snapshot creation. In the
 course of which several members of struct SnapBuild were obsoleted. As
 SnapBuild is serialized to disk we couldn't change the memory layout. 
 Unfortunately I subsequently forgot about removing the backward compat
 gunk, but luckily Heikki just reminded me. 
 This commit bumps SNAPBUILD_VERSION, therefore breaking existing
 slots (which is fine in a major release). 
 Author: Andres Freund 
Reminded-By: Heikki Linnakangas <hlinnaka@iki.fi> Discussion: https://postgr.es/m/
c94be044-818f-15e3-1ad3-
7a7ae2dfed0a@iki.fi  
  Tom Lane [Mon, 15 Feb 2021 15:17:58 +0000 (10:17 -0500)]     Simplify loop logic in nodeIncrementalSort.c.
  The inner loop in switchToPresortedPrefixMode() can be implemented
 as a conventional integer-counter for() loop, removing a couple of
 redundant boolean state variables.  The old logic here was a remnant
 of earlier development, but as things now stand there's no reason
 for extra complexity. 
 Also, annotate the test case added by 
82e0e2930 to explain why it
 manages to hit the corner case fixed in that commit, and add an
 EXPLAIN to verify that it's creating an incremental-sort plan. 
 Back-patch to v13, like the previous patch. 
 James Coleman and Tom Lane 
 Discussion: https://postgr.es/m/16846-
ae49f51ac379a4cb@postgresql.org  
  Heikki Linnakangas [Mon, 15 Feb 2021 07:28:08 +0000 (09:28 +0200)]     Make ExecGetInsertedCols() and friends more robust and improve comments.
  If ExecGetInsertedCols(), ExecGetUpdatedCols() or ExecGetExtraUpdatedCols()
 were called with a ResultRelInfo that's not in the range table and isn't a
 partition routing target, the functions would dereference a NULL pointer,
 relinfo->ri_RootResultRelInfo. Such ResultRelInfos are created when firing
 RI triggers in tables that are not modified directly. None of the current
 callers of these functions pass such relations, so this isn't a live bug,
 but let's make them more robust. 
 Also update comment in ResultRelInfo; after commit 
6214e2b228,
 ri_RangeTableIndex is zero for ResultRelInfos created for partition tuple
 routing. 
 Noted by Coverity. Backpatch down to v11, like commit 
6214e2b228.  
Reviewed-by: Tom Lane, Amit Langote   Fujii Masao [Mon, 15 Feb 2021 06:13:37 +0000 (15:13 +0900)]     Display the time when the process started waiting for the lock, in pg_locks, take 2
  This commit adds new column "waitstart" into pg_locks view. This column
 reports the time when the server process started waiting for the lock
 if the lock is not held. This information is useful, for example, when
 examining the amount of time to wait on a lock by subtracting
 "waitstart" in pg_locks from the current time, and identify the lock
 that the processes are waiting for very long. 
 This feature uses the current time obtained for the deadlock timeout
 timer as "waitstart" (i.e., the time when this process started waiting
 for the lock). Since getting the current time newly can cause overhead,
 we reuse the already-obtained time to avoid that overhead. 
 Note that "waitstart" is updated without holding the lock table's
 partition lock, to avoid the overhead by additional lock acquisition.
 This can cause "waitstart" in pg_locks to become NULL for a very short
 period of time after the wait started even though "granted" is false.
 This is OK in practice because we can assume that users are likely to
 look at "waitstart" when waiting for the lock for a long time. 
 The first attempt of this patch (commit 
3b733fcd04) caused the buildfarm
 member "rorqual" (built with --disable-atomics --disable-spinlocks) to report
 the failure of the regression test. It was reverted by commit 
890d2182a2.
 The cause of this failure was that the atomic variable for "waitstart"
 in the dummy process entry created at the end of prepare transaction was
 not initialized. This second attempt fixes that issue. 
 Bump catalog version. 
 Author: Atsushi Torikoshi 
Reviewed-by: Ian Lawrence Barwick, Robert Haas, Justin Pryzby, Fujii Masao Discussion: https://postgr.es/m/
a96013dc51cdc56b2a2b84fa8a16a993@oss.nttdata.com  
  Peter Geoghegan [Mon, 15 Feb 2021 04:11:11 +0000 (20:11 -0800)]     Add "LP_DEAD item?" column to GiST pageinspect functions
  This brings gist_page_items() and gist_page_items_bytea() in line with
 nbtree's bt_page_items() function. 
 Minor follow-up to commit 
756ab291, which added the GiST functions. 
 Author: Andrey Borodin <x4mmm@yandex-team.ru>
 Discussion: https://postgr.es/m/
E0794687-7315-4C29-A9C7-
EC54D448596D@yandex-team.ru  
  Peter Geoghegan [Mon, 15 Feb 2021 03:43:25 +0000 (19:43 -0800)]     Avoid misinterpreting GiST pages in pageinspect.
  GistPageSetDeleted() sets pd_lower when deleting a page, and sets the
 page contents to a GISTDeletedPageContents.  Avoid treating deleted GiST
 pages as regular slotted pages within pageinspect. 
 Oversight in commit 
756ab291. 
 Author: Andrey Borodin <x4mmm@yandex-team.ru>  
  Peter Geoghegan [Mon, 15 Feb 2021 03:28:37 +0000 (19:28 -0800)]     Adjust lazy_scan_heap() accounting comments.
 
 Explain which particular LP_DEAD line pointers get accounted for by the
 tups_vacuumed variable.
 
 
    Thomas Munro [Mon, 15 Feb 2021 02:43:39 +0000 (15:43 +1300)]     Default to wal_sync_method=fdatasync on FreeBSD.
  FreeBSD 13 gained O_DSYNC, which would normally cause wal_sync_method to
 choose open_datasync as its default value.  That may not be a good
 choice for all systems, and performs worse than fdatasync in some
 scenarios.  Let's preserve the existing default behavior for now. 
 Like commit 
576477e73c4, which did the same for Linux, back-patch to all
 supported releases. 
 Discussion: https://postgr.es/m/CA%2BhUKGLsAMXBQrCxCXoW-JsUYmdOL8ALYvaX%3DCrHqWxm-nWbGA%40mail.gmail.com  
  Thomas Munro [Mon, 15 Feb 2021 02:08:04 +0000 (15:08 +1300)]     Use pg_pwrite() in pg_test_fsync.
 
 For consistency with the PostgreSQL behavior this test program is
 intended to simulate, use pwrite() instead of lseek() + write().
 
 Also fix the final "non-sync" test, which was opening and closing the
 file for every write.
 
 Discussion: https://postgr.es/m/CA%2BhUKGJjjid2BJsvjMALBTduo1ogdx2SPYaTQL3wAy8y2hc4nw%40mail.gmail.com
 
 
    Amit Kapila [Mon, 15 Feb 2021 01:58:02 +0000 (07:28 +0530)]     Fix the warnings introduced in commit 
ce0fdbfe97. 
 Author: Amit Kapila 
Reviewed-by: Tom Lane Discussion: https://postgr.es/m/
1610789.
1613170207@sss.pgh.pa.us  
  Thomas Munro [Mon, 15 Feb 2021 00:32:58 +0000 (13:32 +1300)]     Hold interrupts while running dsm_detach() callbacks.
  While cleaning up after a parallel query or parallel index creation that
 created temporary files, we could be interrupted by a statement timeout.
 The error handling path would then fail to clean up the files when it
 ran dsm_detach() again, because the callback was already popped off the
 list.  Prevent this hazard by holding interrupts while the cleanup code
 runs. 
 Thanks to Heikki Linnakangas for this suggestion, and also to Kyotaro
 Horiguchi, Masahiko Sawada, Justin Pryzby and Tom Lane for discussion of
 this and earlier ideas on how to fix the problem. 
 Back-patch to all supported releases.  
Reported-by: Justin Pryzby <pryzby@telsasoft.com> Discussion: https://postgr.es/m/
20191212180506.GR2082@telsasoft.com  
  Michael Paquier [Mon, 15 Feb 2021 01:18:34 +0000 (10:18 +0900)]     Add result size as argument of pg_cryptohash_final() for overflow checks
  With its current design, a careless use of pg_cryptohash_final() could
 would result in an out-of-bound write in memory as the size of the
 destination buffer to store the result digest is not known to the
 cryptohash internals, without the caller knowing about that.  This
 commit adds a new argument to pg_cryptohash_final() to allow such sanity
 checks, and implements such defenses. 
 The internals of SCRAM for HMAC could be tightened a bit more, but as
 everything is based on SCRAM_KEY_LEN with uses particular to this code
 there is no need to complicate its interface more than necessary, and
 this comes back to the refactoring of HMAC in core.  Except that, this
 minimizes the uses of the existing DIGEST_LENGTH variables, relying
 instead on sizeof() for the result sizes.  In ossp-uuid, this also makes
 the code more defensive, as it already relied on dce_uuid_t being at
 least the size of a MD5 digest. 
 This is in philosophy similar to 
cfc40d3 for base64.c and 
aef8948 for
 hex.c.  
Reported-by: Ranier Vilela Author: Michael Paquier, Ranier Vilela 
Reviewed-by: Kyotaro Horiguchi Discussion: https://postgr.es/m/CAEudQAoqEGmcff3J4sTSV-R_16Monuz-UpJFbf_dnVH=APr02Q@mail.gmail.com  
  Tom Lane [Mon, 15 Feb 2021 00:53:28 +0000 (19:53 -0500)]     Minor fixes to improve regex debugging code.
 
 When REG_DEBUG is defined, ensure that an un-filled "struct cnfa"
 is all-zeroes, not just that it has nstates == 0.  This is mainly
 so that looking at "struct subre" structs in gdb doesn't distract
 one with a lot of garbage fields during regex compilation.
 
 Adjust some places that print debug output to have suitable fflush
 calls afterwards.
 
 In passing, correct an erroneous ancient comment: the concatenation
 subre-s created by parsebranch() have op == '.' not ','.
 
 Noted while fooling around with some regex performance improvements.
 
 
    Thomas Munro [Mon, 15 Feb 2021 00:03:10 +0000 (13:03 +1300)]     ReadNewTransactionId() -> ReadNextTransactionId().
 
 The new name conveys the effect better, is more consistent with similar
 functions ReadNextMultiXactId(), ReadNextFullTransactionId(), and
 matches the name of the variable that it reads.
 
 Reported-by: Peter Geoghegan <pg@bowt.ie>
 Discussion: https://postgr.es/m/CAH2-WzmVR4SakBXQUdhhPpMf1aYvZCnna5%3DHKa7DAgEmBAg%2B8g%40mail.gmail.com
 
 
    Bruce Momjian [Sat, 13 Feb 2021 18:50:49 +0000 (13:50 -0500)]     README/C-comment:  document GiST's NSN value
 
 
    Michael Paquier [Sat, 13 Feb 2021 07:06:11 +0000 (16:06 +0900)]     doc: Mention NO DEPENDS ON EXTENSION in its supported ALTER commands
  This grammar flavor has been added by 
5fc7039. 
 Author: Ian Lawrence Barwick
 Discussion: https://postgr.es/m/CAB8KJ=ii6JScodxkA6-DO8bjatsMYU3OcewnL0mdN9geR+tTaw@mail.gmail.com
 Backpatch-through: 13  
  Tom Lane [Fri, 12 Feb 2021 22:33:14 +0000 (17:33 -0500)]     Tweak compiler version cutoff for no_sanitize("alignment") support.
  Buildfarm results show that gcc up through 7.x produces annoying
 warnings for this construct (and, presumably, wouldn't do the right
 thing anyway).  clang seems okay with the cutoff we have, though. 
 Discussion: https://postgr.es/m/CAPpHfdsne3%3DT%3DfMNU45PtxdhSL_J2PjLTeS8rwKnJzUR4YNd4w%40mail.gmail.com
 Discussion: https://postgr.es/m/475514.
1612745257%40sss.pgh.pa.us  
  Tom Lane [Fri, 12 Feb 2021 21:26:47 +0000 (16:26 -0500)]     Avoid divide-by-zero in regex_selectivity() with long fixed prefix.
  Given a regex pattern with a very long fixed prefix (approaching 500
 characters), the result of pow(FIXED_CHAR_SEL, fixed_prefix_len) can
 underflow to zero.  Typically the preceding selectivity calculation
 would have underflowed as well, so that we compute 0/0 and get NaN.
 In released branches this leads to an assertion failure later on.
 That doesn't happen in HEAD, for reasons I've not explored yet,
 but it's surely still a bug. 
 To fix, just skip the division when the pow() result is zero, so
 that we'll (most likely) return a zero selectivity estimate.  In
 the edge cases where "sel" didn't yet underflow, perhaps this
 isn't desirable, but I'm not sure that the case is worth spending
 a lot of effort on.  The results of regex_selectivity_sub() are
 barely worth the electrons they're written on anyway :-( 
 Per report from Alexander Lakhin.  Back-patch to all supported versions. 
 Discussion: https://postgr.es/m/
6de0a0c3-ada9-cd0c-3e4e-
2fa9964b41e3@gmail.com  
  Alexander Korotkov [Fri, 12 Feb 2021 14:14:33 +0000 (17:14 +0300)]     pg_attribute_no_sanitize_alignment() macro
  Modern gcc and clang compilers offer alignment sanitizers, which help to detect
 pointer misalignment.  However, our codebase already contains x86-specific
 crc32 computation code, which uses unalignment access.  Thankfully, those
 compilers also support the attribute, which disables alignment sanitizers at
 the function level.  This commit adds pg_attribute_no_sanitize_alignment(),
 which wraps this attribute, and applies it to pg_comp_crc32c_sse42() function. 
 Discussion: https://postgr.es/m/CAPpHfdsne3%3DT%3DfMNU45PtxdhSL_J2PjLTeS8rwKnJzUR4YNd4w%40mail.gmail.com
 Discussion: https://postgr.es/m/475514.
1612745257%40sss.pgh.pa.us
 Author: Alexander Korotkov, revised by Tom Lane 
Reviewed-by: Tom Lane   Amit Kapila [Fri, 12 Feb 2021 04:41:16 +0000 (10:11 +0530)]     Fix Subscription test added by commit 
ce0fdbfe97. 
 We want to test the variants of Alter Subscription that are not allowed in
 the transaction block but for that, we don't need to create a subscription
 that tries to connect to the publisher. As such, there is no problem with
 this test but it is good to allow such tests to run with
 wal_level = minimal and max_wal_senders = 0 so as to keep them consistent
 with other tests. 
 Reported by buildfarm. 
 Author: Amit Kapila 
Reviewed-by: Ajin Cherian Discussion: https://postgr.es/m/CAA4eK1Lw0V+e1JPGHDq=+hVACv=14H8sR+2eJ1k3PEgwKmU-jQ@mail.gmail.com  
  Amit Kapila [Fri, 12 Feb 2021 02:11:51 +0000 (07:41 +0530)]     Allow multiple xacts during table sync in logical replication.
 
 For the initial table data synchronization in logical replication, we use
 a single transaction to copy the entire table and then synchronize the
 position in the stream with the main apply worker.
 
 There are multiple downsides of this approach: (a) We have to perform the
 entire copy operation again if there is any error (network breakdown,
 error in the database operation, etc.) while we synchronize the WAL
 position between tablesync worker and apply worker; this will be onerous
 especially for large copies, (b) Using a single transaction in the
 synchronization-phase (where we can receive WAL from multiple
 transactions) will have the risk of exceeding the CID limit, (c) The slot
 will hold the WAL till the entire sync is complete because we never commit
 till the end.
 
 This patch solves all the above downsides by allowing multiple
 transactions during the tablesync phase. The initial copy is done in a
 single transaction and after that, we commit each transaction as we
 receive. To allow recovery after any error or crash, we use a permanent
 slot and origin to track the progress. The slot and origin will be removed
 once we finish the synchronization of the table. We also remove slot and
 origin of tablesync workers if the user performs DROP SUBSCRIPTION .. or
 ALTER SUBSCRIPTION .. REFERESH and some of the table syncs are still not
 finished.
 
 The commands ALTER SUBSCRIPTION ... REFRESH PUBLICATION and
 ALTER SUBSCRIPTION ... SET PUBLICATION ... with refresh option as true
 cannot be executed inside a transaction block because they can now drop
 the slots for which we have no provision to rollback.
 
 This will also open up the path for logical replication of 2PC
 transactions on the subscriber side. Previously, we can't do that because
 of the requirement of maintaining a single transaction in tablesync
 workers.
 
 Bump catalog version due to change of state in the catalog
 (pg_subscription_rel).
 
 Author: Peter Smith, Amit Kapila, and Takamichi Osumi
 Reviewed-by: Ajin Cherian, Petr Jelinek, Hou Zhijie and Amit Kapila
 Discussion: https://postgr.es/m/CAA4eK1KHJxaZS-fod-0fey=0tq3=Gkn4ho=8N4-5HWiCfu0H1A@mail.gmail.com
 
 
    Peter Geoghegan [Fri, 12 Feb 2021 00:49:41 +0000 (16:49 -0800)]     Remove obsolete IndexBulkDeleteResult stats field.
  The pages_removed field is no longer used for anything.  It hasn't been
 possible for an index to physically shrink since old-style VACUUM FULL
 was removed by commit 
0a469c87.  
  Tom Lane [Thu, 11 Feb 2021 20:05:55 +0000 (15:05 -0500)]     Remove dead code in ECPGconnect(), and improve documentation.
  The stanza in ECPGconnect() that intended to allow specification of a
 Unix socket directory path in place of a port has never executed since
 it was committed, nearly two decades ago; the preceding strrchr()
 already found the last colon so there cannot be another one.  The lack
 of complaints about that is doubtless related to the fact that no
 user-facing documentation suggested it was possible. 
 Rather than try to fix that up, let's just remove the unreachable
 code, and instead document the way that does work to write a socket
 directory path, namely specifying it as a "host" option. 
 In support of that, make another pass at clarifying the syntax
 documentation for ECPG connection targets, particularly documenting
 which things are parsed as identifiers and where to use double quotes.
 Rearrange some things that seemed poorly ordered, and fix a couple of
 minor doc errors. 
 Kyotaro Horiguchi, per gripe from Shenhao Wang
 (docs changes mostly by me) 
 Discussion: https://postgr.es/m/
ae52a416bbbf459c96bab30b3038e06c@G08CNEXMBPEKD06.g08.fujitsu.local  
  Tom Lane [Thu, 11 Feb 2021 17:49:22 +0000 (12:49 -0500)]     Simplify jsonfuncs.c code by using strtoint() not strtol().
 
 Explicitly testing for INT_MIN and INT_MAX isn't particularly good
 style; it's tedious and may draw useless compiler warnings on
 machines where int and long are the same width.  We invented
 strtoint() precisely for this usage, so use that instead.
 
 While here, remove gratuitous variations in the way the tests for
 did-strtoint-succeed were spelled.  Also, avoid attempting to
 negate INT_MIN; that would probably work given that the result
 is implicitly cast to uint32, but I think it's nominally undefined
 behavior.
 
 Per gripe from Ranier Vilela, though this isn't his proposed patch.
 
 Discussion: https://postgr.es/m/CAEudQAqge3QfzoBRhe59QrB_5g+NmQUj2QpzqZ9Nc7QepXGAEw@mail.gmail.com
 
 
    Tom Lane [Thu, 11 Feb 2021 16:23:25 +0000 (11:23 -0500)]     Remove no-longer-used RTE argument of markVarForSelectPriv().
  In the wake of 
c028faf2a, this is no longer needed.  I left it
 out of that patch since the API change would be undesirable in
 a released branch; but there's no reason not to do it in HEAD.  
  Michael Paquier [Thu, 11 Feb 2021 10:16:11 +0000 (19:16 +0900)]     Fix copy-paste error with SHA256 digest length in checksum_helper.c
  Issue introduced by 
87ae969, noticed while working on the area.  While
 on it, fix some grammar in the surrounding static assertions.  
  Peter Eisentraut [Thu, 11 Feb 2021 08:56:14 +0000 (09:56 +0100)]     Add test case for abbrev(cidr)
  This will in particular add some good test coverage for
 inet_cidr_ntop.c, which was previously completely uncovered.  
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/
cb0c4662-4596-dab4-7f64-
839c5e8582c8%40enterprisedb.com  
  Magnus Hagander [Wed, 10 Feb 2021 17:21:55 +0000 (18:21 +0100)]     Remove extra Success message at the end of initdb
  This was accidentally included in 
e09155bd62 and is redundant with the
 lines right above it.  
Reported-By: Peter Eisentraut Discussion: https://postgr.es/m/
455845d1-441d-cc40-d2a7-
b47f4e422489@2ndquadrant.com  
  Peter Eisentraut [Wed, 10 Feb 2021 12:08:13 +0000 (13:08 +0100)]     pg_dump: Add const decorations
  Add const decorations to the *info arguments of the dump* functions,
 to clarify that they don't modify that argument.  Many other nearby
 functions modify their arguments, so this can help clarify these
 different APIs a bit. 
 Discussion: https://www.postgresql.org/message-id/flat/
012d3030-9a2c-99a1-ed2d-
988978b5632f%40enterprisedb.com  
  Peter Eisentraut [Wed, 10 Feb 2021 09:47:29 +0000 (10:47 +0100)]     Fix lack of message pluralization
 
 
    Michael Paquier [Wed, 10 Feb 2021 07:59:04 +0000 (16:59 +0900)]     Fix ORDER BY clause in new regression test of REINDEX CONCURRENTLY
  Oversight in 
bd12080.  
Reported-by: Justin Pryzby Discussion: https://postgr.es/m/
20210210065805.GG20012@telsasoft.com
 Backpatch-through: 12  
  Michael Paquier [Wed, 10 Feb 2021 06:28:19 +0000 (15:28 +0900)]     Simplify code related to compilation of SSL and OpenSSL
  This commit makes more generic some comments and code related to the
 compilation with OpenSSL and SSL in general to ease the addition of more
 SSL implementations in the future.  In libpq, some OpenSSL-only code is
 moved under USE_OPENSSL and not USE_SSL. 
 While on it, make a comment more consistent in libpq-fe.h. 
 Author: Daniel Gustafsson
 Discussion: https://postgr.es/m/
5382CB4A-9CF3-4145-BA46-
C802615935E0@yesql.se  
  Michael Paquier [Wed, 10 Feb 2021 04:06:48 +0000 (13:06 +0900)]     Preserve pg_attribute.attstattarget across REINDEX CONCURRENTLY
  For an index, attstattarget can be updated using ALTER INDEX SET
 STATISTICS.  This data was lost on the new index after REINDEX
 CONCURRENTLY. 
 The update of this field is done when the old and new indexes are
 swapped to make the fix back-patchable.  Another approach we could look
 after in the long-term is to change index_create() to pass the wanted
 values of attstattarget when creating the new relation, but, as this
 would cause an ABI breakage this can be done only on HEAD.  
Reported-by: Ronan Dunklau Author: Michael Paquier 
Reviewed-by: Ronan Dunklau, Tomas Vondra Discussion: https://postgr.es/m/
16628084.uLZWGnKmhe@laptop-ronand
 Backpatch-through: 12  
  Amit Kapila [Wed, 10 Feb 2021 01:47:09 +0000 (07:17 +0530)]     Make pg_replication_origin_drop safe against concurrent drops.
 
 Currently, we get the origin id from the name and then drop the origin by
 taking ExclusiveLock on ReplicationOriginRelationId. So, two concurrent
 sessions can get the id from the name at the same time and then when they
 try to drop the origin, one of the sessions will get the either
 "tuple concurrently deleted" or "cache lookup failed for replication
 origin ..".
 
 To prevent this race condition we do the entire operation under lock. This
 obviates the need for replorigin_drop() API and we have removed it so if
 any extension authors are using it they need to instead use
 replorigin_drop_by_name. See it's usage in pg_replication_origin_drop().
 
 Author: Peter Smith
 Reviewed-by: Amit Kapila, Euler Taveira, Petr Jelinek, and Alvaro
 Herrera
 Discussion: https://www.postgresql.org/message-id/CAHut%2BPuW8DWV5fskkMWWMqzt-x7RPcNQOtJQBp6SdwyRghCk7A%40mail.gmail.com
 
 
    Peter Geoghegan [Tue, 9 Feb 2021 19:36:51 +0000 (11:36 -0800)]     Fix obsolete FSM remarks in nbtree README.
 
 The free space map has used a dedicated relation fork rather than shared
 memory segments for over a decade.
 
 
    Fujii Masao [Tue, 9 Feb 2021 09:30:40 +0000 (18:30 +0900)]     Revert "Display the time when the process started waiting for the lock, in pg_locks."
  This reverts commit 
3b733fcd04195399db56f73f0616b4f5c6828e18. 
 Per buildfarm members prion and rorqual.  
  Fujii Masao [Tue, 9 Feb 2021 09:10:19 +0000 (18:10 +0900)]     Display the time when the process started waiting for the lock, in pg_locks.
  This commit adds new column "waitstart" into pg_locks view. This column
 reports the time when the server process started waiting for the lock
 if the lock is not held. This information is useful, for example, when
 examining the amount of time to wait on a lock by subtracting
 "waitstart" in pg_locks from the current time, and identify the lock
 that the processes are waiting for very long. 
 This feature uses the current time obtained for the deadlock timeout
 timer as "waitstart" (i.e., the time when this process started waiting
 for the lock). Since getting the current time newly can cause overhead,
 we reuse the already-obtained time to avoid that overhead. 
 Note that "waitstart" is updated without holding the lock table's
 partition lock, to avoid the overhead by additional lock acquisition.
 This can cause "waitstart" in pg_locks to become NULL for a very short
 period of time after the wait started even though "granted" is false.
 This is OK in practice because we can assume that users are likely to
 look at "waitstart" when waiting for the lock for a long time. 
 Bump catalog version. 
 Author: Atsushi Torikoshi 
Reviewed-by: Ian Lawrence Barwick, Robert Haas, Justin Pryzby, Fujii Masao Discussion: https://postgr.es/m/
a96013dc51cdc56b2a2b84fa8a16a993@oss.nttdata.com  
  Michael Paquier [Tue, 9 Feb 2021 05:13:57 +0000 (14:13 +0900)]     Add option PROCESS_TOAST to VACUUM
  This option controls if toast tables associated with a relation are
 vacuumed or not when running a manual VACUUM.  It was already possible
 to trigger a manual VACUUM on a toast relation without processing its
 main relation, but a manual vacuum on a main relation always forced a
 vacuum on its toast table.  This is useful in scenarios where the level
 of bloat or transaction age of the main and toast relations differs a
 lot. 
 This option is an extension of the existing VACOPT_SKIPTOAST that was
 used by autovacuum to control if toast relations should be skipped or
 not.  This internal flag is renamed to VACOPT_PROCESS_TOAST for
 consistency with the new option. 
 A new option switch, called --no-process-toast, is added to vacuumdb. 
 Author: Nathan Bossart 
Reviewed-by: Kirk Jamison, Michael Paquier, Justin Pryzby Discussion: https://postgr.es/m/
BA8951E9-1524-48C5-94AF-
73B1F0D7857F@amazon.com  
  Peter Geoghegan [Mon, 8 Feb 2021 23:20:08 +0000 (15:20 -0800)]     Correct pgstattuple B-Tree page comments.
 
 
    Tom Lane [Mon, 8 Feb 2021 15:14:09 +0000 (10:14 -0500)]     Fix mishandling of column-level SELECT privileges for join aliases.
  scanNSItemForColumn, expandNSItemAttrs, and ExpandSingleTable would
 pass the wrong RTE to markVarForSelectPriv when dealing with a join
 ParseNamespaceItem: they'd pass the join RTE, when what we need to
 mark is the base table that the join column came from.  The end
 result was to not fill the base table's selectedCols bitmap correctly,
 resulting in an understatement of the set of columns that are read
 by the query.  The executor would still insist on there being at
 least one selectable column; but with a correctly crafted query,
 a user having SELECT privilege on just one column of a table would
 nonetheless be allowed to read all its columns. 
 To fix, make markRTEForSelectPriv fetch the correct RTE for itself,
 ignoring the possibly-mismatched RTE passed by the caller.  Later,
 we'll get rid of some now-unused RTE arguments, but that risks
 API breaks so we won't do it in released branches. 
 This problem was introduced by commit 
9ce77d75c, so back-patch
 to v13 where that came in.  Thanks to Sven Klemm for reporting
 the problem. 
 Security: CVE-2021-20229  
  Heikki Linnakangas [Mon, 8 Feb 2021 09:01:51 +0000 (11:01 +0200)]     Fix permission checks on constraint violation errors on partitions.
  If a cross-partition UPDATE violates a constraint on the target partition,
 and the columns in the new partition are in different physical order than
 in the parent, the error message can reveal columns that the user does not
 have SELECT permission on. A similar bug was fixed earlier in commit 
804b6b6db4. 
 The cause of the bug is that the callers of the
 ExecBuildSlotValueDescription() function got confused when constructing
 the list of modified columns. If the tuple was routed from a parent, we
 converted the tuple to the parent's format, but the list of modified
 columns was grabbed directly from the child's RTE entry. 
 ExecUpdateLockMode() had a similar issue. That lead to confusion on which
 columns are key columns, leading to wrong tuple lock being taken on tables
 referenced by foreign keys, when a row is updated with INSERT ON CONFLICT
 UPDATE. A new isolation test is added for that corner case. 
 With this patch, the ri_RangeTableIndex field is no longer set for
 partitions that don't have an entry in the range table. Previously, it was
 set to the RTE entry of the parent relation, but that was confusing. 
 NOTE: This modifies the ResultRelInfo struct, replacing the
 ri_PartitionRoot field with ri_RootResultRelInfo. That's a bit risky to
 backpatch, because it breaks any extensions accessing the field. The
 change that ri_RangeTableIndex is not set for partitions could potentially
 break extensions, too. The ResultRelInfos are visible to FDWs at least,
 and this patch required small changes to postgres_fdw. Nevertheless, this
 seem like the least bad option. I don't think these fields widely used in
 extensions; I don't think there are FDWs out there that uses the FDW
 "direct update" API, other than postgres_fdw. If there is, you will get a
 compilation error, so hopefully it is caught quickly. 
 Backpatch to 11, where support for both cross-partition UPDATEs, and unique
 indexes on partitioned tables, were added.  
Reviewed-by: Amit Langote Security: CVE-2021-3393  
  Peter Geoghegan [Sun, 7 Feb 2021 18:11:14 +0000 (10:11 -0800)]     Rename removable xid function for consistency.
  GlobalVisIsRemovableFullXid() is now GlobalVisCheckRemovableFullXid().
 This is consistent with the general convention for FullTransactionId
 equivalents of functions that deal with TransactionId values.  It now
 matches the nearby GlobalVisCheckRemovableXid() function, which performs
 the same check for callers that use TransactionId values. 
 Oversight in commit 
dc7420c2c92. 
 Discussion: https://postgr.es/m/CAH2-Wzmes12jFNDcVgpU89Vp=r6uLFrE-MT0fjSWGsE70UiNaA@mail.gmail.com  
  Tom Lane [Sun, 7 Feb 2021 17:54:08 +0000 (12:54 -0500)]     Revert "Propagate CTE property flags when copying a CTE list into a rule."
  This reverts commit 
ed290896335414c6c069b9ccae1f3dcdd2fac6ba and
 equivalent back-branch commits.  The issue is subtler than I thought,
 and it's far from new, so just before a release deadline is no time
 to be fooling with it.  We'll consider what to do at a bit more
 leisure. 
 Discussion: https://postgr.es/m/CAJcOf-fAdj=nDKMsRhQzndm-O13NY4dL6xGcEvdX5Xvbbi0V7g@mail.gmail.com  
  Tatsuo Ishii [Sun, 7 Feb 2021 04:43:50 +0000 (13:43 +0900)]     Docs: fix pg_wal_lsn_diff manual.
  The manual did not mention whether its return value is (first arg -
 second arg) or (second arg - first arg). The order matters because the
 return value could have a sign. Fix the manual so that it mentions the
 function returns (first arg - second arg). 
 Patch reviewed by Tom Lane. 
 Back-patch through v13. Older version's doc format is difficult to add
 more description.
 Discussion: https://postgr.es/m/flat/
20210206.151125.
960423226279810864.t-ishii%40sraoss.co.jp  
  Tom Lane [Sun, 7 Feb 2021 00:28:39 +0000 (19:28 -0500)]     Propagate CTE property flags when copying a CTE list into a rule.
 
 rewriteRuleAction() neglected this step, although it was careful to
 propagate other similar flags such as hasSubLinks or hasRowSecurity.
 Omitting to transfer hasRecursive is just cosmetic at the moment,
 but omitting hasModifyingCTE is a live bug, since the executor
 certainly looks at that.
 
 The proposed test case only fails back to v10, but since the executor
 examines hasModifyingCTE in 9.x as well, I suspect that a test case
 could be devised that fails in older branches.  Given the nearness
 of the release deadline, though, I'm not going to spend time looking
 for a better test.
 
 Report and patch by Greg Nancarrow, cosmetic changes by me
 
 Discussion: https://postgr.es/m/CAJcOf-fAdj=nDKMsRhQzndm-O13NY4dL6xGcEvdX5Xvbbi0V7g@mail.gmail.com
 
 
    Tom Lane [Sat, 6 Feb 2021 20:17:01 +0000 (15:17 -0500)]     Disallow converting an inheritance child table to a view.
  Generally, members of inheritance trees must be plain tables (or,
 in more recent versions, foreign tables).  ALTER TABLE INHERIT
 rejects creating an inheritance relationship that has a view at
 either end.  When DefineQueryRewrite attempts to convert a relation
 to a view, it already had checks prohibiting doing so for partitioning
 parents or children as well as traditional-inheritance parents ...
 but it neglected to check that a traditional-inheritance child wasn't
 being converted.  Since the planner assumes that any inheritance
 child is a table, this led to making plans that tried to do a physical
 scan on a view, causing failures (or even crashes, in recent versions). 
 One could imagine trying to support such a case by expanding the view
 normally, but since the rewriter runs before the planner does
 inheritance expansion, it would take some very fundamental refactoring
 to make that possible.  There are probably a lot of other parts of the
 system that don't cope well with such a situation, too.  For now,
 just forbid it. 
 Per bug #16856 from Yang Lin.  Back-patch to all supported branches.
 (In versions before v10, this includes back-patching the portion of
 commit 
501ed02cf that added has_superclass().  Perhaps the lack of
 that infrastructure partially explains the missing check.) 
 Discussion: https://postgr.es/m/16856-
0363e05c6e1612fd@postgresql.org  
  Michael Paquier [Sat, 6 Feb 2021 01:27:55 +0000 (10:27 +0900)]     Clarify some comments around SharedRecoveryState in xlog.c
  SharedRecoveryState has been switched from a boolean to an enum as of
 commit 
4e87c48, but some comments still referred to it as a boolean. 
 Author: Amul Sul 
Reviewed-by: Dilip Kumar, Kyotaro Horiguchi Discussion: https://postgr.es/m/CAAJ_b97Hf+1SXnm8jySpO+Fhm+-VKFAAce1T_cupUYtnE3Nxig  
  Robert Haas [Fri, 5 Feb 2021 21:08:45 +0000 (16:08 -0500)]     Generalize parallel slot result handling.
  Instead of having a hard-coded behavior that we ignore missing
 tables and report all other errors, let the caller decide what
 to do by setting a callback. 
 Mark Dilger, reviewed and somewhat revised by me. The larger patch
 series of which this is a part has also had review from Peter
 Geoghegan, Andres Freund, Álvaro Herrera, Michael Paquier, and Amul
 Sul, but I don't know whether any of them have reviewed this bit
 specifically. 
 Discussion: http://postgr.es/m/
12ED3DA8-25F0-4B68-937D-
D907CFBF08E7@enterprisedb.com
 Discussion: http://postgr.es/m/
5F743835-3399-419C-8324-
2D424237E999@enterprisedb.com
 Discussion: http://postgr.es/m/
70655DF3-33CE-4527-9A4D-
DDEB582B6BA0@enterprisedb.com  
  Robert Haas [Fri, 5 Feb 2021 18:33:38 +0000 (13:33 -0500)]     Move some code from src/bin/scripts to src/fe_utils to permit reuse.
  The parallel slots infrastructure (which implements client-side
 multiplexing of server connections doing similar things, not
 threading or multiple processes or anything like that) are moved from
 src/bin/scripts/scripts_parallel.c to src/fe_utils/parallel_slot.c. 
 The functions consumeQueryResult() and processQueryResult() which were
 previously part of src/bin/scripts/common.c are now moved into that
 file as well, becoming static helper functions. This might need to be
 changed in the future, but currently they're not used for anything
 else. 
 Some other functions from src/bin/scripts/common.c are moved to to
 src/fe_utils and are split up among several files.  connectDatabase(),
 connectMaintenanceDatabase(), and disconnectDatabase() are moved to
 connect_utils.c.  executeQuery(), executeCommand(), and
 executeMaintenanceCommand() are move to query_utils.c.
 handle_help_version_opts() is moved to option_utils.c. 
 Mark Dilger, reviewed by me. The larger patch series of which this is
 a part has also had review from Peter Geoghegan, Andres Freund, Álvaro
 Herrera, Michael Paquier, and Amul Sul, but I don't know whether any
 of them have reviewed this bit specifically. 
 Discussion: http://postgr.es/m/
12ED3DA8-25F0-4B68-937D-
D907CFBF08E7@enterprisedb.com
 Discussion: http://postgr.es/m/
5F743835-3399-419C-8324-
2D424237E999@enterprisedb.com
 Discussion: http://postgr.es/m/
70655DF3-33CE-4527-9A4D-
DDEB582B6BA0@enterprisedb.com  
  Heikki Linnakangas [Fri, 5 Feb 2021 09:14:56 +0000 (11:14 +0200)]     Fix backslash-escaping multibyte chars in COPY FROM.
  If a multi-byte character is escaped with a backslash in TEXT mode input,
 and the encoding is one of the client-only encodings where the bytes after
 the first one can have an ASCII byte "embedded" in the char, we didn't
 skip the character correctly. After a backslash, we only skipped the first
 byte of the next character, so if it was a multi-byte character, we would
 try to process its second byte as if it was a separate character. If it
 was one of the characters with special meaning, like '\n', '\r', or
 another '\\', that would cause trouble. 
 One such exmple is the byte sequence '\x5ca45c2e666f6f' in Big5 encoding.
 That's supposed to be [backslash][two-byte character][.][f][o][o], but
 because the second byte of the two-byte character is 0x5c, we incorrectly
 treat it as another backslash. And because the next character is a dot, we
 parse it as end-of-copy marker, and throw an "end-of-copy marker corrupt"
 error. 
 Backpatch to all supported versions.  
Reviewed-by: John Naylor, Kyotaro Horiguchi Discussion: https://www.postgresql.org/message-id/
a897f84f-8dca-8798-3139-
07da5bb38728%40iki.fi  
  Etsuro Fujita [Fri, 5 Feb 2021 06:30:00 +0000 (15:30 +0900)]     postgres_fdw: Fix assertion in estimate_path_cost_size().
  Commit 
08d2d58a2 added an assertion assuming that the retrieved_rows
 estimate for a foreign relation, which is re-used to cost pre-sorted
 foreign paths with local stats, is set to at least one row in
 estimate_path_cost_size(), which isn't correct because if the relation
 is a foreign table with tuples=0, the estimate would be set to 0 there
 when not using remote estimates. 
 Per bug #16807 from Alexander Lakhin.  Back-patch to v13 where the
 aforementioned commit went in. 
 Author: Etsuro Fujita 
Reviewed-by: Kyotaro Horiguchi Discussion: https://postgr.es/m/16807-
9fe4e08fbaa5c7ce%40postgresql.org  
  Tom Lane [Fri, 5 Feb 2021 04:01:33 +0000 (23:01 -0500)]     Fix bug in HashAgg's selective-column-spilling logic.
  Commit 
230230223 taught nodeAgg.c that, when spilling tuples from
 memory in an oversized hash aggregation, it only needed to spill
 input columns referenced in the node's tlist and quals.  Unfortunately,
 that's wrong: we also have to save the grouping columns.  The error
 is masked in common cases because the grouping columns also appear
 in the tlist, but that's not necessarily true.  The main category
 of plans where it's not true seem to come from semijoins ("WHERE
 outercol IN (SELECT innercol FROM innertable)") where the innercol
 needs an implicit promotion to make it comparable to the outercol.
 The grouping column will be "innercol::promotedtype", but that
 expression appears nowhere in the Agg node's own tlist and quals;
 only the bare "innercol" is found in the tlist. 
 I spent quite a bit of time looking for a suitable regression test
 case for this, without much success.  If the number of distinct
 values of the innercol is large enough to make spilling happen,
 the planner tends to prefer a non-HashAgg plan, at least for
 problem sizes that are reasonable to use in the regression tests.
 So, no new regression test.  However, this patch does demonstrably
 fix the originally-reported test case. 
 Per report from s.p.e (at) gmx-topmail.de.  Backpatch to v13
 where the troublesome code came in. 
 Discussion: https://postgr.es/m/trinity-
1c565d44-159f-488b-a518-
caf13883134f-
1611835701633@3c-app-gmx-bap78  
  Thomas Munro [Fri, 5 Feb 2021 02:30:56 +0000 (15:30 +1300)]     Tab-complete CREATE DATABASE ... LOCALE.
 
 Author: Ian Lawrence Barwick <barwick@gmail.com>
 Discussion: https://postgr.es/m/CAB8KJ%3Dh0XO2CB4QbLBc1Tm9Bg5wzSGQtT-eunaCmrghJp4nqdA%40mail.gmail.com
 
 
    Tom Lane [Fri, 5 Feb 2021 00:12:09 +0000 (19:12 -0500)]     Fix YA incremental sort bug.
  switchToPresortedPrefixMode() did the wrong thing if it detected
 a batch boundary just at the last tuple of a fullsort group. 
 The initially-reported symptom was a "retrieved too many tuples in a
 bounded sort" error, but the test case added here just silently gives
 the wrong answer without this patch. 
 I (tgl) am not really happy about committing this patch without review
 from the incremental-sort authors, but they seem AWOL and we are hard
 against a release deadline.  This does demonstrably make some cases
 better, anyway. 
 Per bug #16846 from Yoran Heling.  Back-patch to v13 where incremental
 sort was introduced. 
 Neil Chen 
 Discussion: https://postgr.es/m/16846-
ae49f51ac379a4cb@postgresql.org  
  Peter Geoghegan [Thu, 4 Feb 2021 23:42:36 +0000 (15:42 -0800)]     Harden nbtree page deletion.
  Add some additional defensive checks in the second phase of index
 deletion to detect and report index corruption during VACUUM, and to
 avoid having VACUUM become stuck in more cases.  The code is still not
 robust in the presence of a circular chain of sibling links, though it's
 not clear whether that really matters.  This is follow-up work to commit 
3a01f68e. 
 The new defensive checks rely on the assumption that there can be no
 more than one VACUUM operation running for an index at any given time.
 Remove an old comment suggesting that multiple concurrent VACUUMs need
 to be considered here.  This concern now seems highly unlikely to have
 any real validity, since we clearly rely on the same assumption in
 several other places.  For example, there are much more recent comments
 that appear in the same function (added by commit 
efada2b8e92) that make
 the same assumption. 
 Also add a CHECK_FOR_INTERRUPTS() to the relevant code path.  Contrary
 to comments added by commit 
3a01f68e, it is actually possible to handle
 interrupts here, at least in the common case where processing takes
 place at the leaf level.  We only hold a pin on leafbuf/target page when
 stepping right at the leaf level. 
 No backpatch due to the lack of complaints following hardening added to
 the same area by commit 
3a01f68e.  
  Heikki Linnakangas [Thu, 4 Feb 2021 15:40:33 +0000 (17:40 +0200)]     Fix small error in COPY FROM progress reporting.
 
 The # of bytes processed was accumulated slightly incorrectly. After
 loading more data to the input buffer, we added the number of bytes in
 the buffer to the sum. But in case of multi-byte characters or escapes,
 there can be a few unprocessed bytes left over from previous load in the
 buffer. Those bytes got counted twice.
 
 
    Peter Eisentraut [Thu, 4 Feb 2021 12:31:13 +0000 (13:31 +0100)]     Refactor Windows error message for easier translation
 
 In the error messages referring to the user right "Lock pages in
 memory", this is a term from the Windows OS, so it should be
 translated in accordance with the OS localization.  Refactor the error
 messages so this is easier and clearer.  Also fix the capitalization
 to match the existing capitalization in the OS.
 
 
    Michael Paquier [Thu, 4 Feb 2021 08:16:47 +0000 (17:16 +0900)]     Ensure unlinking of old index file with REINDEX (TABLESPACE)
  The original versions of the patch included this part, but a mismerge
 from my side has made this piece go missing.  Oversight in 
c5b28604.  
  Michael Paquier [Thu, 4 Feb 2021 07:02:31 +0000 (16:02 +0900)]     Clarify comment in tablesync.c
 
 Author: Peter Smith
 Reviewed-by: Amit Kapila, Michael Paquier, Euler Taveira
 Discussion: https://postgr.es/m/CAHut+Pt9_T6pWar0FLtPsygNmme8HPWPdGUyZ_8mE1Yvjdf0ZA@mail.gmail.com
 
 
    Michael Paquier [Thu, 4 Feb 2021 05:34:20 +0000 (14:34 +0900)]     Add TABLESPACE option to REINDEX
  This patch adds the possibility to move indexes to a new tablespace
 while rebuilding them.  Both the concurrent and the non-concurrent cases
 are supported, and the following set of restrictions apply:
 - When using TABLESPACE with a REINDEX command that targets a
 partitioned table or index, all the indexes of the leaf partitions are
 moved to the new tablespace.  The tablespace references of the non-leaf,
 partitioned tables in pg_class.reltablespace are not changed. This
 requires an extra ALTER TABLE SET TABLESPACE.
 - Any index on a toast table rebuilt as part of a parent table is kept
 in its original tablespace.
 - The operation is forbidden on system catalogs, including trying to
 directly move a toast relation with REINDEX.  This results in an error
 if doing REINDEX on a single object.  REINDEX SCHEMA, DATABASE and
 SYSTEM skip system relations when TABLESPACE is used. 
 Author: Alexey Kondratov, Michael Paquier, Justin Pryzby 
Reviewed-by: Álvaro Herrera, Michael Paquier Discussion: https://postgr.es/m/
8a8f5f73-00d3-55f8-7583-
1375ca8f6a91@postgrespro.ru  
  Tom Lane [Thu, 4 Feb 2021 00:38:29 +0000 (19:38 -0500)]     Avoid crash when rolling back within a prepared statement.
  If a portal is used to run a prepared CALL or DO statement that
 contains a ROLLBACK, PortalRunMulti fails because the portal's
 statement list gets cleared by the rollback.  (Since the grammar
 doesn't allow CALL/DO in PREPARE, the only easy way to get to this is
 via extended query protocol, which treats all inputs as prepared
 statements.)  It's difficult to avoid resetting the portal early
 because of resource-management issues, so work around this by teaching
 PortalRunMulti to be wary of portal->stmts having suddenly become NIL. 
 The crash has only been seen to occur in v13 and HEAD (as a
 consequence of commit 
1cff1b95a having added an extra touch of
 portal->stmts).  But even before that, the code involved touching a
 List that the portal no longer has any claim on.  In the test case at
 hand, the List will still exist because of another refcount on the
 cached plan; but I'm far from convinced that it's impossible for the
 cached plan to have been dropped by the time control gets back to
 PortalRunMulti.  Hence, backpatch to v11 where nested transactions
 were added. 
 Thomas Munro and Tom Lane, per bug #16811 from James Inform 
 Discussion: https://postgr.es/m/16811-
c1b599b2c6c2d622@postgresql.org  
  Robert Haas [Wed, 3 Feb 2021 18:19:41 +0000 (13:19 -0500)]     Factor pattern-construction logic out of processSQLNamePattern.
  The logic for converting the shell-glob-like syntax supported by
 utilities like psql and pg_dump to regular expression is
 extracted into a new function patternToSQLRegex. The existing
 function processSQLNamePattern now uses this function as a
 subroutine. 
 patternToSQLRegex is a little more general than what is required
 by processSQLNamePattern. That function is only interested in
 patterns that can have up to 2 parts, a schema and a relation;
 but patternToSQLRegex can limit the maximum number of parts to
 between 1 and 3, so that patterns can look like either
 "database.schema.relation", "schema.relation", or "relation"
 depending on how it's invoked and what the user specifies. 
 processSQLNamePattern only passes two buffers, so works exactly
 the same as before, always interpreting the pattern as either
 a "schema.relation" pattern or a "relation" pattern. But,
 future callers can use this function in other ways. 
 Mark Dilger, reviewed by me. The larger patch series of which this is
 a part has also had review from Peter Geoghegan, Andres Freund, Álvaro
 Herrera, Michael Paquier, and Amul Sul, but I don't know whether
 any of them have reviewed this bit specifically. 
 Discussion: http://postgr.es/m/
12ED3DA8-25F0-4B68-937D-
D907CFBF08E7@enterprisedb.com
 Discussion: http://postgr.es/m/
5F743835-3399-419C-8324-
2D424237E999@enterprisedb.com
 Discussion: http://postgr.es/m/
70655DF3-33CE-4527-9A4D-
DDEB582B6BA0@enterprisedb.com  
  Tom Lane [Wed, 3 Feb 2021 17:01:48 +0000 (12:01 -0500)]     Remove special BKI_LOOKUP magic for namespace and role OIDs.
  Now that commit 
62f34097c attached BKI_LOOKUP annotation to all the
 namespace and role OID columns in the catalogs, there's no real reason
 to have the magic PGNSP and PGUID symbols.  Get rid of them in favor
 of implementing those lookups according to genbki.pl's normal pattern. 
 This means that in the catalog headers, BKI_DEFAULT(PGNSP) becomes
 BKI_DEFAULT(pg_catalog), which seems a lot more transparent.
 BKI_DEFAULT(PGUID) becomes BKI_DEFAULT(POSTGRES), which is perhaps
 less so; but you can look into pg_authid.dat to discover that
 POSTGRES is the nonce name for the bootstrap superuser. 
 This change also means that if we ever need cross-references in the
 initial catalog data to any of the other built-in roles besides
 POSTGRES, or to some other built-in schema besides pg_catalog,
 we can just do it. 
 No catversion bump here, as there's no actual change in the contents
 of postgres.bki. 
 Discussion: https://postgr.es/m/
3240355.
1612129197@sss.pgh.pa.us  
  Peter Eisentraut [Wed, 3 Feb 2021 10:27:13 +0000 (11:27 +0100)]     pg_dump: Fix dumping of inherited generated columns
  Generation expressions of generated columns are always inherited, so
 there is no need to set them separately in child tables, and there is
 no syntax to do so either.  The code previously used the code paths
 for the handling of default values, for which different rules apply;
 in particular it might want to set a default value explicitly for an
 inherited column.  This resulted in unrestorable dumps.  For generated
 columns, just skip them in inherited tables.  
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/15830.
1575468847%40sss.pgh.pa.us  
  Tom Lane [Tue, 2 Feb 2021 22:21:37 +0000 (17:21 -0500)]     Retire findoidjoins.
  In the wake of commit 
62f34097c, we no longer need this tool. 
 Discussion: https://postgr.es/m/
3240355.
1612129197@sss.pgh.pa.us  
  Tom Lane [Tue, 2 Feb 2021 22:11:55 +0000 (17:11 -0500)]     Build in some knowledge about foreign-key relationships in the catalogs.
  This follows in the spirit of commit 
dfb75e478, which created primary
 key and uniqueness constraints to improve the visibility of constraints
 imposed on the system catalogs.  While our catalogs contain many
 foreign-key-like relationships, they don't quite follow SQL semantics,
 in that the convention for an omitted reference is to write zero not
 NULL.  Plus, we have some cases in which there are arrays each of whose
 elements is supposed to be an FK reference; SQL has no way to model that.
 So we can't create actual foreign key constraints to describe the
 situation.  Nonetheless, we can collect and use knowledge about these
 relationships. 
 This patch therefore adds annotations to the catalog header files to
 declare foreign-key relationships.  (The BKI_LOOKUP annotations cover
 simple cases, but we weren't previously distinguishing which such
 columns are allowed to contain zeroes; we also need new markings for
 multi-column FK references.)  Then, Catalog.pm and genbki.pl are
 taught to collect this information into a table in a new generated
 header "system_fk_info.h".  The only user of that at the moment is
 a new SQL function pg_get_catalog_foreign_keys(), which exposes the
 table to SQL.  The oidjoins regression test is rewritten to use
 pg_get_catalog_foreign_keys() to find out which columns to check.
 Aside from removing the need for manual maintenance of that test
 script, this allows it to cover numerous relationships that were not
 checked by the old implementation based on findoidjoins.  (As of this
 commit, 217 relationships are checked by the test, versus 181 before.) 
 Discussion: https://postgr.es/m/
3240355.
1612129197@sss.pgh.pa.us  
  Tom Lane [Tue, 2 Feb 2021 21:15:29 +0000 (16:15 -0500)]     Doc: consistently identify OID catalog columns that can be zero.
  Not all OID-reference columns that can contain zeroes (indicating
 "no reference") were explicitly marked in catalogs.sgml.  Fix that,
 and try to make the style a little more consistent while at it ---
 for example, consistently write "zero" not "0" for these cases. 
 Joel Jacobson and Tom Lane 
 Discussion: https://postgr.es/m/
4ed9a372-7bf9-479a-926c-
ae8e774717a8@www.fastmail.com  
  Tom Lane [Tue, 2 Feb 2021 19:35:12 +0000 (14:35 -0500)]     Remove extra increment of plpgsql's statement counter for FOR loops.
  This left gaps in the internal statement numbering, which is not
 terribly harmful (else we'd have noticed sooner), but it's not
 great either. 
 Oversight in 
bbd5c207b; backpatch to v12 where that came in. 
 Pavel Stehule 
 Discussion: https://postgr.es/m/CAFj8pRDXyQaJmpotNTQVc-t-WxdWZC35V2PnmwOaV1-taidFWA@mail.gmail.com  
  Tom Lane [Tue, 2 Feb 2021 18:49:08 +0000 (13:49 -0500)]     Fix ancient memory leak in contrib/auto_explain.
 
 The ExecutorEnd hook is invoked in a context that could be quite
 long-lived, not the executor's own per-query context as I think
 we were sort of assuming.  Thus, any cruft generated while producing
 the EXPLAIN output could accumulate over multiple queries.  This can
 result in spectacular leakage if log_nested_statements is on, and
 even without that I'm surprised nobody complained before.
 
 To fix, just switch into the executor's context so that anything we
 allocate will be released when standard_ExecutorEnd frees the executor
 state.  We might as well nuke the code's retail pfree of the explain
 output string, too; that's laughably inadequate to the need.
 
 Japin Li, per report from Jeff Janes.  This bug is old, so
 back-patch to all supported branches.
 
 Discussion: https://postgr.es/m/CAMkU=1wCVtbeRn0s9gt12KwQ7PLXovbpM8eg25SYocKW3BT4hg@mail.gmail.com
 
 
    Peter Eisentraut [Tue, 2 Feb 2021 08:20:22 +0000 (09:20 +0100)]     Improve confusing variable names
 
 The prototype calls the second argument of
 pgstat_progress_update_multi_param() "index", and some callers name
 their local variable that way.  But when the surrounding code deals
 with index relations, this is confusing, and in at least one case
 shadowed another variable that is referring to an index relation.
 Adjust those call sites to have clearer local variable naming, similar
 to existing callers in indexcmds.c.
 
 
    Michael Paquier [Tue, 2 Feb 2021 04:59:23 +0000 (13:59 +0900)]     Remove unused column atttypmod from initial tablesync query
  The initial tablesync done by logical replication used a query to fetch
 the information of a relation's columns that included atttypmod, but it
 was left unused.  This was added by 
7c4f524. 
 Author: Euler Taveira 
Reviewed-by: Önder Kalacı, Amit Langote, Japin Li Discussion: https://postgr.es/m/CAHE3wggb715X+mK_DitLXF25B=jE6xyNCH4YOwM860JR7HarGQ@mail.gmail.com  
  Tom Lane [Mon, 1 Feb 2021 21:38:52 +0000 (16:38 -0500)]     Doc: work a little harder on the initial examples for regex matching.
  Writing unnecessary '.*' at start and end of a POSIX regex doesn't
 do much except confuse the reader about whether that might be
 necessary after all.  Make the examples in table 9.16 a tad more
 realistic, and try to turn the next group of examples into something
 self-contained. 
 Per gripe from rmzgrimes.  Back-patch to v13 because it's easy. 
 Discussion: https://postgr.es/m/
161215841824.14653.
8969016349304314299@wrigleys.postgresql.org  
  Tom Lane [Mon, 1 Feb 2021 19:43:54 +0000 (14:43 -0500)]     Remove [Merge]AppendPath.partitioned_rels.
  It turns out that the calculation of [Merge]AppendPath.partitioned_rels
 in allpaths.c is faulty and sometimes omits relevant non-leaf partitions,
 allowing an assertion added by commit 
a929e17e5a8 to trigger.  Rather
 than fix that, it seems better to get rid of those fields altogether.
 We don't really need the info until create_plan time, and calculating
 it once for the selected plan should be cheaper than calculating it
 for each append path we consider. 
 The preceding two commits did away with all use of the partitioned_rels
 values; this commit just mechanically removes the fields and the code
 that calculated them. 
 Discussion: https://postgr.es/m/87sg8tqhsl.fsf@aurora.ydns.eu
 Discussion: https://postgr.es/m/CAJKUy5gCXDSmFs2c=R+VGgn7FiYcLCsEFEuDNNLGfoha=pBE_g@mail.gmail.com  
  Tom Lane [Mon, 1 Feb 2021 19:34:59 +0000 (14:34 -0500)]     Remove incidental dependencies on partitioned_rels lists.
  It turns out that the calculation of [Merge]AppendPath.partitioned_rels
 in allpaths.c is faulty and sometimes omits relevant non-leaf partitions,
 allowing an assertion added by commit 
a929e17e5a8 to trigger.  Rather
 than fix that, it seems better to get rid of those fields altogether.
 We don't really need the info until create_plan time, and calculating
 it once for the selected plan should be cheaper than calculating it
 for each append path we consider. 
 This patch undoes a couple of very minor uses of the partitioned_rels
 values. 
 createplan.c was testing for nil-ness to optimize away the preparatory
 work for make_partition_pruneinfo().  That is worth doing if the check
 is nigh free, but it's not worth going to any great lengths to avoid. 
 create_append_path() was testing for nil-ness as part of deciding how
 to set up ParamPathInfo for an AppendPath.  I replaced that with a
 check for the appendrel's parent rel being partitioned.  That's not
 quite the same thing but should cover most cases.  If we note any
 interesting loss of optimizations, we can dumb this down to just
 always use the more expensive method when the parent is a baserel. 
 Discussion: https://postgr.es/m/87sg8tqhsl.fsf@aurora.ydns.eu
 Discussion: https://postgr.es/m/CAJKUy5gCXDSmFs2c=R+VGgn7FiYcLCsEFEuDNNLGfoha=pBE_g@mail.gmail.com  
  Tom Lane [Mon, 1 Feb 2021 19:05:51 +0000 (14:05 -0500)]     Revise make_partition_pruneinfo to not use its partitioned_rels input.
  It turns out that the calculation of [Merge]AppendPath.partitioned_rels
 in allpaths.c is faulty and sometimes omits relevant non-leaf partitions,
 allowing an assertion added by commit 
a929e17e5a8 to trigger.  Rather
 than fix that, it seems better to get rid of those fields altogether.
 We don't really need the info until create_plan time, and calculating
 it once for the selected plan should be cheaper than calculating it
 for each append path we consider. 
 As a first step, teach make_partition_pruneinfo to collect the relevant
 partitioned tables for itself.  It's not hard to do so by traversing
 from child tables up to parents using the AppendRelInfo links. 
 While here, make some minor stylistic improvements; mainly, don't use
 the "Relids" alias for bitmapsets that are not identities of any
 relation considered by the planner.  Try to document the logic better,
 too. 
 No backpatch, as there does not seem to be a live problem before 
a929e17e5a8.  Also no new regression test; the code where the bug
 was will be gone at the end of this patch series, so it seems a
 bit pointless to memorialize the issue. 
 Tom Lane and David Rowley, per reports from Andreas Seltenreich
 and Jaime Casanova. 
 Discussion: https://postgr.es/m/87sg8tqhsl.fsf@aurora.ydns.eu
 Discussion: https://postgr.es/m/CAJKUy5gCXDSmFs2c=R+VGgn7FiYcLCsEFEuDNNLGfoha=pBE_g@mail.gmail.com  
  Peter Eisentraut [Mon, 1 Feb 2021 12:54:59 +0000 (13:54 +0100)]     SEARCH and CYCLE clauses
  This adds the SQL standard feature that adds the SEARCH and CYCLE
 clauses to recursive queries to be able to do produce breadth- or
 depth-first search orders and detect cycles.  These clauses can be
 rewritten into queries using existing syntax, and that is what this
 patch does in the rewriter.  
Reviewed-by: Vik Fearing <vik@postgresfriends.org> Reviewed-by: Pavel Stehule <pavel.stehule@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/
db80ceee-6f97-9b4a-8ee8-
3ba0c58e5be2@2ndquadrant.com  
  Alexander Korotkov [Mon, 1 Feb 2021 11:06:02 +0000 (14:06 +0300)]     Get rid of unnecessary memory allocation in jsonb_subscript_assign()
 
 Current code allocates memory for JsonbValue, but it could be placed locally.
 
 
    Michael Paquier [Mon, 1 Feb 2021 10:19:44 +0000 (19:19 +0900)]     Introduce --with-ssl={openssl} as a configure option
  This is a replacement for the existing --with-openssl, extending the
 logic to make easier the addition of new SSL libraries.  The grammar is
 chosen to be similar to --with-uuid, where multiple values can be
 chosen, with "openssl" as the only supported value for now. 
 The original switch, --with-openssl, is kept for compatibility. 
 Author: Daniel Gustafsson, Michael Paquier 
Reviewed-by: Jacob Champion Discussion: https://postgr.es/m/
FAB21FC8-0F62-434F-AA78-
6BD9336D630A@yesql.se  
  Tom Lane [Mon, 1 Feb 2021 07:03:59 +0000 (02:03 -0500)]     Fix portability issue in new jsonbsubs code.
 
 On machines where sizeof(Datum) > sizeof(Oid) (that is, any 64-bit
 platform), the previous coding would compute a misaligned
 workspace->index pointer if nupper is odd.  Architectures where
 misaligned access is a hard no-no would then fail.  This appears
 to explain why thorntail is unhappy but other buildfarm members
 are not.