]> granicus.if.org Git - postgresql/log
postgresql
4 years agopg_rewind: Allow writing recovery configuration
Alvaro Herrera [Mon, 30 Sep 2019 15:57:35 +0000 (12:57 -0300)]
pg_rewind: Allow writing recovery configuration

This is provided with a new switch --write-recovery-conf and reuses the
pg_basebackup code.

Author: Paul Guo, Jimmy Yih, Ashwin Agrawal
Reviewed-by: Alexey Kondratov, Michaël Paquier, Álvaro Herrera
Discussion: https://postgr.es/m/CAEET0ZEffUkXc48pg2iqARQgGRYDiiVxDu+yYek_bTwJF+q=Uw@mail.gmail.com

4 years agoFix SSL test for libpq connection parameter channel_binding
Michael Paquier [Mon, 30 Sep 2019 04:11:31 +0000 (13:11 +0900)]
Fix SSL test for libpq connection parameter channel_binding

When compiling Postgres with OpenSSL 1.0.1 or older versions, SCRAM's
channel binding cannot be supported as X509_get_signature_nid() is
needed, which causes a regression test with channel_binding='require' to
fail as the server cannot publish SCRAM-SHA-256-PLUS as SASL mechanism
over an SSL connection.

Fix the issue by using a method similar to c3d41cc, making the test
result conditional.  The test passes if X509_get_signature_nid() is
present, and when missing we test for a connection failure.  Testing a
connection failure is more useful than skipping the test as we should
fail the connection if channel binding is required by the client but the
server does not support it.

Reported-by: Tom Lane, Michael Paquier
Author: Michael Paquier
Discussion: https://postgr.es/m/20190927024457.GA8485@paquier.xyz
Discussion: https://postgr.es/m/24857.1569775891@sss.pgh.pa.us

4 years agoMake crash recovery ignore recovery target settings.
Fujii Masao [Mon, 30 Sep 2019 01:18:15 +0000 (10:18 +0900)]
Make crash recovery ignore recovery target settings.

In v11 or before, recovery target settings could not take effect in
crash recovery because they are specified in recovery.conf and
crash recovery always starts without recovery.conf. But commit
2dedf4d9a8 integrated recovery.conf into postgresql.conf and
which unexpectedly allowed recovery target settings to take effect
even in crash recovery. This is definitely not good behavior.

To fix the issue, this commit makes crash recovery always ignore
recovery target settings.

Back-patch to v12.

Author: Peter Eisentraut
Reviewed-by: Fujii Masao
Discussion: https://postgr.es/m/e445616d-023e-a268-8aa1-67b8b335340c@pgmasters.net

4 years agojit: Re-allow JIT compilation of execGrouping.c hashtable comparisons.
Andres Freund [Sun, 29 Sep 2019 23:24:32 +0000 (16:24 -0700)]
jit: Re-allow JIT compilation of execGrouping.c hashtable comparisons.

In the course of 5567d12ce03356687bd8 and 317ffdfeaac, I changed
BuildTupleHashTable[Ext]'s call to ExecBuildGroupingEqual to not pass
in the parent node, but NULL. Which in turn prevents the tuple
equality comparator from being JIT compiled.  While that fixes
bug #15486, it is not actually necessary after all of the above commits,
as we don't re-build the comparator when using the new
BuildTupleHashTableExt() interface (as the content of the hashtable
are reset, but the TupleHashTable itself is not).

Therefore re-allow jit compilation for callers that use
BuildTupleHashTableExt with a separate context for "metadata" and
content.

As in the previous commit, there's ongoing work to make this easier to
test to prevent such regressions in the future, but that
infrastructure is not going to be backpatchable.

The performance impact of not JIT compiling hashtable equality
comparators can be substantial e.g. for aggregation queries that
aggregate a lot of input rows to few output rows (when there are a lot
of output groups, there will be fewer comparisons).

Author: Andres Freund
Discussion: https://postgr.es/m/20190927072053.njf6prdl3vb7y7qb@alap3.anarazel.de
Backpatch: 11, just as 5567d12ce03

4 years agoFix determination when slot types for upper executor nodes are fixed.
Andres Freund [Sun, 29 Sep 2019 22:24:54 +0000 (15:24 -0700)]
Fix determination when slot types for upper executor nodes are fixed.

For many queries the fact that the tuple descriptor from the lower
node was not taken into account when determining whether the type of a
slot is fixed, lead to tuple deforming for such upper nodes not to be
JIT accelerated.

I broke this in 675af5c01e297.

There is ongoing work to enable writing regression tests for related
behavior (including a patch that would have detected this
regression), by optionally showing such details in EXPLAIN. But as it
seems unlikely that that will be suitable for stable branches, just
merge the fix for now.

While it's fairly close to the 12 release window, the fact that 11
continues to perform JITed tuple deforming in these cases, that
there's still cases where we do so in 12, and the fact that the
performance regression can be sizable, weigh in favor of fixing it
now.

Author: Andres Freund
Discussion: https://postgr.es/m/20190927072053.njf6prdl3vb7y7qb@alap3.anarazel.de
Backpatch: 12-, where 675af5c01e297 was merged.

4 years agoAllow SSL TAP tests to run on Windows
Andrew Dunstan [Sun, 29 Sep 2019 21:32:46 +0000 (17:32 -0400)]
Allow SSL TAP tests to run on Windows

Windows does not enforce key file permissions checks in libpq, and psql
can produce CRLF line endings on Windows.

Backpatch to Release 12 (CRLF) and Release 11 (permissions check)

4 years agodoc: Further clarify how recovery target parameters are applied
Peter Eisentraut [Sun, 29 Sep 2019 21:07:22 +0000 (23:07 +0200)]
doc: Further clarify how recovery target parameters are applied

Recovery target parameters are all applied even in standby mode.  The
previous documentation mostly wished they were not but this was never
the case.

Discussion: https://www.postgresql.org/message-id/flat/e445616d-023e-a268-8aa1-67b8b335340c%40pgmasters.net

4 years agoFix bogus order of error checks in new channel_binding code.
Tom Lane [Sun, 29 Sep 2019 16:35:53 +0000 (12:35 -0400)]
Fix bogus order of error checks in new channel_binding code.

Coverity pointed out that it's pretty silly to check for a null pointer
after we've already dereferenced the pointer.  To fix, just swap the
order of the two error checks.  Oversight in commit d6e612f83.

4 years agodoc: Add a link target
Peter Eisentraut [Sun, 29 Sep 2019 07:50:36 +0000 (09:50 +0200)]
doc: Add a link target

Forward-patched from PostgreSQL 12 release notes patch, for
consistency.

4 years agoFix compilation with older OpenSSL versions
Peter Eisentraut [Sat, 28 Sep 2019 13:54:02 +0000 (15:54 +0200)]
Fix compilation with older OpenSSL versions

Some older OpenSSL versions (0.9.8 branch) define TLS*_VERSION macros
but not the corresponding SSL_OP_NO_* macro, which causes the code for
handling ssl_min_protocol_version/ssl_max_protocol_version to fail to
compile.  To fix, add more #ifdefs and error handling.

Reported-by: Victor Wagner <vitus@wagner.pp.ru>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://www.postgresql.org/message-id/flat/20190924101859.09383b4f%40fafnir.local.vm

4 years agoImprove stability of partition_prune regression test.
Tom Lane [Sat, 28 Sep 2019 17:33:34 +0000 (13:33 -0400)]
Improve stability of partition_prune regression test.

This test already knew that, to get stable test output, it had to hide
"loops" counts in EXPLAIN ANALYZE results.  But that's not nearly enough:
if we get a smaller number of workers than we planned for, then the
"Workers Launched" number will change, and so will all the rows and loops
counts up to the Gather node.  This has resulted in repeated failures in
the buildfarm, so adjust the test to filter out all these counts.

(Really, we wouldn't bother with EXPLAIN ANALYZE at all here, except
that currently the only way to verify that executor-time pruning has
happened is to look for '(never executed)' annotations.  Those are
stable and needn't be filtered out.)

Back-patch to v11 where the test was introduced.

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

4 years agoRemove code relevant to OpenSSL 0.9.6 in be/fe-secure-openssl.c
Michael Paquier [Sat, 28 Sep 2019 06:22:49 +0000 (15:22 +0900)]
Remove code relevant to OpenSSL 0.9.6 in be/fe-secure-openssl.c

HEAD supports OpenSSL 0.9.8 and newer versions, and this code likely got
forgotten as its surrounding comments mention an incorrect version
number.

Author: Michael Paquier
Reviewed-by: Peter Eisentraut
Discussion: https://postgr.es/m/20190927032311.GB8485@paquier.xyz

4 years agoMake pg_regress.c unset PGDATABASE during make installcheck.
Tom Lane [Fri, 27 Sep 2019 22:19:37 +0000 (18:19 -0400)]
Make pg_regress.c unset PGDATABASE during make installcheck.

For the most part, we leave libpq-controlling environment variables
alone during "make installcheck", reasoning that connecting to the
server the user expects us to connect to may depend on those variables.
But that argument doesn't apply to PGDATABASE, since we always want
to connect to a specific database name within the server.  And failing
to unset it causes certain ECPG tests to fail, as various people have
complained of in the past.  So let's unset it.

Possibly this should be back-patched, but I'm disinclined to do that
right before 12.0 release.  Maybe later.

Discussion: https://postgr.es/m/20180318205548.2akxjqvo7hrk5wbc@alap3.anarazel.de
Discussion: https://postgr.es/m/E1bOum4-0002EA-2y@gemulon.postgresql.org

4 years agoSilence -Wmaybe-uninitialized compiler warnings in dbcommands.c.
Andres Freund [Fri, 27 Sep 2019 21:10:16 +0000 (14:10 -0700)]
Silence -Wmaybe-uninitialized compiler warnings in dbcommands.c.

When compiling postgres using gcc -O3, there are false-positive
warnings about the now initialized variables. Silence them.

Author: Peter Eisentraut, Andres Freund
Discussion: https://postgr.es/m/15fb2350-b8b8-e188-278f-0b34fdee5210@2ndquadrant.com

4 years agoHave pg_rewind run crash recovery before rewinding
Alvaro Herrera [Fri, 27 Sep 2019 19:40:01 +0000 (16:40 -0300)]
Have pg_rewind run crash recovery before rewinding

If we don't do this, the rewind fails if the server wasn't cleanly shut
down, which seems unhelpful serving no purpose.

Also provide a new option --no-ensure-shutdown to suppress this
behavior, for alleged advanced usage that prefers to avoid the crash
recovery.

Authors: Paul Guo, Jimmy Yih, Ashwin Agrawal
Reviewed-by: Álvaro Herrera
Discussion: https://postgr.es/m/CAEET0ZEffUkXc48pg2iqARQgGRYDiiVxDu+yYek_bTwJF+q=Uw@mail.gmail.com

4 years agoFix implicit-fallthrough compiler warning introduced in 6dda292d4df82.
Andres Freund [Fri, 27 Sep 2019 17:25:08 +0000 (10:25 -0700)]
Fix implicit-fallthrough compiler warning introduced in 6dda292d4df82.

For some reason at least gcc-9 warns about the fallthrough, even
though it otherwise recognizes that elog(ERROR, ...) doesn't return.

Author: Andres Freund

4 years agoANALYZE a_star and its children to avoid plan instability in tests.
Tom Lane [Fri, 27 Sep 2019 15:28:24 +0000 (11:28 -0400)]
ANALYZE a_star and its children to avoid plan instability in tests.

We've noted certain EXPLAIN queries on these tables occasionally showing
unexpected plan choices.  This seems to happen because VACUUM sometimes
fails to update relpages/reltuples for one of these single-page tables,
due to bgwriter or checkpointer holding a pin on the lone page at just
the wrong time.  To ensure those values get set, insert explicit ANALYZE
operations on these tables after we finish populating them.  This
doesn't seem to affect any other test cases, so it's a usable fix.

Back-patch to v12.  In principle the issue exists further back, but
we have not seen it before v12, so I won't risk back-patching further.

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

4 years agoFinish reverting "Insert temporary debugging output in regression tests."
Tom Lane [Fri, 27 Sep 2019 15:20:09 +0000 (11:20 -0400)]
Finish reverting "Insert temporary debugging output in regression tests."

This removes the last of the temporary debugging queries added to the
regression tests by commit f03a9ca43.  We've pretty much convinced
ourselves that the plan instability we were seeing is due to VACUUM
sometimes failing to update relpages/reltuples for a single-page table,
due to bgwriter or checkpointer holding a pin on that page at just the
wrong time.  I'll push a workaround for that separately.

Discussion: https://postgr.es/m/CA+hUKG+0CxrKRWRMf5ymN3gm+BECHna2B-q1w8onKBep4HasUw@mail.gmail.com

4 years agoDoc: clean up markup for jsonb_set and related functions.
Tom Lane [Fri, 27 Sep 2019 15:01:36 +0000 (11:01 -0400)]
Doc: clean up markup for jsonb_set and related functions.

The markup for optional parameters was neither correct nor consistent.
In passing, fix a spelling mistake.

Per report from Alex Macy.  Some of these mistakes are old, so
back-patch as appropriate.

Discussion: https://postgr.es/m/156953522258.1204.12736099368284950578@wrigleys.postgresql.org

4 years agodoc: Add timeline as valid recovery target in standby.signal documentation
Peter Eisentraut [Fri, 27 Sep 2019 14:21:47 +0000 (16:21 +0200)]
doc: Add timeline as valid recovery target in standby.signal documentation

The documentation states that no target settings will be used when
standby.signal is present, but this is not quite the case since
recovery_target_timeline is a valid recovery target for a standby.

Update the documentation with this exception.

Author: David Steele <david@pgmasters.net>
Discussion: https://www.postgresql.org/message-id/flat/e445616d-023e-a268-8aa1-67b8b335340c%40pgmasters.net

4 years agoAdd tab completion for EXPLAIN (SETTINGS) in psql
Michael Paquier [Fri, 27 Sep 2019 03:53:43 +0000 (12:53 +0900)]
Add tab completion for EXPLAIN (SETTINGS) in psql

Author: Justin Pryzby
Reviewed-by: Tatsuro Yamada
Discussion: https://postgr.es/m/20190927022051.GC24334@telsasoft.com
Backpatch-through: 12

4 years agoFix oversight in commit 4429f6a9e3e12bb4af6e3677fbc78cd80f160252.
Amit Kapila [Wed, 18 Sep 2019 03:44:26 +0000 (09:14 +0530)]
Fix oversight in commit 4429f6a9e3e12bb4af6e3677fbc78cd80f160252.

The test name and the following test cases suggest the index created
should be hash index, but it forgot to add 'using hash' in the test case.
This in itself won't improve code coverage as there were some other tests
which were covering the corresponding code.  However, it is better if the
added tests serve their actual purpose.

Reported-by: Paul A Jungwirth
Author: Paul A Jungwirth
Reviewed-by: Mahendra Singh
Backpatch-through: 9.4
Discussion: https://postgr.es/m/CA+renyV=Us-5XfMC25bNp-uWSj39XgHHmGE9Rh2cQKMegSj52g@mail.gmail.com

4 years agoFix lockmode initialization for custom relation options
Michael Paquier [Fri, 27 Sep 2019 00:31:20 +0000 (09:31 +0900)]
Fix lockmode initialization for custom relation options

The code was enforcing AccessExclusiveLock for all custom relation
options, which is incorrect as the APIs allow a custom lock level to be
set.

While on it, fix a couple of inconsistencies in the tests and the README
of dummy_index_am.

Oversights in commit 773df88.

Discussion: https://postgr.es/m/20190925234152.GA2115@paquier.xyz

4 years agodoc: Fix whitespace in markup
Peter Eisentraut [Thu, 26 Sep 2019 19:29:14 +0000 (21:29 +0200)]
doc: Fix whitespace in markup

4 years agodoc: Format example JSON data better
Peter Eisentraut [Thu, 26 Sep 2019 19:27:34 +0000 (21:27 +0200)]
doc: Format example JSON data better

4 years agodoc: Update a confusing sentence about SQL/JSON
Peter Eisentraut [Thu, 26 Sep 2019 14:35:10 +0000 (16:35 +0200)]
doc: Update a confusing sentence about SQL/JSON

Author: Liudmila Mantrova <l.mantrova@postgrespro.ru>
Reported-by: Jeff Janes <jeff.janes@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/CAMkU%3D1wP-SO4KpiLxHJuPezTJCmK%3DJqefLXrr3eXFO7Qku%2BtMg%40mail.gmail.com

4 years agodoc: Update note about source code formatting
Peter Eisentraut [Thu, 26 Sep 2019 08:51:39 +0000 (10:51 +0200)]
doc: Update note about source code formatting

Update the note about why not to use // comments, even though it's now
technically supported.

The note about variable declarations was dropped here because it's
addressed more properly later in the chapter.

Discussion: https://www.postgresql.org/message-id/flat/156924954640.1117.6309209869705522549%40wrigleys.postgresql.org

4 years agodoc: Reorder JSON functions documentation
Peter Eisentraut [Thu, 26 Sep 2019 07:44:22 +0000 (09:44 +0200)]
doc: Reorder JSON functions documentation

Put the description of the SQL/JSON path language after the
description of the general JSON functions and operators, instead of
before.

Discussion: https://www.postgresql.org/message-id/16968.1569189812@sss.pgh.pa.us

4 years agoFix comment in xlogreader.c
Michael Paquier [Thu, 26 Sep 2019 02:53:37 +0000 (11:53 +0900)]
Fix comment in xlogreader.c

This has been introduced by 709d003, that has moved readSegNo, readOff
and readPageTLI into a new structure called WALOpenSegment initialized
separately.

Author: Kyotaro Horiguchi
Discussion: https://postgr.es/m/20190926.110809.248342687.horikyota.ntt@gmail.com

4 years agoCorrectly cast types to Datum and back in compareDatetime()
Alexander Korotkov [Wed, 25 Sep 2019 23:06:45 +0000 (02:06 +0300)]
Correctly cast types to Datum and back in compareDatetime()

Discussion: https://postgr.es/m/CAPpHfdteFKW6MLpXM4md99m55YAuXs0n9_P2wiTq_EmG09doUA%40mail.gmail.com

4 years agoFix handling of GENERATED columns in CREATE TABLE LIKE INCLUDING DEFAULTS.
Tom Lane [Wed, 25 Sep 2019 21:30:42 +0000 (17:30 -0400)]
Fix handling of GENERATED columns in CREATE TABLE LIKE INCLUDING DEFAULTS.

LIKE INCLUDING DEFAULTS tried to copy the attrdef expression without
copying the state of the attgenerated column.  This is in fact wrong,
because GENERATED and DEFAULT expressions are not the same kind of animal;
one can contain Vars and the other not.  We *must* copy attgenerated
when we're copying the attrdef expression.  Rearrange the if-tests
so that the expression is copied only when the correct one of
INCLUDING DEFAULTS and INCLUDING GENERATED has been specified.

Per private report from Manuel Rigger.

Tom Lane and Peter Eisentraut

4 years agoImplement jsonpath .datetime() method
Alexander Korotkov [Wed, 25 Sep 2019 18:54:14 +0000 (21:54 +0300)]
Implement jsonpath .datetime() method

This commit implements jsonpath .datetime() method as it's specified in
SQL/JSON standard.  There are no-argument and single-argument versions of
this method.  No-argument version selects first of ISO datetime formats
matching input string.  Single-argument version accepts template string as
its argument.

Additionally to .datetime() method itself this commit also implements
comparison ability of resulting date and time values.  There is some difficulty
because exising jsonb_path_*() functions are immutable, while comparison of
timezoned and non-timezoned types involves current timezone.  At first, current
timezone could be changes in session.  Moreover, timezones themselves are not
immutable and could be updated.  This is why we let existing immutable functions
throw errors on such non-immutable comparison.  In the same time this commit
provides jsonb_path_*_tz() functions which are stable and support operations
involving timezones.  As new functions are added to the system catalog,
catversion is bumped.

Support of .datetime() method was the only blocker prevents T832 from being
marked as supported.  sql_features.txt is updated correspondingly.

Extracted from original patch by Nikita Glukhov, Teodor Sigaev, Oleg Bartunov.
Heavily revised by me.  Comments were adjusted by Liudmila Mantrova.

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: Alexander Korotkov, Nikita Glukhov, Teodor Sigaev, Oleg Bartunov, Liudmila Mantrova
Reviewed-by: Anastasia Lubennikova, Peter Eisentraut
4 years agoAllow datetime values in JsonbValue
Alexander Korotkov [Wed, 25 Sep 2019 18:53:41 +0000 (21:53 +0300)]
Allow datetime values in JsonbValue

SQL/JSON standard allows manipulation with datetime values.  So, it appears to
be convinient to allow datetime values to be represented in JsonbValue struct.
These datetime values are allowed for temporary representation only.  During
serialization datetime values are converted into strings.

SQL/JSON requires writing timestamps with timezone in the same timezone offset
as they were parsed.  This is why we allow storage of timezone offset in
JsonbValue struct.  For the same reason timezone offset argument is added to
JsonEncodeDateTime() function.

Extracted from original patch by Nikita Glukhov, Teodor Sigaev, Oleg Bartunov.
Revised by me.  Comments were adjusted by Liudmila Mantrova.

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, Liudmila Mantrova
Reviewed-by: Anastasia Lubennikova, Peter Eisentraut
4 years agoError suppression support for upcoming jsonpath .datetime() method
Alexander Korotkov [Wed, 25 Sep 2019 18:51:47 +0000 (21:51 +0300)]
Error suppression support for upcoming jsonpath .datetime() method

Add support of error suppression in some date and time manipulation functions
as it's required for jsonpath .datetime() method support.  This commit doesn't
use PG_TRY()/PG_CATCH() in order to implement that.  Instead, it provides
internal versions of date and time functions used, which support error
suppression.

Discussion: https://postgr.es/m/CAPpHfdsZgYEra_PeCLGNoXOWYx6iU-S3wF8aX0ObQUcZU%2B4XTw%40mail.gmail.com
Author: Alexander Korotkov, Nikita Glukhov
Reviewed-by: Anastasia Lubennikova, Peter Eisentraut
4 years agoImplement parse_datetime() function
Alexander Korotkov [Wed, 25 Sep 2019 18:50:55 +0000 (21:50 +0300)]
Implement parse_datetime() function

This commit adds parse_datetime() function, which implements datetime
parsing with extended features demanded by upcoming jsonpath .datetime()
method:

 * Dynamic type identification based on template string,
 * Support for standard-conforming 'strict' mode,
 * Timezone offset is returned as separate value.

Extracted from original patch by Nikita Glukhov, Teodor Sigaev, Oleg Bartunov.
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 agoImplement standard datetime parsing mode
Alexander Korotkov [Wed, 25 Sep 2019 18:44:48 +0000 (21:44 +0300)]
Implement standard datetime parsing mode

SQL Standard 2016 defines rules for handling separators in datetime template
strings, which are different to to_date()/to_timestamp() rules.  Standard
allows only small set of separators and requires strict matching for them.

Standard applies to jsonpath .datetime() method and CAST (... FORMAT ...) SQL
clause.  We're not going to change handling of separators in existing
to_date()/to_timestamp() functions, because their current behavior is familiar
for users.  Standard behavior now available by special flag, which will be used
in upcoming .datetime() jsonpath method.

Discussion: https://postgr.es/m/CAPpHfdsZgYEra_PeCLGNoXOWYx6iU-S3wF8aX0ObQUcZU%2B4XTw%40mail.gmail.com
Author: Alexander Korotkov

4 years agoUpdate expected output for dummy_index_am
Alvaro Herrera [Wed, 25 Sep 2019 19:17:19 +0000 (16:17 -0300)]
Update expected output for dummy_index_am

Forgot to add the file in the previous commit.

4 years agoSupport reloptions of enum type
Alvaro Herrera [Wed, 25 Sep 2019 18:56:52 +0000 (15:56 -0300)]
Support reloptions of enum type

All our current in core relation options of type string (not many,
admittedly) behave in reality like enums.  But after seeing an
implementation for enum reloptions, it's clear that strings are messier,
so introduce the new reloption type.  Switch all string options to be
enums instead.

Fortunately we have a recently introduced test module for reloptions, so
we don't lose coverage of string reloptions, which may still be used by
third-party modules.

Authors: Nikolay Shaplov, Álvaro Herrera
Reviewed-by: Nikita Glukhov, Aleksandr Parfenov
Discussion: https://postgr.es/m/43332102.S2V5pIjXRx@x200m

4 years agoSplit out recovery confing-writing code from pg_basebackup
Alvaro Herrera [Wed, 25 Sep 2019 17:35:24 +0000 (14:35 -0300)]
Split out recovery confing-writing code from pg_basebackup

... into a new file, fe_utils/recovery_gen.c.

This can later be used by pg_rewind.

Authors: Paul Guo, Jimmy Yih, Ashwin Agrawal.  A few tweaks by Álvaro Herrera
Reviewed-by: Michaël Paquier
Discussion: https://postgr.es/m/CAEET0ZEffUkXc48pg2iqARQgGRYDiiVxDu+yYek_bTwJF+q=Uw@mail.gmail.com

4 years agoDoc: Fix example related to partition pruning
Michael Paquier [Wed, 25 Sep 2019 04:44:30 +0000 (13:44 +0900)]
Doc: Fix example related to partition pruning

Append node has been removed in v12 when there would be only one subnode
under it.

Author: Amit Langote
Discussion: https://postgr.es/m/CA+HiwqHhS62w8zUFXF4NBjvMboCXYnD-jWoWp-tfo2aHvP3Gxg@mail.gmail.com
Backpatch-through: 12

4 years agoMake more stable regression tests of dummy_index_am for string validations
Michael Paquier [Wed, 25 Sep 2019 03:48:26 +0000 (12:48 +0900)]
Make more stable regression tests of dummy_index_am for string validations

Several buildfarm members (crake, loach and spurfowl) are complaining
about two queries looking up at pg_class.reloptions which trigger the
validation routines for string reloptions with default values.  This
commit limits the routines to be triggered only when building an index
with all custom options set in CREATE INDEX, which is sufficient for the
coverage.

Introduced by 640c198.

4 years agoAdd dummy_index_am to src/test/modules/
Michael Paquier [Wed, 25 Sep 2019 03:11:12 +0000 (12:11 +0900)]
Add dummy_index_am to src/test/modules/

This includes more tests dedicated to relation options, bringing the
coverage of this code close to 100%, and the module can be used for
other purposes, like a base template for an index AM implementation.

Author: Nikolay Sharplov, Michael Paquier
Reviewed-by: Álvaro Herrera, Dent John
Discussion: https://postgr.es/m/17071942.m9zZutALE6@x200m

4 years agoAllow definition of lock mode for custom reloptions
Michael Paquier [Wed, 25 Sep 2019 01:13:52 +0000 (10:13 +0900)]
Allow definition of lock mode for custom reloptions

Relation options can define a lock mode other than AccessExclusiveMode
since 47167b7, but modules defining custom relation options did not
really have a way to enforce that.  Correct that by extending the
current API set so as modules can define a custom lock mode.

Author: Michael Paquier
Reviewed-by: Kuntal Ghosh
Discussion: https://postgr.es/m/20190920013831.GD1844@paquier.xyz

4 years agoFix failure with lock mode used for custom relation options
Michael Paquier [Wed, 25 Sep 2019 01:07:23 +0000 (10:07 +0900)]
Fix failure with lock mode used for custom relation options

In-core relation options can use a custom lock mode since 47167b7, that
has lowered the lock available for some autovacuum parameters.  However
it forgot to consider custom relation options.  This causes failures
with ALTER TABLE SET when changing a custom relation option, as its lock
is not defined.  The existing APIs to define a custom reloption does not
allow to define a custom lock mode, so enforce its initialization to
AccessExclusiveMode which should be safe enough in all cases.  An
upcoming patch will extend the existing APIs to allow a custom lock mode
to be defined.

The problem can be reproduced with bloom indexes, so add a test there.

Reported-by: Nikolay Sharplov
Analyzed-by: Thomas Munro, Michael Paquier
Author: Michael Paquier
Reviewed-by: Kuntal Ghosh
Discussion: https://postgr.es/m/20190920013831.GD1844@paquier.xyz
Backpatch-through: 9.6

4 years agoFix bug in pairingheap_SpGistSearchItem_cmp()
Alexander Korotkov [Tue, 24 Sep 2019 22:47:36 +0000 (01:47 +0300)]
Fix bug in pairingheap_SpGistSearchItem_cmp()

Our item contains only so->numberOfNonNullOrderBys of distances.  Reflect that
in the loop upper bound.

Discussion: https://postgr.es/m/53536807-784c-e029-6e92-6da802ab8d60%40postgrespro.ru
Author: Nikita Glukhov
Backpatch-through: 12

4 years agoRework WAL-reading supporting structs
Alvaro Herrera [Tue, 24 Sep 2019 19:08:31 +0000 (16:08 -0300)]
Rework WAL-reading supporting structs

The state-tracking of WAL reading in various places was pretty messy,
mostly because the ancient physical-replication WAL reading code wasn't
using the XLogReader abstraction.  This led to some untidy code.  Make
it prettier by creating two additional supporting structs,
WALSegmentContext and WALOpenSegment which keep track of WAL-reading
state.  This makes code cleaner, as well as supports more future
cleanup.

Author: Antonin Houska
Reviewed-by: Álvaro Herrera and (older versions) Robert Haas
Discussion: https://postgr.es/m/14984.1554998742@spoje.net

4 years agoPrevent bogus pullup of constant-valued functions returning composite.
Tom Lane [Tue, 24 Sep 2019 16:11:32 +0000 (12:11 -0400)]
Prevent bogus pullup of constant-valued functions returning composite.

Fix an oversight in commit 7266d0997: as it stood, the code failed
when a function-in-FROM returns composite and can be simplified
to a composite constant.

For the moment, just test for composite result and abandon pullup
if we see one.  To make it actually work, we'd have to decompose
the composite constant into per-column constants; which is surely
do-able, but I'm not convinced it's worth the code space.

Per report from Raúl Marín Rodríguez.

Discussion: https://postgr.es/m/CAM6_UM4isP+buRA5sWodO_MUEgutms-KDfnkwGmryc5DGj9XuQ@mail.gmail.com

4 years agoSpeedup truncations of relation forks.
Fujii Masao [Tue, 24 Sep 2019 08:31:26 +0000 (17:31 +0900)]
Speedup truncations of relation forks.

When a relation is truncated, shared_buffers needs to be scanned
so that any buffers for the relation forks are invalidated in it.
Previously, shared_buffers was scanned for each relation forks, i.e.,
MAIN, FSM and VM, when VACUUM truncated off any empty pages
at the end of relation or TRUNCATE truncated the relation in place.
Since shared_buffers needed to be scanned multiple times,
it could take a long time to finish those commands especially
when shared_buffers was large.

This commit changes the logic so that shared_buffers is scanned only
one time for those three relation forks.

Author: Kirk Jamison
Reviewed-by: Masahiko Sawada, Thomas Munro, Alvaro Herrera, Takayuki Tsunakawa and Fujii Masao
Discussion: https://postgr.es/m/D09B13F772D2274BB348A310EE3027C64E2067@g01jpexmbkw24

4 years agoDon't disable ccache when building with coverage support
Peter Eisentraut [Tue, 24 Sep 2019 08:00:56 +0000 (10:00 +0200)]
Don't disable ccache when building with coverage support

This was working around a bug in ccache that was fixed in ccache
3.2.2 (released 2015-05-10).  (Users of older ccache versions can
continue to set CCACHE_DISABLE themselves.)

Discussion: https://www.postgresql.org/message-id/20190530191130.GA24528@alvherre.pgsql

4 years agoFix ExprState's tag to be of type NodeTag rather than Node.
Andres Freund [Mon, 23 Sep 2019 22:28:13 +0000 (15:28 -0700)]
Fix ExprState's tag to be of type NodeTag rather than Node.

This appears to have been an oversight in b8d7f053c5c2. As it's
effectively harmless, though confusing, only fix in master.

Author: Andres Freund

4 years agoAdd libpq parameter 'channel_binding'.
Jeff Davis [Mon, 23 Sep 2019 20:45:23 +0000 (13:45 -0700)]
Add libpq parameter 'channel_binding'.

Allow clients to require channel binding to enhance security against
untrusted servers.

Author: Jeff Davis
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/227015d8417f2b4fef03f8966dbfa5cbcc4f44da.camel%40j-davis.com

4 years agoDoc: clarify handling of duplicate elements in array containment tests.
Tom Lane [Mon, 23 Sep 2019 16:37:04 +0000 (12:37 -0400)]
Doc: clarify handling of duplicate elements in array containment tests.

The array <@ and @> operators do not worry about duplicates: if every
member of array X matches some element of array Y, then X is contained
in Y, even if several members of X get matched to the same Y member.
This was not explicitly stated in the docs though, so improve matters.

Discussion: https://postgr.es/m/156614120484.1310.310161642239149585@wrigleys.postgresql.org

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