]> granicus.if.org Git - postgresql/log
postgresql
8 years agoAllow pg_create_physical_replication_slot() to reserve WAL.
Andres Freund [Tue, 11 Aug 2015 10:34:31 +0000 (12:34 +0200)]
Allow pg_create_physical_replication_slot() to reserve WAL.

When creating a physical slot it's often useful to immediately reserve
the current WAL position instead of only doing after the first feedback
message arrives. That e.g. allows slots to guarantee that all the WAL
for a base backup will be available afterwards.

Logical slots already have to reserve WAL during creation, so generalize
that logic into being usable for both physical and logical slots.

Catversion bump because of the new parameter.

Author: Gurjeet Singh
Reviewed-By: Andres Freund
Discussion: CABwTF4Wh_dBCzTU=49pFXR6coR4NW1ynb+vBqT+Po=7fuq5iCw@mail.gmail.com

8 years agoIntroduce macros determining if a replication slot is physical or logical.
Andres Freund [Tue, 11 Aug 2015 10:32:48 +0000 (12:32 +0200)]
Introduce macros determining if a replication slot is physical or logical.

These make the code a bit easier to read, and make it easier to add a
more explicit notion of a slot's type at some point in the future.

Author: Gurjeet Singh
Discussion: CABwTF4Wh_dBCzTU=49pFXR6coR4NW1ynb+vBqT+Po=7fuq5iCw@mail.gmail.com

8 years agoMinor cleanups in slot related code.
Andres Freund [Tue, 11 Aug 2015 10:32:48 +0000 (12:32 +0200)]
Minor cleanups in slot related code.

Fix a bunch of typos, and remove two superflous includes.

Author: Gurjeet Singh
Discussion: CABwTF4Wh_dBCzTU=49pFXR6coR4NW1ynb+vBqT+Po=7fuq5iCw@mail.gmail.com
Backpatch: 9.4

8 years agoFix privilege dumping from servers too old to have that type of privilege.
Tom Lane [Tue, 11 Aug 2015 00:10:15 +0000 (20:10 -0400)]
Fix privilege dumping from servers too old to have that type of privilege.

pg_dump produced fairly silly GRANT/REVOKE commands when dumping types from
pre-9.2 servers, and when dumping functions or procedural languages from
pre-7.3 servers.  Those server versions lack the typacl, proacl, and/or
lanacl columns respectively, and pg_dump substituted default values that
were in fact incorrect.  We ended up revoking all the owner's own
privileges for the object while granting all privileges to PUBLIC.
Of course the owner would then have those privileges again via PUBLIC, so
long as she did not try to revoke PUBLIC's privileges; which may explain
the lack of field reports.  Nonetheless this is pretty silly behavior.

The stakes were raised by my recent patch to make pg_dump dump shell types,
because 9.2 and up pg_dump would proceed to emit bogus GRANT/REVOKE
commands for a shell type if dumping from a pre-9.2 server; and the server
will not accept GRANT/REVOKE commands for a shell type.  (Perhaps it
should, but that's a topic for another day.)  So the resulting dump script
wouldn't load without errors.

The right thing to do is to act as though these objects have default
privileges (null ACL entries), which causes pg_dump to print no
GRANT/REVOKE commands at all for them.  That fixes the silly results
and also dodges the problem with shell types.

In passing, modify getProcLangs() to be less creatively different about
how to handle missing columns when dumping from older server versions.
Every other data-acquisition function in pg_dump does that by substituting
appropriate default values in the version-specific SQL commands, and I see
no reason why this one should march to its own drummer.  Its use of
"SELECT *" was likewise not conformant with anyplace else, not to mention
it's not considered good SQL style for production queries.

Back-patch to all supported versions.  Although 9.0 and 9.1 pg_dump don't
have the issue with typacl, they are more likely than newer versions to be
used to dump from ancient servers, so we ought to fix the proacl/lanacl
issues all the way back.

8 years agoAccept alternate spellings of __sparcv7 and __sparcv8.
Tom Lane [Mon, 10 Aug 2015 21:34:51 +0000 (17:34 -0400)]
Accept alternate spellings of __sparcv7 and __sparcv8.

Apparently some versions of gcc prefer __sparc_v7__ and __sparc_v8__.
Per report from Waldemar Brodkorb.

8 years agoFurther mucking with PlaceHolderVar-related restrictions on join order.
Tom Lane [Mon, 10 Aug 2015 21:18:17 +0000 (17:18 -0400)]
Further mucking with PlaceHolderVar-related restrictions on join order.

Commit 85e5e222b1dd02f135a8c3bf387d0d6d88e669bd turns out not to have taken
care of all cases of the partially-evaluatable-PlaceHolderVar problem found
by Andreas Seltenreich's fuzz testing.  I had set it up to check for risky
PHVs only in the event that we were making a star-schema-based exception to
the param_source_rels join ordering heuristic.  However, it turns out that
the problem can occur even in joins that satisfy the param_source_rels
heuristic, in which case allow_star_schema_join() isn't consulted.
Refactor so that we check for risky PHVs whenever the proposed join has
any remaining parameterization.

Back-patch to 9.2, like the previous patch (except for the regression test
case, which only works back to 9.3 because it uses LATERAL).

Note that this discovery implies that problems of this sort could've
occurred in 9.2 and up even before the star-schema patch; though I've not
tried to prove that experimentally.

8 years agoWork around an apparent bug in the Msys DTK perl's regex engine.
Andrew Dunstan [Mon, 10 Aug 2015 14:42:05 +0000 (10:42 -0400)]
Work around an apparent bug in the Msys DTK perl's regex engine.

Several versions of the perl that comes with the Msys DTK have been
found to have a bug that fails to recognize a ' before a multiline $ in
some circumstances. To work around the problem, use a character class
for the '. Another solution would have been to use \n instead of $, but
that would have changed the test semantics very slightly.

8 years agoTemporarily(?) remove BRIN isolation test.
Tom Lane [Mon, 10 Aug 2015 14:22:37 +0000 (10:22 -0400)]
Temporarily(?) remove BRIN isolation test.

Commit 2834855cb added a not-very-carefully-thought-out isolation test
to check a BRIN index bug fix.  The test depended on the availability
of the pageinspect contrib module, which meant it did not work in
several common testing scenarios such as "make check-world".  It's not
clear whether we want a core test depending on a contrib module like
that, but in any case, failing to deal with the possibility that the
module isn't present in the installation-under-test is not acceptable.

Remove that test pending some better solution.

8 years agoAdd confirmed_flush column to pg_replication_slots.
Andres Freund [Mon, 10 Aug 2015 11:28:18 +0000 (13:28 +0200)]
Add confirmed_flush column to pg_replication_slots.

There's no reason not to expose both restart_lsn and confirmed_flush
since they have rather distinct meanings. The former is the oldest WAL
still required and valid for both physical and logical slots, whereas
the latter is the location up to which a logical slot's consumer has
confirmed receiving data. Most of the time a slot will require older
WAL (i.e. restart_lsn) than the confirmed
position (i.e. confirmed_flush_lsn).

Author: Marko Tiikkaja, editorialized by me
Discussion: 559D110B.1020109@joh.to

8 years agoFix copy & paste mistake in pg_get_replication_slots().
Andres Freund [Mon, 10 Aug 2015 11:28:18 +0000 (13:28 +0200)]
Fix copy & paste mistake in pg_get_replication_slots().

XLogRecPtr was compared with InvalidTransactionId instead of
InvalidXLogRecPtr. As both are defined to the same value this doesn't
cause any actual problems, but it's still wrong.

Backpatch: 9.4-master, bug was introduced in 9.4

8 years agoDon't start to stream after pg_receivexlog --create-slot.
Andres Freund [Mon, 10 Aug 2015 11:28:18 +0000 (13:28 +0200)]
Don't start to stream after pg_receivexlog --create-slot.

Immediately starting to stream after --create-slot is inconvenient in a
number of situations (e.g. when configuring a slot for use in
recovery.conf) and it's easy to just call pg_receivexlog twice in the
rest of the cases.

Author: Michael Paquier
Discussion: CAB7nPqQ9qEtuDiKY3OpNzHcz5iUA+DUX9FcN9K8GUkCZvG7+Ew@mail.gmail.com
Backpatch: 9.5, where the option was introduced

8 years agoRemove gram.y's precedence declaration for OVERLAPS.
Tom Lane [Sun, 9 Aug 2015 23:01:04 +0000 (19:01 -0400)]
Remove gram.y's precedence declaration for OVERLAPS.

The allowed syntax for OVERLAPS, viz "row OVERLAPS row", is sufficiently
constrained that we don't actually need a precedence declaration for
OVERLAPS; indeed removing this declaration does not change the generated
gram.c file at all.  Let's remove it to avoid confusion about whether
OVERLAPS has precedence or not.  If we ever generalize what we allow for
OVERLAPS, we might need to put back a precedence declaration for it,
but we might want some other level than what it has today --- and leaving
the declaration there would just risk confusion about whether that would
be an incompatible change.

Likewise, remove OVERLAPS from the documentation's precedence table.

Per discussion with Noah Misch.  Back-patch to 9.5 where we hacked up some
nearby precedence decisions.

8 years agoFix typo in LDAP example
Magnus Hagander [Sun, 9 Aug 2015 12:49:47 +0000 (14:49 +0200)]
Fix typo in LDAP example

Reported by William Meitzen

8 years agodocs: update major release notes item checklist
Bruce Momjian [Sun, 9 Aug 2015 02:36:06 +0000 (22:36 -0400)]
docs:  update major release notes item checklist

8 years agoFix broken multibyte regression tests.
Tatsuo Ishii [Sun, 9 Aug 2015 01:55:41 +0000 (10:55 +0900)]
Fix broken multibyte regression tests.

commit 9043Fe390f4f0b4586cfe59cbd22314b9c3e2957 broke multibyte
regression tests because the commit removes the warning message when
temporary hash indexes is created, which has been added by commit
07af523870bcfe930134054febd3a6a114942e5b.

Back patched to 9.5 stable tree.

8 years agodocs: fix typo in rules.sgml
Bruce Momjian [Sun, 9 Aug 2015 00:40:53 +0000 (20:40 -0400)]
docs:  fix typo in rules.sgml

Report by Dean Rasheed

Patch by Dean Rasheed

Backpatch through 9.5

8 years agoDocument items that should appear in the major release notes
Bruce Momjian [Sat, 8 Aug 2015 21:33:55 +0000 (17:33 -0400)]
Document items that should appear in the major release notes

8 years ago9.5 release notes: add increase buffer mapping partitions item
Bruce Momjian [Sat, 8 Aug 2015 17:38:31 +0000 (13:38 -0400)]
9.5 release notes:  add increase buffer mapping partitions item

Report by Robert Haas, Andres Freund

Backpatch through 9.5

8 years agoAttempt to work around a 32bit xlc compiler bug from a different place.
Andres Freund [Fri, 7 Aug 2015 23:19:02 +0000 (01:19 +0200)]
Attempt to work around a 32bit xlc compiler bug from a different place.

In de6fd1c8 I moved the the work around from 53f73879 into the aix
template. The previous location was removed in the former commit, and I
thought that it would be nice to emit a warning when running configure.

That didn't turn out to work because at the point the template is
included we don't know whether we're compiling a 32/64 bit binary and
it's possible to install compilers for both on a 64 bit kernel/OS.

So go back to a less ambitious approach and define
PG_FORCE_DISABLE_INLINE in port/aix.h, without emitting a warning. We
could try a more fancy approach, but it doesn't seem worth it.

This requires moving the check for PG_FORCE_DISABLE_INLINE in c.h to
after including the system headers included from therein which isn't
perfect, as it seems slightly more robust to include all system headers
in a similar environment. Oh well.

Discussion: 20150807132000.GC13310@awork2.anarazel.de

8 years agoFix bug slowing down pgbench when -P is used.
Andres Freund [Fri, 7 Aug 2015 23:19:02 +0000 (01:19 +0200)]
Fix bug slowing down pgbench when -P is used.

A removed check in ba3deeefb made all threads but the main one busy-loop
when -P was used. All threads computed the time to the next time the
progress report should be printed, but only the main thread did so and
re-scheduled it only for the future.

Reported-By: Jesper Pedersen
Discussion: 55C4E190.3050104@redhat.com

8 years agoFurther adjustments to PlaceHolderVar removal.
Tom Lane [Fri, 7 Aug 2015 18:13:38 +0000 (14:13 -0400)]
Further adjustments to PlaceHolderVar removal.

A new test case from Andreas Seltenreich showed that we were still a bit
confused about removing PlaceHolderVars during join removal.  Specifically,
remove_rel_from_query would remove a PHV that was used only underneath
the removable join, even if the place where it's used was the join partner
relation and not the join clause being deleted.  This would lead to a
"too late to create a new PlaceHolderInfo" error later on.  We can defend
against that by checking ph_eval_at to see if the PHV could possibly be
getting used at some partner rel.

Also improve some nearby LATERAL-related logic.  I decided that the check
on ph_lateral needed to take precedence over the check on ph_needed, in
case there's a lateral reference underneath the join being considered.
(That may be impossible, but I'm not convinced of it, and it's easy enough
to defend against the case.)  Also, I realized that remove_rel_from_query's
logic for updating LateralJoinInfos is dead code, because we don't build
those at all until after join removal.

Back-patch to 9.3.  Previous versions didn't have the LATERAL issues, of
course, and they also didn't attempt to remove PlaceHolderInfos during join
removal.  (I'm starting to wonder if changing that was really such a great
idea.)

8 years agoFix attach-related race condition in shm_mq_send_bytes.
Robert Haas [Fri, 7 Aug 2015 14:04:07 +0000 (09:04 -0500)]
Fix attach-related race condition in shm_mq_send_bytes.

Spotted by Antonin Houska.

8 years agoDon't include low level locking code from frontend code.
Andres Freund [Fri, 7 Aug 2015 13:10:56 +0000 (15:10 +0200)]
Don't include low level locking code from frontend code.

Some frontend code like e.g. pg_xlogdump or pg_resetxlog, has to use
backend headers. Unfortunately until now that code includes most of the
locking code. It's generally not nice to expose such low level details,
but de6fd1c898 made that a hard problem. We fall back to defining
'inline' away if the compiler doesn't support it - that can cause linker
errors like on buildfarm animal pademelon if a inline function
references backend only code.

To fix that problem separate definitions from lock.h that are required
from frontend code into lockdefs.h and use it in the relevant
places. I've only removed the minimal amount of necessary definitions
for now - it might turn out that we want more for other reasons.

To avoid such details being exposed again put some checks against being
included from frontend code into atomics.h, lock.h, lwlock.h and
s_lock.h. It's otherwise fairly easy to indirectly include these
headers.

Discussion: 20150806070902.GE12214@awork2.anarazel.de

8 years agoAddress points made in post-commit review of replication origins.
Andres Freund [Fri, 7 Aug 2015 13:08:51 +0000 (15:08 +0200)]
Address points made in post-commit review of replication origins.

Amit reviewed the replication origins patch and made some good
points. Address them. This fixes typos in error messages, docs and
comments and adds a missing error check (although in a
should-never-happen scenario).

Discussion: CAA4eK1JqUBVeWWKwUmBPryFaje4190ug0y-OAUHWQ6tD83V4xg@mail.gmail.com
Backpatch: 9.5, where replication origins were introduced.

8 years ago9.5 release notes: updates from Andres Freund and Jeff Janes
Bruce Momjian [Fri, 7 Aug 2015 02:33:15 +0000 (22:33 -0400)]
9.5 release notes:  updates from Andres Freund and Jeff Janes

Report by Andres Freund and Jeff Janes

Backpatch through 9.5

8 years agoFix old oversight in join removal logic.
Tom Lane [Fri, 7 Aug 2015 02:14:07 +0000 (22:14 -0400)]
Fix old oversight in join removal logic.

Commit 9e7e29c75ad441450f9b8287bd51c13521641e3b introduced an Assert that
join removal didn't reduce the eval_at set of any PlaceHolderVar to empty.
At first glance it looks like join_is_removable ensures that's true --- but
actually, the loop in join_is_removable skips PlaceHolderVars that are not
referenced above the join due to be removed.  So, if we don't want any
empty eval_at sets, the right thing to do is to delete any now-unreferenced
PlaceHolderVars from the data structure entirely.

Per fuzz testing by Andreas Seltenreich.  Back-patch to 9.3 where the
aforesaid Assert was added.

8 years ago9.5 release notes: mention ON CONFLICT DO NOTHING for FDWs
Bruce Momjian [Fri, 7 Aug 2015 01:08:08 +0000 (21:08 -0400)]
9.5 release notes:  mention ON CONFLICT DO NOTHING for FDWs

Report by Peter Geoghegan

Backpatch through 9.5

8 years agoFix eclass_useful_for_merging to give valid results for appendrel children.
Tom Lane [Fri, 7 Aug 2015 00:14:37 +0000 (20:14 -0400)]
Fix eclass_useful_for_merging to give valid results for appendrel children.

Formerly, this function would always return "true" for an appendrel child
relation, because it would think that the appendrel parent was a potential
join target for the child.  In principle that should only lead to some
inefficiency in planning, but fuzz testing by Andreas Seltenreich disclosed
that it could lead to "could not find pathkey item to sort" planner errors
in odd corner cases.  Specifically, we would think that all columns of a
child table's multicolumn index were interesting pathkeys, causing us to
generate a MergeAppend path that sorts by all the columns.  However, if any
of those columns weren't actually used above the level of the appendrel,
they would not get added to that rel's targetlist, which would result in
being unable to resolve the MergeAppend's sort keys against its targetlist
during createplan.c.

Backpatch to 9.3.  In older versions, columns of an appendrel get added
to its targetlist even if they're not mentioned above the scan level,
so that the failure doesn't occur.  It might be worth back-patching this
fix to older versions anyway, but I'll refrain for the moment.

8 years ago9.5 release notes: mention change to CRC-32C
Bruce Momjian [Thu, 6 Aug 2015 22:03:39 +0000 (18:03 -0400)]
9.5 release notes:  mention change to CRC-32C

Report by Andres Freund

Backpatch through 9.5

8 years ago9.5 release notes: adjustments suggested by Andres Freund
Bruce Momjian [Thu, 6 Aug 2015 21:34:38 +0000 (17:34 -0400)]
9.5 release notes:  adjustments suggested by Andres Freund

Report by Andres Freund

Backpatch through 9.5

8 years ago9.5 release notes: add non-LEAKPROOF view pushdown mention
Bruce Momjian [Thu, 6 Aug 2015 20:07:27 +0000 (16:07 -0400)]
9.5 release notes:  add non-LEAKPROOF view pushdown mention

Report by Dean Rasheed

Backpatch through 9.5

8 years agoFurther fixes for degenerate outer join clauses.
Tom Lane [Thu, 6 Aug 2015 19:35:27 +0000 (15:35 -0400)]
Further fixes for degenerate outer join clauses.

Further testing revealed that commit f69b4b9495269cc4 was still a few
bricks shy of a load: minor tweaking of the previous test cases resulted
in the same wrong-outer-join-order problem coming back.  After study
I concluded that my previous changes in make_outerjoininfo() were just
accidentally masking the problem, and should be reverted in favor of
forcing syntactic join order whenever an upper outer join's predicate
doesn't mention a lower outer join's LHS.  This still allows the
chained-outer-joins style that is the normally optimizable case.

I also tightened things up some more in join_is_legal().  It seems to me
on review that what's really happening in the exception case where we
ignore a mismatched special join is that we're allowing the proposed join
to associate into the RHS of the outer join we're comparing it to.  As
such, we should *always* insist that the proposed join be a left join,
which eliminates a bunch of rather dubious argumentation.  The case where
we weren't enforcing that was the one that was already known buggy anyway
(it had a violatable Assert before the aforesaid commit) so it hardly
deserves a lot of deference.

Back-patch to all active branches, like the previous patch.  The added
regression test case failed in all branches back to 9.1, and I think it's
only an unrelated change in costing calculations that kept 9.0 from
choosing a broken plan.

8 years agoFix incorrect calculation in shm_mq_receive.
Robert Haas [Thu, 6 Aug 2015 17:25:45 +0000 (13:25 -0400)]
Fix incorrect calculation in shm_mq_receive.

If some, but not all, of the length word has already been read, and the
next attempt to read sees exactly the number of bytes needed to complete
the length word, or fewer, then we'll incorrectly read less than all of
the available data.

Antonin Houska

8 years agoReduce ProcArrayLock contention by removing backends in batches.
Robert Haas [Thu, 6 Aug 2015 15:52:51 +0000 (11:52 -0400)]
Reduce ProcArrayLock contention by removing backends in batches.

When a write transaction commits, it must clear its XID advertised via
the ProcArray, which requires that we hold ProcArrayLock in exclusive
mode in order to prevent concurrent processes running GetSnapshotData
from seeing inconsistent results.  When many processes try to commit
at once, ProcArrayLock must change hands repeatedly, with each
concurrent process trying to commit waking up to acquire the lock in
turn.  To make things more efficient, when more than one backend is
trying to commit a write transaction at the same time, have just one
of them acquire ProcArrayLock in exclusive mode and clear the XIDs of
all processes in the group.  Benchmarking reveals that this is much
more efficient at very high client counts.

Amit Kapila, heavily revised by me, with some review also from Pavan
Deolasee.

8 years agoFix `make installcheck` for serializable transactions.
Kevin Grittner [Thu, 6 Aug 2015 15:47:47 +0000 (10:47 -0500)]
Fix `make installcheck` for serializable transactions.

Commit e5550d5fec66aa74caad1f79b79826ec64898688 added some new
tests for ALTER TABLE which involved table scans.  When
default_transaction_isolation = 'serializable' these acquire
relation-level SIReadLocks.  The test results didn't cope with
that.  Add SIReadLock as the minimum lock level for purposes of
these tests.

This could also be fixed by excluding this type of lock from the
my_locks view, but it would be a bug for SIReadLock to show up for
a relation which was not otherwise locked, so do it this way to
allow that sort of condition to cause a regression test failure.

There is some question whether we could avoid taking SIReadLocks
during these operations, but confirming the safety of that and
figuring out how to avoid the locks is not trivial, and would be
a separate patch.

Backpatch to 9.4 where the new tests were added.

8 years agoImprove includes introduced in the replication origins patch.
Andres Freund [Thu, 6 Aug 2015 10:38:35 +0000 (12:38 +0200)]
Improve includes introduced in the replication origins patch.

pg_resetxlog.h contained two superfluous includes, origin.h superfluously
depended on logical.h, and pg_xlogdump's rmgrdesc.h only indirectly
included origin.h.

Backpatch: 9.5, where replication origins were introduced.

8 years agodocs: HTML-escape '>' in '=>' using HTML entities
Bruce Momjian [Thu, 6 Aug 2015 03:03:45 +0000 (23:03 -0400)]
docs:  HTML-escape '>' in '=>' using HTML entities

8 years agoReconcile nodes/*funcs.c with recent work.
Noah Misch [Thu, 6 Aug 2015 00:44:27 +0000 (20:44 -0400)]
Reconcile nodes/*funcs.c with recent work.

A few of the discrepancies had semantic significance, but I did not
track down the resulting user-visible bugs, if any.  Back-patch to 9.5,
where all but one discrepancy appeared.  The _equalCreateEventTrigStmt()
situation dates to 9.3 but does not affect semantics.

catversion bump due to readfuncs.c field order changes.

8 years agoLink $(WIN32RES) into single-file modules only when PGFILEDESC is set.
Noah Misch [Thu, 6 Aug 2015 00:43:07 +0000 (20:43 -0400)]
Link $(WIN32RES) into single-file modules only when PGFILEDESC is set.

Commit 0ffc201a51395ca71fe429ef86c872850a5850ee included this object
unconditionally.  Being unprepared for that, most external, single-file
modules failed to build.  This better aligns the GNU make build system
with the heuristic in the MSVC build's Project::AddDirResourceFile().
In-tree, installed modules set PGFILEDESC, so they will see no change.
Also, under PGXS, omit the nonfunctioning rule to build win32ver.rc.
Back-patch to 9.5, where the aforementioned commit first appeared.

8 years agoAllow pg_rewind tap tests to run with older File::Path versions
Andrew Dunstan [Wed, 5 Aug 2015 20:21:54 +0000 (16:21 -0400)]
Allow pg_rewind tap tests to run with older File::Path versions

Older versions have rmtree but not remove_tree. The one-argument forms
of these are equivalent, so replace remove_tree with rmtree. This allows
the tests to be run on oldish Msys systems.

8 years agoRemove carriage returns from certain tap test output under Msys
Andrew Dunstan [Wed, 5 Aug 2015 20:19:23 +0000 (16:19 -0400)]
Remove carriage returns from certain tap test output under Msys

These were causing spurious test failures.

8 years agoFix BRIN to use SnapshotAny during summarization
Alvaro Herrera [Wed, 5 Aug 2015 19:20:50 +0000 (16:20 -0300)]
Fix BRIN to use SnapshotAny during summarization

For correctness of summarization results, it is critical that the
snapshot used during the summarization scan is able to see all tuples
that are live to all transactions -- including tuples inserted or
deleted by in-progress transactions.  Otherwise, it would be possible
for a transaction to insert a tuple, then idle for a long time while a
concurrent transaction executes summarization of the range: this would
result in the inserted value not being considered in the summary.
Previously we were trying to use a MVCC snapshot in conjunction with
adding a "placeholder" tuple in the index: the snapshot would see all
committed tuples, and the placeholder tuple would catch insertions by
any new inserters.  The hole is that prior insertions by transactions
that are still in progress by the time the MVCC snapshot was taken were
ignored.

Kevin Grittner reported this as a bogus error message during vacuum with
default transaction isolation mode set to repeatable read (because the
error report mentioned a function name not being invoked during), but
the problem is larger than that.

To fix, tweak IndexBuildHeapRangeScan to have a new mode that behaves
the way we need using SnapshotAny visibility rules.  This change
simplifies the BRIN code a bit, mainly by removing large comments that
were mistaken.  Instead, rely on the SnapshotAny semantics to provide
what it needs.  (The business about a placeholder tuple needs to remain:
that covers the case that a transaction inserts a a tuple in a page that
summarization already scanned.)

Discussion: https://www.postgresql.org/message-id/20150731175700.GX2441@postgresql.org

In passing, remove a couple of unused declarations from brin.h and
reword a comment to be proper English.  This part submitted by Kevin
Grittner.

Backpatch to 9.5, where BRIN was introduced.

8 years agoMake real sure we don't reassociate joins into or out of SEMI/ANTI joins.
Tom Lane [Wed, 5 Aug 2015 18:39:07 +0000 (14:39 -0400)]
Make real sure we don't reassociate joins into or out of SEMI/ANTI joins.

Per the discussion in optimizer/README, it's unsafe to reassociate anything
into or out of the RHS of a SEMI or ANTI join.  An example from Piotr
Stefaniak showed that join_is_legal() wasn't sufficiently enforcing this
rule, so lock it down a little harder.

I couldn't find a reasonably simple example of the optimizer trying to
do this, so no new regression test.  (Piotr's example involved the random
search in GEQO accidentally trying an invalid case and triggering a sanity
check way downstream in clause selectivity estimation, which did not seem
like a sequence of events that would be useful to memorialize in a
regression test as-is.)

Back-patch to all active branches.

8 years agoFix typo in commit de6fd1c.
Andres Freund [Wed, 5 Aug 2015 16:39:05 +0000 (18:39 +0200)]
Fix typo in commit de6fd1c.

Per buildfarm members mandrill and hornet.

8 years agoRely on inline functions even if that causes warnings in older compilers.
Andres Freund [Wed, 5 Aug 2015 16:19:52 +0000 (18:19 +0200)]
Rely on inline functions even if that causes warnings in older compilers.

So far we have worked around the fact that some very old compilers do
not support 'inline' functions by only using inline functions
conditionally (or not at all). Since such compilers are very rare by
now, we have decided to rely on inline functions from 9.6 onwards.

To avoid breaking these old compilers inline is defined away when not
supported. That'll cause "function x defined but not used" type of
warnings, but since nobody develops on such compilers anymore that's
ok.

This change in policy will allow us to more easily employ inline
functions.

I chose to remove code previously conditional on PG_USE_INLINE as it
seemed confusing to have code dependent on a define that's always
defined.

Blacklisting of compilers, like in c53f73879f, now has to be done
differently. A platform template can define PG_FORCE_DISABLE_INLINE to
force inline to be defined empty.

Discussion: 20150701161447.GB30708@awork2.anarazel.de

8 years agoFix debug message output when connecting to a logical slot.
Andres Freund [Wed, 5 Aug 2015 11:26:01 +0000 (13:26 +0200)]
Fix debug message output when connecting to a logical slot.

Previously the message erroneously printed the same LSN twice as the
assignment to the start_lsn variable was before the message. Correct
that.

Reported-By: Marko Tiikkaja
Author: Marko Tiikkaja
Backpatch: 9.5, where logical decoding was introduced

8 years agoFix comment atomics.h.
Andres Freund [Wed, 5 Aug 2015 11:06:04 +0000 (13:06 +0200)]
Fix comment atomics.h.

I appear to accidentally have switched the comments for
pg_atomic_write_u32 and pg_atomic_read_u32 around. Also fix some minor
typos I found while fixing.

Noticed-By: Amit Kapila
Backpatch: 9.5

8 years agoDocs: add an explicit example about controlling overall greediness of REs.
Tom Lane [Wed, 5 Aug 2015 01:09:12 +0000 (21:09 -0400)]
Docs: add an explicit example about controlling overall greediness of REs.

Per discussion of bug #13538.

8 years agoFix pg_dump to dump shell types.
Tom Lane [Tue, 4 Aug 2015 23:34:12 +0000 (19:34 -0400)]
Fix pg_dump to dump shell types.

Per discussion, it really ought to do this.  The original choice to
exclude shell types was probably made in the dark ages before we made
it harder to accidentally create shell types; but that was in 7.3.

Also, cause the standard regression tests to leave a shell type behind,
for convenience in testing the case in pg_dump and pg_upgrade.

Back-patch to all supported branches.

8 years agoFix bogus "out of memory" reports in tuplestore.c.
Tom Lane [Tue, 4 Aug 2015 22:18:46 +0000 (18:18 -0400)]
Fix bogus "out of memory" reports in tuplestore.c.

The tuplesort/tuplestore memory management logic assumed that the chunk
allocation overhead for its memtuples array could not increase when
increasing the array size.  This is and always was true for tuplesort,
but we (I, I think) blindly copied that logic into tuplestore.c without
noticing that the assumption failed to hold for the much smaller array
elements used by tuplestore.  Given rather small work_mem, this could
result in an improper complaint about "unexpected out-of-memory situation",
as reported by Brent DeSpain in bug #13530.

The easiest way to fix this is just to increase tuplestore's initial
array size so that the assumption holds.  Rather than relying on magic
constants, though, let's export a #define from aset.c that represents
the safe allocation threshold, and make tuplestore's calculation depend
on that.

Do the same in tuplesort.c to keep the logic looking parallel, even though
tuplesort.c isn't actually at risk at present.  This will keep us from
breaking it if we ever muck with the allocation parameters in aset.c.

Back-patch to all supported versions.  The error message doesn't occur
pre-9.3, not so much because the problem can't happen as because the
pre-9.3 tuplestore code neglected to check for it.  (The chance of
trouble is a great deal larger as of 9.3, though, due to changes in the
array-size-increasing strategy.)  However, allowing LACKMEM() to become
true unexpectedly could still result in less-than-desirable behavior,
so let's patch it all the way back.

8 years agoFix a PlaceHolderVar-related oversight in star-schema planning patch.
Tom Lane [Tue, 4 Aug 2015 18:55:32 +0000 (14:55 -0400)]
Fix a PlaceHolderVar-related oversight in star-schema planning patch.

In commit b514a7460d9127ddda6598307272c701cbb133b7, I changed the planner
so that it would allow nestloop paths to remain partially parameterized,
ie the inner relation might need parameters from both the current outer
relation and some upper-level outer relation.  That's fine so long as we're
talking about distinct parameters; but the patch also allowed creation of
nestloop paths for cases where the inner relation's parameter was a
PlaceHolderVar whose eval_at set included the current outer relation and
some upper-level one.  That does *not* work.

In principle we could allow such a PlaceHolderVar to be evaluated at the
lower join node using values passed down from the upper relation along with
values from the join's own outer relation.  However, nodeNestloop.c only
supports simple Vars not arbitrary expressions as nestloop parameters.
createplan.c is also a few bricks shy of being able to handle such cases;
it misplaces the PlaceHolderVar parameters in the plan tree, which is why
the visible symptoms of this bug are "plan should not reference subplan's
variable" and "failed to assign all NestLoopParams to plan nodes" planner
errors.

Adding the necessary complexity to make this work doesn't seem like it
would be repaid in significantly better plans, because in cases where such
a PHV exists, there is probably a corresponding join order constraint that
would allow a good plan to be found without using the star-schema exception.
Furthermore, adding complexity to nodeNestloop.c would create a run-time
penalty even for plans where this whole consideration is irrelevant.
So let's just reject such paths instead.

Per fuzz testing by Andreas Seltenreich; the added regression test is based
on his example query.  Back-patch to 9.2, like the previous patch.

8 years agoCap wal_buffers to avoid a server crash when it's set very large.
Robert Haas [Tue, 4 Aug 2015 16:58:54 +0000 (12:58 -0400)]
Cap wal_buffers to avoid a server crash when it's set very large.

It must be possible to multiply wal_buffers by XLOG_BLCKSZ without
overflowing int, or calculations in StartupXLOG will go badly wrong
and crash the server.  Avoid that by imposing a maximum value on
wal_buffers.  This will be just under 2GB, assuming the usual value
for XLOG_BLCKSZ.

Josh Berkus, per an analysis by Andrew Gierth.

8 years agoTab completion for CREATE SEQUENCE.
Robert Haas [Tue, 4 Aug 2015 16:29:20 +0000 (12:29 -0400)]
Tab completion for CREATE SEQUENCE.

Vik Fearing, reviewed by Brendan Jurd, Michael Paquier, and myself

8 years agoUpdate comment to match behavior of latest code.
Robert Haas [Tue, 4 Aug 2015 15:45:29 +0000 (11:45 -0400)]
Update comment to match behavior of latest code.

Peter Geoghegan

8 years agoShare transition state between different aggregates when possible.
Heikki Linnakangas [Tue, 4 Aug 2015 14:53:10 +0000 (17:53 +0300)]
Share transition state between different aggregates when possible.

If there are two different aggregates in the query with same inputs, and
the aggregates have the same initial condition and transition function,
only calculate the state value once, and only call the final functions
separately. For example, AVG(x) and SUM(x) aggregates have the same
transition function, which accumulates the sum and number of input tuples.
For a query like "SELECT AVG(x), SUM(x) FROM x", we can therefore
accumulate the state function only once, which gives a nice speedup.

David Rowley, reviewed and edited by me.

8 years agoRLS: Keep deny policy when only restrictive exist
Stephen Frost [Mon, 3 Aug 2015 19:32:49 +0000 (15:32 -0400)]
RLS: Keep deny policy when only restrictive exist

Only remove the default deny policy when a permissive policy exists
(either from the hook or defined by the user).  If only restrictive
policies exist then no rows will be visible, as restrictive policies
shouldn't make rows visible.  To address this requirement, a single
"USING (true)" permissive policy can be created.

Update the test_rls_hooks regression tests to create the necessary
"USING (true)" permissive policy.

Back-patch to 9.5 where RLS was added.

Per discussion with Dean.

8 years agoUpdate 9.5 release notes through today.
Tom Lane [Mon, 3 Aug 2015 16:29:10 +0000 (12:29 -0400)]
Update 9.5 release notes through today.

8 years agoFix psql \d output of policies.
Joe Conway [Mon, 3 Aug 2015 16:07:47 +0000 (09:07 -0700)]
Fix psql \d output of policies.

psql neglected to wrap parenthesis around USING and WITH CHECK
expressions -- fixed. Back-patched to 9.5 where RLS policies were
introduced.

8 years agoMake recovery rename tablespace_map to *.old if backup_label is not present.
Fujii Masao [Mon, 3 Aug 2015 14:04:41 +0000 (23:04 +0900)]
Make recovery rename tablespace_map to *.old if backup_label is not present.

If tablespace_map file is present without backup_label file, there is
no use of such file.  There is no harm in retaining it, but it is better
to get rid of the map file so that we don't have any redundant file
in data directory and it will avoid any sort of confusion. It seems
prudent though to just rename the file out of the way rather than
delete it completely, also we ignore any error that occurs in rename
operation as even if map file is present without backup_label file,
it is harmless.

Back-patch to 9.5 where tablespace_map file was introduced.

Amit Kapila, reviewed by Robert Haas, Alvaro Herrera and me.

8 years agoFix pg_rewind when pg_xlog is a symlink.
Heikki Linnakangas [Mon, 3 Aug 2015 12:32:06 +0000 (15:32 +0300)]
Fix pg_rewind when pg_xlog is a symlink.

pg_xlog is often a symlink, typically to a different filesystem. Don't
get confused and comlain about by that, and just always pretend that it's a
normal directory, even if it's really a symlink.

Also add a test case for this.

Backpatch to 9.5.

8 years agoClean up pg_rewind regression test script.
Heikki Linnakangas [Mon, 3 Aug 2015 10:06:47 +0000 (13:06 +0300)]
Clean up pg_rewind regression test script.

Since commit 01f6bb4b2, TestLib.pm has exported path to tmp_check directory,
so let's use that also for the pg_rewind test clusters etc.

Also, in master, the $tempdir_short variable has not been used since commit
13d856e17, which moved the initdb-running code to TestLib.pm.

Backpatch to 9.5.

8 years agoMake modules/test_ddl_deparse/.gitignore match its siblings.
Tom Lane [Mon, 3 Aug 2015 04:02:26 +0000 (00:02 -0400)]
Make modules/test_ddl_deparse/.gitignore match its siblings.

Not sure why /tmp_check/ was omitted from this one, but even if it
isn't really needed right now, it's inconsistent not to include it.

8 years agocontrib/isn now needs a .gitignore file.
Tom Lane [Mon, 3 Aug 2015 03:57:32 +0000 (23:57 -0400)]
contrib/isn now needs a .gitignore file.

Oversight in commit cb3384a0cb4cf900622b77865f60e31259923079.
Back-patch to 9.1, like that commit.

8 years agoFix a number of places that produced XX000 errors in the regression tests.
Tom Lane [Mon, 3 Aug 2015 03:49:19 +0000 (23:49 -0400)]
Fix a number of places that produced XX000 errors in the regression tests.

It's against project policy to use elog() for user-facing errors, or to
omit an errcode() selection for errors that aren't supposed to be "can't
happen" cases.  Fix all the violations of this policy that result in
ERRCODE_INTERNAL_ERROR log entries during the standard regression tests,
as errors that can reliably be triggered from SQL surely should be
considered user-facing.

I also looked through all the files touched by this commit and fixed
other nearby problems of the same ilk.  I do not claim to have fixed
all violations of the policy, just the ones in these files.

In a few places I also changed existing ERRCODE choices that didn't
seem particularly appropriate; mainly replacing ERRCODE_SYNTAX_ERROR
by something more specific.

Back-patch to 9.5, but no further; changing ERRCODE assignments in
stable branches doesn't seem like a good idea.

8 years agoAllow TAP tests to run under Msys
Andrew Dunstan [Mon, 3 Aug 2015 00:58:18 +0000 (20:58 -0400)]
Allow TAP tests to run under Msys

The Msys DTK perl, which is required to run TAP tests under Msys as a
native perl won't recognize the correct virtual paths, has its osname
recorded in the Config module as 'msys' instead of 'MSWin32'. To avoid
having to repeat the test a variable is created that is true iff the
osname is either of these values, and is then used everywhere that
matters.

8 years agoAvoid calling memcpy() with a NULL source pointer and count == 0.
Tom Lane [Sun, 2 Aug 2015 19:48:27 +0000 (15:48 -0400)]
Avoid calling memcpy() with a NULL source pointer and count == 0.

As in commit 0a52d378b03b7d5a, avoid doing something that has undefined
results according to the C standard, even though in practice there does
not seem to be any problem with it.

This fixes two places in numeric.c that demonstrably could call memcpy()
with such arguments.  I looked through that file and didn't see any other
places with similar hazards; this is not to claim that there are not such
places in other files.

Per report from Piotr Stefaniak.  Back-patch to 9.5 which is where the
previous commit was added.  We're more or less setting a precedent that
we will not worry about this type of issue in pre-9.5 branches unless
someone demonstrates a problem in the field.

8 years agoFix output of ISBN-13 numbers beginning with 979.
Heikki Linnakangas [Sun, 2 Aug 2015 19:12:33 +0000 (22:12 +0300)]
Fix output of ISBN-13 numbers beginning with 979.

An EAN beginning with 979 (but not 9790 - those are ISMN's) are accepted
as ISBN numbers, but they cannot be represented in the old, 10-digit ISBN
format. They must be output in the new 13-digit ISBN-13 format. We printed
out an incorrect value for those.

Also add a regression test, to test this and some other basic functionality
of the module.

Patch by Fabien Coelho. This fixes bug #13442, reported by B.Z. Backpatch
to 9.1, where we started to recognize ISBN-13 numbers.

8 years agoFix incorrect order of lock file removal and failure to close() sockets.
Tom Lane [Sun, 2 Aug 2015 18:54:44 +0000 (14:54 -0400)]
Fix incorrect order of lock file removal and failure to close() sockets.

Commit c9b0cbe98bd783e24a8c4d8d8ac472a494b81292 accidentally broke the
order of operations during postmaster shutdown: it resulted in removing
the per-socket lockfiles after, not before, postmaster.pid.  This creates
a race-condition hazard for a new postmaster that's started immediately
after observing that postmaster.pid has disappeared; if it sees the
socket lockfile still present, it will quite properly refuse to start.
This error appears to be the explanation for at least some of the
intermittent buildfarm failures we've seen in the pg_upgrade test.

Another problem, which has been there all along, is that the postmaster
has never bothered to close() its listen sockets, but has just allowed them
to close at process death.  This creates a different race condition for an
incoming postmaster: it might be unable to bind to the desired listen
address because the old postmaster is still incumbent.  This might explain
some odd failures we've seen in the past, too.  (Note: this is not related
to the fact that individual backends don't close their client communication
sockets.  That behavior is intentional and is not changed by this patch.)

Fix by adding an on_proc_exit function that closes the postmaster's ports
explicitly, and (in 9.3 and up) reshuffling the responsibility for where
to unlink the Unix socket files.  Lock file unlinking can stay where it
is, but teach it to unlink the lock files in reverse order of creation.

8 years agoFix race condition that lead to WALInsertLock deadlock with commit_delay.
Heikki Linnakangas [Sun, 2 Aug 2015 17:08:10 +0000 (20:08 +0300)]
Fix race condition that lead to WALInsertLock deadlock with commit_delay.

If a call to WaitForXLogInsertionsToFinish() returned a value in the middle
of a page, and another backend then started to insert a record to the same
page, and then you called WaitXLogInsertionsToFinish() again, the second
call might return a smaller value than the first call. The problem was in
GetXLogBuffer(), which always updated the insertingAt value to the
beginning of the requested page, not the actual requested location. Because
of that, the second call might return a xlog pointer to the beginning of
the page, while the first one returned a later position on the same page.
XLogFlush() performs two calls to WaitXLogInsertionsToFinish() in
succession, and holds WALWriteLock on the second call, which can deadlock
if the second call to WaitXLogInsertionsToFinish() blocks.

Reported by Spiros Ioannou. Backpatch to 9.4, where the more scalable
WALInsertLock mechanism, and this bug, was introduced.

8 years agoMicro optimize LWLockAttemptLock() a bit.
Andres Freund [Fri, 31 Jul 2015 18:50:35 +0000 (20:50 +0200)]
Micro optimize LWLockAttemptLock() a bit.

LWLockAttemptLock pointlessly read the lock's state in every loop
iteration, even though pg_atomic_compare_exchange_u32() returns the old
value. Instead do that only once before the loop iteration.

Additionally there's no need to have the expected_state variable,
old_state mostly had the same value anyway.

Noticed-By: Heikki Linnakangas
Backpatch: 9.5, no reason to let the branches diverge at this point

8 years agoFix issues around the "variable" support in the lwlock infrastructure.
Andres Freund [Fri, 31 Jul 2015 18:20:43 +0000 (20:20 +0200)]
Fix issues around the "variable" support in the lwlock infrastructure.

The lwlock scalability work introduced two race conditions into the
lwlock variable support provided for xlog.c. First, and harmlessly on
most platforms, it set/read the variable without the spinlock in some
places. Secondly, due to the removal of the spinlock, it was possible
that a backend missed changes to the variable's state if it changed in
the wrong moment because checking the lock's state, the variable's state
and the queuing are not protected by a single spinlock acquisition
anymore.

To fix first move resetting the variable's from LWLockAcquireWithVar to
WALInsertLockRelease, via a new function LWLockReleaseClearVar. That
prevents issues around waiting for a variable's value to change when a
new locker has acquired the lock, but not yet set the value. Secondly
re-check that the variable hasn't changed after enqueing, that prevents
the issue that the lock has been released and already re-acquired by the
time the woken up backend checks for the lock's state.

Reported-By: Jeff Janes
Analyzed-By: Heikki Linnakangas
Reviewed-By: Heikki Linnakangas
Discussion: 5592DB35.2060401@iki.fi
Backpatch: 9.5, where the lwlock scalability went in

8 years agoFix some planner issues with degenerate outer join clauses.
Tom Lane [Sun, 2 Aug 2015 00:57:41 +0000 (20:57 -0400)]
Fix some planner issues with degenerate outer join clauses.

An outer join clause that didn't actually reference the RHS (perhaps only
after constant-folding) could confuse the join order enforcement logic,
leading to wrong query results.  Also, nested occurrences of such things
could trigger an Assertion that on reflection seems incorrect.

Per fuzz testing by Andreas Seltenreich.  The practical use of such cases
seems thin enough that it's not too surprising we've not heard field
reports about it.

This has been broken for a long time, so back-patch to all active branches.

8 years agoTeach predtest.c that "foo" implies "foo IS NOT NULL".
Tom Lane [Sat, 1 Aug 2015 18:31:46 +0000 (14:31 -0400)]
Teach predtest.c that "foo" implies "foo IS NOT NULL".

Per complaint from Peter Holzer.  It's useful to cover this special case,
since for a boolean variable "foo", earlier parts of the planner will have
reduced variants like "foo = true" to just "foo", and thus we may fail
to recognize the applicability of a partial index with predicate
"foo IS NOT NULL".

Back-patch to 9.5, but not further; given the lack of previous complaints
this doesn't seem like behavior to change in stable branches.

8 years agoFix an oversight in checking whether a join with LATERAL refs is legal.
Tom Lane [Fri, 31 Jul 2015 23:26:33 +0000 (19:26 -0400)]
Fix an oversight in checking whether a join with LATERAL refs is legal.

In many cases, we can implement a semijoin as a plain innerjoin by first
passing the righthand-side relation through a unique-ification step.
However, one of the cases where this does NOT work is where the RHS has
a LATERAL reference to the LHS; that makes the RHS dependent on the LHS
so that unique-ification is meaningless.  joinpath.c understood this,
and so would not generate any join paths of this kind ... but join_is_legal
neglected to check for the case, so it would think that we could do it.
The upshot would be a "could not devise a query plan for the given query"
failure once we had failed to generate any join paths at all for the bogus
join pair.

Back-patch to 9.3 where LATERAL was added.

8 years agoClean up Makefile.win32 "-I" flag additions.
Noah Misch [Fri, 31 Jul 2015 00:48:46 +0000 (20:48 -0400)]
Clean up Makefile.win32 "-I" flag additions.

The PGXS-case directory does not exist in the non-PGXS case, and vice
versa.  Add one or the other, not both.  This is essentially cosmetic.
It makes Makefile.win32 more like the similar Makefile.global code.

8 years agoConsolidate makefile code for setting top_srcdir, srcdir and VPATH.
Noah Misch [Fri, 31 Jul 2015 00:48:41 +0000 (20:48 -0400)]
Consolidate makefile code for setting top_srcdir, srcdir and VPATH.

Responsibility was formerly split between Makefile.global and pgxs.mk.
As a result of commit b58233c71b93a32fcab7219585cafc25a27eb769, in the
PGXS case, these variables were unset while parsing Makefile.global and
callees.  Inclusion of Makefile.custom did not work from PGXS, and the
subtle difference seemed like a recipe for future bugs.  Back-patch to
9.4, where that commit first appeared.

8 years agoFix volatility marking of commit timestamp functions
Alvaro Herrera [Thu, 30 Jul 2015 18:19:49 +0000 (15:19 -0300)]
Fix volatility marking of commit timestamp functions

They are marked stable, but since they act on instantaneous state and it
is possible to consult state of transactions as they commit, the results
could change mid-query.  They need to be marked volatile, and this
commit does so.

There would normally be a catversion bump here, but this is so much a
niche feature and I don't believe there's real damage from the incorrect
marking, that I refrained.

Backpatch to 9.5, where commit timestamps where introduced.

Per note from Fujii Masao.

8 years agoFix broken assertion in BRIN code
Alvaro Herrera [Thu, 30 Jul 2015 18:07:19 +0000 (15:07 -0300)]
Fix broken assertion in BRIN code

The code was assuming that any NULL value in scan keys was due to IS
NULL or IS NOT NULL, but it turns out to be possible to get them with
other operators too, if they are used in contrived-enough ways.  Easiest
way out of the problem seems to check explicitely for the IS NOT NULL
flag, instead of assuming it must be set if the IS NULL flag is not set,
when a null scan key is found; if neither flag is set, follow the lead
of other index AMs and assume that all indexable operators must be
strict, and thus the query is never satisfiable.

Also, add a comment to try and lure some future hacker into improving
analysis of scan keys in brin.

Per report from Andreas Seltenreich; diagnosis by Tom Lane.
Backpatch to 9.5.

Discussion: http://www.postgresql.org/message-id/20646.1437919632@sss.pgh.pa.us

8 years agoImprove CREATE FUNCTION doc WRT to LEAKPROOF RLS interaction.
Joe Conway [Thu, 30 Jul 2015 17:16:36 +0000 (10:16 -0700)]
Improve CREATE FUNCTION doc WRT to LEAKPROOF RLS interaction.

Patch by Dean Rasheed. Back-patched to 9.5 where RLS was introduced.

8 years agoUse appropriate command type when retrieving relation's policies.
Joe Conway [Thu, 30 Jul 2015 16:38:15 +0000 (09:38 -0700)]
Use appropriate command type when retrieving relation's policies.

When retrieving policies, if not working on the root target relation,
we actually want the relation's SELECT policies, regardless of
the top level query command type. For example in UPDATE t1...FROM t2
we need to apply t1's UPDATE policies and t2's SELECT policies.
Previously top level query command type was applied to all relations,
which was wrong. Add some regression coverage to ensure we don't
violate this principle in the future.

Report and patch by Dean Rasheed. Cherry picked from larger refactoring
patch and tweaked by me. Back-patched to 9.5 where RLS was introduced.

8 years agoAvoid some zero-divide hazards in the planner.
Tom Lane [Thu, 30 Jul 2015 16:11:23 +0000 (12:11 -0400)]
Avoid some zero-divide hazards in the planner.

Although I think on all modern machines floating division by zero
results in Infinity not SIGFPE, we still don't want infinities
running around in the planner's costing estimates; too much risk
of that leading to insane behavior.

grouping_planner() failed to consider the possibility that final_rel
might be known dummy and hence have zero rowcount.  (I wonder if it
would be better to set a rows estimate of 1 for dummy relations?
But at least in the back branches, changing this convention seems
like a bad idea, so I'll leave that for another day.)

Make certain that get_variable_numdistinct() produces a nonzero result.
The case that can be shown to be broken is with stadistinct < 0.0 and
small ntuples; we did not prevent the result from rounding to zero.
For good luck I applied clamp_row_est() to all the nonconstant return
values.

In ExecChooseHashTableSize(), Assert that we compute positive nbuckets
and nbatch.  I know of no reason to think this isn't the case, but it
seems like a good safety check.

Per reports from Piotr Stefaniak.  Back-patch to all active branches.

8 years agoFix calculation of latency of pgbench backslash commands.
Heikki Linnakangas [Thu, 30 Jul 2015 11:50:51 +0000 (14:50 +0300)]
Fix calculation of latency of pgbench backslash commands.

When we loop back to the top of doCustom after processing a backslash
command, we must reset the "now" timestamp, because that's used to
calculate the time spent executing the previous command.

Report and fix by Fabien Coelho. Backpatch to 9.5, where this was broken.

8 years agoUpdate ax_pthread.m4 to an experimental draft version from upstream.
Heikki Linnakangas [Thu, 30 Jul 2015 11:14:50 +0000 (14:14 +0300)]
Update ax_pthread.m4 to an experimental draft version from upstream.

The current version is adding a spurious -pthread option on some Darwin
systems that don't need it, which leads to a bunch of "unrecognized option
'-pthread'" warnings. There is a proposed fix for that in the upstream
autoconf archive's bug tracker, see https://savannah.gnu.org/patch/?8186.
This commit updates our version of ax_pthread.m4 to the "draft2" version
proposed there by Daniel Richard G. I'm using our buildfarm to help Daniel
to test this, before he commits this to the upstream repository.

8 years agoBlacklist xlc 32-bit inlining.
Noah Misch [Thu, 30 Jul 2015 02:49:48 +0000 (22:49 -0400)]
Blacklist xlc 32-bit inlining.

Per a suggestion from Tom Lane.  Back-patch to 9.0 (all supported
versions).  While only 9.4 and up have code known to elicit this
compiler bug, we were disabling inlining by accident until commit
43d89a23d59c487bc9258fad7a6187864cb8c0c0.

8 years agoRemove redundant "make install" from pg_upgrade test suite.
Noah Misch [Thu, 30 Jul 2015 02:49:36 +0000 (22:49 -0400)]
Remove redundant "make install" from pg_upgrade test suite.

A top-level "make install" includes pg_upgrade since commit
9fa8b0ee90c44c0f97d16bf65e94322988c94864.  Back-patch to 9.5, where that
commit first appeared.

8 years agoMSVC: Revert most 9.5 changes to pre-9.5 vcregress.pl tests.
Noah Misch [Thu, 30 Jul 2015 02:48:56 +0000 (22:48 -0400)]
MSVC: Revert most 9.5 changes to pre-9.5 vcregress.pl tests.

The reverted changes did not narrow the semantic gap between the MSVC
build system and the GNU make build system.  For targets old and new
that run multiple suites (contribcheck, modulescheck, tapcheck), restore
vcregress.pl to mimicking "make -k" rather than the "make -S" default.
Lack of "-k" would be more burdensome than lack of "-S".  Keep changes
reflecting contemporary changes to the GNU make build system, and keep
updates to Makefile parsing.  Keep the loss of --psqldir in "check" and
"ecpgcheck" targets; it had been a no-op when used alongside
--temp-install.  No log message mentioned any of the reverted changes.
Based on a germ by Michael Paquier.  Back-patch to 9.5.

8 years agoMSVC: Remove duplicate PATH entry in test harness.
Noah Misch [Thu, 30 Jul 2015 02:48:43 +0000 (22:48 -0400)]
MSVC: Remove duplicate PATH entry in test harness.

Back-patch to 9.5, where commit 4cb7d671fddc8855c8def2de51fb23df1c8ac0af
introduced it.

8 years agoMSVC: Future-proof installation file skip logic.
Noah Misch [Thu, 30 Jul 2015 02:48:25 +0000 (22:48 -0400)]
MSVC: Future-proof installation file skip logic.

This code relied on knowing exactly where in the source tree temporary
installations might appear.  A reasonable hacker may not think to update
this code when adding use of a temporary installation, making it
fragile.  Observe that commit 9fa8b0ee90c44c0f97d16bf65e94322988c94864
broke it unnoticed, and commit dcae5faccab64776376d354decda0017c648bb53
fixed it unnoticed.  Back-patch to 9.5 only; use of temporary
installations is unlikely to change in released versions.

8 years agoAdd IF NOT EXISTS processing to ALTER TABLE ADD COLUMN
Andrew Dunstan [Thu, 30 Jul 2015 01:30:00 +0000 (21:30 -0400)]
Add IF NOT EXISTS processing to ALTER TABLE ADD COLUMN

Fabrízio de Royes Mello, reviewed by Payal Singh, Alvaro Herrera and
Michael Paquier.

8 years agoCreate new ParseExprKind for use by policy expressions.
Joe Conway [Wed, 29 Jul 2015 22:37:48 +0000 (15:37 -0700)]
Create new ParseExprKind for use by policy expressions.

Policy USING and WITH CHECK expressions were using EXPR_KIND_WHERE for
parse analysis, which results in inappropriate ERROR messages when
the expression contains unsupported constructs such as aggregates.
Create a new ParseExprKind called EXPR_KIND_POLICY and tailor the
related messages to fit.

Reported by Noah Misch. Reviewed by Dean Rasheed, Alvaro Herrera,
and Robert Haas. Back-patch to 9.5 where RLS was introduced.

8 years agoFix incorrect comment.
Robert Haas [Wed, 29 Jul 2015 20:47:12 +0000 (16:47 -0400)]
Fix incorrect comment.

Amit Langote

8 years agoFlesh out the background worker documentation.
Robert Haas [Wed, 29 Jul 2015 18:41:07 +0000 (14:41 -0400)]
Flesh out the background worker documentation.

Make it more clear that bgw_main is usually not what you want.  Put the
background worker flags in a variablelist rather than having them as
part of a paragraph.  Explain important limits on how bgw_main_arg can
be used.

Craig Ringer, substantially revised by me.

8 years agoFix TAP tests with "make installcheck".
Heikki Linnakangas [Wed, 29 Jul 2015 17:59:24 +0000 (20:59 +0300)]
Fix TAP tests with "make installcheck".

I neglected that the prove_installcheck rule also needs to also define
PG_REGRESS, like prove_check does.

8 years agoAdd some test coverage of EvalPlanQual with non-locked tables.
Tom Lane [Wed, 29 Jul 2015 17:27:15 +0000 (13:27 -0400)]
Add some test coverage of EvalPlanQual with non-locked tables.

A Salesforce colleague of mine griped that the regression tests don't
exercise EvalPlanQualFetchRowMarks() and allied routines.  Which is
a fair complaint.  Add test cases that go through the REFERENCE and COPY
code paths.  Unfortunately we don't have sufficient infrastructure right
now to exercise the FDW code path in the isolation tests, but this is
surely better than before.

8 years agoAdd missing post create and alter hooks to policy objects.
Joe Conway [Wed, 29 Jul 2015 16:47:49 +0000 (09:47 -0700)]
Add missing post create and alter hooks to policy objects.

AlterPolicy() and CreatePolicy() lacked their respective hook invocations.
Noted by Noah Misch, review by Dean Rasheed. Back-patch to 9.5 where
RLS was introduced.

8 years agoMake TAP tests work on Windows.
Heikki Linnakangas [Wed, 29 Jul 2015 16:17:02 +0000 (19:17 +0300)]
Make TAP tests work on Windows.

On Windows, use listen_address=127.0.0.1 to allow TCP connections. We were
already using "pg_regress --config-auth" to set up HBA appropriately. The
standard_initdb helper function now sets up the server's
unix_socket_directories or listen_addresses in the config file, so that
they don't need to be specified in the pg_ctl command line anymore. That
way, the pg_ctl invocations in test programs don't need to differ between
Windows and Unix.

Add another helper function to configure the server's pg_hba.conf to allow
replication connections. The configuration is done similarly to "pg_regress
--config-auth": trust on domain sockets on Unix, and SSPI authentication on
Windows.

Replace calls to "cat" and "touch" programs with built-in perl code, as
those programs don't normally exist on Windows.

Add instructions in the docs on how to install IPC::Run on Windows. Adjust
vcregress.pl to not replace PERL5LIB completely in vcregress.pl, because
otherwise cannot install IPC::Run in a non-standard location easily.

Michael Paquier, reviewed by Noah Misch, some additional tweaking by me.

8 years agoDocument how to build the docs using the website style.
Robert Haas [Wed, 29 Jul 2015 15:16:55 +0000 (11:16 -0400)]
Document how to build the docs using the website style.

Craig Ringer

8 years agoRemove outdated comment in LWLockDequeueSelf's header.
Andres Freund [Wed, 29 Jul 2015 08:13:10 +0000 (10:13 +0200)]
Remove outdated comment in LWLockDequeueSelf's header.

Noticed-By: Robert Haas
Backpatch: 9.5, where the function was added

8 years agoFix typo in comment.
Heikki Linnakangas [Wed, 29 Jul 2015 07:55:43 +0000 (10:55 +0300)]
Fix typo in comment.

Amit Langote

8 years agopg_basebackup: Add --slot option
Peter Eisentraut [Wed, 22 Jul 2015 01:06:45 +0000 (21:06 -0400)]
pg_basebackup: Add --slot option

This option specifies a replication slot for WAL streaming (-X stream),
so that there can be continuous replication slot use between WAL
streaming during the base backup and the start of regular streaming
replication.

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>