]> granicus.if.org Git - postgresql/log
postgresql
4 years agoMessage style fixes
Peter Eisentraut [Mon, 23 Sep 2019 11:37:33 +0000 (13:37 +0200)]
Message style fixes

4 years agoNLS: Fix backend gettext triggers
Peter Eisentraut [Mon, 23 Sep 2019 07:04:20 +0000 (09:04 +0200)]
NLS: Fix backend gettext triggers

The backend also needs to pull in translations from the frontend
pg_log_*() functions, since some files in src/common/ use those.

4 years agoFix failure to zero-pad the result of bitshiftright().
Tom Lane [Sun, 22 Sep 2019 21:45:59 +0000 (17:45 -0400)]
Fix failure to zero-pad the result of bitshiftright().

If the bitstring length is not a multiple of 8, we'd shift the
rightmost bits into the pad space, which must be zeroes --- bit_cmp,
for one, depends on that.  This'd lead to the result failing to
compare equal to what it should compare equal to, as reported in
bug #16013 from Daryl Waycott.

This is, if memory serves, not the first such bug in the bitstring
functions.  In hopes of making it the last one, do a bit more work
than minimally necessary to fix the bug:

* Add assertion checks to bit_out() and varbit_out() to complain if
they are given incorrectly-padded input.  This will improve the
odds that manual testing of any new patch finds problems.

* Encapsulate the padding-related logic in macros to make it
easier to use.

Also, remove unnecessary padding logic from bit_or() and bitxor().
Somebody had already noted that we need not re-pad the result of
bit_and() since the inputs are required to be the same length,
but failed to extrapolate that to the other two.

Also, move a comment block that once was near the head of varbit.c
(but people kept putting other stuff in front of it), to put it in
the header block.

Note for the release notes: if anyone has inconsistent data as a
result of saving the output of bitshiftright() in a table, it's
possible to fix it with something like
UPDATE mytab SET bitcol = ~(~bitcol) WHERE bitcol != ~(~bitcol);

This has been broken since day one, so back-patch to all supported
branches.

Discussion: https://postgr.es/m/16013-c2765b6996aacae9@postgresql.org

4 years agoFix typo in tts_virtual_copyslot.
Tom Lane [Sun, 22 Sep 2019 18:21:07 +0000 (14:21 -0400)]
Fix typo in tts_virtual_copyslot.

The code used the destination slot's natts where it intended to
use the source slot's natts.  Adding an Assert shows that there
is no case in "make check-world" where these counts are different,
so maybe this is a harmless bug, but it's still a bug.

Takayuki Tsunakawa

Discussion: https://postgr.es/m/0A3221C70F24FB45833433255569204D1FD34C0E@G01JPEXMBYT05

4 years agoMake some efficiency improvements in LISTEN/NOTIFY.
Tom Lane [Sun, 22 Sep 2019 15:46:29 +0000 (11:46 -0400)]
Make some efficiency improvements in LISTEN/NOTIFY.

Move the responsibility for advancing the NOTIFY queue tail pointer
from the listener(s) to the notification sender, and only have the
sender do it once every few queue pages, rather than after every batch
of notifications as at present.  This reduces the number of times we
execute asyncQueueAdvanceTail, and reduces contention when there are
multiple listeners (since that function requires exclusive lock).
This change relies on the observation that we don't really need the tail
pointer to be exactly up-to-date.  It's certainly not necessary to
attempt to release disk space more often than once per SLRU segment.
The only other usage of the tail pointer is that an incoming listener,
if it's the only listener in its database, will need to scan the queue
forward from the tail; but that's surely a less performance-critical
path than routine sending and receiving of notifies.  We compromise by
advancing the tail pointer after every 4 pages of output, so that it
shouldn't get more than a few pages behind.

Also, when sending signals to other backends after adding notify
message(s) to the queue, recognize that only backends in our own
database are going to care about those messages, so only such
backends really need to be awakened promptly.  Backends in other
databases should get kicked if they're well behind on reading the
queue, else they'll hold back the global tail pointer; but wakening
them for every single message is pointless.  This change can
substantially reduce signal traffic if listeners are spread among
many databases.  It won't help for the common case of only a single
active database, but the extra check costs very little.

Martijn van Oosterhout, with some adjustments by me

Discussion: https://postgr.es/m/CADWG95vtRBFDdrx1JdT1_9nhOFw48KaeTev6F_LtDQAFVpSPhA@mail.gmail.com
Discussion: https://postgr.es/m/CADWG95uFj8rLM52Er80JnhRsTbb_AqPP1ANHS8XQRGbqLrU+jA@mail.gmail.com

4 years agoRemove removed file from nls.mk
Peter Eisentraut [Sat, 21 Sep 2019 21:22:15 +0000 (23:22 +0200)]
Remove removed file from nls.mk

part of revert "Add DECLARE STATEMENT support to ECPG."

4 years agoStraighten out leakproofness markings on text comparison functions.
Tom Lane [Sat, 21 Sep 2019 20:56:30 +0000 (16:56 -0400)]
Straighten out leakproofness markings on text comparison functions.

Since we introduced the idea of leakproof functions, texteq and textne
were marked leakproof but their sibling text comparison functions were
not.  This inconsistency seemed justified because texteq/textne just
relied on memcmp() and so could easily be seen to be leakproof, while
the other comparison functions are far more complex and indeed can
throw input-dependent errors.

However, that argument crashed and burned with the addition of
nondeterministic collations, because now texteq/textne may invoke
the exact same varstr_cmp() infrastructure as the rest.  It makes no
sense whatever to give them different leakproofness markings.

After a certain amount of angst we've concluded that it's all right
to consider varstr_cmp() to be leakproof, mostly because the other
choice would be disastrous for performance of many queries where
leakproofness matters.  The input-dependent errors should only be
reachable for corrupt input data, or so we hope anyway; certainly,
if they are reachable in practice, we've got problems with requirements
as basic as maintaining a btree index on a text column.

Hence, run around to all the SQL functions that derive from varstr_cmp()
and mark them leakproof.  This should result in a useful gain in
flexibility/performance for queries in which non-leakproofness degrades
the efficiency of the query plan.

Back-patch to v12 where nondeterministic collations were added.
While this isn't an essential bug fix given the determination
that varstr_cmp() is leakproof, we might as well apply it now that
we've been forced into a post-beta4 catversion bump.

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

4 years agoFix up handling of nondeterministic collations with pattern_ops opclasses.
Tom Lane [Sat, 21 Sep 2019 20:29:17 +0000 (16:29 -0400)]
Fix up handling of nondeterministic collations with pattern_ops opclasses.

text_pattern_ops and its siblings can't be used with nondeterministic
collations, because they use the text_eq operator which will not behave
as bitwise equality if applied with a nondeterministic collation.  The
initial implementation of that restriction was to insert a run-time test
in the related comparison functions, but that is inefficient, may throw
misleading errors, and will throw errors in some cases that would work.
It seems sufficient to just prevent the combination during CREATE INDEX,
so do that instead.

Lacking any better way to identify the opclasses involved, we need to
hard-wire tests for them, which requires hand-assigned values for their
OIDs, which forces a catversion bump because they previously had OIDs
that would be assigned automatically.  That's slightly annoying in the
v12 branch, but fortunately we're not at rc1 yet, so just do it.

Back-patch to v12 where nondeterministic collations were added.

In passing, run make reformat-dat-files, which found some unrelated
whitespace issues (slightly different ones in HEAD and v12).

Peter Eisentraut, with small corrections by me

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

4 years agoUpdate time zone data files to tzdata release 2019c.
Tom Lane [Fri, 20 Sep 2019 23:53:33 +0000 (19:53 -0400)]
Update time zone data files to tzdata release 2019c.

DST law changes in Fiji and Norfolk Island.  Historical corrections
for Alberta, Austria, Belgium, British Columbia, Cambodia, Hong Kong,
Indiana (Perry County), Kaliningrad, Kentucky, Michigan, Norfolk
Island, South Korea, and Turkey.

4 years agoSplit out code into new getKeyJsonValueFromContainer()
Alvaro Herrera [Fri, 20 Sep 2019 23:18:11 +0000 (20:18 -0300)]
Split out code into new getKeyJsonValueFromContainer()

The new function stashes its output value in a JsonbValue that can be
passed in by the caller, which enables some of them to pass
stack-allocated structs -- saving palloc cycles.  It also allows some
callers that know they are handling a jsonb object to use this new jsonb
object-specific API, instead of going through generic container
findJsonbValueFromContainer.

Author: Nikita Glukhov
Discussion: https://postgr.es/m/7c417f90-f95f-247e-ba63-d95e39c0ad14@postgrespro.ru

4 years agoOptimize get_jsonb_path_all avoiding an iterator
Alvaro Herrera [Fri, 20 Sep 2019 22:18:24 +0000 (19:18 -0300)]
Optimize get_jsonb_path_all avoiding an iterator

Instead of creating an iterator object at each step down the JSONB
object/array, we can just just examine its object/array flags, which is
faster.  Also, use the recently introduced JsonbValueAsText instead of
open-coding the same thing, for code simplicity.

Author: Nikita Glukhov
Discussion: https://postgr.es/m/7c417f90-f95f-247e-ba63-d95e39c0ad14@postgrespro.ru

4 years agoRefactor code into new JsonbValueAsText, and use it more
Alvaro Herrera [Fri, 20 Sep 2019 21:34:31 +0000 (18:34 -0300)]
Refactor code into new JsonbValueAsText, and use it more

jsonb_object_field_text and jsonb_array_element_text both contained
identical copies of this code, so extract that into new routine
JsonbValueAsText.  This can also be used in other places, to measurable
performance benefit: the jsonb_each() and jsonb_array_elements()
functions can use it for outputting text forms instead of their less
efficient current implementation (because we no longer need to build
intermediate a jsonb representation of each value).

Author: Nikita Glukhov
Discussion: https://postgr.es/m/7c417f90-f95f-247e-ba63-d95e39c0ad14@postgrespro.ru

4 years agoFix some minor spec-compliance issues in jsonpath lexer.
Tom Lane [Fri, 20 Sep 2019 18:22:58 +0000 (14:22 -0400)]
Fix some minor spec-compliance issues in jsonpath lexer.

Although the SQL/JSON tech report makes reference to ECMAScript which
allows both single- and double-quoted strings, all the rest of the
report speaks only of double-quoted string literals in jsonpaths.
That's more compatible with JSON itself; moreover single-quoted strings
are hard to use inside a jsonpath that is itself a single-quoted SQL
literal.  So guess that the intent is to allow only double-quoted
literals, and remove lexer support for single-quoted literals.
It'll be less painful to add this again later if we're wrong, than to
remove a shipped feature.

Also, adjust the lexer so that unrecognized backslash sequences are
treated as just meaning the escaped character, not as errors.  This
change has much better support in the standards, as JSON, JavaScript
and ECMAScript all make it plain that that's what's supposed to
happen.

Back-patch to v12.

Discussion: https://postgr.es/m/CAPpHfdvDci4iqNF9fhRkTqhe-5_8HmzeLt56drH%2B_Rv2rNRqfg@mail.gmail.com

4 years agoRevert "Add DECLARE STATEMENT support to ECPG."
Tom Lane [Fri, 20 Sep 2019 16:47:21 +0000 (12:47 -0400)]
Revert "Add DECLARE STATEMENT support to ECPG."

This reverts commit bd7c95f0c1a38becffceb3ea7234d57167f6d4bf,
along with assorted follow-on fixes.  There are some questions
about the definition and implementation of that statement, and
we don't have time to resolve them before v13 release.  Rather
than ship the feature and then have backwards-compatibility
concerns constraining any redesign, let's remove it for now
and try again later.

Discussion: https://postgr.es/m/TY2PR01MB2443EC8286995378AEB7D9F8F5B10@TY2PR01MB2443.jpnprd01.prod.outlook.com

4 years agoFix progress report of REINDEX INDEX
Alvaro Herrera [Fri, 20 Sep 2019 15:53:58 +0000 (12:53 -0300)]
Fix progress report of REINDEX INDEX

I (Álvaro) broke that in commit 6212276e4343 -- forgot to set the
necessary flag.  Repair.

Author: Amit Langote
Discussion: https://postgr.es/m/CA+HiwqEaM2tV5awKhP1vSbgjQe_uXVU15Oi4sTgwgempwMiT8g@mail.gmail.com

4 years agoProvide stable test for NULL-values in KNN SP-GiST
Alexander Korotkov [Fri, 20 Sep 2019 12:31:12 +0000 (15:31 +0300)]
Provide stable test for NULL-values in KNN SP-GiST

f5f084fc3e has removed test because of its instability.  This commit provides
alternative test with determined ordering using extra ORDER BY expression.

Backpatch-through: 12

4 years agoFix typo in commit 82fa3ff8672.
Amit Kapila [Fri, 20 Sep 2019 02:08:06 +0000 (07:38 +0530)]
Fix typo in commit 82fa3ff8672.

Reported-By: Kuntal Ghosh (off-list)
Backpatch-through: 9.4, like 82fa3ff8672

4 years agoRemove unstable KNN SP-GiST test
Alexander Korotkov [Thu, 19 Sep 2019 22:46:49 +0000 (01:46 +0300)]
Remove unstable KNN SP-GiST test

6cae9d2c10 introduced test for NULL values in KNN SP-GiST.  This test relies on
undetermined ordering showing different results on various platforms.  This
commit removes that test.  Will be replaced with better test later.

Discussion: https://postgr.es/m/6d51305e1159241cabee132f7efc7eff%40xs4all.nl
Backpatch-through: 12

4 years agoFix freeing old values in index_store_float8_orderby_distances()
Alexander Korotkov [Thu, 19 Sep 2019 22:10:56 +0000 (01:10 +0300)]
Fix freeing old values in index_store_float8_orderby_distances()

6cae9d2c10 has added an error in freeing old values in
index_store_float8_orderby_distances() function.  It looks for old value in
scan->xs_orderbynulls[i] after setting a new value there.
This commit fixes that.  Also it removes short-circuit in handling
distances == NULL situation.  Now distances == NULL will be treated the same
way as array with all null distances.  That is, previous values will be freed
if any.

Reported-by: Tom Lane, Nikita Glukhov
Discussion: https://postgr.es/m/CAPpHfdu2wcoAVAm3Ek66rP%3Duo_C-D84%2B%2Buf1VEcbyi_caBXWCA%40mail.gmail.com
Discussion: https://postgr.es/m/426580d3-a668-b9d1-7b8e-f74d1a6524e0%40postgrespro.ru
Backpatch-through: 12

4 years agoImprove handling of NULLs in KNN-GiST and KNN-SP-GiST
Alexander Korotkov [Thu, 19 Sep 2019 18:30:19 +0000 (21:30 +0300)]
Improve handling of NULLs in KNN-GiST and KNN-SP-GiST

This commit improves subject in two ways:

 * It removes ugliness of 02f90879e7, which stores distance values and null
   flags in two separate arrays after GISTSearchItem struct.  Instead we pack
   both distance value and null flag in IndexOrderByDistance struct.  Alignment
   overhead should be negligible, because we typically deal with at most few
   "col op const" expressions in ORDER BY clause.
 * It fixes handling of "col op NULL" expression in KNN-SP-GiST.  Now, these
   expression are not passed to support functions, which can't deal with them.
   Instead, NULL result is implicitly assumed.  It future we may decide to
   teach support functions to deal with NULL arguments, but current solution is
   bugfix suitable for backpatch.

Reported-by: Nikita Glukhov
Discussion: https://postgr.es/m/826f57ee-afc7-8977-c44c-6111d18b02ec%40postgrespro.ru
Author: Nikita Glukhov
Reviewed-by: Alexander Korotkov
Backpatch-through: 9.4

4 years agoDoc: improve documentation around jsonpath regular expressions.
Tom Lane [Thu, 19 Sep 2019 15:22:21 +0000 (11:22 -0400)]
Doc: improve documentation around jsonpath regular expressions.

Provide some documentation about the differences between XQuery
regular expressions and those supported by Spencer's regex engine.
Since SQL now exposes XQuery regexps with the LIKE_REGEX operator,
I made this a standalone section designed to help somebody who
has to translate a LIKE_REGEX query to Postgres.  (Eventually we might
extend Spencer's engine to allow precise implementation of XQuery,
but not today.)

Reference that in the jsonpath docs, provide definitions of the
XQuery flag letters, and add a description of the JavaScript-inspired
string literal syntax used within jsonpath.  Also point out explicitly
that backslashes used within like_regex patterns will need to be doubled.

This also syncs the docs with the decision implemented in commit
d5b90cd64 to desupport XQuery's 'x' flag for now.

Jonathan Katz and Tom Lane

Discussion: https://postgr.es/m/CAPpHfdvDci4iqNF9fhRkTqhe-5_8HmzeLt56drH%2B_Rv2rNRqfg@mail.gmail.com

4 years agoGSSAPI error message improvements
Peter Eisentraut [Thu, 19 Sep 2019 13:03:23 +0000 (15:03 +0200)]
GSSAPI error message improvements

Make the error messages around GSSAPI encryption a bit clearer.  Tweak
some messages to avoid plural problems.

Also make a code change for clarity.  Using "conf" for "confidential"
is quite confusing.  Using "conf_state" is perhaps not much better but
that's what the GSSAPI documentation uses, so there is at least some
hope of understanding it.

4 years agoFix typo in commit 578b229718.
Amit Kapila [Thu, 19 Sep 2019 09:10:09 +0000 (14:40 +0530)]
Fix typo in commit 578b229718.

Reported-by: Filip Rembiałkowski
Author: Filip Rembiałkowski
Backpatch-through: 12, where it was introduced
Discussion: https://postgr.es/m/CAP_rwwmSNy1=_82rwGe3-X4PjWqPSFXtzNf43DCtGzD7SazdXA@mail.gmail.com

4 years agoRevert change of ecpglib major version
Peter Eisentraut [Thu, 19 Sep 2019 07:02:41 +0000 (09:02 +0200)]
Revert change of ecpglib major version

The major version of ecpglib was changed in
bd7c95f0c1a38becffceb3ea7234d57167f6d4bf, apparently without
justification.  Revert this, since nothing has changed in this library
except some added functions.

Discussion: https://www.postgresql.org/message-id/flat/48ee4c56-e1df-b39d-2cad-c7d80b120eb5%402ndquadrant.com

4 years agoDoc: Fix incorrect mention to connection_object in CONNECT command of ECPG
Michael Paquier [Thu, 19 Sep 2019 04:18:53 +0000 (13:18 +0900)]
Doc: Fix incorrect mention to connection_object in CONNECT command of ECPG

This fixes an inconsistency with this parameter name not listed in the
command synopsis, and connection_name is the parameter name more
commonly used in the docs for ECPG commands.

Reported-by: Yusuke Egashita
Discussion: https://postgr.es/m/156870956796.1259.11456186889345212399@wrigleys.postgresql.org
Backpatch-through: 9.4

4 years agoDoc: document autovacuum interruption.
Amit Kapila [Thu, 19 Sep 2019 02:32:12 +0000 (08:02 +0530)]
Doc: document autovacuum interruption.

It's important users be able to know (without looking at the source code)
that running DDL or DDL-like commands can interrupt autovacuum which can
lead to a lot of dead tuples and hence slower database operations.

Reported-by: James Coleman
Author: James Coleman
Reviewed-by: Amit Kapila
Backpatch-through: 9.4
Discussion: https://postgr.es/m/CAAaqYe-XYyNwML1=f=gnd0qWg46PnvD=BDrCZ5-L94B887XVxQ@mail.gmail.com

4 years agoRedesign pageinspect function printing infomask bits
Michael Paquier [Thu, 19 Sep 2019 02:01:52 +0000 (11:01 +0900)]
Redesign pageinspect function printing infomask bits

After more discussion, the new function added by ddbd5d8 could have been
designed in a better way.  Based on an idea from Álvaro, instead of
returning one column which includes both the raw and combined flags, use
two columns, with one for the raw flags and one for the combined flags.

This also takes care of some issues with HEAP_LOCKED_UPGRADED and
HEAP_XMAX_IS_LOCKED_ONLY which are not really combined flags as they
depend on conditions defined by other raw bits, as mentioned by Amit.

While on it, fix an extra issue with combined flags.  A combined flag
was returned if at least one of its bits was set, but all its bits need
to be set to include it in the result.

Author: Michael Paquier
Reviewed-by: Álvaro Herrera, Amit Kapila
Discussion: https://postgr.es/m/20190913114950.GA3824@alvherre.pgsql

4 years agoFix example program in docs too (??)
Alvaro Herrera [Wed, 18 Sep 2019 19:50:20 +0000 (16:50 -0300)]
Fix example program in docs too (??)

Fixup for previous commit: actually, the complete source for
testlibpq3.c appears in SGML docs, so we need to patch that also.
Go figure.

4 years agoFix testlibpq3
Alvaro Herrera [Wed, 18 Sep 2019 19:29:55 +0000 (16:29 -0300)]
Fix testlibpq3

The sample output assumes non-standard-conforming interpretation of
backslashes in input literals, so the actual output didn't match.

Noticed while perusing another patch that touches this file.

Evidently this code is seldom checked, so I'm not going to bother
backpatching this fix.

4 years agopg_upgrade/test.sh: Quote sed(1) argument
Alvaro Herrera [Wed, 18 Sep 2019 14:24:12 +0000 (11:24 -0300)]
pg_upgrade/test.sh: Quote sed(1) argument

Lack of quotes results in failure to run the test under older Solaris.

Author: Marina Polyakova, Victor Wagner
Discussion: https://postgr.es/m/feba89f89e8925b3535cb7d72b9e05e1@postgrespro.ru

4 years agoRemove unused smgrdounlinkfork() function.
Fujii Masao [Wed, 18 Sep 2019 12:05:33 +0000 (21:05 +0900)]
Remove unused smgrdounlinkfork() function.

smgrdounlinkfork() became dead code as the result of commit ece01aae47,
but it was left in place just in case we want it someday. However no users
have appeared in 7 years, so it's time to remove this unused function.

Author: Kirk Jamison
Discussion: https://www.postgresql.org/message-id/D09B13F772D2274BB348A310EE3027C64E2067@g01jpexmbkw24

4 years agoDoc: Update FDW documentation about direct foreign table modification.
Etsuro Fujita [Wed, 18 Sep 2019 09:50:00 +0000 (18:50 +0900)]
Doc: Update FDW documentation about direct foreign table modification.

1. Commit 7086be6e3 should have documented the limitation that the direct
   modification is disabled when WCO constraints are present, but didn't,
   which is definitely my fault.  Update the documentation (Postgres 9.6
   onwards).

2. Commit fc22b6623 should have documented the limitation that the direct
   modification is disabled when generated columns are defined, but
   didn't.  Update the documentation (Postgres 12 onwards).

Author: Etsuro Fujita
Discussion: https://postgr.es/m/CAPmGK14AYCPunLb6TRz1CQsW5Le01Z2ox8LSOKH0P-cOVDcQRA%40mail.gmail.com

4 years agoAdd some const decorations to array constants
Peter Eisentraut [Tue, 17 Sep 2019 20:03:00 +0000 (22:03 +0200)]
Add some const decorations to array constants

Author: Mark G <markg735@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAEeOP_YFVeFjq4zDZLDQbLSRFxBiTpwBQHxCNgGd%2Bp5VztTXyQ%40mail.gmail.com

4 years agoFix bogus handling of XQuery regex option flags.
Tom Lane [Tue, 17 Sep 2019 19:39:51 +0000 (15:39 -0400)]
Fix bogus handling of XQuery regex option flags.

The SQL spec defers to XQuery to define what the option flags are
for LIKE_REGEX patterns.  XQuery says that:
* 's' allows the dot character to match newlines, which by
  default it will not;
* 'm' allows ^ and $ to match at newlines, not only at the
  start/end of the whole string.
Thus, these are *not* inverses as they are for the similarly-named
POSIX options, and neither one corresponds to the POSIX 'n' option.
Fortunately, Spencer's library does expose these two behaviors as
separately twiddlable flags, so we just have to fix the mapping from
JSP flag bits to REG flag bits.  I also chose to rename the symbol
for 's' to DOTALL, to make it clearer that it's not the inverse
of MLINE.

Also, XQuery says that if the 'q' flag "is used together with the m, s,
or x flag, that flag has no effect".  I read this as saying that 'q'
overrides the other flags; whoever wrote our code seems to have read
it backwards.

Lastly, while XQuery's 'x' flag is related to what Spencer's code
does for REG_EXPANDED, it's not the same or a subset.  It seems best
to treat XQuery's 'x' as unimplemented for now.  Maybe later we can
expand our regex code to offer 'x'-style parsing as a separate option.

While at it, refactor the jsonpath code so that (a) there's only
one copy of the flag transformation logic not two, and (b) the
processing of flags is independent of the order in which the flags
are written.

We need some documentation updates to go with this, but I'll
tackle that separately.

Back-patch to v12 where this code originated.

Discussion: https://postgr.es/m/CAPpHfdvDci4iqNF9fhRkTqhe-5_8HmzeLt56drH%2B_Rv2rNRqfg@mail.gmail.com
Reference: https://www.w3.org/TR/2017/REC-xpath-functions-31-20170321/#flags

4 years agoRemove mingwcompat.c
Peter Eisentraut [Tue, 17 Sep 2019 09:32:33 +0000 (11:32 +0200)]
Remove mingwcompat.c

We believe that the issues that this was working around have been
fixed in MinGW more than 5 years ago, so this isn't necessary anymore.

Discussion: https://www.postgresql.org/message-id/flat/20190719050830.GK1859%40paquier.xyz

4 years agoSupport for SSSSS datetime format pattern
Alexander Korotkov [Mon, 16 Sep 2019 18:02:32 +0000 (21:02 +0300)]
Support for SSSSS datetime format pattern

SQL Standard 2016 defines SSSSS format pattern for seconds past midnight in
jsonpath .datetime() method and CAST (... FORMAT ...) SQL clause.  In our
datetime parsing engine we currently support it with SSSS name.

This commit adds SSSSS as an alias for SSSS.  Alias is added in favor of
upcoming jsonpath .datetime() method.  But it's also supported in to_date()/
to_timestamp() as positive side effect.

Discussion: https://postgr.es/m/CAPpHfdsZgYEra_PeCLGNoXOWYx6iU-S3wF8aX0ObQUcZU%2B4XTw%40mail.gmail.com
Author: Nikita Glukhov, Alexander Korotkov
Reviewed-by: Anastasia Lubennikova, Peter Eisentraut
4 years agoSupport for FF1-FF6 datetime format patterns
Alexander Korotkov [Mon, 16 Sep 2019 18:02:14 +0000 (21:02 +0300)]
Support for FF1-FF6 datetime format patterns

SQL Standard 2016 defines FF1-FF9 format patters for fractions of seconds in
jsonpath .datetime() method and CAST (... FORMAT ...) SQL clause.  Parsing
engine of upcoming .datetime() method will be shared with to_date()/
to_timestamp().

This patch implements FF1-FF6 format patterns for upcoming jsonpath .datetime()
method.  to_date()/to_timestamp() functions will also get support of this
format patterns as positive side effect.  FF7-FF9 are not supported due to
lack of precision in our internal timestamp representation.

Extracted from original patch by Nikita Glukhov, Teodor Sigaev, Oleg Bartunov.
Heavily revised by me.

Discussion: https://postgr.es/m/fcc6fc6a-b497-f39a-923d-aa34d0c588e8%402ndQuadrant.com
Discussion: https://postgr.es/m/CAPpHfdsZgYEra_PeCLGNoXOWYx6iU-S3wF8aX0ObQUcZU%2B4XTw%40mail.gmail.com
Author: Nikita Glukhov, Teodor Sigaev, Oleg Bartunov, Alexander Korotkov
Reviewed-by: Anastasia Lubennikova, Peter Eisentraut
4 years agoFix bogus sizeof calculations.
Tom Lane [Sun, 15 Sep 2019 15:51:57 +0000 (11:51 -0400)]
Fix bogus sizeof calculations.

Noted by Coverity.  Typo in 27cc7cd2b, so back-patch to v12
as that was.

4 years agoFix intermittent self-test failures caused by the stats_ext test.
Dean Rasheed [Sun, 15 Sep 2019 12:13:59 +0000 (13:13 +0100)]
Fix intermittent self-test failures caused by the stats_ext test.

Commit d7f8d26d9 added new tests to the stats_ext regression test that
included creating a view in the public schema, without realising that
the stats_ext test runs in the same parallel group as the rules test,
which makes doing that unsafe.

This led to intermittent failures of the rules test on the buildfarm,
although I wasn't able to reproduce that locally. Fix by creating the
view in a different schema.

Tomas Vondra and Dean Rasheed, report and diagnosis by Thomas Munro.

Discussion: https://postgr.es/m/CA+hUKGKX9hFZrYA7rQzAMRE07L4hziCc-nO_b3taJpiuKyLLxg@mail.gmail.com

4 years agoRevert "For all ppc compilers, implement pg_atomic_fetch_add_ with inline asm."
Noah Misch [Sun, 15 Sep 2019 02:38:41 +0000 (19:38 -0700)]
Revert "For all ppc compilers, implement pg_atomic_fetch_add_ with inline asm."

This reverts commit e7ff59686eacf5021fb84be921116986c3828d8a.  It
defined pg_atomic_fetch_add_u32_impl() without defining
pg_atomic_compare_exchange_u32_impl(), which is incompatible with
src/include/port/atomics/fallback.h.  Per buildfarm member prairiedog.

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

4 years agoFor all ppc compilers, implement pg_atomic_fetch_add_ with inline asm.
Noah Misch [Sat, 14 Sep 2019 02:34:30 +0000 (19:34 -0700)]
For all ppc compilers, implement pg_atomic_fetch_add_ with inline asm.

This is more like how we handle s_lock.h and arch-x86.h.  This does not
materially affect code generation for gcc 7.2.0 or xlc 13.1.3.

Reviewed by Tom Lane.

Discussion: https://postgr.es/m/20190831071157.GA3251746@rfd.leadboat.com

4 years agoReplace xlc __fetch_and_add() with inline asm.
Noah Misch [Sat, 14 Sep 2019 02:34:06 +0000 (19:34 -0700)]
Replace xlc __fetch_and_add() with inline asm.

PostgreSQL has been unusable when built with xlc 13 and newer, which are
incompatible with our use of __fetch_and_add().  Back-patch to 9.5,
which introduced pg_atomic_fetch_add_u32().

Reviewed by Tom Lane.

Discussion: https://postgr.es/m/20190831071157.GA3251746@rfd.leadboat.com

4 years agoTest pg_atomic_fetch_add_ with variable addend and 16-bit edge cases.
Noah Misch [Sat, 14 Sep 2019 02:33:30 +0000 (19:33 -0700)]
Test pg_atomic_fetch_add_ with variable addend and 16-bit edge cases.

Back-patch to 9.5, which introduced these functions.

Reviewed by Tom Lane.

Discussion: https://postgr.es/m/20190831071157.GA3251746@rfd.leadboat.com

4 years agoMake tuplesort_set_bound() assertions more comprehensible, hopefully.
Tom Lane [Fri, 13 Sep 2019 20:56:58 +0000 (16:56 -0400)]
Make tuplesort_set_bound() assertions more comprehensible, hopefully.

Add the comments that I griped were missing.  Also re-order tests
so that parallelism-related tests aren't randomly separated from
each other.

Discussion: https://postgr.es/m/CAAaqYe9GD__4Crm=ddz+-XXcNhfY_V5gFYdLdmkFNq=2VHO56Q@mail.gmail.com

4 years agological decoding: process ASSIGNMENT during snapshot build
Alvaro Herrera [Fri, 13 Sep 2019 19:36:28 +0000 (16:36 -0300)]
logical decoding: process ASSIGNMENT during snapshot build

Most WAL records are ignored in early SnapBuild snapshot build phases.
But it's critical to process some of them, so that later messages have
the correct transaction state after the snapshot is completely built; in
particular, XLOG_XACT_ASSIGNMENT messages are critical in order for
sub-transactions to be correctly assigned to their parent transactions,
or at least one assert misbehaves, as reported by Ildar Musin.

Diagnosed-by: Masahiko Sawada
Author: Masahiko Sawada
Discussion: https://postgr.es/m/CAONYFtOv+Er1p3WAuwUsy1zsCFrSYvpHLhapC_fMD-zNaRWxYg@mail.gmail.com

4 years agoFix under-parenthesized macro definitions
Alvaro Herrera [Fri, 13 Sep 2019 19:26:55 +0000 (16:26 -0300)]
Fix under-parenthesized macro definitions

Lack of parens in the definitions could cause a statement using these
macros to have unexpected semantics.  In current code no bug is
apparent, but best to fix the definitions to avoid problems down the
line.

Reported-by: Tom Lane
Discussion: https://postgr.es/m/19795.1568400476@sss.pgh.pa.us

4 years agoFix progress reporting of CLUSTER / VACUUM FULL
Alvaro Herrera [Fri, 13 Sep 2019 17:51:13 +0000 (14:51 -0300)]
Fix progress reporting of CLUSTER / VACUUM FULL

The progress state was being clobbered once the first index completed
being rebuilt, causing the final phases of the operation not show
anything in the progress view.  This was inadvertently broken in
03f9e5cba0ee, which added progress tracking for REINDEX.

(The reason this bugfix is this small is that I had already noticed this
problem when writing monitoring for CREATE INDEX, and had already worked
around it, as can be seen in discussion starting at
https://postgr.es/m/20190329150218.GA25010@alvherre.pgsql Fixing the
problem is just a matter of fixing one place touched by the REINDEX
monitoring.)

Reported by: Álvaro Herrera
Author: Álvaro Herrera
Discussion: https://postgr.es/m/20190801184333.GA21369@alvherre.pgsql

4 years agoTypo fixes for documentation
Alexander Korotkov [Fri, 13 Sep 2019 14:21:20 +0000 (17:21 +0300)]
Typo fixes for documentation

Discussion: https://postgr.es/m/CAEkD-mDUZrRE%3Dk-FznEg4Ed2VdjpZCyHoyo%2Bp0%2B8KvHqR%3DpNVQ%40mail.gmail.com
Author: Liudmila Mantrova, Alexander Lakhin
Reviewed-by: Alexander Korotkov, Alvaro Herrera
Backpatch-through: 12

4 years agoDocumentation improvements to jsonpath
Alexander Korotkov [Fri, 13 Sep 2019 14:12:20 +0000 (17:12 +0300)]
Documentation improvements to jsonpath

Besides cosmetic improvements it removes statement that operators necessary
need to be separated from operands with spaces, which is not really true.

Discussion: https://postgr.es/m/CAEkD-mDUZrRE%3Dk-FznEg4Ed2VdjpZCyHoyo%2Bp0%2B8KvHqR%3DpNVQ%40mail.gmail.com
Author: Liudmila Mantrova, Alexander Lakhin
Reviewed-by: Alexander Korotkov, Alvaro Herrera
Backpatch-through: 12

4 years agoAdd tab completion for CREATE OR REPLACE in psql.
Fujii Masao [Fri, 13 Sep 2019 09:16:40 +0000 (18:16 +0900)]
Add tab completion for CREATE OR REPLACE in psql.

Author: Shenhao Wang
Discussion: https://postgr.es/m/63580B24E208E3429D94153A03C68E0901AA8002D5@G08CNEXMBPEKD02.g08.fujitsu.local

4 years agoFix nbtree page split rmgr desc routine.
Peter Geoghegan [Thu, 12 Sep 2019 22:45:08 +0000 (15:45 -0700)]
Fix nbtree page split rmgr desc routine.

Include newitemoff in rmgr desc output for nbtree page split records.
In passing, correct an obsolete comment that claimed that newitemoff is
only logged for _L variant nbtree page split WAL records.

Both issues were oversights in commit 2c03216d831, which revamped the
WAL format.

Author: Peter Geoghegan
Backpatch: 9.5-, where the WAL format was revamped.

4 years agoFix usage of whole-row variables in WCO and RLS policy expressions.
Tom Lane [Thu, 12 Sep 2019 22:29:17 +0000 (18:29 -0400)]
Fix usage of whole-row variables in WCO and RLS policy expressions.

Since WITH CHECK OPTION was introduced, ExecInitModifyTable has
initialized WCO expressions with the wrong plan node as parent -- that is,
it passed its input subplan not the ModifyTable node itself.  Up to now
we thought this was harmless, but bug #16006 from Vinay Banakar shows it's
not: if the input node is a SubqueryScan then ExecInitWholeRowVar can get
confused into doing the wrong thing.  (The fact that ExecInitWholeRowVar
contains such logic is certainly a horrid kluge that doesn't deserve to
live, but figuring out another way to do that is a task for some other day.)

Andres had already noticed the wrong-parent mistake and fixed it in commit
148e632c0, but not being aware of any user-visible consequences, he quite
reasonably didn't back-patch.  This patch is simply a back-patch of
148e632c0, plus addition of a test case based on bug #16006.  I also added
the test case to v12/HEAD, even though the bug is already fixed there.

Back-patch to all supported branches.  9.4 lacks RLS policies so the
new test case doesn't work there, but I'm pretty sure a test could be
devised based on using a whole-row Var in a plain WITH CHECK OPTION
condition.  (I lack the cycles to do so myself, though.)

Andres Freund and Tom Lane

Discussion: https://postgr.es/m/16006-99290d2e4642cbd5@postgresql.org
Discussion: https://postgr.es/m/20181205225213.hiwa3kgoxeybqcqv@alap3.anarazel.de

4 years agoReorder two nbtree.h function prototypes.
Peter Geoghegan [Thu, 12 Sep 2019 16:59:16 +0000 (09:59 -0700)]
Reorder two nbtree.h function prototypes.

Make the function prototype order consistent with the definition order
in nbtinsert.c.

4 years agoRemove redundant _bt_truncate() comment paragraph.
Peter Geoghegan [Thu, 12 Sep 2019 16:51:27 +0000 (09:51 -0700)]
Remove redundant _bt_truncate() comment paragraph.

4 years agoMerge two assertions to make comment clearer
Alvaro Herrera [Thu, 12 Sep 2019 13:34:50 +0000 (10:34 -0300)]
Merge two assertions to make comment clearer

Authored by Tom Lane, after a gripe from James Coleman.

Discussion: https://postgr.es/m/CAAaqYe9GD__4Crm=ddz+-XXcNhfY_V5gFYdLdmkFNq=2VHO56Q@mail.gmail.com

4 years agoDoc: Update PL/pgSQL sample function in plpgsql.sgml.
Amit Kapila [Wed, 11 Sep 2019 04:55:49 +0000 (10:25 +0530)]
Doc: Update PL/pgSQL sample function in plpgsql.sgml.

The example used to explain 'Looping Through Query Results' uses
pseudo-materialized views.  Replace it with a more up-to-date example
which does the same thing with actual materialized views, which have
been available since PostgreSQL 9.3.

In the passing, change '%' as format specifier instead of '%s' as is used
in other examples in plpgsql.sgml.

Reported-by: Ian Barwick
Author: Ian Barwick
Reviewed-by: Amit Kapila
Backpatch-through: 9.4
Discussion: https://postgr.es/m/9a70d393-7904-4918-c97c-649f6d114b6a@2ndquadrant.com

4 years agoAdd to pageinspect function to make t_infomask/t_infomask2 human-readable
Michael Paquier [Thu, 12 Sep 2019 06:06:00 +0000 (15:06 +0900)]
Add to pageinspect function to make t_infomask/t_infomask2 human-readable

Flags of t_infomask and t_infomask2 for each tuple are already included
in the information returned by heap_page_items as integers, and we
lacked a way to make that information human-readable.

Per discussion, the function includes an option which controls if
combined flags should be decomposed or not.  The default is false, to
not decompose combined flags.

The module is bumped to version 1.8.

Author: Craig Ringer, Sawada Masahiko
Reviewed-by: Peter Geoghegan, Robert Haas, Álvaro Herrera, Moon Insung,
Amit Kapila, Michael Paquier, Tomas Vondra
Discussion: https://postgr.es/m/CAMsr+YEY7jeaXOb+oX+RhDyOFuTMdmHjGsBxL=igCm03J0go9Q@mail.gmail.com

4 years agoImprove coverage of psql for backslash commands with \if and \elif
Michael Paquier [Thu, 12 Sep 2019 01:35:13 +0000 (10:35 +0900)]
Improve coverage of psql for backslash commands with \if and \elif

This adds tests to cover more code paths to ignore backslash commands in
false branches when using \if|\elif|\else, and improves the coverage of
\elif.

Author: Fabien Coelho
Discussion: https://postgr.es/m/alpine.DEB.2.21.1908281618520.28828@lancre

5 years agoRearrange postmaster's startup sequence for better syslogger results.
Tom Lane [Wed, 11 Sep 2019 15:43:01 +0000 (11:43 -0400)]
Rearrange postmaster's startup sequence for better syslogger results.

This is a second try at what commit 57431a911 tried to do, namely,
launch the syslogger before we open postmaster sockets so that our
messages about the sockets end up in the syslogger files.  That
commit fell foul of a bunch of subtle issues caused by trying to
launch a postmaster child process before creating shared memory.
Rather than messing with that interaction, let's postpone opening
the sockets till after we launch the syslogger.

This would not have been terribly safe before commit 7de19fbc0,
because we relied on socket opening to detect whether any competing
postmasters were using the same port number.  But now that we choose
IPC keys without regard to the port number, there's no interaction
to worry about.

Also delay creation of the external PID file (if requested) till after
the sockets are open, since external code could plausibly be relying
on that ordering of events.  And postpone most of the work of
RemovePgTempFiles() so that that potentially-slow processing still
happens after we make the external PID file.  We have to be a bit
careful about that last though: as noted in the discussion subsequent to
bug #15804, EXEC_BACKEND builds still have to clear the parameter-file
temp dir before launching the syslogger.

Patch by me; thanks to Michael Paquier for review/testing.

Discussion: https://postgr.es/m/15804-3721117bf40fb654@postgresql.org

5 years agolibpq docs: be clearer about conninfo's 'hostaddr'
Alvaro Herrera [Wed, 11 Sep 2019 13:15:23 +0000 (10:15 -0300)]
libpq docs: be clearer about conninfo's 'hostaddr'

The previous wording was a bit too terse, too vague on the subject of
'host' and 'hostaddr' in connection specifications, which has caused
people to waste time trying to conform to rules because of
misunderstanding the whole thing; this small change should make things
clearer.

Author: Robert Haas, stemming from Fabien Coelho's complaints
Discussion: https://postgr.es/m/alpine.DEB.2.21.1808201323020.13832@lancre

5 years agoFix comment in psql's describe.c
Michael Paquier [Wed, 11 Sep 2019 06:17:35 +0000 (15:17 +0900)]
Fix comment in psql's describe.c

Procedures are supported since v11 and \dfp can be used since this
version, but it was not mentioned as a supported option in the
description of describeFunctions() which handles \df in psql.

Extracted from a larger patch.

Author: Fabien Coelho
Discussion: https://postgr.es/m/alpine.DEB.2.21.1908281618520.28828@lancre

5 years agoExpand properly list of TAP tests used for prove in vcregress.pl
Michael Paquier [Wed, 11 Sep 2019 02:07:18 +0000 (11:07 +0900)]
Expand properly list of TAP tests used for prove in vcregress.pl

Depending on the system used, t/*.pl may not be expanded into a list of
tests which can be consumed by prove when attempting to run TAP tests on
a given path.  Fix that by using glob() directly in the script, to make
sure that a complete list of tests is provided.  This has not proved to
be an issue with MSVC as the list was properly expanded, but it is on
Linux with perl's system().

This is extracted from a larger patch.

Author: Tom Lane
Discussion: https://postgr.es/m/6628.1567958876@sss.pgh.pa.us
Backpatch-through: 9.4

5 years agoAllow setting statistics target for extended statistics
Tomas Vondra [Tue, 10 Sep 2019 18:09:27 +0000 (20:09 +0200)]
Allow setting statistics target for extended statistics

When building statistics, we need to decide how many rows to sample and
how accurate the resulting statistics should be. Until now, it was not
possible to explicitly define statistics target for extended statistics
objects, the value was always computed from the per-attribute targets
with a fallback to the system-wide default statistics target.

That's a bit inconvenient, as it ties together the statistics target set
for per-column and extended statistics. In some cases it may be useful
to require larger sample / higher accuracy for extended statics (or the
other way around), but with this approach that's not possible.

So this commit introduces a new command, allowing to specify statistics
target for individual extended statistics objects, overriding the value
derived from per-attribute targets (and the system default).

  ALTER STATISTICS stat_name SET STATISTICS target_value;

When determining statistics target for an extended statistics object we
first look at this explicitly set value. When this value is -1, we fall
back to the old formula, looking at the per-attribute targets first and
then the system default. This means the behavior is backwards compatible
with older PostgreSQL releases.

Author: Tomas Vondra
Discussion: https://postgr.es/m/20190618213357.vli3i23vpkset2xd@development
Reviewed-by: Kirk Jamison, Dean Rasheed
5 years agoReduce overhead of scanning the backend[] array in LISTEN/NOTIFY.
Tom Lane [Tue, 10 Sep 2019 22:15:17 +0000 (18:15 -0400)]
Reduce overhead of scanning the backend[] array in LISTEN/NOTIFY.

Up to now, async.c scanned its whole array of per-backend state
whenever it needed to find listening backends.  That's expensive
if MaxBackends is large, so extend the data structure with list
links that thread the active entries together.

A downside of this change is that asyncQueueUnregister (unregister
a listening backend at backend exit) now requires exclusive not shared
lock, and it can take awhile if there are many other listening
backends.  We could improve the latter issue by using a doubly- not
singly-linked list, but it's probably not worth the storage space;
typical usage patterns for LISTEN/NOTIFY have fairly long-lived
listeners.

In return for that, Exec_ListenPreCommit (initially register a
listening backend), SignalBackends, and asyncQueueAdvanceTail
get significantly faster when MaxBackends is much larger than
the number of listening backends.  If most of the potential
backend slots are listening, we don't win, but that's a case
where the actual interprocess-signal overhead is going to swamp
these considerations anyway.

Martijn van Oosterhout, hacked a bit more by me

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

5 years agoFix unaccent generation script in Windows
Alvaro Herrera [Tue, 10 Sep 2019 20:56:11 +0000 (17:56 -0300)]
Fix unaccent generation script in Windows

As originally coded, the script would fail on Windows 10 and Python 3
because stdout would not be switched to UTF-8 only for Python 2.  This
patch makes that apply to both versions.

Also add python 2 compatibility markers so that we know what to remove
once we drop support for that.  Also use a "with" clause to ensure file
descriptor is closed promptly.

Author: Hugh Ranalli, Ramanarayana
Reviewed-by: Kyotaro Horiguchi
Discussion: https://postgr.es/m/CAKm4Xs7_61XMyOWmHs3n0mmkS0O4S0pvfWk=7cQ5P0gs177f7A@mail.gmail.com
Discussion: https://postgr.es/m/15548-cef1b3f8de190d4f@postgresql.org

5 years agoRestructure libpq code to remove some duplicity
Alvaro Herrera [Tue, 10 Sep 2019 15:13:29 +0000 (12:13 -0300)]
Restructure libpq code to remove some duplicity

There was some duplicate code to run SHOW transaction_read_only to
determine whether the server is read-write or read-only.  Reduce it by
adding another state to the state machine.

Author: Hari Babu Kommi
Reviewed-by: Takayuki Tsunakawa, Álvaro Herrera
Discussion: https://postgr.es/m/CAJrrPGe_qgdbbN+yBgEVpd+YLHXXjTruzk6RmTMhqrFig+32ag@mail.gmail.com

5 years agoAdd _bt_binsrch() scantid assertion to nbtree.
Peter Geoghegan [Mon, 9 Sep 2019 18:41:19 +0000 (11:41 -0700)]
Add _bt_binsrch() scantid assertion to nbtree.

Assert that _bt_binsrch() binary searches with scantid set in insertion
scankey cannot be performed on leaf pages.  Leaf-level binary searches
where scantid is set must use _bt_binsrch_insert() instead.

_bt_binsrch_insert() is likely to have additional responsibilities in
the future, such as searching within GIN-style posting lists using
scantid.  It seems like a good idea to tighten things up now.

5 years agoBe more careful about port selection in src/test/ldap/.
Tom Lane [Mon, 9 Sep 2019 18:21:40 +0000 (14:21 -0400)]
Be more careful about port selection in src/test/ldap/.

Don't just assume that the next port is free; it might not be, or
if we're really unlucky it might even be out of the TCP range.
Do it honestly with two get_free_port() calls instead.

This is surely a pretty low-probability problem, but I think it
explains a buildfarm failure seen today, so let's fix it.

Back-patch to v11 where this script was added.

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

5 years agoPrevent msys2 conversion of "cmd /c" switch to a file path
Andrew Dunstan [Mon, 9 Sep 2019 12:56:33 +0000 (08:56 -0400)]
Prevent msys2 conversion of "cmd /c" switch to a file path

Modern versions of msys2 have changed the treatment of "cmd /c" so that
the runtime will try to convert the switch to a native file path. This
patch adds a setting to inhibit that behaviour.

Discussion: https://postgr.es/m/3227042f-cfcc-745a-57dd-fb8c471f8ddf@2ndQuadrant.com

Backpatch to all live branches.

5 years agoReorder EPQ work, to fix rowmark related bugs and improve efficiency.
Andres Freund [Thu, 5 Sep 2019 20:00:20 +0000 (13:00 -0700)]
Reorder EPQ work, to fix rowmark related bugs and improve efficiency.

In ad0bda5d24ea I changed the EvalPlanQual machinery to store
substitution tuples in slot, instead of using plain HeapTuples. The
main motivation for that was that using HeapTuples will be inefficient
for future tableams.  But it turns out that that conversion was buggy
for non-locking rowmarks - the wrong tuple descriptor was used to
create the slot.

As a secondary issue 5db6df0c0 changed ExecLockRows() to begin EPQ
earlier, to allow to fetch the locked rows directly into the EPQ
slots, instead of having to copy tuples around. Unfortunately, as Tom
complained, that forces some expensive initialization to happen
earlier.

As a third issue, the test coverage for EPQ was clearly insufficient.

Fixing the first issue is unfortunately not trivial: Non-locked row
marks were fetched at the start of EPQ, and we don't have the type
information for the rowmarks available at that point. While we could
change that, it's not easy. It might be worthwhile to change that at
some point, but to fix this bug, it seems better to delay fetching
non-locking rowmarks when they're actually needed, rather than
eagerly. They're referenced at most once, and in cases where EPQ
fails, might never be referenced. Fetching them when needed also
increases locality a bit.

To be able to fetch rowmarks during execution, rather than
initialization, we need to be able to access the active EPQState, as
that contains necessary data. To do so move EPQ related data from
EState to EPQState, and, only for EStates creates as part of EPQ,
reference the associated EPQState from EState.

To fix the second issue, change EPQ initialization to allow use of
EvalPlanQualSlot() to be used before EvalPlanQualBegin() (but
obviously still requiring EvalPlanQualInit() to have been done).

As these changes made struct EState harder to understand, e.g. by
adding multiple EStates, significantly reorder the members, and add a
lot more comments.

Also add a few more EPQ tests, including one that fails for the first
issue above. More is needed.

Reported-By: yi huang
Author: Andres Freund
Reviewed-By: Tom Lane
Discussion:
    https://postgr.es/m/CAHU7rYZo_C4ULsAx_LAj8az9zqgrD8WDd4hTegDTMM1LMqrBsg@mail.gmail.com
    https://postgr.es/m/24530.1562686693@sss.pgh.pa.us
Backpatch: 12-, where the EPQ changes were introduced

5 years agoFix handling of non-key columns get_index_column_opclass()
Alexander Korotkov [Mon, 9 Sep 2019 10:50:12 +0000 (13:50 +0300)]
Fix handling of non-key columns get_index_column_opclass()

f2e40380 introduces support of non-key attributes in GiST indexes.  Then if
get_index_column_opclass() is asked by gistproperty() to get an opclass of
non-key column, it returns garbage past oidvector value.  This commit fixes
that by making get_index_column_opclass() return InvalidOid in this case.

Discussion: https://postgr.es/m/20190902231948.GA5343%40alvherre.pgsql
Author: Nikita Glukhov, Alexander Korotkov
Backpatch-through: 12

5 years agoImprove new AND CHAIN tests
Peter Eisentraut [Mon, 9 Sep 2019 08:30:22 +0000 (10:30 +0200)]
Improve new AND CHAIN tests

Tweak the tests so that we're not just testing the default setting of
transaction_read_only.

Reported-by: fn ln <emuser20140816@gmail.com>
5 years agoFix RelationIdGetRelation calls that weren't bothering with error checks.
Tom Lane [Sun, 8 Sep 2019 21:00:29 +0000 (17:00 -0400)]
Fix RelationIdGetRelation calls that weren't bothering with error checks.

Some of these are quite old, but that doesn't make them not bugs.
We'd rather report a failure via elog than SIGSEGV.

While at it, uniformly spell the error check as !RelationIsValid(rel)
rather than a bare rel == NULL test.  The machine code is the same
but it seems better to be consistent.

Coverity complained about this today, not sure why, because the
mistake is in fact old.

5 years agoFix handling of NULL distances in KNN-GiST
Alexander Korotkov [Sun, 8 Sep 2019 18:13:40 +0000 (21:13 +0300)]
Fix handling of NULL distances in KNN-GiST

In order to implement NULL LAST semantic GiST previously assumed distance to
the NULL value to be Inf.  However, our distance functions can return Inf and
NaN for non-null values.  In such cases, NULL LAST semantic appears to be
broken.  This commit fixes that by introducing separate array of null flags for
distances.

Backpatch to all supported versions.

Discussion: https://postgr.es/m/CAPpHfdsNvNdA0DBS%2BwMpFrgwT6C3-q50sFVGLSiuWnV3FqOJuQ%40mail.gmail.com
Author: Alexander Korotkov
Backpatch-through: 9.4

5 years agoFix handling Inf and Nan values in GiST pairing heap comparator
Alexander Korotkov [Sun, 8 Sep 2019 18:07:30 +0000 (21:07 +0300)]
Fix handling Inf and Nan values in GiST pairing heap comparator

Previously plain float comparison was used in GiST pairing heap.  Such
comparison doesn't provide proper ordering for value sets containing Inf and Nan
values.  This commit fixes that by usage of float8_cmp_internal().  Note, there
is remaining problem with NULL distances, which are represented as Inf in
pairing heap.  It would be fixes in subsequent commit.

Backpatch to all supported versions.

Reported-by: Andrey Borodin
Discussion: https://postgr.es/m/CAPpHfdsNvNdA0DBS%2BwMpFrgwT6C3-q50sFVGLSiuWnV3FqOJuQ%40mail.gmail.com
Author: Alexander Korotkov
Reviewed-by: Heikki Linnakangas
Backpatch-through: 9.4

5 years agoFix behavior of AND CHAIN outside of explicit transaction blocks
Peter Eisentraut [Sun, 8 Sep 2019 14:11:21 +0000 (16:11 +0200)]
Fix behavior of AND CHAIN outside of explicit transaction blocks

When using COMMIT AND CHAIN or ROLLBACK AND CHAIN not in an explicit
transaction block, the previous implementation would leave a
transaction block active in the ROLLBACK case but not the COMMIT case.
To fix for now, error out when using these commands not in an explicit
transaction block.  This restriction could be lifted if a sensible
definition and implementation is found.

Bug: #15977
Author: fn ln <emuser20140816@gmail.com>
Reviewed-by: Fabien COELHO <coelho@cri.ensmp.fr>
5 years agodoc: effective -> efficient
Peter Eisentraut [Sun, 8 Sep 2019 09:10:49 +0000 (11:10 +0200)]
doc: effective -> efficient

5 years agodoc: Clean up title case use
Peter Eisentraut [Sun, 8 Sep 2019 08:26:35 +0000 (10:26 +0200)]
doc: Clean up title case use

Note: Following existing practice, titles of formalpara and step are
not titlecased.

5 years agoAvoid using INFO elevel for what are fundamentally debug messages.
Tom Lane [Sat, 7 Sep 2019 23:03:11 +0000 (19:03 -0400)]
Avoid using INFO elevel for what are fundamentally debug messages.

Commit 6f6b99d13 stuck an INFO message into the fast path for
checking partition constraints, for no very good reason except
that it made it easy for the regression tests to verify that
that path was taken.  Assorted later patches did likewise,
increasing the unsuppressable-chatter level from ALTER TABLE
even more.  This isn't good for the user experience, so let's
drop these messages down to DEBUG1 where they belong.  So as
not to have a loss of test coverage, create a TAP test that
runs the relevant queries with client_min_messages = DEBUG1
and greps for the expected messages.

This testing method is a bit brute-force --- in particular,
it duplicates the execution of a fair amount of the core
create_table and alter_table tests.  We experimented with
other solutions, but running any significant amount of
standard testing with client_min_messages = DEBUG1 seems
to have a lot of output-stability pitfalls, cf commits
bbb96c370 and 5655565c0.  Possibly at some point we'll look
into whether we can reduce the amount of test duplication.

Backpatch into v12, because some of these messages are new
in v12 and we don't really want to ship it that way.

Sergei Kornilov

Discussion: https://postgr.es/m/81911511895540@web58j.yandex.ru
Discussion: https://postgr.es/m/4859321552643736@myt5-02b80404fd9e.qloud-c.yandex.net

5 years agoFix issues around strictness of SIMILAR TO.
Tom Lane [Sat, 7 Sep 2019 18:21:59 +0000 (14:21 -0400)]
Fix issues around strictness of SIMILAR TO.

As a result of some long-ago quick hacks, the SIMILAR TO operator
and the corresponding flavor of substring() interpreted "ESCAPE NULL"
as selecting the default escape character '\'.  This is both
surprising and not per spec: the standard is clear that these
functions should return NULL for NULL input.

Additionally, because of inconsistency of the strictness markings
of 3-argument substring() and similar_escape(), the planner could not
inline the SQL definition of substring(), resulting in a substantial
performance penalty compared to the underlying POSIX substring()
function.

The simplest fix for this would be to change the strictness marking
of similar_escape(), but if we do that we risk breaking existing views
that depend on that function.  Hence, leave similar_escape() as-is
as a compatibility function, and instead invent a new function
similar_to_escape() that comes in two strict variants.

There are a couple of other behaviors in this area that are also
not per spec, but they are documented and seem generally at least
as sane as the spec's definition, so leave them alone.  But improve
the documentation to describe them fully.

Patch by me; thanks to Álvaro Herrera and Andrew Gierth for review
and discussion.

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

5 years agoMessage style fixes
Peter Eisentraut [Fri, 6 Sep 2019 14:12:28 +0000 (16:12 +0200)]
Message style fixes

5 years agodoc: Fix awkward markup
Peter Eisentraut [Fri, 6 Sep 2019 20:19:53 +0000 (22:19 +0200)]
doc: Fix awkward markup

5 years agodoc: Postgres -> PostgreSQL
Peter Eisentraut [Fri, 6 Sep 2019 20:16:58 +0000 (22:16 +0200)]
doc: Postgres -> PostgreSQL

5 years agoAlways skip recovery SysV shared memory tests on Windows
Andrew Dunstan [Fri, 6 Sep 2019 19:47:23 +0000 (15:47 -0400)]
Always skip recovery SysV shared memory tests on Windows

The test for SysV support currently involves looking for the perl
modules IPC::SharedMem and IPC::SysV. However, the perl on msys2 has
these modules but the tests fail. Therefore, force skipping the tests on
Windows platforms unconditionally.

Discussion: https://postgr.es/m/176e86ba-1a46-9d8c-5ae4-9865a463b411@2ndQuadrant.com

5 years agoDoc: tweak installation doc edits made by commit 76c2af926.
Tom Lane [Fri, 6 Sep 2019 15:24:36 +0000 (11:24 -0400)]
Doc: tweak installation doc edits made by commit 76c2af926.

We don't consider that building with MinGW is deprecated,
so adjust some places that gave that impression.
Per discussion with Peter Eisentraut.

Discussion: https://postgr.es/m/4a023388-8652-fea0-a0b4-35ad5e734e9a@2ndquadrant.com

5 years agoCreate an API for inserting and deleting rows in TOAST tables.
Robert Haas [Fri, 6 Sep 2019 14:38:51 +0000 (10:38 -0400)]
Create an API for inserting and deleting rows in TOAST tables.

This moves much of the non-heap-specific logic from toast_delete and
toast_insert_or_update into a helper functions accessible via a new
header, toast_helper.h.  Using the functions in this module, a table
AM can implement creation and deletion of TOAST table rows with
much less code duplication than was possible heretofore.  Some
table AMs won't want to use the TOAST logic at all, but for those
that do this will make that easier.

Patch by me, reviewed and tested by Prabhat Sabu, Thomas Munro,
Andres Freund, and Álvaro Herrera.

Discussion: http://postgr.es/m/CA+TgmoZv-=2iWM4jcw5ZhJeL18HF96+W1yJeYrnGMYdkFFnEpQ@mail.gmail.com

5 years agoWhen performing a base backup, check for read errors.
Robert Haas [Fri, 6 Sep 2019 12:22:32 +0000 (08:22 -0400)]
When performing a base backup, check for read errors.

The old code didn't differentiate between a read error and a
concurrent truncation. fread reports both of these by returning 0;
you have to use feof() or ferror() to distinguish between them,
which this code did not do.

It might be a better idea to use read() rather than fread() here,
so that we can display a less-generic error message, but I'm not
sure that would qualify as a back-patchable bug fix, so just do
this much for now.

Jeevan Chalke, reviewed by Jeevan Ladhe and by me.

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

5 years agolibpq: ccache -> credential cache
Peter Eisentraut [Fri, 6 Sep 2019 07:15:35 +0000 (09:15 +0200)]
libpq: ccache -> credential cache

The term "ccache" is overloaded.  Let's be more clear, in case someone
other than a Kerberos wizard has to read this code.

5 years agoMake pg_promote() detect postmaster death while waiting for promotion to end.
Fujii Masao [Fri, 6 Sep 2019 05:27:25 +0000 (14:27 +0900)]
Make pg_promote() detect postmaster death while waiting for promotion to end.

Previously even if postmaster died and WaitLatch() woke up with that event
while pg_promote() was waiting for the standby promotion to finish,
pg_promote() did nothing special and kept waiting until timeout occurred.
This could cause a busy loop.

This patch make pg_promote() return false immediately when postmaster
dies, to avoid such a busy loop.

Back-patch to v12 where pg_promote() was added.

Author: Fujii Masao
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/CAHGQGwEs9ROgSp+QF+YdDU+xP8W=CY1k-_Ov-d_Z3JY+to3eXA@mail.gmail.com

5 years agoMake use of generic logging in vacuumlo and oid2name
Michael Paquier [Fri, 6 Sep 2019 05:00:13 +0000 (14:00 +0900)]
Make use of generic logging in vacuumlo and oid2name

Doing the switch reduces the footprint of "progname" in both utilities
for the messages produced.  This also cleans up a couple of
inconsistencies in the message formats.

Author: Michael Paquier
Reviewed-by: Álvaro Herrera, Peter Eisentraut
Discussion: https://postgr.es/m/20190820012819.GA8326@paquier.xyz

5 years agoUse data directory inode number, not port, to select SysV resource keys.
Tom Lane [Thu, 5 Sep 2019 17:31:41 +0000 (13:31 -0400)]
Use data directory inode number, not port, to select SysV resource keys.

This approach provides a much tighter binding between a data directory
and the associated SysV shared memory block (and SysV or named-POSIX
semaphores, if we're using those).  Key collisions are still possible,
but only between data directories stored on different filesystems,
so the situation should be negligible in practice.  More importantly,
restarting the postmaster with a different port number no longer
risks failing to identify a relevant shared memory block, even when
postmaster.pid has been removed.  A standalone backend is likewise
much more certain to detect conflicting leftover backends.

(In the longer term, we might now think about deprecating the port as
a cluster-wide value, so that one postmaster could support sockets
with varying port numbers.  But that's for another day.)

The hazards fixed here apply only on Unix systems; our Windows code
paths already use identifiers derived from the data directory path
name rather than the port.

src/test/recovery/t/017_shm.pl, which intends to test key-collision
cases, has been substantially rewritten since it can no longer use
two postmasters with identical port numbers to trigger the case.
Instead, use Perl's IPC::SharedMem module to create a conflicting
shmem segment directly.  The test script will be skipped if that
module is not available.  (This means that some older buildfarm
members won't run it, but I don't think that that results in any
meaningful coverage loss.)

Patch by me; thanks to Noah Misch and Peter Eisentraut for discussion
and review.

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

5 years agoSplit tuptoaster.c into three separate files.
Robert Haas [Mon, 8 Jul 2019 15:58:05 +0000 (11:58 -0400)]
Split tuptoaster.c into three separate files.

detoast.c/h contain functions required to detoast a datum, partially
or completely, plus a few other utility functions for examining the
size of toasted datums.

toast_internals.c/h contain functions that are used internally to the
TOAST subsystem but which (mostly) do not need to be accessed from
outside.

heaptoast.c/h contains code that is intrinsically specific to the
heap AM, either because it operates on HeapTuples or is based on the
layout of a heap page.

detoast.c and toast_internals.c are placed in
src/backend/access/common rather than src/backend/access/heap.  At
present, both files still have dependencies on the heap, but that will
be improved in a future commit.

Patch by me, reviewed and tested by Prabhat Sabu, Thomas Munro,
Andres Freund, and Álvaro Herrera.

Discussion: http://postgr.es/m/CA+TgmoZv-=2iWM4jcw5ZhJeL18HF96+W1yJeYrnGMYdkFFnEpQ@mail.gmail.com

5 years agoUse explicit_bzero
Peter Eisentraut [Thu, 5 Sep 2019 06:15:58 +0000 (08:15 +0200)]
Use explicit_bzero

Use the explicit_bzero() function in places where it is important that
security information such as passwords is cleared from memory.  There
might be other places where it could be useful; this is just an
initial collection.

For platforms that don't have explicit_bzero(), provide various
fallback implementations.  (explicit_bzero() itself isn't standard,
but as Linux/glibc, FreeBSD, and OpenBSD have it, it's the most common
spelling, so it makes sense to make that the invocation point.)

Discussion: https://www.postgresql.org/message-id/flat/42d26bde-5d5b-c90d-87ae-6cab875f73be%402ndquadrant.com

5 years agoFix thinko when ending progress report for a backend
Michael Paquier [Wed, 4 Sep 2019 06:46:37 +0000 (15:46 +0900)]
Fix thinko when ending progress report for a backend

The logic ending progress reporting for a backend entry introduced by
b6fb647 causes callers of pgstat_progress_end_command() to do some extra
work when track_activities is enabled as the process fields are reset in
the backend entry even if no command were started for reporting.

This resets the fields only if a command is registered for progress
reporting, and only if track_activities is enabled.

Author: Masahiho Sawada
Discussion: https://postgr.es/m/CAD21AoCry_vJ0E-m5oxJXGL3pnos-xYGCzF95rK5Bbi3Uf-rpA@mail.gmail.com
Backpatch-through: 9.6

5 years agoDelay fsyncs of pg_basebackup until the end of backup
Michael Paquier [Wed, 4 Sep 2019 04:21:11 +0000 (13:21 +0900)]
Delay fsyncs of pg_basebackup until the end of backup

Since the addition of fsync requests in bc34223 to make base backup data
consistent on disk once pg_basebackup finishes, each tablespace tar file
is individually flushed once completed, with an additional flush of the
parent directory when the base backup finishes.  While holding a
connection to the server, a fsync request taking a long time may cause a
failure of the base backup, which is annoying for any integration.  A
recent example of breakage can involve tcp_user_timeout, but
wal_sender_timeout can cause similar problems.

While reviewing the code, there was a second issue causing too many
fsync requests to be done for the same WAL data.  As recursive fsyncs
are done at the end of the backup for both the plain and tar formats
from the base target directory where everything is written, it is fine
to disable fsyncs when fetching or streaming WAL.

Reported-by: Ryohei Takahashi
Author: Michael Paquier
Reviewed-by: Ryohei Takahashi
Discussion: https://postgr.es/m/OSBPR01MB4550DAE2F8C9502894A45AAB82BE0@OSBPR01MB4550.jpnprd01.prod.outlook.com
Backpatch-through: 10

5 years agoMake XLogReaderInvalReadState static
Alvaro Herrera [Tue, 3 Sep 2019 21:41:43 +0000 (17:41 -0400)]
Make XLogReaderInvalReadState static

This function is only used by xlogreader.c itself, so there's no need to
export it.  It was introduced by commit 3b02ea4f0780 with the apparent
intention that it could be used externally, but I couldn't find any
external code calling it.

I (Álvaro) couldn't resist the urge to sort nearby function prototypes
properly while at it.

Author: Antonin Houska
Discussion: https://postgr.es/m/14984.1554998742@spoje.net

5 years agoRemove 'msg' parameter from convert_tuples_by_name
Alvaro Herrera [Tue, 3 Sep 2019 18:47:29 +0000 (14:47 -0400)]
Remove 'msg' parameter from convert_tuples_by_name

The message was included as a parameter when this function was added in
dcb2bda9b704, but I don't think it has ever served any useful purpose.
Let's stop spreading it pointlessly.

Reviewed by Amit Langote and Peter Eisentraut.

Discussion: https://postgr.es/m/20190806224728.GA17233@alvherre.pgsql

5 years agoClarify pg_dump documentation
Peter Eisentraut [Tue, 3 Sep 2019 12:25:26 +0000 (14:25 +0200)]
Clarify pg_dump documentation

Clarify in the help output and documentation that -n, -t etc. take a
"pattern" rather than a "schema" or "table" etc.  This was especially
confusing now that the new pg_dumpall --exclude-database option was
documented with "pattern" and the others not, even though they all
behave the same.

Discussion: https://www.postgresql.org/message-id/flat/b85f3fa1-b350-38d1-1893-4f7911bd7310%402ndquadrant.com

5 years agoImprove base backup protocol documentation
Peter Eisentraut [Tue, 3 Sep 2019 09:59:36 +0000 (11:59 +0200)]
Improve base backup protocol documentation

Document that the tablespace sizes are in units of kilobytes.  Make
the pg_basebackup source code a bit clearer about this, too.

Reviewed-by: Magnus Hagander <magnus@hagander.net>
5 years agopg_checksums: Handle read and write returns correctly
Peter Eisentraut [Tue, 3 Sep 2019 06:26:55 +0000 (08:26 +0200)]
pg_checksums: Handle read and write returns correctly

The read() return was not checking for errors, the write() return was
not checking for short writes.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/flat/5de61b6b-8be9-7771-0048-860328efe027%402ndquadrant.com