Commit Graph

44927 Commits

Author SHA1 Message Date
Tom Lane b2328bf62b Fix some assorted compiler warnings on Windows.
Don't overflow the result type of constant expressions.  Don't negate
unsigned types.  Define HAVE_STDBOOL_H for Visual C++ 2013 and later.

Thomas Munro
Reviewed-By: Michael Paquier and Tom Lane

Discussion: https://postgr.es/m/CAEepm%3D3%3DTDYEXUEcHpEx%2BTwc31wo7PA0oBAiNt6sWmq93MW02A%40mail.gmail.com
2018-05-01 19:38:26 -04:00
Tom Lane 41c912cad1 Clean up warnings from -Wimplicit-fallthrough.
Recent gcc can warn about switch-case fall throughs that are not
explicitly labeled as intentional.  This seems like a good thing,
so clean up the warnings exposed thereby by labeling all such
cases with comments that gcc will recognize.

In files that already had one or more suitable comments, I generally
matched the existing style of those.  Otherwise I went with
/* FALLTHROUGH */, which is one of the spellings approved at the
more-restrictive-than-default level -Wimplicit-fallthrough=4.
(At the default level you can also spell it /* FALL ?THRU */,
and it's not picky about case.  What you can't do is include
additional text in the same comment, so some existing comments
containing versions of this aren't good enough.)

Testing with gcc 8.0.1 (Fedora 28's current version), I found that
I also had to put explicit "break"s after elog(ERROR) or ereport(ERROR);
apparently, for this purpose gcc doesn't recognize that those don't
return.  That seems like possibly a gcc bug, but it's fine because
in most places we did that anyway; so this amounts to a visit from the
style police.

Discussion: https://postgr.es/m/15083.1525207729@sss.pgh.pa.us
2018-05-01 19:35:08 -04:00
Andres Freund 1667148a4d Improve representation of 'moved partitions' indicator on deleted tuples.
Previously a tuple that has been moved to a different partition (see
f16241bef7), set the block number on the old tuple to an invalid
value to indicate that fact. But the tuple offset was left
untouched. That turned out to trigger a wal_consistency_checking
failure as reported by Peter Geoghegan, as the offset wasn't
always overwritten during WAL replay.

Heikki observed that we're wasting valuable data by not putting
information also in the offset. Thus set that to
MovedPartitionsOffsetNumber when a tuple indicates it has moved.

We continue to set the block number to MovedPartitionsBlockNumber, as
that seems more likely to cause problems for code not updated to know
about moved tuples.

As t_ctid's offset number is now always set, this refinement also
fixes the wal_consistency_checking issue.

This technically is a minor disk format break, with previously created
moved tuples not being recognized anymore. But since there not even
has been a beta release since f16241bef7c...

Reported-By: Peter Geoghegan
Author: Heikki Linnakangas, Amul Sul
Discussion: https://postgr.es/m/CAH2-Wzm9ty+1BX7-GMNJ=xPRg67oJTVeDNdA9LSyJJtMgRiCMA@mail.gmail.com
2018-05-01 13:30:12 -07:00
Robert Haas 37a3058bc7 Fix interaction of foreign tuple routing with remote triggers.
Without these fixes, changes to the inserted tuple made by remote
triggers are ignored when building local RETURNING tuples.

In the core code, call ExecInitRoutingInfo at a later point from
within ExecInitPartitionInfo so that the FDW callback gets invoked
after the returning list has been built.  But move CheckValidResultRel
out of ExecInitRoutingInfo so that it can happen at an earlier stage.

In postgres_fdw, refactor assorted deparsing functions to work with
the RTE rather than the PlannerInfo, which saves us having to
construct a fake PlannerInfo in cases where we don't have a real one.
Then, we can pass down a constructed RTE that yields the correct
deparse result when no real one exists.  Unfortunately, this
necessitates a hack that understands how the core code manages RT
indexes for update tuple routing, which is ugly, but we don't have a
better idea right now.

Original report, analysis, and patch by Etsuro Fujita.  Heavily
refactored by me.  Then worked over some more by Amit Langote.

Discussion: http://postgr.es/m/5AD4882B.10002@lab.ntt.co.jp
2018-05-01 13:21:46 -04:00
Tom Lane 6594ee2803 Remove jsonb_plperl test cases for Inf/NaN conversions.
It turns out that old Perl versions (before about 5.10) don't have any
very reliable way to generate Inf or NaN numeric values.  Getting around
that would require way more work than is really justified to test the
code involved, so let's just drop these new test cases.

Discussion: https://postgr.es/m/28585.1525131438@sss.pgh.pa.us
2018-05-01 13:21:16 -04:00
Tom Lane bcbf2346d6 Remove investigative code for can't-reattach-to-shared-memory errors.
Revert commits 23078689a, 73042b8d1, ce07aff48, f7df8043f, 6ba0cc4bd,
eb16011f4, 68e7e973d, 63ca350ef.  We still have a problem here, but
somebody who's actually a Windows developer will need to spend time
on it.

Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
2018-05-01 13:06:31 -04:00
Peter Eisentraut fa94fa6d82 Document that subscription tests require hstore 2018-05-01 10:33:02 -04:00
Bruce Momjian 81ff9ec8f8 doc comments: rendering engines are another UTF8 restriction 2018-05-01 10:17:55 -04:00
Bruce Momjian 3960fa5f63 docs comments: clarify why not to use UTF8 still in docs
Back branches still are SGML.
2018-05-01 09:26:11 -04:00
Peter Eisentraut 5a6ab0a1b1 doc: Update limitations of partitions
David Rowley, Amit Langote
2018-05-01 07:48:51 -04:00
Tom Lane 827eb4393c Tweak new jsonb_plperl test cases to work with old Perl versions.
The previous coding here didn't actually produce Inf or NaN double
values in Perl versions 5.8.x.  Adopt a suggestion from stackoverflow.

Discussion: https://postgr.es/m/28585.1525131438@sss.pgh.pa.us
2018-04-30 23:58:48 -04:00
Tom Lane 23078689a9 Does it help to wait before reattaching?
Revert the map/unmap dance I tried in commit 73042b8d1; that helps
not at all.

Instead, speculate that the unwanted allocation is being done on
another thread, and thus timing variations explain the apparent
unpredictability.  Temporarily add a 1-second sleep before the
VirtualFree call, in hopes that any such other threads will
quiesce and not jog our elbow.

This is obviously not a desirable long-term fix, but as a means of
investigation it seems useful.

Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
2018-04-30 20:09:31 -04:00
Tom Lane 73042b8d13 Map and unmap the shared memory block before risking VirtualFree.
The idea here is to get Windows' userspace infrastructure to allocate
whatever space it needs for MapViewOfFileEx() before we release the
locked-down space that we want to map the shared memory block into.

This is a fairly brute-force attempt, and would likely (for example)
fail with large shared memory on 32-bit Windows.  We could perhaps
ameliorate that by mapping only part of the shared memory block in
this way, but for the moment I just want to see if this approach
will fix dory's problem.

Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
2018-04-30 17:07:14 -04:00
Tom Lane ce07aff48f Further effort at preventing memory map dump from affecting the results.
Rather than elog'ing immediately, push the map data into a preallocated
StringInfo.  Perhaps this will prevent some of the mid-operation
allocations that are evidently happening now.

Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
2018-04-30 16:19:51 -04:00
Peter Eisentraut b04ebca6cd Remove plperl isnan hack
The code previously undefined isnan because of a compiler warning on
MinGW.  Since we now need to use isnan, we can't do that anymore.

We might need a different solution if the compiler warning is too
annoying.
2018-04-30 14:34:05 -04:00
Peter Eisentraut c5679256e9 Write error messages about duplicate OIDs to stderr 2018-04-30 14:18:46 -04:00
Peter Eisentraut 33a1c2145c Remove "Generating" output from catalog scripts
So by default, they don't output anything if everything is well.

Discussion: https://www.postgresql.org/message-id/867f8a1a-6cf0-d835-78d8-0844e4936241%402ndquadrant.com
2018-04-30 14:18:07 -04:00
Peter Eisentraut 92e1583b43 Don't do logical replication of TRUNCATE of zero tables
When due to publication configuration, a TRUNCATE change ends up with
zero tables to be published, don't send the message out, just skip it.
It's not wrong, but obviously useless overhead.
2018-04-30 13:49:20 -04:00
Peter Eisentraut e348e7ae57 Prevent infinity and NaN in jsonb/plperl transform
jsonb uses numeric internally, and numeric can store NaN, but that is
not allowed by jsonb on input, so we shouldn't store it.  Also prevent
infinity to get a consistent error message.  (numeric input would reject
infinity anyway.)

Reported-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
2018-04-30 13:22:57 -04:00
Tom Lane f7df8043f0 Remove Windows module-list-dumping code.
This code is evidently allocating memory and thus confusing matters
even more.  Let's see whether we can learn anything with
just VirtualQuery.

Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
2018-04-30 13:20:13 -04:00
Andrew Dunstan bb779006f4 clean up pg_upgrade tmp_check under MSVC 2018-04-30 12:43:57 -04:00
Andrew Dunstan 0146e32f9f Ignore file generated during pg_upgrade testing 2018-04-30 12:39:29 -04:00
Tom Lane 6ba0cc4bd3 Dump full memory maps around failing Windows reattach code.
This morning's results from buildfarm member dory make it pretty
clear that something is getting mapped into the just-freed space,
but not what that something is.  Replace my minimalistic probes
with a full dump of the process address space and module space,
based on Noah's work at
<20170403065106.GA2624300%40tornado.leadboat.com>

This is all (probably) to get reverted once we have fixed the
problem, but for now we need information.

Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
2018-04-30 11:16:21 -04:00
Tom Lane c5e46c7c3b Fix bogus list-iteration code in pg_regress.c, affecting ecpg tests only.
While looking at a recent buildfarm failure in the ecpg tests, I wondered
why the pg_regress output claimed the stderr part of the test failed, when
the regression diffs were clearly for the stdout part.  Looking into it,
the reason is that pg_regress.c's logic for iterating over three parallel
lists is wrong, and has been wrong since it was written: it advances the
"tag" pointer at a different place in the loop than the other two pointers.
Fix that.
2018-04-29 21:56:27 -04:00
Tom Lane eb16011f4c Get still more info about Windows can't-reattach-to-shared-memory errors.
After some thought about the info captured so far, it seems possible
that MapViewOfFileEx is itself causing some DLL to get loaded into
the space just freed by VirtualFree.  The previous commit here didn't
capture enough info to really prove the case for that, so let's add
one more VirtualQuery in between those steps.  Also, be sure to
capture the post-Map state before we emit any log entries, just in
case elog() is invoking some code not previously loaded.

Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
2018-04-29 20:41:19 -04:00
Tom Lane 6bdf1303b3 Avoid wrong results for power() with NaN input on more platforms.
Buildfarm results show that the modern POSIX rule that 1 ^ NaN = 1 is not
honored on *BSD until relatively recently, and really old platforms don't
believe that NaN ^ 0 = 1 either.  (This is unsurprising, perhaps, since
SUSv2 doesn't require either behavior.)  In hopes of getting to platform
independent behavior, let's deal with all the NaN-input cases explicitly
in dpow().

Note that numeric_power() doesn't know either of these special cases.
But since that behavior is platform-independent, I think it should be
addressed separately, and probably not back-patched.

Discussion: https://postgr.es/m/75DB81BEEA95B445AE6D576A0A5C9E936A73E741@BPXM05GP.gisp.nec.co.jp
2018-04-29 18:15:16 -04:00
Tom Lane 68e7e973d2 Get more info about Windows can't-reattach-to-shared-memory errors.
Commit 63ca350ef neglected to probe the state of things *before*
the VirtualFree call, which now looks like it might be interesting.

Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
2018-04-29 16:02:45 -04:00
Tom Lane df629586e8 Update time zone data files to tzdata release 2018d.
DST law changes in Palestine and Antarctica (Casey Station).  Historical
corrections for Portugal and its colonies, as well as Enderbury, Jamaica,
Turks & Caicos Islands, and Uruguay.
2018-04-29 15:50:08 -04:00
Tom Lane 61b200e2f5 Avoid wrong results for power() with NaN input on some platforms.
Per spec, the result of power() should be NaN if either input is NaN.
It appears that on some versions of Windows, the libc function does
return NaN, but it also sets errno = EDOM, confusing our code that
attempts to work around shortcomings of other platforms.  Hence, add
guard tests to avoid substituting a wrong result for the right one.

It's been like this for a long time (and the odd behavior only appears
in older MSVC releases, too) so back-patch to all supported branches.

Dang Minh Huong, reviewed by David Rowley

Discussion: https://postgr.es/m/75DB81BEEA95B445AE6D576A0A5C9E936A73E741@BPXM05GP.gisp.nec.co.jp
2018-04-29 15:21:44 -04:00
Tom Lane 85475afdb6 Cosmetic improvement: use BKI_DEFAULT and BKI_LOOKUP in pg_language.
The point of this is not really to remove redundancy in pg_language.dat;
with only three entries, it's hardly worth it.  Rather, it is to get
to a point where there are exactly zero hard-coded numeric pg_proc OID
references in the catalog .dat files.  The lanvalidator column was the
only remaining location of such references, and it seems like a good
thing for future-proofing reasons to make it not be a special case.

There are still a few places in the .dat files with numeric OID references
to other catalogs, but after review I don't see any that seem worth
changing at present.  In each case there are just too few entries to make
it worth the trouble to create lookup infrastructure.

This doesn't change the emitted postgres.bki file, so no catversion bump.
2018-04-29 13:26:26 -04:00
Tom Lane 9cb7db3f0c In AtEOXact_Files, complain if any files remain unclosed at commit.
This change makes this module act more like most of our other low-level
resource management modules.  It's a caller error if something is not
explicitly closed by the end of a successful transaction, so issue
a WARNING about it.  This would not actually have caught the file leak
bug fixed in commit 231bcd080, because that was in a transaction-abort
path; but it still seems like a good, and pretty cheap, cross-check.

Discussion: https://postgr.es/m/152056616579.4966.583293218357089052@wrigleys.postgresql.org
2018-04-28 17:45:02 -04:00
Tom Lane cfffe83ba8 Fix incorrect field type for PlannedStmt.jitFlags in outfuncs/readfuncs.
This field was a bool at one point, but now it's an int.
Spotted by Hari Babu; trivial patch is by Ashutosh Bapat.

Discussion: https://postgr.es/m/CAJrrPGedKiFE2fqntSauUfhapCksOJzam+QtHfSgx86LhXLeOQ@mail.gmail.com
2018-04-28 16:46:24 -04:00
Tom Lane 84549ebd4c Tweak reformat_dat_file.pl to make it more easily hand-invokable.
Use the same code we already applied in duplicate_oids and unused_oids
to let this script find Catalog.pm without help.  This removes the need
to supply a -I switch in most cases.

Also, mark the script executable, again to follow the precedent of
duplicate_oids and unused_oids.  Now you can just do
"./reformat_dat_file.pl pg_proc.dat"
if you want to reformat only one or a few .dat files rather than all.

It'd be possible to remove the -I switches in the Makefile's convenience
targets, but I chose to leave them: they don't hurt anything, and it's
possible that in weird VPATH situations they might be of value.
2018-04-28 16:09:03 -04:00
Tom Lane 45c6d75f8c Clarify handling of special-case values in bootstrap catalog data.
I (tgl) originally coded the special case for pg_proc.pronargs as
though it were a kind of default value.  It seems better though to
treat computable columns as an independent concern: this makes the
code clearer, and probably a bit faster too since we needn't do
work inside the per-column loop.

Improve related comments, as well, in the expectation that there
might be more cases like this in future.

John Naylor, some additional comment-hacking by me

Discussion: https://postgr.es/m/CAJVSVGW-D7OobzU=dybVT2JqZAx-4X1yvBJdavBmqQL05Q6CLw@mail.gmail.com
2018-04-28 15:27:16 -04:00
Tom Lane f2bb32dbd6 Un-break contrib install with llvm.
Apparently $(foreach ... $(call install_llvm_module,...)) doesn't work
too well without a blank line ending the install_llvm_module macro.
The previous coding hackishly dodged this problem with some parens,
but that's not really a good solution because make misunderstands
where the command boundaries are that way.

Discussion: https://postgr.es/m/20180428073935.GB1736@paquier.xyz
2018-04-28 14:45:39 -04:00
Tom Lane bc19b78362 Minor cleanups for install_llvm_module/uninstall_llvm_module Make macros.
Don't put comments inside the macros, per complaint from Michael Paquier.

Quote target directory path with single quotes, not double; that seems
to be our project standard.  Not quoting it at all definitely isn't
per standard.

Remove excess slash in one instance of path.

Remove useless semicolon.

Discussion: https://postgr.es/m/20180428073935.GB1736@paquier.xyz
2018-04-28 14:02:57 -04:00
Tom Lane 4094031dd3 Assorted minor doc/comment fixes.
Identify pg_replication_origin as a shared catalog in catalogs.sgml,
using the same boilerplate wording used for most other shared catalogs
(and tweak another place where someone had randomly deviated from
that boilerplate).

Make an example in mmgr/README more consistent with surrounding text.

Update an obsolete cross-reference in a comment in storage/block.h.

Zhuo Ql

Discussion: https://postgr.es/m/44296255.1819230.1524889719001@mail.yahoo.com
2018-04-28 11:46:15 -04:00
Tom Lane 63ca350ef9 Try to get some info about Windows can't-reattach-to-shared-memory errors.
Add some debug printouts focused on the idea that MapViewOfFileEx might
be rounding its virtual memory allocation up more than we expect (and,
in particular, more than VirtualAllocEx does).

Once we've seen what this reports in one of the failures on buildfarm
members dory or jacana, we might revert this ... or perhaps just
decrease the log level.

Discussion: https://postgr.es/m/25495.1524517820@sss.pgh.pa.us
2018-04-27 21:59:58 -04:00
Tom Lane 2e83e6bd74 Adjust hints and docs to suggest CREATE EXTENSION not CREATE LANGUAGE.
The core PLs have been extension-ified for seven years now, and we can
reasonably hope that all out-of-core PLs have been too.  So adjust a few
places that were still recommending CREATE LANGUAGE as the user-level
way to install a PL.

Discussion: https://postgr.es/m/CA+TgmoaJTUDMSuSCg4k08Dv8vhbrJq9nP3ZfPbmysVz_616qxw@mail.gmail.com
2018-04-27 13:42:03 -04:00
Peter Eisentraut 76ece16974 perltidy: Add option --nooutdent-long-comments 2018-04-27 11:37:43 -04:00
Peter Eisentraut d4f16d5071 perltidy: Add option --nooutdent-long-quotes 2018-04-27 11:37:43 -04:00
Peter Eisentraut a2ada08d4c perltidy: Don't write backup files
Newer perltidy versions can just avoid writing backup files, so we don't
need the old dance of deleting them afterwards.  Supported since 20120619.

https://metacpan.org/source/SHANCOCK/Perl-Tidy-20120619/CHANGES#L61
2018-04-27 11:37:43 -04:00
Heikki Linnakangas 45f87b7710 Remove outdated comment on how to set logtape's read buffer size.
Commit b75f467b6e removed the LogicalTapeAssignReadBufferSize() function,
but forgot to update this comment. The read buffer size is an argument to
LogicalTapeRewindForRead() now. Doesn't seem worth going into the details
in the file header comment, so remove the outdated sentence altogether.
2018-04-27 09:31:43 +03:00
Bruce Momjian 7551d9bc40 C comment: add description of root_tuple_slot
Reported-by: Amit Langote

Discussion: https://postgr.es/m/d2e6674c-c5c6-fe89-1d0b-3534b9db0476@lab.ntt.co.jp
2018-04-26 14:55:03 -04:00
Tom Lane bdf46af748 Post-feature-freeze pgindent run.
Discussion: https://postgr.es/m/15719.1523984266@sss.pgh.pa.us
2018-04-26 14:47:16 -04:00
Tom Lane f83bf385c1 Preliminary work for pgindent run.
Update typedefs.list from current buildfarm results.  Adjust pgindent's
typedef blacklist to block some more unfortunate typedef names that have
snuck in since last time.  Manually tweak a few places where I didn't
like the initial results of pgindent'ing.
2018-04-26 14:45:04 -04:00
Tom Lane a0854f1072 Avoid parsing catalog data twice during BKI file construction.
In the wake of commit 5602265f7, we were doing duplicate-OID detection
quite inefficiently, by invoking duplicate_oids which does all the same
parsing of catalog headers and .dat files as genbki.pl does.  That adds
under half a second on modern machines, but quite a bit more on slow
buildfarm critters, so it seems worth avoiding.  Let's just extend
genbki.pl a little so it can also detect duplicate OIDs, and remove
the duplicate_oids call from the build process.

(This also means that duplicate OID detection will happen during
Windows builds, which AFAICS it didn't before.)

This makes the use-case for duplicate_oids a bit dubious, but it's
possible that people will still want to run that check without doing
a whole build run, so let's keep that script.

In passing, move down genbki.pl's creation of its temp output files
so that it doesn't happen until after we've done parsing and validation
of the input.  This avoids leaving a lot of clutter around after a
failure.

John Naylor and Tom Lane

Discussion: https://postgr.es/m/37D774E4-FE1F-437E-B3D2-593F314B7505@postgrespro.ru
2018-04-26 13:22:27 -04:00
Tom Lane dd4cc9d706 Fix duplicate_oids and unused_oids so user needn't cd to catalog dir.
Previously, you had to cd into src/include/catalog before running either
of these scripts.  That's a bit tedious, so let's make the scripts do it
for you.

In passing, improve the initial comments in both scripts.  Also remove
unused_oids' code to complain about duplicate oids.  That was added in
yesterday's commit 5602265f7, but on second thought we shouldn't be
randomly redefining the script's behavior that way.

John Naylor and Tom Lane

Discussion: https://postgr.es/m/37D774E4-FE1F-437E-B3D2-593F314B7505@postgrespro.ru
2018-04-26 11:20:01 -04:00
Bruce Momjian 1900365c1e docs: remove "III" version text from pgAdmin link
Reported-by: vodevsh@gmail.com

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

Backpatch-through: 9.3
2018-04-26 11:10:43 -04:00
Noah Misch 6336b6dfc5 Correct pg_recvlogical server version test.
The predecessor test boiled down to "PQserverVersion(NULL) >= 100000",
which is always false.  No release includes that, so it could not have
reintroduced CVE-2018-1058.  Back-patch to 9.4, like the addition of the
predecessor in commit 8d2814f274.

Discussion: https://postgr.es/m/20180422215551.GB2676194@rfd.leadboat.com
2018-04-25 18:50:29 -07:00