]> granicus.if.org Git - postgresql/log
postgresql
7 years agoRestore test case from a2b70c89ca1a5fcf6181d3c777d82e7b83d2de1b.
Tom Lane [Wed, 30 Aug 2017 13:59:23 +0000 (09:59 -0400)]
Restore test case from a2b70c89ca1a5fcf6181d3c777d82e7b83d2de1b.

Revert the reversion commits a20aac890 and 9b644745c.  In the wake of
commit 7df2c1f8d, we should get stable buildfarm results from this test;
if not, I'd like to know sooner not later.

Discussion: https://postgr.es/m/CAA4eK1JkByysFJNh9M349u_nNjqETuEnY_y1VUc_kJiU0bxtaQ@mail.gmail.com

7 years agoForce rescanning of parallel-aware scan nodes below a Gather[Merge].
Tom Lane [Wed, 30 Aug 2017 13:29:55 +0000 (09:29 -0400)]
Force rescanning of parallel-aware scan nodes below a Gather[Merge].

The ExecReScan machinery contains various optimizations for postponing
or skipping rescans of plan subtrees; for example a HashAgg node may
conclude that it can re-use the table it built before, instead of
re-reading its input subtree.  But that is wrong if the input contains
a parallel-aware table scan node, since the portion of the table scanned
by the leader process is likely to vary from one rescan to the next.
This explains the timing-dependent buildfarm failures we saw after
commit a2b70c89c.

The established mechanism for showing that a plan node's output is
potentially variable is to mark it as depending on some runtime Param.
Hence, to fix this, invent a dummy Param (one that has a PARAM_EXEC
parameter number, but carries no actual value) associated with each Gather
or GatherMerge node, mark parallel-aware nodes below that node as dependent
on that Param, and arrange for ExecReScanGather[Merge] to flag that Param
as changed whenever the Gather[Merge] node is rescanned.

This solution breaks an undocumented assumption made by the parallel
executor logic, namely that all rescans of nodes below a Gather[Merge]
will happen synchronously during the ReScan of the top node itself.
But that's fundamentally contrary to the design of the ExecReScan code,
and so was doomed to fail someday anyway (even if you want to argue
that the bug being fixed here wasn't a failure of that assumption).
A follow-on patch will address that issue.  In the meantime, the worst
that's expected to happen is that given very bad timing luck, the leader
might have to do all the work during a rescan, because workers think
they have nothing to do, if they are able to start up before the eventual
ReScan of the leader's parallel-aware table scan node has reset the
shared scan state.

Although this problem exists in 9.6, there does not seem to be any way
for it to manifest there.  Without GatherMerge, it seems that a plan tree
that has a rescan-short-circuiting node below Gather will always also
have one above it that will short-circuit in the same cases, preventing
the Gather from being rescanned.  Hence we won't take the risk of
back-patching this change into 9.6.  But v10 needs it.

Discussion: https://postgr.es/m/CAA4eK1JkByysFJNh9M349u_nNjqETuEnY_y1VUc_kJiU0bxtaQ@mail.gmail.com

7 years agodoc: Avoid sidebar element
Peter Eisentraut [Tue, 29 Aug 2017 23:33:24 +0000 (19:33 -0400)]
doc: Avoid sidebar element

The formatting of the sidebar element didn't carry over to the new tool
chain.  Instead of inventing a whole new way of dealing with it, just
convert the one use to a "note".

7 years agoDoc: document libpq's restriction to INT_MAX rows in a PGresult.
Tom Lane [Tue, 29 Aug 2017 19:38:05 +0000 (15:38 -0400)]
Doc: document libpq's restriction to INT_MAX rows in a PGresult.

As long as PQntuples, PQgetvalue, etc, use "int" for row numbers, we're
pretty much stuck with this limitation.  The documentation formerly stated
that the result of PQntuples "might overflow on 32-bit operating systems",
which is just nonsense: that's not where the overflow would happen, and
if you did reach an overflow it would not be on a 32-bit machine, because
you'd have OOM'd long since.

Discussion: https://postgr.es/m/CA+FnnTxyLWyjY1goewmJNxC==HQCCF4fKkoCTa9qR36oRAHDPw@mail.gmail.com

7 years agoTeach libpq to detect integer overflow in the row count of a PGresult.
Tom Lane [Tue, 29 Aug 2017 19:18:01 +0000 (15:18 -0400)]
Teach libpq to detect integer overflow in the row count of a PGresult.

Adding more than 1 billion rows to a PGresult would overflow its ntups and
tupArrSize fields, leading to client crashes.  It'd be desirable to use
wider fields on 64-bit machines, but because all of libpq's external APIs
use plain "int" for row counters, that's going to be hard to accomplish
without an ABI break.  Given the lack of complaints so far, and the general
pain that would be involved in using such huge PGresults, let's settle for
just preventing the overflow and reporting a useful error message if it
does happen.  Also, for a couple more lines of code we can increase the
threshold of trouble from INT_MAX/2 to INT_MAX rows.

To do that, refactor pqAddTuple() to allow returning an error message that
replaces the default assumption that it failed because of out-of-memory.

Along the way, fix PQsetvalue() so that it reports all failures via
pqInternalNotice().  It already did so in the case of bad field number,
but neglected to report anything for other error causes.

Because of the potential for crashes, this seems like a back-patchable
bug fix, despite the lack of field reports.

Michael Paquier, per a complaint from Igor Korot.

Discussion: https://postgr.es/m/CA+FnnTxyLWyjY1goewmJNxC==HQCCF4fKkoCTa9qR36oRAHDPw@mail.gmail.com

7 years agoPropagate sort instrumentation from workers back to leader.
Robert Haas [Tue, 29 Aug 2017 17:22:49 +0000 (13:22 -0400)]
Propagate sort instrumentation from workers back to leader.

Up until now, when parallel query was used, no details about the
sort method or space used by the workers were available; details
were shown only for any sorting done by the leader.  Fix that.

Commit 1177ab1dabf72bafee8f19d904cee3a299f25892 forced the test case
added by commit 1f6d515a67ec98194c23a5db25660856c9aab944 to run
without parallelism; now that we have this infrastructure, allow
that again, with a little tweaking to make it pass with and without
force_parallel_mode.

Robert Haas and Tom Lane

Discussion: http://postgr.es/m/CA+Tgmoa2VBZW6S8AAXfhpHczb=Rf6RqQ2br+zJvEgwJ0uoD_tQ@mail.gmail.com

7 years agoPush tuple limits through Gather and Gather Merge.
Robert Haas [Tue, 29 Aug 2017 17:12:23 +0000 (13:12 -0400)]
Push tuple limits through Gather and Gather Merge.

If we only need, say, 10 tuples in total, then we certainly don't need
more than 10 tuples from any single process.  Pushing down the limit
lets workers exit early when possible.  For Gather Merge, there is
an additional benefit: a Sort immediately below the Gather Merge can
be done as a bounded sort if there is an applicable limit.

Robert Haas and Tom Lane

Discussion: http://postgr.es/m/CA+TgmoYa3QKKrLj5rX7UvGqhH73G1Li4B-EKxrmASaca2tFu9Q@mail.gmail.com

7 years agoImprove docs about numeric formatting patterns (to_char/to_number).
Tom Lane [Tue, 29 Aug 2017 13:34:21 +0000 (09:34 -0400)]
Improve docs about numeric formatting patterns (to_char/to_number).

The explanation about "0" versus "9" format characters was confusing
and arguably wrong; the discussion of sign handling wasn't very good
either.  Notably, while it's accurate to say that "FM" strips leading
zeroes in date/time values, what it really does with numeric values
is to strip *trailing* zeroes, and then only if you wrote "9" rather
than "0".  Per gripes from Erwin Brandstetter.

Discussion: https://postgr.es/m/CAGHENJ7jgRbTn6nf48xNZ=FHgL2WQ4X8mYsUAU57f-vq8PubEw@mail.gmail.com
Discussion: https://postgr.es/m/CAGHENJ45ymd=GOCu1vwV9u7GmCR80_5tW0fP9C_gJKbruGMHvQ@mail.gmail.com

7 years agoDoc: adjust release-note credit for parallel pg_restore fix.
Tom Lane [Mon, 28 Aug 2017 15:40:47 +0000 (11:40 -0400)]
Doc: adjust release-note credit for parallel pg_restore fix.

Discussion: https://postgr.es/m/CAFcNs+pJ6_Ud-zg3vY_Y0mzfESdM34Humt8avKrAKq_H+v18Cg@mail.gmail.com

7 years agoFix over-aggressive sanity check in misc_sanity.sql.
Tom Lane [Mon, 28 Aug 2017 14:14:20 +0000 (10:14 -0400)]
Fix over-aggressive sanity check in misc_sanity.sql.

Fix thinko in commit 8be8510cf: it's okay to have dbid == 0 in normal
(non-pin) entries in pg_shdepend, because global objects such as
databases are entered that way.  The test would pass so long as it
was run in a cluster containing no databases/tablespaces owned by,
or granted to, roles other than the bootstrap superuser.  That's the
expected situation for "make check", but for "make installcheck", not
so much.

Reported by Ryan Murphy.

Discussion: https://postgr.es/m/CAHeEsBc6EQe0mxGBKDXAwJbntgfvoAd5MQC-5362SmC3Tng_6g@mail.gmail.com

7 years agoClarify documentation
Peter Eisentraut [Mon, 28 Aug 2017 01:29:54 +0000 (21:29 -0400)]
Clarify documentation

Discussion: https://www.postgresql.org/message-id/flat/20170618071607.GA16418%40nol.local

7 years agoRelease notes for 9.6.5, 9.5.9, 9.4.14, 9.3.19, 9.2.23.
Tom Lane [Sun, 27 Aug 2017 21:35:04 +0000 (17:35 -0400)]
Release notes for 9.6.5, 9.5.9, 9.4.14, 9.3.19, 9.2.23.

7 years agoDoc: update v10 release notes through today.
Tom Lane [Sat, 26 Aug 2017 20:50:19 +0000 (16:50 -0400)]
Doc: update v10 release notes through today.

7 years agoFirst-draft release notes for 9.6.5.
Tom Lane [Sat, 26 Aug 2017 19:19:24 +0000 (15:19 -0400)]
First-draft release notes for 9.6.5.

As usual, the release notes for other branches will be made by cutting
these down, but put them up for community review first.  Note the first
entry is only for 9.4.

7 years agoChanged order of statements and added an additiona MSVC safeguard to make ecpg
Michael Meskes [Sat, 26 Aug 2017 17:07:25 +0000 (19:07 +0200)]
Changed order of statements and added an additiona MSVC safeguard to make ecpg
thread test cases work on Windows.

7 years agopg_test_timing: Some NLS fixes
Peter Eisentraut [Sat, 26 Aug 2017 13:21:46 +0000 (09:21 -0400)]
pg_test_timing: Some NLS fixes

The string "% of total" was marked by xgettext to be a c-format, but it
is actually not, so mark up the source to prevent that.

Compute the column widths of the final display dynamically based on the
translated strings, so that translations don't mess up the display
accidentally.

7 years agoMake setlocale in ECPG test cases thread aware on Windows.
Michael Meskes [Sat, 26 Aug 2017 10:57:21 +0000 (12:57 +0200)]
Make setlocale in ECPG test cases thread aware on Windows.

Fix threaded test cases on Windows not to crash in setlocale() which can be
global or local to a thread on Windows.

Author: Christian Ullrich

7 years agoImprove low-level backup documentation.
Robert Haas [Fri, 25 Aug 2017 19:07:44 +0000 (15:07 -0400)]
Improve low-level backup documentation.

Our documentation hasn't really caught up with the fact that
non-exclusive backups can now be taken using pg_start_backup and
pg_stop_backup even on standbys.  Update, also correcting some
errors introduced by 52f8a59dd953c6820baf153e97cf07d31b8ac1d6.
Updates to the 9.6 documentation are needed as well, but that
will need a separate patch as some things are different on that
version.

David Steele, reviewed by Robert Haas and Michael Paquier

Discussion: http://postgr.es/m/d4d951b9-89c0-6bc1-b6ff-d0b2dd5a8966@pgmasters.net

7 years agoFix locale dependency in new ecpg test case.
Tom Lane [Fri, 25 Aug 2017 18:17:33 +0000 (14:17 -0400)]
Fix locale dependency in new ecpg test case.

Force sorting in "C" locale so that the output ordering doesn't vary,
per buildfarm.

In passing, add missing .gitignore entries.

Discussion: https://postgr.es/m/0975f4bb-5dee-c33c-b719-3ce44026d397@chrullrich.net

7 years agopg_upgrade: Remove more dead code
Peter Eisentraut [Fri, 25 Aug 2017 16:02:29 +0000 (12:02 -0400)]
pg_upgrade: Remove more dead code

related to 6ce6a61840cc90172ad3da7bf303656132fa5fab

Reported-by: Christoph Berg <myon@debian.org>
7 years agoMessage translatability fixes
Peter Eisentraut [Fri, 25 Aug 2017 15:49:05 +0000 (11:49 -0400)]
Message translatability fixes

7 years agoImplement DO CONTINUE action for ECPG WHENEVER statement.
Michael Meskes [Fri, 25 Aug 2017 13:15:03 +0000 (15:15 +0200)]
Implement DO CONTINUE action for ECPG WHENEVER statement.

Author: Vinayak Pokale
Reviewed-By: Masahiko Sawada
7 years agoCode review for pushing LIMIT through subqueries.
Tom Lane [Fri, 25 Aug 2017 13:05:17 +0000 (09:05 -0400)]
Code review for pushing LIMIT through subqueries.

Minor improvements for commit 1f6d515a6.  We do not need the (rather
expensive) test for SRFs in the targetlist, because since v10 any
such SRFs would appear in separate ProjectSet nodes.  Also, make the
code look more like the existing cases by turning it into a simple
recursion --- the argument that there might be some performance
benefit to contorting the code seems unfounded to me, especially since
any good compiler should turn the tail-recursion into iteration anyway.

Discussion: http://postgr.es/m/CADE5jYLuugnEEUsyW6Q_4mZFYTxHxaVCQmGAsF0yiY8ZDggi-w@mail.gmail.com

7 years agoAdd minimal regression test for blessed record type transfer.
Andres Freund [Fri, 25 Aug 2017 00:42:49 +0000 (17:42 -0700)]
Add minimal regression test for blessed record type transfer.

Test that blessed records can be transferred through a TupleQueue and
correctly decoded by another backend.  While touching the file, make
sure that force_parallel_mode settings only cover relevant tests.

Author: Thomas Munro, editorialized by Andres Freund
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/20170823054644.efuzftxjpfi6wwqs%40alap3.anarazel.de

7 years agoConsolidate the function pointer types used by dshash.c.
Andres Freund [Fri, 25 Aug 2017 00:01:36 +0000 (17:01 -0700)]
Consolidate the function pointer types used by dshash.c.

Commit 8c0d7bafad36434cb08ac2c78e69ae72c194ca20 introduced dshash with hash
and compare functions like DynaHash's, and also variants that take a user
data pointer instead of size.  Simplify the interface by merging them into
a single pair of function pointer types that take both size and a user data
pointer.

Since it is anticipated that memcmp and tag_hash behavior will be a common
requirement, provide wrapper functions dshash_memcmp and dshash_memhash that
conform to the new function types.

Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/20170823054644.efuzftxjpfi6wwqs%40alap3.anarazel.de

7 years agoFix unlikely shared memory leak after failure in dshash_create().
Andres Freund [Thu, 24 Aug 2017 23:58:30 +0000 (16:58 -0700)]
Fix unlikely shared memory leak after failure in dshash_create().

Tidy-up for commit 8c0d7bafad36434cb08ac2c78e69ae72c194ca20, based on a
complaint from Andres Freund.

Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/20170823054644.efuzftxjpfi6wwqs%40alap3.anarazel.de

7 years agoFix harmless thinko in dsa.c.
Andres Freund [Thu, 24 Aug 2017 22:07:40 +0000 (15:07 -0700)]
Fix harmless thinko in dsa.c.

Commit 16be2fd100199bdf284becfcee02c5eb20d8a11d added DSA_ALLOC_HUGE,
DSA_ALLOC_ZERO and DSA_ALLOC_NO_OOM which have the same numerical
values and meanings as the similarly named MCXT_... macros.  In one
place we accidentally used MCXT_ALLOC_NO_OOM when DSA_ALLOC_NO_OOM is
wanted, so tidy that up.

Author: Thomas Munro
Discussion: http://postgr.es/m/CAEepm=2AimHxVkkxnMfQvbZMkXy0uKbVa0-D38c5-qwrCm4CMQ@mail.gmail.com
Backpatch: 10, where dsa was introduced.

7 years agopsql: Fix \gx when FETCH_COUNT is used
Stephen Frost [Thu, 24 Aug 2017 20:20:50 +0000 (16:20 -0400)]
psql: Fix \gx when FETCH_COUNT is used

Set expanded output when requested through \gx in ExecQueryUsingCursor()
(used when FETCH_COUNT is set).

Discussion: https://www.postgresql.org/message-id/CB7A53AA-5645-4BDD-AB07-4D22CD9D8FF1%40gmx.net
Author: Tobias Bussmann

7 years agopg_upgrade: Remove dead code
Peter Eisentraut [Thu, 24 Aug 2017 19:29:35 +0000 (15:29 -0400)]
pg_upgrade: Remove dead code

Remove code meant for upgrading to a particular version of PostgreSQL
9.0.  Since pg_upgrade only supports upgrading to the current major
version, this code is no longer useful.

7 years agoIncrease SCRAM salt length
Peter Eisentraut [Thu, 24 Aug 2017 18:04:28 +0000 (14:04 -0400)]
Increase SCRAM salt length

The original value 12 was set based on RFC 5802 for SCRAM-SHA-1, but RFC
7677 for SCRAM-SHA-256 uses 16, so use that.  (This does not affect the
validity of already stored verifiers.)

Discussion: https://www.postgresql.org/message-id/flat/12cc9297-7e05-932f-d863-765e5626ead4%402ndquadrant.com

7 years agoMake new regression test case parallel-safe, and improve its output.
Tom Lane [Thu, 24 Aug 2017 17:39:51 +0000 (13:39 -0400)]
Make new regression test case parallel-safe, and improve its output.

The test case added by commit 1f6d515a6 fails on buildfarm members that
have force_parallel_mode turned on, because we currently don't report sort
performance details from worker processes back to the master.  To fix that,
just make the test table be temp rather than regular; that's a good idea
anyway to forestall any possible interference from auto-analyze.
(The restriction that workers can't access temp tables might go away
someday, but almost certainly not before the other thing gets fixed.)

Also, improve the test so that we retain as much as possible of the
EXPLAIN ANALYZE output.  This aids debugging failures, and might also
expose problems that the preceding version masked.

Discussion: http://postgr.es/m/CADE5jYLuugnEEUsyW6Q_4mZFYTxHxaVCQmGAsF0yiY8ZDggi-w@mail.gmail.com

7 years agoFix up secondary expected files
Peter Eisentraut [Thu, 24 Aug 2017 15:13:55 +0000 (11:13 -0400)]
Fix up secondary expected files

for commit 237a0b87b1dc90f8789aa5441a2a11e67f46c96e

7 years agoUpdate code comment for temporary replication slots
Peter Eisentraut [Wed, 23 Aug 2017 18:59:25 +0000 (14:59 -0400)]
Update code comment for temporary replication slots

Reported-by: Alvaro Herrera <alvherre@2ndquadrant.com>
7 years agoFix outdated comment
Peter Eisentraut [Wed, 23 Aug 2017 18:19:35 +0000 (14:19 -0400)]
Fix outdated comment

Author: Thomas Munro <thomas.munro@enterprisedb.com>

7 years agoImprove plural handling in error message
Peter Eisentraut [Wed, 23 Aug 2017 17:56:59 +0000 (13:56 -0400)]
Improve plural handling in error message

This does not use the normal plural handling, because no numbers appear
in the actual message.

7 years agoTweak some SCRAM error messages and code comments
Peter Eisentraut [Wed, 23 Aug 2017 16:01:43 +0000 (12:01 -0400)]
Tweak some SCRAM error messages and code comments

Clarify/correct some error messages, fix up some code comments that
confused SASL and SCRAM, and other minor fixes.  No changes in
functionality.

7 years agoFix translation marker
Peter Eisentraut [Wed, 23 Aug 2017 13:56:38 +0000 (09:56 -0400)]
Fix translation marker

This was erroneously removed in
55a70a023c3daefca9bbd68bfbe6862af10ab479.

7 years agoHash tables backed by DSA shared memory.
Andres Freund [Wed, 23 Aug 2017 05:41:32 +0000 (22:41 -0700)]
Hash tables backed by DSA shared memory.

Add general purpose chaining hash tables for DSA memory.  Unlike
DynaHash in shared memory mode, these hash tables can grow as
required, and cope with being mapped into different addresses in
different backends.

There is a wide range of potential users for such a hash table, though
it's very likely the interface will need to evolve as we come to
understand the needs of different kinds of users.  E.g support for
iterators and incremental resizing is planned for later commits and
the details of the callback signatures are likely to change.

Author: Thomas Munro
Reviewed-By: John Gorman, Andres Freund, Dilip Kumar, Robert Haas
Discussion:
https://postgr.es/m/CAEepm=3d8o8XdVwYT6O=bHKsKAM2pu2D6sV1S_=4d+jStVCE7w@mail.gmail.com
https://postgr.es/m/CAEepm=0ZtQ-SpsgCyzzYpsXS6e=kZWqk3g5Ygn3MDV7A8dabUA@mail.gmail.com

7 years agopg_upgrade: Message translatability and style fixes
Peter Eisentraut [Wed, 23 Aug 2017 00:32:17 +0000 (20:32 -0400)]
pg_upgrade: Message translatability and style fixes

7 years agodoc: Mention identity column feature in section on serial
Peter Eisentraut [Tue, 22 Aug 2017 23:55:21 +0000 (19:55 -0400)]
doc: Mention identity column feature in section on serial

Reported-by: Basil Bourque <basil.bourque@pobox.com>
7 years agoRefactor typcache.c's record typmod hash table.
Andres Freund [Tue, 22 Aug 2017 23:05:48 +0000 (16:05 -0700)]
Refactor typcache.c's record typmod hash table.

Previously, tuple descriptors were stored in chains keyed by a fixed size
array of OIDs.  That meant there were effectively two levels of collision
chain -- one inside and one outside the hash table.  Instead, let dynahash.c
look after conflicts for us by supplying a proper hash and equal function
pair.

This is a nice cleanup on its own, but also simplifies followup
changes allowing blessed TupleDescs to be shared between backends
participating in parallel query.

Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm%3D34GVhOL%2BarUx56yx7OPk7%3DqpGsv3CpO54feqjAwQKm5g%40mail.gmail.com

7 years agoAdd a hash_combine function for mixing hash values.
Andres Freund [Tue, 22 Aug 2017 22:36:49 +0000 (15:36 -0700)]
Add a hash_combine function for mixing hash values.

This hash function is derived from Boost's function of the same name.

Author: Andres Freund, Thomas Munro
Discussion: https://postgr.es/m/CAEepm%3D3rdgjfxW4cKvJ0OEmya2-34B0qHNG1xV0vK7TGPJGMUQ%40mail.gmail.com
Discussion: https://postgr.es/m/20170731210844.3cwrkmsmbbpt4rjc%40alap3.anarazel.de

7 years agoDon't install ICU collation keyword variants
Peter Eisentraut [Mon, 21 Aug 2017 15:22:00 +0000 (11:22 -0400)]
Don't install ICU collation keyword variants

Users can still create them themselves.  Instead, document Unicode TR 35
collation options for ICU, so users can create all this themselves.

Reviewed-by: Peter Geoghegan <pg@bowt.ie>
7 years agoExpand set of predefined ICU locales
Peter Eisentraut [Mon, 21 Aug 2017 13:17:06 +0000 (09:17 -0400)]
Expand set of predefined ICU locales

Install language+region combinations even if they are not distinct from
the language's base locale.  This gives better long-term stability of
the set of predefined locales and makes the predefined locales less
implementation-dependent and more practical for users.

Reviewed-by: Peter Geoghegan <pg@bowt.ie>
7 years agoPush limit through subqueries to underlying sort, where possible.
Robert Haas [Mon, 21 Aug 2017 18:43:01 +0000 (14:43 -0400)]
Push limit through subqueries to underlying sort, where possible.

Douglas Doole, reviewed by Ashutosh Bapat and by me.  Minor formatting
change by me.

Discussion: http://postgr.es/m/CADE5jYLuugnEEUsyW6Q_4mZFYTxHxaVCQmGAsF0yiY8ZDggi-w@mail.gmail.com

7 years agopg_prewarm: Add automatic prewarm feature.
Robert Haas [Mon, 21 Aug 2017 18:43:00 +0000 (14:43 -0400)]
pg_prewarm: Add automatic prewarm feature.

Periodically while the server is running, and at shutdown, write out a
list of blocks in shared buffers.  When the server reaches consistency
-- unfortunatey, we can't do it before that point without breaking
things -- reload those blocks into any still-unused shared buffers.

Mithun Cy and Robert Haas, reviewed and tested by Beena Emerson,
Amit Kapila, Jim Nasby, and Rafia Sabih.

Discussion: http://postgr.es/m/CAD__OugubOs1Vy7kgF6xTjmEqTR4CrGAv8w+ZbaY_+MZeitukw@mail.gmail.com

7 years agoInject $(ICU_LIBS) regardless of platform.
Noah Misch [Mon, 21 Aug 2017 04:22:18 +0000 (21:22 -0700)]
Inject $(ICU_LIBS) regardless of platform.

It appeared in a conditional that excludes AIX, Cygwin and MinGW.  Give
ICU support a chance to work on those platforms.  Back-patch to v10,
where ICU support was introduced.

7 years agoPartially flatten struct tupleDesc so that it can be used in DSM.
Andres Freund [Sun, 20 Aug 2017 18:19:12 +0000 (11:19 -0700)]
Partially flatten struct tupleDesc so that it can be used in DSM.

TupleDesc's attributes were already stored in contiguous memory after the
struct.  Go one step further and get rid of the array of pointers to
attributes so that they can be stored in shared memory mapped at different
addresses in each backend.  This won't work for TupleDescs with contraints
and defaults, since those point to other objects, but for many purposes
only attributes are needed.

Author: Thomas Munro
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm=0ZtQ-SpsgCyzzYpsXS6e=kZWqk3g5Ygn3MDV7A8dabUA@mail.gmail.com

7 years agoChange tupledesc->attrs[n] to TupleDescAttr(tupledesc, n).
Andres Freund [Sun, 20 Aug 2017 18:19:07 +0000 (11:19 -0700)]
Change tupledesc->attrs[n] to TupleDescAttr(tupledesc, n).

This is a mechanical change in preparation for a later commit that
will change the layout of TupleDesc.  Introducing a macro to abstract
the details of where attributes are stored will allow us to change
that in separate step and revise it in future.

Author: Thomas Munro, editorialized by Andres Freund
Reviewed-By: Andres Freund
Discussion: https://postgr.es/m/CAEepm=0ZtQ-SpsgCyzzYpsXS6e=kZWqk3g5Ygn3MDV7A8dabUA@mail.gmail.com

7 years agoFix possible core dump in parallel restore when using a TOC list.
Tom Lane [Sat, 19 Aug 2017 17:39:37 +0000 (13:39 -0400)]
Fix possible core dump in parallel restore when using a TOC list.

Commit 3eb9a5e7c unintentionally introduced an ordering dependency
into restore_toc_entries_prefork().  The existing coding of
reduce_dependencies() contains a check to skip moving a TOC entry
to the ready_list if it wasn't initially in the pending_list.
This used to suffice to prevent reduce_dependencies() from trying to
move anything into the ready_list during restore_toc_entries_prefork(),
because the pending_list stayed empty throughout that phase; but it no
longer does.  The problem doesn't manifest unless the TOC has been
reordered by SortTocFromFile, which is how I missed it in testing.

To fix, just add a test for ready_list == NULL, converting the call
with NULL from a poor man's sanity check into an explicit command
not to touch TOC items' list membership.  Clarify some of the comments
around this; in particular, note the primary purpose of the check for
pending_list membership, which is to ensure that we can't try to restore
the same item twice, in case a TOC list forces it to be restored before
its dependency count goes to zero.

Per report from Fabrízio de Royes Mello.  Back-patch to 9.3, like the
previous commit.

Discussion: https://postgr.es/m/CAFcNs+pjuv0JL_x4+=71TPUPjdLHOXA4YfT32myj_OrrZb4ohA@mail.gmail.com

7 years agoFix creation of ICU comments for keyword variants
Peter Eisentraut [Sat, 19 Aug 2017 03:02:28 +0000 (23:02 -0400)]
Fix creation of ICU comments for keyword variants

It would create the comment referring to the keyword-less parent
locale.  This was broken in ddb5fdc068635d003a0d1c303cb109d1cb3ebeb1.

7 years agoFix interaction of triggers, partitioning, and EXPLAIN ANALYZE.
Robert Haas [Fri, 18 Aug 2017 17:01:05 +0000 (13:01 -0400)]
Fix interaction of triggers, partitioning, and EXPLAIN ANALYZE.

Add a new EState member es_leaf_result_relations, so that the trigger
code knows about ResultRelInfos created by tuple routing.  Also make
sure ExplainPrintTriggers knows about partition-related
ResultRelInfos.

Etsuro Fujita, reviewed by Amit Langote

Discussion: http://postgr.es/m/57163e18-8e56-da83-337a-22f2c0008051@lab.ntt.co.jp

7 years agoTemporarily revert test case from a2b70c89ca1a5fcf6181d3c777d82e7b83d2de1b.
Tom Lane [Thu, 17 Aug 2017 22:35:14 +0000 (18:35 -0400)]
Temporarily revert test case from a2b70c89ca1a5fcf6181d3c777d82e7b83d2de1b.

That code patch was good as far as it went, but the associated test case
has exposed fundamental brain damage in the parallel scan mechanism,
which is going to take nontrivial work to correct.  In the interests of
getting the buildfarm back to green so that unrelated work can proceed,
let's temporarily remove the test case.

7 years agoDon't lock tables in RelationGetPartitionDispatchInfo.
Robert Haas [Thu, 17 Aug 2017 19:39:17 +0000 (15:39 -0400)]
Don't lock tables in RelationGetPartitionDispatchInfo.

Instead, lock them in the caller using find_all_inheritors so that
they get locked in the standard order, minimizing deadlock risks.

Also in RelationGetPartitionDispatchInfo, avoid opening tables which
are not partitioned; there's no need.

Amit Langote, reviewed by Ashutosh Bapat and Amit Khandekar

Discussion: http://postgr.es/m/91b36fa1-c197-b72f-ca6e-56c593bae68c@lab.ntt.co.jp

7 years agoRefactor validation of new partitions a little bit.
Robert Haas [Thu, 17 Aug 2017 18:49:45 +0000 (14:49 -0400)]
Refactor validation of new partitions a little bit.

Move some logic that is currently in ATExecAttachPartition to
separate functions to facilitate future code reuse.

Ashutosh Bapat and Jeevan Ladhe

Discussion: http://postgr.es/m/CA+Tgmobbnamyvii0pRdg9pp_jLHSUvq7u5SiRrVV0tEFFU58Tg@mail.gmail.com

7 years agoAttempt to clarify comments related to force_parallel_mode.
Robert Haas [Thu, 17 Aug 2017 18:04:15 +0000 (14:04 -0400)]
Attempt to clarify comments related to force_parallel_mode.

Per discussion with Tom Lane.

Discussion: http://postgr.es/m/28589.1502902172@sss.pgh.pa.us

7 years agoFix ExecReScanGatherMerge.
Tom Lane [Thu, 17 Aug 2017 17:49:22 +0000 (13:49 -0400)]
Fix ExecReScanGatherMerge.

Not surprisingly, since it'd never ever been tested, ExecReScanGatherMerge
didn't work.  Fix it, and add a regression test case to exercise it.

Amit Kapila

Discussion: https://postgr.es/m/CAA4eK1JkByysFJNh9M349u_nNjqETuEnY_y1VUc_kJiU0bxtaQ@mail.gmail.com

7 years agoFurther tweaks to compiler flags for PL/Perl on Windows.
Tom Lane [Thu, 17 Aug 2017 17:13:47 +0000 (13:13 -0400)]
Further tweaks to compiler flags for PL/Perl on Windows.

It now emerges that we can only rely on Perl to tell us we must use
-D_USE_32BIT_TIME_T if it's Perl 5.13.4 or later.  For older versions,
revert to our previous practice of assuming we need that symbol in
all 32-bit Windows builds.  This is not ideal, but inquiring into
which compiler version Perl was built with seems far too fragile.
In any case, we had not previously had complaints about these old
Perl versions, so let's assume this is Good Enough.  (It's still
better than the situation ante commit 5a5c2feca, in that at least
the effects are confined to PL/Perl rather than the whole PG build.)

Back-patch to all supported versions, like 5a5c2feca and predecessors.

Discussion: https://postgr.es/m/CANFyU97OVQ3+Mzfmt3MhuUm5NwPU=-FtbNH5Eb7nZL9ua8=rcA@mail.gmail.com

7 years agodoc: Update RFC URLs
Peter Eisentraut [Thu, 17 Aug 2017 15:39:00 +0000 (11:39 -0400)]
doc: Update RFC URLs

Consistently use the IETF HTML links instead of a random mix of
different sites and formats.  Correct one RFC number and fix one broken
link.

7 years agoRemove bogus line from comment.
Robert Haas [Thu, 17 Aug 2017 15:19:07 +0000 (11:19 -0400)]
Remove bogus line from comment.

Spotted by Tom Lane

Discussion: http://postgr.es/m/27897.1502901074@sss.pgh.pa.us

7 years agoAdd missing "static" marker.
Tom Lane [Thu, 17 Aug 2017 15:17:39 +0000 (11:17 -0400)]
Add missing "static" marker.

Per pademelon.

7 years agodoc: Fix table column count
Peter Eisentraut [Thu, 17 Aug 2017 14:37:12 +0000 (10:37 -0400)]
doc: Fix table column count

Author: Erik Rijkers <er@xs4all.nl>

7 years agopg_dump: Support using synchronized snapshots on standbys
Peter Eisentraut [Wed, 16 Aug 2017 23:46:50 +0000 (19:46 -0400)]
pg_dump: Support using synchronized snapshots on standbys

This became possible by commit
6c2003f8a1bbc7c192a2e83ec51581c018aa162f.  This just makes pg_dump aware
of it and updates the documentation.

Author: Petr Jelinek <petr.jelinek@2ndquadrant.com>

7 years agoFix pg_atomic_u64 initialization.
Heikki Linnakangas [Wed, 16 Aug 2017 21:48:44 +0000 (00:48 +0300)]
Fix pg_atomic_u64 initialization.

As Andres pointed out, pg_atomic_init_u64 must be used to initialize an
atomic variable, before it can be accessed with the actual atomic ops.
Trying to use pg_atomic_write_u64 on an uninitialized variable leads to a
failure with the fallback implementation that uses a spinlock.

Discussion: https://www.postgresql.org/message-id/20170816191346.d3ke5tpshhco4bnd%40alap3.anarazel.de

7 years agoExtend the default rules file for contrib/unaccent with Vietnamese letters.
Tom Lane [Wed, 16 Aug 2017 20:51:56 +0000 (16:51 -0400)]
Extend the default rules file for contrib/unaccent with Vietnamese letters.

Improve generate_unaccent_rules.py to handle composed characters whose base
is another composed character rather than a plain letter.  The net effect
of this is to add a bunch of multi-accented Vietnamese characters to
unaccent.rules.

Original complaint from Kha Nguyen, diagnosis of the script's shortcoming
by Thomas Munro.

Dang Minh Huong and Michael Paquier

Discussion: https://postgr.es/m/CALo3sF6EC8cy1F2JUz=GRf5h4LMUJTaG3qpdoiLrNbWEXL-tRg@mail.gmail.com

7 years agoMake the planner assume that the entries in a VALUES list are distinct.
Tom Lane [Wed, 16 Aug 2017 19:37:14 +0000 (15:37 -0400)]
Make the planner assume that the entries in a VALUES list are distinct.

Previously, if we had to estimate the number of distinct values in a
VALUES column, we fell back on the default behavior used whenever we lack
statistics, which effectively is that there are Min(# of entries, 200)
distinct values.  This can be very badly off with a large VALUES list,
as noted by Jeff Janes.

We could consider actually running an ANALYZE-like scan on the VALUES,
but that seems unduly expensive, and anyway it could not deliver reliable
info if the entries are not all constants.  What seems like a better choice
is to assume that the values are all distinct.  This will sometimes be just
as wrong as the old code, but it seems more likely to be more nearly right
in many common cases.  Also, it is more consistent with what happens in
some related cases, for example WHERE x = ANY(ARRAY[1,2,3,...,n]) and
WHERE x = ANY(VALUES (1),(2),(3),...,(n)) now are estimated similarly.

This was discussed some time ago, but consensus was it'd be better
to slip it in at the start of a development cycle not near the end.
(It should've gone into v10, really, but I forgot about it.)

Discussion: https://postgr.es/m/CAMkU=1xHkyPa8VQgGcCNg3RMFFvVxUdOpus1gKcFuvVi0w6Acg@mail.gmail.com

7 years agoFix shm_toc.c to always return buffer-aligned memory.
Heikki Linnakangas [Wed, 16 Aug 2017 18:52:38 +0000 (21:52 +0300)]
Fix shm_toc.c to always return buffer-aligned memory.

Previously, if you passed a non-aligned size to shm_toc_create(), the
memory returned by shm_toc_allocate() would be similarly non-aligned.
This was exposed by commit 3cda10f41b, which allocated structs containing
a pg_atomic_uint64 field with shm_toc_allocate(). On systems with
MAXIMUM_ALIGNOF = 4, such structs still need to be 8-bytes aligned, but
the memory returned by shm_toc_allocate() was only 4-bytes aligned.

It's quite bogus that we abuse BUFFERALIGN to align the structs for
pg_atomic_uint64. It doesn't really have anything to do with buffers. But
that's a separate issue.

This ought to fix the buildfarm failures on 32-bit x86 systems.

Discussion: https://www.postgresql.org/message-id/7e0a73a5-0df9-1859-b8ae-9acf122dc38d@iki.fi

7 years agodoc: Update URL of DocBook XSL stylesheets
Peter Eisentraut [Wed, 16 Aug 2017 18:44:26 +0000 (14:44 -0400)]
doc: Update URL of DocBook XSL stylesheets

Author: Masahiko Sawada <sawada.mshk@gmail.com>

7 years agodoc: Add logical replication to comparison matrix
Peter Eisentraut [Wed, 16 Aug 2017 17:59:40 +0000 (13:59 -0400)]
doc: Add logical replication to comparison matrix

Author: Steve Singer <steve@ssinger.info>

7 years agoCorrect representation of foreign tables in information schema
Peter Eisentraut [Wed, 16 Aug 2017 15:03:33 +0000 (11:03 -0400)]
Correct representation of foreign tables in information schema

tables.table_type is supposed to be 'FOREIGN' rather than 'FOREIGN
TABLE' according to the SQL standard.

7 years agoUse atomic ops to hand out pages to scan in parallel scan.
Heikki Linnakangas [Wed, 16 Aug 2017 13:18:41 +0000 (16:18 +0300)]
Use atomic ops to hand out pages to scan in parallel scan.

With a lot of CPUs, the spinlock that protects the current scan location
in a parallel scan can become a bottleneck. Use an atomic fetch-and-add
instruction instead.

David Rowley

Discussion: https://www.postgresql.org/message-id/CAKJS1f9tgsPhqBcoPjv9_KUPZvTLCZ4jy%3DB%3DbhqgaKn7cYzm-w@mail.gmail.com

7 years agoRemove dedicated B-tree root-split record types.
Heikki Linnakangas [Wed, 16 Aug 2017 09:16:18 +0000 (12:16 +0300)]
Remove dedicated B-tree root-split record types.

Since commit 40dae7ec53, which changed the way b-tree page splitting
works, there has been no difference in the handling of root, and non-root
split WAL records. We don't need to distinguish them anymore

If you're worried about the loss of debugging information, note that
usually a root split record will normally be followed by a WAL record to
create the new root page. The root page will also have the BTP_ROOT flag
set on the page itself, and there is a pointer to it from the metapage.

Author: Aleksander Alekseev
Discussion: https://www.postgresql.org/message-id/20170406122116.GA11081@e733.localdomain

7 years agoFix up some misusage of appendStringInfo() and friends
Peter Eisentraut [Wed, 16 Aug 2017 03:34:39 +0000 (23:34 -0400)]
Fix up some misusage of appendStringInfo() and friends

Change to appendStringInfoChar() or appendStringInfoString() where those
can be used.

Author: David Rowley <david.rowley@2ndquadrant.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat@enterprisedb.com>
7 years agoInitialize replication_slot_catalog_xmin in procarray
Peter Eisentraut [Wed, 16 Aug 2017 01:05:21 +0000 (21:05 -0400)]
Initialize replication_slot_catalog_xmin in procarray

Although not confirmed and probably rare, if the newly allocated memory
is not already zero, this could possibly have caused some problems.

Also reorder the initializations slightly so they match the order of the
struct definition.

Author: Wong, Yi Wen <yiwong@amazon.com>
Reviewed-by: Masahiko Sawada <sawada.mshk@gmail.com>
7 years agodoc: Document pg_receivewal exit behavior and status
Peter Eisentraut [Wed, 16 Aug 2017 00:26:58 +0000 (20:26 -0400)]
doc: Document pg_receivewal exit behavior and status

7 years agopg_receivewal: Improve verbose mode
Peter Eisentraut [Wed, 16 Aug 2017 00:25:37 +0000 (20:25 -0400)]
pg_receivewal: Improve verbose mode

Some informational messages showed up even if verbose mode was not
used.  Move them to verbose mode.

Author: Michael Paquier <michael.paquier@gmail.com>
Reviewed-by: Daniel Gustafsson <daniel@yesql.se>
7 years agoInclude foreign tables in information_schema.table_privileges
Peter Eisentraut [Tue, 15 Aug 2017 23:27:22 +0000 (19:27 -0400)]
Include foreign tables in information_schema.table_privileges

This appears to have been an omission in the original commit
0d692a0dc9f.  All related information_schema views already include
foreign tables.

Reported-by: Nicolas Thauvin <nicolas.thauvin@dalibo.com>
7 years agopsql: Add tab completion for \pset pager
Peter Eisentraut [Tue, 15 Aug 2017 23:10:38 +0000 (19:10 -0400)]
psql: Add tab completion for \pset pager

Author: Pavel Stehule <pavel.stehule@gmail.com>

7 years agoSimplify autovacuum work-item implementation
Alvaro Herrera [Tue, 15 Aug 2017 21:14:07 +0000 (18:14 -0300)]
Simplify autovacuum work-item implementation

The initial implementation of autovacuum work-items used a dynamic
shared memory area (DSA).  However, it's argued that dynamic shared
memory is not portable enough, so we cannot rely on it being supported
everywhere; at the same time, autovacuum work-items are now a critical
part of the server, so it's not acceptable that they don't work in the
cases where dynamic shared memory is disabled.  Therefore, let's fall
back to a simpler implementation of work-items that just uses
autovacuum's main shared memory segment for storage.

Discussion: https://postgr.es/m/CA+TgmobQVbz4K_+RSmiM9HeRKpy3vS5xnbkL95gSEnWijzprKQ@mail.gmail.com

7 years agoMake simpler-simple-expressions code cope with a Gather plan.
Tom Lane [Tue, 15 Aug 2017 20:49:47 +0000 (16:49 -0400)]
Make simpler-simple-expressions code cope with a Gather plan.

Commit 00418c612 expected that the plan generated for a simple-expression
query would always be a plain Result node.  However, if force_parallel_mode
is on, the planner might stick a Gather atop that.  Cope by looking through
the Gather.  For safety, assert that the Gather's tlist is trivial.

Per buildfarm.

Discussion: https://postgr.es/m/23425.1502822098@sss.pgh.pa.us

7 years agoFix logical replication protocol comparison logic
Peter Eisentraut [Tue, 15 Aug 2017 20:20:20 +0000 (16:20 -0400)]
Fix logical replication protocol comparison logic

Since we currently only have one protocol, this doesn't make much of a
difference other than the error message.

Author: Yugo Nagata <nagata@sraoss.co.jp>

7 years agodoc: Add missing logical replication protocol message
Peter Eisentraut [Tue, 15 Aug 2017 19:36:18 +0000 (15:36 -0400)]
doc: Add missing logical replication protocol message

Author: Masahiko Sawada <sawada.mshk@gmail.com>

7 years agoSimplify some code in logical replication launcher
Peter Eisentraut [Tue, 15 Aug 2017 19:13:06 +0000 (15:13 -0400)]
Simplify some code in logical replication launcher

Avoid unnecessary locking calls when a subscription is disabled.

Author: Yugo Nagata <nagata@sraoss.co.jp>

7 years agodoc: Improve PDF bookmarks
Peter Eisentraut [Tue, 15 Aug 2017 18:37:44 +0000 (14:37 -0400)]
doc: Improve PDF bookmarks

Also create PDF bookmarks/ToC entries for subsections of reference
pages.  This was a regression from the previous jadetex-based build.

Reported-by: Erik Rijkers <er@xs4all.nl>
7 years agoAvoid out-of-memory in a hash join with many duplicate inner keys.
Tom Lane [Tue, 15 Aug 2017 18:05:46 +0000 (14:05 -0400)]
Avoid out-of-memory in a hash join with many duplicate inner keys.

The executor is capable of splitting buckets during a hash join if
too much memory is being used by a small number of buckets.  However,
this only helps if a bucket's population is actually divisible; if
all the hash keys are alike, the tuples still end up in the same
new bucket.  This can result in an OOM failure if there are enough
inner keys with identical hash values.  The planner's cost estimates
will bias it against choosing a hash join in such situations, but not
by so much that it will never do so.  To mitigate the OOM hazard,
explicitly estimate the hash bucket space needed by just the inner
side's most common value, and if that would exceed work_mem then
add disable_cost to the hash cost estimate.

This approach doesn't account for the possibility that two or more
common values would share the same hash value.  On the other hand,
work_mem is normally a fairly conservative bound, so that eating
two or more times that much space is probably not going to kill us.

If we have no stats about the inner side, ignore this consideration.
There was some discussion of making a conservative assumption, but that
would effectively result in disabling hash join whenever we lack stats,
which seems like an overreaction given how seldom the problem manifests
in the field.

Per a complaint from David Hinkle.  Although this could be viewed
as a bug fix, the lack of similar complaints weighs against back-
patching; indeed we waited for v11 because it seemed already rather
late in the v10 cycle to be making plan choice changes like this one.

Discussion: https://postgr.es/m/32013.1487271761@sss.pgh.pa.us

7 years agoFix error handling path in autovacuum launcher
Alvaro Herrera [Tue, 15 Aug 2017 16:35:12 +0000 (13:35 -0300)]
Fix error handling path in autovacuum launcher

The original code (since 00e6a16d01) was assuming aborting the
transaction in autovacuum launcher was sufficient to release all
resources, but in reality the launcher runs quite a lot of code out of
any transactions.  Re-introduce individual cleanup calls to make abort
more robust.

Reported-by: Robert Haas
Discussion: https://postgr.es/m/CA+TgmobQVbz4K_+RSmiM9HeRKpy3vS5xnbkL95gSEnWijzprKQ@mail.gmail.com

7 years agoAssorted preparatory refactoring for partition-wise join.
Robert Haas [Tue, 15 Aug 2017 16:30:38 +0000 (12:30 -0400)]
Assorted preparatory refactoring for partition-wise join.

Instead of duplicating the logic to search for a matching
ParamPathInfo in multiple places, factor it out into a separate
function.

Pass only the relevant bits of the PartitionKey to
partition_bounds_equal instead of the whole thing, because
partition-wise join will want to call this without having a
PartitionKey available.

Adjust allow_star_schema_join and calc_nestloop_required_outer
to take relevant Relids rather than the entire Path, because
partition-wise join will want to call it with the top-parent
relids to determine whether a child join is allowable.

Ashutosh Bapat.  Review and testing of the larger patch set of which
this is a part by Amit Langote, Rajkumar Raghuwanshi, Rafia Sabih,
Thomas Munro, Dilip Kumar, and me.

Discussion: http://postgr.es/m/CA+TgmobQK80vtXjAsPZWWXd7c8u13G86gmuLupN+uUJjA+i4nA@mail.gmail.com

7 years agoSimplify plpgsql's check for simple expressions.
Tom Lane [Tue, 15 Aug 2017 16:28:39 +0000 (12:28 -0400)]
Simplify plpgsql's check for simple expressions.

plpgsql wants to recognize expressions that it can execute directly
via ExecEvalExpr() instead of going through the full SPI machinery.
Originally the test for this consisted of recursively groveling through
the post-planning expression tree to see if it contained only nodes that
plpgsql recognized as safe.  That was a major maintenance headache, since
it required updating plpgsql every time we added any kind of expression
node.  It was also kind of expensive, so over time we added various
pre-planning checks to try to short-circuit having to do that.
Robert Haas pointed out that as of the SRF-processing changes in v10,
particularly the addition of Query.hasTargetSRFs, there really isn't
any reason to make the recursive scan at all: the initial checks cover
everything we really care about.  We do have to make sure that those
checks agree with what inline_function() considers, so that inlining
of a function that formerly wasn't inlined can't cause an expression
considered simple to become non-simple.

Hence, delete the recursive function exec_simple_check_node(), and tweak
those other tests to more exactly agree with inline_function().  Adjust
some comments and function naming to match.

Discussion: https://postgr.es/m/CA+TgmoZGZpwdEV2FQWaVxA_qZXsQE1DAS5Fu8fwxXDNvfndiUQ@mail.gmail.com

7 years agoAllow continuation lines in ecpg cppline parsing.
Michael Meskes [Tue, 15 Aug 2017 14:06:56 +0000 (16:06 +0200)]
Allow continuation lines in ecpg cppline parsing.

7 years agoDistinguish wait-for-connection from wait-for-write-ready on Windows.
Tom Lane [Tue, 15 Aug 2017 15:07:52 +0000 (11:07 -0400)]
Distinguish wait-for-connection from wait-for-write-ready on Windows.

The API for WaitLatch and friends followed the Unix convention in which
waiting for a socket connection to complete is identical to waiting for
the socket to accept a write.  While Windows provides a select(2)
emulation that agrees with that, the native WaitForMultipleObjects API
treats them as quite different --- and for some bizarre reason, it will
report a not-yet-connected socket as write-ready.  libpq itself has so
far escaped dealing with this because it waits with select(), but in
libpqwalreceiver.c we want to wait using WaitLatchOrSocket.  The semantics
mismatch resulted in replication connection failures on Windows, but only
for remote connections (apparently, localhost connections complete
immediately, or at least too fast for anyone to have noticed the problem
in single-machine testing).

To fix, introduce an additional WL_SOCKET_CONNECTED wait flag for
WaitLatchOrSocket, which is identical to WL_SOCKET_WRITEABLE on
non-Windows, but results in waiting for FD_CONNECT events on Windows.

Ideally, we would also distinguish the two conditions in the API for
PQconnectPoll(), but changing that API at this point seems infeasible.
Instead, cheat by checking for PQstatus() == CONNECTION_STARTED to
determine that we're still waiting for the connection to complete.
(This is a cheat mainly because CONNECTION_STARTED is documented as an
internal state rather than something callers should rely on.  Perhaps
we ought to change the documentation ... but this patch doesn't.)

Per reports from Jobin Augustine and Igor Neyman.  Back-patch to v10
where commit 1e8a85009 exposed this longstanding shortcoming.

Andres Freund, minor fix and some code review/beautification by me

Discussion: https://postgr.es/m/CAHBggj8g2T+ZDcACZ2FmzX9CTxkWjKBsHd6NkYB4i9Ojf6K1Fw@mail.gmail.com

7 years agoTeach adjust_appendrel_attrs(_multilevel) to do multiple translations.
Robert Haas [Tue, 15 Aug 2017 14:49:06 +0000 (10:49 -0400)]
Teach adjust_appendrel_attrs(_multilevel) to do multiple translations.

Currently, child relations are always base relations, so when we
translate parent relids to child relids, we only need to translate
a singler relid.  However, the proposed partition-wise join feature
will create child joins, which will mean we need to translate a set
of parent relids to the corresponding child relids.  This is
preliminary refactoring to make that possible.

Ashutosh Bapat.  Review and testing of the larger patch set of which
this is a part by Amit Langote, Rajkumar Raghuwanshi, Rafia Sabih,
Thomas Munro, Dilip Kumar, and me.  Some adjustments, mostly
cosmetic, by me.

Discussion: http://postgr.es/m/CA+TgmobQK80vtXjAsPZWWXd7c8u13G86gmuLupN+uUJjA+i4nA@mail.gmail.com

7 years agoAvoid unnecessary single-child Append nodes.
Robert Haas [Tue, 15 Aug 2017 13:16:33 +0000 (09:16 -0400)]
Avoid unnecessary single-child Append nodes.

Before commit d3cc37f1d801a6b5cad9bf179274a8, an inheritance parent
whose only children were temp tables of other sessions would end up
as a simple scan of the parent; but with that commit, we end up with
an Append node, per a report from Ashutosh Bapat.  Tweak the logic
so that we go back to the old way, and update the function header
comment for partitioning while we're at it.

Ashutosh Bapat, reviewed by Amit Langote and adjusted by me.

Discussion: http://postgr.es/m/CAFjFpReWJr1yTkHU=OqiMBmcYCMoSW3VPR39RBuQ_ovwDFBT5Q@mail.gmail.com

7 years agoAdd missing call to ExecReScanGatherMerge.
Robert Haas [Tue, 15 Aug 2017 12:06:36 +0000 (08:06 -0400)]
Add missing call to ExecReScanGatherMerge.

Amit Kapila

Discussion: http://postgr.es/m/CAA4eK1KeQWZOoDmDmGMwuqzPW9JhRS+ditQVFdAfGjNmMZzqMQ@mail.gmail.com

7 years agopg_dump: Add a --load-via-partition-root option.
Robert Haas [Tue, 15 Aug 2017 02:54:41 +0000 (22:54 -0400)]
pg_dump: Add a --load-via-partition-root option.

Rushabh Lathia, reviewed and somewhat revised by me.  Testing by
Rajkumar Raghuwanshi.

Discussion: http://postgr.es/m/CAGPqQf0C1he087bz9xRBOGZBuESYz9X=Fp8Ca_g+TfHgAff75g@mail.gmail.com

7 years agoExpand coverage of parallel gather merge a bit.
Andres Freund [Mon, 14 Aug 2017 22:21:26 +0000 (15:21 -0700)]
Expand coverage of parallel gather merge a bit.

Previously paths reaching heap_compare_slots weren't covered.

Author: Rushabh Lathia
Reviewed-By: Andres Freund
Discussion:
https://postgr.es/m/CAGPqQf3C+3PBujb+7m=ceWeii4-vBY=XS99LjzrpkpefvzJbFg@mail.gmail.com
https://postgr.es/m/27200.1502482851@sss.pgh.pa.us
Backpatch: 10, where gather merge was introduced

7 years agoStamp HEAD as 11devel.
Tom Lane [Mon, 14 Aug 2017 22:08:30 +0000 (18:08 -0400)]
Stamp HEAD as 11devel.

Note that we no longer require any manual adjustments to shared-library
minor version numbers, cf commit a3bce17ef.  So this should be everything.

7 years agoFinal pgindent + perltidy run for v10.
Tom Lane [Mon, 14 Aug 2017 21:29:33 +0000 (17:29 -0400)]
Final pgindent + perltidy run for v10.

7 years agoHandle elog(FATAL) during ROLLBACK more robustly.
Tom Lane [Mon, 14 Aug 2017 19:43:20 +0000 (15:43 -0400)]
Handle elog(FATAL) during ROLLBACK more robustly.

Stress testing by Andreas Seltenreich disclosed longstanding problems that
occur if a FATAL exit (e.g. due to receipt of SIGTERM) occurs while we are
trying to execute a ROLLBACK of an already-failed transaction.  In such a
case, xact.c is in TBLOCK_ABORT state, so that AbortOutOfAnyTransaction
would skip AbortTransaction and go straight to CleanupTransaction.  This
led to an assert failure in an assert-enabled build (due to the ROLLBACK's
portal still having a cleanup hook) or without assertions, to a FATAL exit
complaining about "cannot drop active portal".  The latter's not
disastrous, perhaps, but it's messy enough to want to improve it.

We don't really want to run all of AbortTransaction in this code path.
The minimum required to clean up the open portal safely is to do
AtAbort_Memory and AtAbort_Portals.  It seems like a good idea to
do AtAbort_Memory unconditionally, to be entirely sure that we are
starting with a safe CurrentMemoryContext.  That means that if the
main loop in AbortOutOfAnyTransaction does nothing, we need an extra
step at the bottom to restore CurrentMemoryContext = TopMemoryContext,
which I chose to do by invoking AtCleanup_Memory.  This'll result in
calling AtCleanup_Memory twice in many of the paths through this function,
but that seems harmless and reasonably inexpensive.

The original motivation for the assertion in AtCleanup_Portals was that
we wanted to be sure that any user-defined code executed as a consequence
of the cleanup hook runs during AbortTransaction not CleanupTransaction.
That still seems like a valid concern, and now that we've seen one case
of the assertion firing --- which means that exactly that would have
happened in a production build --- let's replace the Assert with a runtime
check.  If we see the cleanup hook still set, we'll emit a WARNING and
just drop the hook unexecuted.

This has been like this a long time, so back-patch to all supported
branches.

Discussion: https://postgr.es/m/877ey7bmun.fsf@ansel.ydns.eu

7 years agoFix typo
Peter Eisentraut [Mon, 14 Aug 2017 17:53:05 +0000 (13:53 -0400)]
Fix typo

Author: Masahiko Sawada <sawada.mshk@gmail.com>

7 years agodoc: Fix logical replication protocol doc detail
Peter Eisentraut [Mon, 14 Aug 2017 17:42:03 +0000 (13:42 -0400)]
doc: Fix logical replication protocol doc detail

Author: Masahiko Sawada <sawada.mshk@gmail.com>
Reported-by: Kyle Conroy <kyle@kyleconroy.com>
Bug: #14775