]> granicus.if.org Git - postgresql/log
postgresql
9 years agoAllow "dbname" from connection string to be overridden in PQconnectDBParams
Heikki Linnakangas [Tue, 25 Nov 2014 15:12:07 +0000 (17:12 +0200)]
Allow "dbname" from connection string to be overridden in PQconnectDBParams

If the "dbname" attribute in PQconnectDBParams contained a connection string
or URI (and expand_dbname = TRUE), the database name from the connection
string could not be overridden by a subsequent "dbname" keyword in the
array. That was not intentional; all other options can be overridden.
Furthermore, any subsequent "dbname" caused the connection string from the
first dbname value to be processed again, overriding any values for the same
options that were given between the connection string and the second dbname
option.

In the passing, clarify in the docs that only the first dbname option in the
array is parsed as a connection string.

Alex Shulgin. Backpatch to all supported versions.

9 years agoSuppress DROP CASCADE notices in regression tests
Stephen Frost [Tue, 25 Nov 2014 14:49:48 +0000 (09:49 -0500)]
Suppress DROP CASCADE notices in regression tests

In the regression tests, when doing cascaded drops, we need to suppress
the notices from DROP CASCADE or there can be transient regression
failures as the order of drops can depend on the physical row order in
pg_depend.

Report and fix suggestion from Tom.

9 years agoCheck return value of strdup() in libpq connection option parsing.
Heikki Linnakangas [Tue, 25 Nov 2014 10:55:00 +0000 (12:55 +0200)]
Check return value of strdup() in libpq connection option parsing.

An out-of-memory in most of these would lead to strange behavior, like
connecting to a different database than intended, but some would lead to
an outright segfault.

Alex Shulgin and me. Backpatch to all supported versions.

9 years agoMake Port->ssl_in_use available, even when built with !USE_SSL
Heikki Linnakangas [Tue, 25 Nov 2014 07:39:31 +0000 (09:39 +0200)]
Make Port->ssl_in_use available, even when built with !USE_SSL

Code that check the flag no longer need #ifdef's, which is more convenient.
In particular, makes it easier to write extensions that depend on it.

In the passing, modify sslinfo's ssl_is_used function to check ssl_in_use
instead of the OpenSSL specific 'ssl' pointer. It doesn't make any
difference currently, as sslinfo is only compiled when built with OpenSSL,
but seems cleaner anyway.

9 years agoAdd infrastructure to save and restore GUC values.
Robert Haas [Mon, 24 Nov 2014 21:13:11 +0000 (16:13 -0500)]
Add infrastructure to save and restore GUC values.

This is further infrastructure for parallelism.

Amit Khandekar, Noah Misch, Robert Haas

9 years agoAdd a few paragraphs to B-tree README explaining L&Y algorithm.
Heikki Linnakangas [Mon, 24 Nov 2014 11:41:47 +0000 (13:41 +0200)]
Add a few paragraphs to B-tree README explaining L&Y algorithm.

This gives an overview of what Lehman & Yao's paper is all about, so that
you can understand the rest of the README without having to read the paper.

Per discussion with Peter Geoghegan and others.

9 years agoDistinguish XLOG_FPI records generated for hint-bit updates.
Heikki Linnakangas [Mon, 24 Nov 2014 08:43:32 +0000 (10:43 +0200)]
Distinguish XLOG_FPI records generated for hint-bit updates.

Add a new XLOG_FPI_FOR_HINT record type, and use that for full-page images
generated for hint bit updates, when checksums are enabled. The new record
type is replayed exactly the same as XLOG_FPI, but allows them to be tallied
separately e.g. in pg_xlogdump.

9 years agoGet rid of redundant production in plpgsql grammar.
Tom Lane [Sun, 23 Nov 2014 20:31:32 +0000 (15:31 -0500)]
Get rid of redundant production in plpgsql grammar.

There may once have been a reason for the intermediate proc_stmts
production in the plpgsql grammar, but it isn't doing anything useful
anymore, so let's collapse it into proc_sect.  Saves some code and
probably a small number of nanoseconds per statement list.

In passing, correctly alphabetize keyword lists to match pl_scanner.c;
note that for "rowtype" vs "row_count", pl_scanner.c must sort on the
basis of the lower-case spelling.

Noted while fooling with a patch to de-reserve more plpgsql keywords.

9 years agoFix memory leaks introduced by commit eca2b9b
Andrew Dunstan [Sun, 23 Nov 2014 18:47:08 +0000 (13:47 -0500)]
Fix memory leaks introduced by commit eca2b9b

9 years agoDetect PG_PRINTF_ATTRIBUTE automatically.
Noah Misch [Sun, 23 Nov 2014 14:34:03 +0000 (09:34 -0500)]
Detect PG_PRINTF_ATTRIBUTE automatically.

This eliminates gobs of "unrecognized format function type" warnings
under MinGW compilers predating GCC 4.4.

9 years agoAllow simplification of EXISTS() subqueries containing LIMIT.
Tom Lane [Sun, 23 Nov 2014 00:12:38 +0000 (19:12 -0500)]
Allow simplification of EXISTS() subqueries containing LIMIT.

The locution "EXISTS(SELECT ... LIMIT 1)" seems to be rather common among
people who don't realize that the database already performs optimizations
equivalent to putting LIMIT 1 in the sub-select.  Unfortunately, this was
actually making things worse, because it prevented us from optimizing such
EXISTS clauses into semi or anti joins.  Teach simplify_EXISTS_query() to
suppress constant-positive LIMIT clauses.  That fixes the semi/anti-join
case, and may help marginally even for cases that have to be left as
sub-SELECTs.

Marti Raudsepp, reviewed by David Rowley

9 years agoFix mishandling of system columns in FDW queries.
Tom Lane [Sat, 22 Nov 2014 21:01:05 +0000 (16:01 -0500)]
Fix mishandling of system columns in FDW queries.

postgres_fdw would send query conditions involving system columns to the
remote server, even though it makes no effort to ensure that system
columns other than CTID match what the remote side thinks.  tableoid,
in particular, probably won't match and might have some use in queries.
Hence, prevent sending conditions that include non-CTID system columns.

Also, create_foreignscan_plan neglected to check local restriction
conditions while determining whether to set fsSystemCol for a foreign
scan plan node.  This again would bollix the results for queries that
test a foreign table's tableoid.

Back-patch the first fix to 9.3 where postgres_fdw was introduced.
Back-patch the second to 9.2.  The code is probably broken in 9.1 as
well, but the patch doesn't apply cleanly there; given the weak state
of support for FDWs in 9.1, it doesn't seem worth fixing.

Etsuro Fujita, reviewed by Ashutosh Bapat, and somewhat modified by me

9 years agoRework echo_hidden for \sf and \ef from commit e4d2817.
Andrew Dunstan [Sat, 22 Nov 2014 14:39:01 +0000 (09:39 -0500)]
Rework echo_hidden for \sf and \ef from commit e4d2817.

PSQLexec's error reporting turns out to be too verbose for this case, so
revert to using PQexec instead with minimal error reporting. Prior to
calling PQexec, we call a function that mimics just the echo_hidden
piece of PSQLexec.

9 years agoRearrange CustomScan API.
Tom Lane [Fri, 21 Nov 2014 23:21:46 +0000 (18:21 -0500)]
Rearrange CustomScan API.

Make it work more like FDW plans do: instead of assuming that there are
expressions in a CustomScan plan node that the core code doesn't know
about, insist that all subexpressions that need planner attention be in
a "custom_exprs" list in the Plan representation.  (Of course, the
custom plugin can break the list apart again at executor initialization.)
This lets us revert the parts of the patch that exposed setrefs.c and
subselect.c processing to the outside world.

Also revert the GetSpecialCustomVar stuff in ruleutils.c; that concept
may work in future, but it's far from fully baked right now.

9 years agoSimplify API for initially hooking custom-path providers into the planner.
Tom Lane [Fri, 21 Nov 2014 19:05:46 +0000 (14:05 -0500)]
Simplify API for initially hooking custom-path providers into the planner.

Instead of register_custom_path_provider and a CreateCustomScanPath
callback, let's just provide a standard function hook in set_rel_pathlist.
This is more flexible than what was previously committed, is more like the
usual conventions for planner hooks, and requires less support code in the
core.  We had discussed this design (including centralizing the
set_cheapest() calls) back in March or so, so I'm not sure why it wasn't
done like this already.

9 years agoFix an error in psql that overcounted output lines.
Andrew Dunstan [Fri, 21 Nov 2014 17:37:09 +0000 (12:37 -0500)]
Fix an error in psql that overcounted output lines.

This error counted the first line of a cell as "extra". The effect was
to cause far too frequent invocation of the pager. In most cases this
can be worked around (for example, by using the "less" pager with the -F
flag), so don't backpatch.

9 years agoMake psql's \sf and \ef honor ECHO_HIDDEN.
Andrew Dunstan [Fri, 21 Nov 2014 17:14:05 +0000 (12:14 -0500)]
Make psql's \sf and \ef honor ECHO_HIDDEN.

These commands were calling the database direct rather than  calling
PSQLexec like other slash commands that needed database data.

The code is also changed not to pass the connection as a parameter to
the helper functions. It's available in a global variable, and that's
what PSQLexec uses.

9 years agoNo need to call XLogEnsureRecordSpace when the relation is unlogged.
Heikki Linnakangas [Fri, 21 Nov 2014 13:13:15 +0000 (15:13 +0200)]
No need to call XLogEnsureRecordSpace when the relation is unlogged.

Amit Kapila

9 years agoAdd a comment to regress.c explaining what it contains.
Heikki Linnakangas [Fri, 21 Nov 2014 13:07:29 +0000 (15:07 +0200)]
Add a comment to regress.c explaining what it contains.

Ian Barwick

9 years agoFix bogus comments in XLogRecordAssemble
Heikki Linnakangas [Fri, 21 Nov 2014 10:13:10 +0000 (12:13 +0200)]
Fix bogus comments in XLogRecordAssemble

Pointed out by Michael Paquier

9 years agoAdd pageinspect functions for inspecting GIN indexes.
Heikki Linnakangas [Fri, 21 Nov 2014 09:46:50 +0000 (11:46 +0200)]
Add pageinspect functions for inspecting GIN indexes.

Patch by me, Peter Geoghegan and Michael Paquier, reviewed by Amit Kapila.

9 years agoRemove dead code supporting mark/restore in SeqScan, TidScan, ValuesScan.
Tom Lane [Fri, 21 Nov 2014 01:20:54 +0000 (20:20 -0500)]
Remove dead code supporting mark/restore in SeqScan, TidScan, ValuesScan.

There seems no prospect that any of this will ever be useful, and indeed
it's questionable whether some of it would work if it ever got called;
it's certainly not been exercised in a very long time, if ever. So let's
get rid of it, and make the comments about mark/restore in execAmi.c less
wishy-washy.

The mark/restore support for Result nodes is also currently dead code,
but that's due to planner limitations not because it's impossible that
it could be useful.  So I left it in.

9 years agoInitial code review for CustomScan patch.
Tom Lane [Thu, 20 Nov 2014 23:36:07 +0000 (18:36 -0500)]
Initial code review for CustomScan patch.

Get rid of the pernicious entanglement between planner and executor headers
introduced by commit 0b03e5951bf0a1a8868db13f02049cf686a82165.

Also, rearrange the CustomFoo struct/typedef definitions so that all the
typedef names are seen as used by the compiler.  Without this pgindent
will mess things up a bit, which is not so important perhaps, but it also
removes a bizarre discrepancy between the declaration arrangement used for
CustomExecMethods and that used for CustomScanMethods and
CustomPathMethods.

Clean up the commentary around ExecSupportsMarkRestore to reflect the
rather large change in its API.

Const-ify register_custom_path_provider's argument.  This necessitates
casting away const in the function, but that seems better than forcing
callers of the function to do so (or else not const-ify their method
pointer structs, which was sort of the whole point).

De-export fix_expr_common.  I don't like the exporting of fix_scan_expr
or replace_nestloop_params either, but this one surely has got little
excuse.

9 years agoFix another oversight in CustomScan patch.
Tom Lane [Thu, 20 Nov 2014 20:56:39 +0000 (15:56 -0500)]
Fix another oversight in CustomScan patch.

execCurrent.c's search_plan_tree() must recognize a CustomScan on the
target relation.  This would only be helpful for custom providers that
support CurrentOfExpr quals, which is probably a bit far-fetched, but
it's not impossible I think.  But even without assuming that, we need
to recognize a scanned-relation match so that we will properly throw
error if the desired relation is being scanned with both a CustomScan
and a regular scan (ie, self-join).

Also recognize ForeignScanState for similar reasons.  Supporting WHERE
CURRENT OF on a foreign table is probably even more far-fetched than
it is for custom scans, but I think in principle you could do it with
postgres_fdw (or another FDW that supports the ctid column).  This
would be a back-patchable bug fix if existing FDWs handled CurrentOfExpr,
but I doubt any do so I won't bother back-patching.

9 years agoFix another oversight in CustomScan patch.
Tom Lane [Thu, 20 Nov 2014 19:49:02 +0000 (14:49 -0500)]
Fix another oversight in CustomScan patch.

disuse_physical_tlist() must work for all plan types handled by
create_scan_plan().

9 years agoRemove no-longer-needed phony typedefs in genbki.h.
Tom Lane [Thu, 20 Nov 2014 18:16:14 +0000 (13:16 -0500)]
Remove no-longer-needed phony typedefs in genbki.h.

Now that we have a policy of hiding varlena catalog fields behind
"#ifdef CATALOG_VARLEN", there is no need for their type names to be
acceptable to the C compiler.  And experimentation shows that it does
not matter to pgindent either.  (If it did, we'd have problems anyway,
since these typedefs are unreferenced so far as the C compiler is
concerned, and find_typedef fails to identify such typedefs.)

Hence, remove the phony typedefs that genbki.h provided to make
some varlena field definitions compilable.

In passing, rearrange #define's into what seemed a more logical order.

9 years agoAdd missing case for CustomScan.
Tom Lane [Thu, 20 Nov 2014 17:32:19 +0000 (12:32 -0500)]
Add missing case for CustomScan.

Per KaiGai Kohei.

In passing improve formatting of some code added in commit 30d7ae3c,
because otherwise pgindent will make a mess of it.

9 years agoSilence compiler warning about variable being used uninitialized.
Heikki Linnakangas [Thu, 20 Nov 2014 17:16:12 +0000 (19:16 +0200)]
Silence compiler warning about variable being used uninitialized.

It's a false positive - the variable is only used when 'onleft' is true,
and it is initialized in that case. But the compiler doesn't necessarily
see that.

9 years agoRevamp the WAL record format.
Heikki Linnakangas [Thu, 20 Nov 2014 15:56:26 +0000 (17:56 +0200)]
Revamp the WAL record format.

Each WAL record now carries information about the modified relation and
block(s) in a standardized format. That makes it easier to write tools that
need that information, like pg_rewind, prefetching the blocks to speed up
recovery, etc.

There's a whole new API for building WAL records, replacing the XLogRecData
chains used previously. The new API consists of XLogRegister* functions,
which are called for each buffer and chunk of data that is added to the
record. The new API also gives more control over when a full-page image is
written, by passing flags to the XLogRegisterBuffer function.

This also simplifies the XLogReadBufferForRedo() calls. The function can dig
the relation and block number from the WAL record, so they no longer need to
be passed as arguments.

For the convenience of redo routines, XLogReader now disects each WAL record
after reading it, copying the main data part and the per-block data into
MAXALIGNed buffers. The data chunks are not aligned within the WAL record,
but the redo routines can assume that the pointers returned by XLogRecGet*
functions are. Redo routines are now passed the XLogReaderState, which
contains the record in the already-disected format, instead of the plain
XLogRecord.

The new record format also makes the fixed size XLogRecord header smaller,
by removing the xl_len field. The length of the "main data" portion is now
stored at the end of the WAL record, and there's a separate header after
XLogRecord for it. The alignment padding at the end of XLogRecord is also
removed. This compansates for the fact that the new format would otherwise
be more bulky than the old format.

Reviewed by Andres Freund, Amit Kapila, Michael Paquier, Alvaro Herrera,
Fujii Masao.

9 years agoFix suggested layout for PGXS makefile
Peter Eisentraut [Thu, 20 Nov 2014 03:21:54 +0000 (22:21 -0500)]
Fix suggested layout for PGXS makefile

Custom rules must come after pgxs inclusion, not before, because any
rule added before pgxs will break the default 'all' target.

Author: Cédric Villemain <cedric@2ndquadrant.fr>

9 years agoImprove documentation's description of JOIN clauses.
Tom Lane [Wed, 19 Nov 2014 21:00:24 +0000 (16:00 -0500)]
Improve documentation's description of JOIN clauses.

In bug #12000, Andreas Kunert complained that the documentation was
misleading in saying "FROM T1 CROSS JOIN T2 is equivalent to FROM T1, T2".
That's correct as far as it goes, but the equivalence doesn't hold when
you consider three or more tables, since JOIN binds more tightly than
comma.  I added a <note> to explain this, and ended up rearranging some
of the existing text so that the note would make sense in context.

In passing, rewrite the description of JOIN USING, which was unnecessarily
vague, and hadn't been helped any by somebody's reliance on markup as a
substitute for clear writing.  (Mostly this involved reintroducing a
concrete example that was unaccountably removed by commit 032f3b7e166cfa28.)

Back-patch to all supported branches.

9 years agoAdd test cases for indexam operations not currently covered.
Heikki Linnakangas [Wed, 19 Nov 2014 17:24:58 +0000 (19:24 +0200)]
Add test cases for indexam operations not currently covered.

That includes VACUUM on GIN, GiST and SP-GiST indexes, and B-tree indexes
large enough to cause page deletions in B-tree. Plus some other special
cases.

After this patch, the regression tests generate all different WAL record
types. Not all branches within the redo functions are covered, but it's a
step forward.

9 years agoAvoid file descriptor leak in pg_test_fsync.
Robert Haas [Wed, 19 Nov 2014 16:57:54 +0000 (11:57 -0500)]
Avoid file descriptor leak in pg_test_fsync.

This can cause problems on Windows, where files that are still open
can't be unlinked.

Jeff Janes

9 years agoFix bug in the test of file descriptor of current WAL file in pg_receivexlog.
Fujii Masao [Wed, 19 Nov 2014 10:10:04 +0000 (19:10 +0900)]
Fix bug in the test of file descriptor of current WAL file in pg_receivexlog.

In pg_receivexlog, in order to check whether the current WAL file is
being opened or not, its file descriptor has to be checked against -1
as an invalid value. But, oops, 7900e94 added the incorrect test
checking the descriptor against 1. This commit fixes that bug.

Back-patch to 9.4 where the bug was added.

Spotted by Magnus Hagander

9 years agoFix pg_receivexlog --slot so that it doesn't prevent the server shutdown.
Fujii Masao [Wed, 19 Nov 2014 05:11:12 +0000 (14:11 +0900)]
Fix pg_receivexlog --slot so that it doesn't prevent the server shutdown.

When pg_receivexlog --slot is connecting to the server, at the shutdown
of the server, walsender keeps waiting for the last WAL record to be
replicated and flushed in pg_receivexlog. But previously pg_receivexlog
issued sync command only when WAL file was switched. So there was
the case where the last WAL was never flushed and walsender had to
keep waiting infinitely. This caused the server shutdown to get stuck.

pg_recvlogical handles this problem by calling fsync() when it receives
the request of immediate reply from the server. That is, at shutdown,
walsender sends the request, pg_recvlogical receives it, flushes the last
WAL record, and sends the flush location back to the server. Since
walsender can see that the last WAL record is successfully flushed, it can
exit cleanly.

This commit introduces the same logic as pg_recvlogical has,
to pg_receivexlog.

Back-patch to 9.4 where pg_receivexlog was changed so that it can use
the replication slot.

Original patch by Michael Paquier, rewritten by me.
Bug report by Furuya Osamu.

9 years agoDon't require bleeding-edge timezone data in timestamptz regression test.
Tom Lane [Wed, 19 Nov 2014 02:36:39 +0000 (21:36 -0500)]
Don't require bleeding-edge timezone data in timestamptz regression test.

The regression test cases added in commits b2cbced9e et al depended in part
on the Russian timezone offset changes of Oct 2014.  While this is of no
particular concern for a default Postgres build, it was possible for a
build using --with-system-tzdata to fail the tests if the system tzdata
database wasn't au courant.  Bjorn Munch and Christoph Berg both complained
about this while packaging 9.4rc1, so we probably shouldn't insist on the
system tzdata being up-to-date.  Instead, make an equivalent test using a
zone change that occurred in Venezuela in 2007.  With this patch, the
regression tests should pass using any tzdata set from 2012 or later.
(I can't muster much sympathy for somebody using --with-system-tzdata
on a machine whose system tzdata is more than three years out-of-date.)

9 years agoUpdate comments in find_typedef.
Tom Lane [Tue, 18 Nov 2014 20:51:45 +0000 (15:51 -0500)]
Update comments in find_typedef.

These comments don't seem to have been touched in a long time.  Make them
describe the current implementation rather than what was here last century,
and be a bit more explicit about the unreferenced-typedefs issue.

9 years agoFix some bogus direct uses of realloc().
Tom Lane [Tue, 18 Nov 2014 18:28:06 +0000 (13:28 -0500)]
Fix some bogus direct uses of realloc().

pg_dump/parallel.c was using realloc() directly with no error check.
While the odds of an actual failure here seem pretty low, Coverity
complains about it, so fix by using pg_realloc() instead.

While looking for other instances, I noticed a couple of places in
psql that hadn't gotten the memo about the availability of pg_realloc.
These aren't bugs, since they did have error checks, but verbosely
inconsistent code is not a good thing.

Back-patch as far as 9.3.  9.2 did not have pg_dump/parallel.c, nor
did it have pg_realloc available in all frontend code.

9 years agoReduce btree scan overhead for < and > strategies
Simon Riggs [Tue, 18 Nov 2014 10:24:55 +0000 (10:24 +0000)]
Reduce btree scan overhead for < and > strategies

For <, <=, > and >= strategies, mark the first scan key
as already matched if scanning in an appropriate direction.
If index tuple contains no nulls we can skip the first
re-check for each tuple.

Author: Rajeev Rastogi
Reviewer: Haribabu Kommi
Rework of the code and comments by Simon Riggs

9 years agoRemove obsolete debugging option, RTDEBUG.
Heikki Linnakangas [Tue, 18 Nov 2014 07:55:05 +0000 (09:55 +0200)]
Remove obsolete debugging option, RTDEBUG.

The r-tree AM that used it was removed back in 2005.

Peter Geoghegan

9 years agoAdd pg_dump --snapshot option
Simon Riggs [Mon, 17 Nov 2014 22:15:07 +0000 (22:15 +0000)]
Add pg_dump --snapshot option

Allows pg_dump to use a snapshot previously defined by a concurrent
session that has either used pg_export_snapshot() or obtained a
snapshot when creating a logical slot. When this option is used with
parallel pg_dump, the snapshot defined by this option is used and no
new snapshot is taken.

Simon Riggs and Michael Paquier

9 years agoUpdate 9.4 release notes for commits through today.
Tom Lane [Mon, 17 Nov 2014 19:47:10 +0000 (14:47 -0500)]
Update 9.4 release notes for commits through today.

9 years agoAdd --synchronous option to pg_receivexlog, for more reliable WAL writing.
Fujii Masao [Mon, 17 Nov 2014 17:32:48 +0000 (02:32 +0900)]
Add --synchronous option to pg_receivexlog, for more reliable WAL writing.

Previously pg_receivexlog flushed WAL data only when WAL file was switched.
Then 3dad73e added -F option to pg_receivexlog so that users could control
how frequently sync commands were issued to WAL files. It also allowed users
to make pg_receivexlog flush WAL data immediately after writing by
specifying 0 in -F option. However feedback messages were not sent back
immediately even after a flush location was updated. So even if WAL data
was flushed in real time, the server could not see that for a while.

This commit removes -F option from and adds --synchronous to pg_receivexlog.
If --synchronous is specified, like the standby's wal receiver, pg_receivexlog
flushes WAL data as soon as there is WAL data which has not been flushed yet.
Then it sends back the feedback message identifying the latest flush location
to the server. This option is useful to make pg_receivexlog behave as sync
standby by using replication slot, for example.

Original patch by Furuya Osamu, heavily rewritten by me.
Reviewed by Heikki Linnakangas, Alvaro Herrera and Sawada Masahiko.

9 years agoUpdate time zone data files to tzdata release 2014j.
Tom Lane [Mon, 17 Nov 2014 17:08:02 +0000 (12:08 -0500)]
Update time zone data files to tzdata release 2014j.

DST law changes in the Turks & Caicos Islands (America/Grand_Turk) and
in Fiji.  New zone Pacific/Bougainville for portions of Papua New Guinea.
Historical changes for Korea and Vietnam.

9 years agoFix WAL-logging of B-tree "unlink halfdead page" operation.
Heikki Linnakangas [Mon, 17 Nov 2014 16:42:04 +0000 (18:42 +0200)]
Fix WAL-logging of B-tree "unlink halfdead page" operation.

There was some confusion on how to record the case that the operation
unlinks the last non-leaf page in the branch being deleted.
_bt_unlink_halfdead_page set the "topdead" field in the WAL record to
the leaf page, but the redo routine assumed that it would be an invalid
block number in that case. This commit fixes _bt_unlink_halfdead_page to
do what the redo routine expected.

This code is new in 9.4, so backpatch there.

9 years agoFix relpersistence setting in reindex_index
Alvaro Herrera [Mon, 17 Nov 2014 14:23:35 +0000 (11:23 -0300)]
Fix relpersistence setting in reindex_index

Buildfarm members with CLOBBER_CACHE_ALWAYS advised us that commit
85b506bbfc2937 was mistaken in setting the relpersistence value of the
index directly in the relcache entry, within reindex_index.  The reason
for the failure is that an invalidation message that comes after mucking
with the relcache entry directly, but before writing it to the catalogs,
would cause the entry to become rebuilt in place from catalogs with the
old contents, losing the update.

Fix by passing the correct persistence value to
RelationSetNewRelfilenode instead; this routine also writes the updated
tuple to pg_class, avoiding the problem.  Suggested by Tom Lane.

9 years agoTranslation updates
Peter Eisentraut [Mon, 17 Nov 2014 02:31:08 +0000 (21:31 -0500)]
Translation updates

9 years agoMention the TZ environment variable for initdb
Magnus Hagander [Sun, 16 Nov 2014 14:48:30 +0000 (15:48 +0100)]
Mention the TZ environment variable for initdb

Daniel Gustafsson

9 years agoRestructure doc sections about statistics views
Magnus Hagander [Sun, 16 Nov 2014 12:47:44 +0000 (13:47 +0100)]
Restructure doc sections about statistics views

Break out the "dynamic statistics" views in the table from the
"collected statistics" ones. Could do with some more refactoring,
but this is a start.

9 years agoEmit msg re skipping ANALYZE for absent inh tree
Simon Riggs [Sat, 15 Nov 2014 22:49:54 +0000 (22:49 +0000)]
Emit msg re skipping ANALYZE for absent inh tree

When checking a table that has an inheritance tree marked,
if no child tables remain, we skip ANALYZE. This patch emits
a message to show that the action has been skipped.

Author: Etsuro Fujita
Reviewer: Furuya Osamu

9 years agoGet rid of SET LOGGED indexes persistence kludge
Alvaro Herrera [Sat, 15 Nov 2014 04:19:49 +0000 (01:19 -0300)]
Get rid of SET LOGGED indexes persistence kludge

This removes ATChangeIndexesPersistence() introduced by f41872d0c1239d36
which was too ugly to live for long.  Instead, the correct persistence
marking is passed all the way down to reindex_index, so that the
transient relation built to contain the index relfilenode can
get marked correctly right from the start.

Author: Fabrízio de Royes Mello
Review and editorialization by Michael Paquier
                                     and Álvaro Herrera

9 years agoRemove unused InhPaths
Alvaro Herrera [Sat, 15 Nov 2014 04:19:39 +0000 (01:19 -0300)]
Remove unused InhPaths

Allegedly, the last remaining usages of that struct were removed by
0e99be1c.

Author: Peter Geoghegan

9 years agopostgres_fdw.h: don't pull in rel.h when relcache.h is enough
Alvaro Herrera [Sat, 15 Nov 2014 00:48:53 +0000 (21:48 -0300)]
postgres_fdw.h: don't pull in rel.h when relcache.h is enough

9 years agoFix initdb --sync-only to also sync tablespaces.
Andres Freund [Fri, 14 Nov 2014 17:22:12 +0000 (18:22 +0100)]
Fix initdb --sync-only to also sync tablespaces.

630cd14426dc added initdb --sync-only, for use by pg_upgrade, by just
exposing the existing fsync code. That's wrong, because initdb so far
had absolutely no reason to deal with tablespaces.

Fix --sync-only by additionally explicitly syncing each of the
tablespaces.

Backpatch to 9.3 where --sync-only was introduced.

Abhijit Menon-Sen and Andres Freund

9 years agoSync unlogged relations to disk after they have been reset.
Andres Freund [Fri, 14 Nov 2014 17:21:30 +0000 (18:21 +0100)]
Sync unlogged relations to disk after they have been reset.

Unlogged relations are only reset when performing a unclean
restart. That means they have to be synced to disk during clean
shutdowns. During normal processing that's achieved by registering a
buffer's file to be fsynced at the next checkpoint when flushed. But
ResetUnloggedRelations() doesn't go through the buffer manager, so
nothing will force reset relations to disk before the next shutdown
checkpoint.

So just make ResetUnloggedRelations() fsync the newly created main
forks to disk.

Discussion: 20140912112246.GA4984@alap3.anarazel.de

Backpatch to 9.1 where unlogged tables were introduced.

Abhijit Menon-Sen and Andres Freund

9 years agoEnsure unlogged tables are reset even if crash recovery errors out.
Andres Freund [Fri, 14 Nov 2014 17:20:59 +0000 (18:20 +0100)]
Ensure unlogged tables are reset even if crash recovery errors out.

Unlogged relations are reset at the end of crash recovery as they're
only synced to disk during a proper shutdown. Unfortunately that and
later steps can fail, e.g. due to running out of space. This reset
was, up to now performed after marking the database as having finished
crash recovery successfully. As out of space errors trigger a crash
restart that could lead to the situation that not all unlogged
relations are reset.

Once that happend usage of unlogged relations could yield errors like
"could not open file "...": No such file or directory". Luckily
clusters that show the problem can be fixed by performing a immediate
shutdown, and starting the database again.

To fix, just call ResetUnloggedRelations(UNLOGGED_RELATION_INIT)
earlier, before marking the database as having successfully recovered.

Discussion: 20140912112246.GA4984@alap3.anarazel.de

Backpatch to 9.1 where unlogged tables were introduced.

Abhijit Menon-Sen and Andres Freund

9 years agoDocument evaluation-order considerations for aggregate functions.
Tom Lane [Fri, 14 Nov 2014 22:19:29 +0000 (17:19 -0500)]
Document evaluation-order considerations for aggregate functions.

The SELECT reference page didn't really address the question of when
aggregate function evaluation occurs, nor did the "expression evaluation
rules" documentation mention that CASE can't be used to control whether
an aggregate gets evaluated or not.  Improve that.

Per discussion of bug #11661.  Original text by Marti Raudsepp and Michael
Paquier, rewritten significantly by me.

9 years agoClean up includes from RLS patch
Stephen Frost [Fri, 14 Nov 2014 21:53:51 +0000 (16:53 -0500)]
Clean up includes from RLS patch

The initial patch for RLS mistakenly included headers associated with
the executor and planner bits in rewrite/rowsecurity.h.  Per policy and
general good sense, executor headers should not be included in planner
headers or vice versa.

The include of execnodes.h was a mistaken holdover from previous
versions, while the include of relation.h was used for Relation's
definition, which should have been coming from utils/relcache.h.  This
patch cleans these issues up, adds comments to the RowSecurityPolicy
struct and the RowSecurityConfigType enum, and changes Relation->rsdesc
to Relation->rd_rsdesc to follow Relation field naming convention.

Additionally, utils/rel.h was including rewrite/rowsecurity.h, which
wasn't a great idea since that was pulling in things not really needed
in utils/rel.h (which gets included in quite a few places).  Instead,
use 'struct RowSecurityDesc' for the rd_rsdesc field and add comments
explaining why.

Lastly, add an include into access/nbtree/nbtsort.c for
utils/sortsupport.h, which was evidently missed due to the above mess.

Pointed out by Tom in 16970.1415838651@sss.pgh.pa.us; note that the
concerns regarding a similar situation in the custom-path commit still
need to be addressed.

9 years agoDocument BRIN's pages_per_range in CREATE INDEX
Alvaro Herrera [Fri, 14 Nov 2014 20:36:10 +0000 (17:36 -0300)]
Document BRIN's pages_per_range in CREATE INDEX

Author: Michael Paquier

9 years agoRevert change to ALTER TABLESPACE summary.
Stephen Frost [Fri, 14 Nov 2014 20:16:01 +0000 (15:16 -0500)]
Revert change to ALTER TABLESPACE summary.

When ALTER TABLESPACE MOVE ALL was changed to be ALTER TABLE ALL IN
TABLESPACE, the ALTER TABLESPACE summary should have been adjusted back
to its original definition.

Patch by Thom Brown (thanks!).

9 years agoReduce disk footprint of brin regression test
Alvaro Herrera [Fri, 14 Nov 2014 19:27:26 +0000 (16:27 -0300)]
Reduce disk footprint of brin regression test

Per complaint from Tom.

While at it, throw in some extra tests for nulls as well, and make sure
that the set of data we insert on the second round is not identical to
the first one.  Both measures are intended to improve coverage of the
test.

Also uncomment the ON COMMIT DROP clause on the CREATE TEMP TABLE
commands.  This doesn't have any effect for someone examining the
regression database after the tests are done, but it reduces clutter for
those that execute the script directly.

9 years agoAllow interrupting GetMultiXactIdMembers
Alvaro Herrera [Fri, 14 Nov 2014 18:14:01 +0000 (15:14 -0300)]
Allow interrupting GetMultiXactIdMembers

This function has a loop which can lead to uninterruptible process
"stalls" (actually infinite loops) when some bugs are triggered.  Avoid
that unpleasant situation by adding a check for interrupts in a place
that shouldn't degrade performance in the normal case.

Backpatch to 9.3.  Older branches have an identical loop here, but the
aforementioned bugs are only a problem starting in 9.3 so there doesn't
seem to be any point in backpatching any further.

9 years agoMove BufferGetBlockNumber() out of heap_page_is_all_visible()'s inner loop.
Andres Freund [Fri, 14 Nov 2014 16:04:44 +0000 (17:04 +0100)]
Move BufferGetBlockNumber() out of heap_page_is_all_visible()'s inner loop.

In some workloads BufferGetBlockNumber() shows up in profiles due to
the sheer number of calls to it (and because it causes cache
misses). The compiler can't move it out of the loop because it's a
full extern function call...

9 years agoAdd valgrind suppression for pg_atomic_init_u64.
Andres Freund [Fri, 14 Nov 2014 15:58:00 +0000 (16:58 +0100)]
Add valgrind suppression for pg_atomic_init_u64.

pg_atomic_init_u64 (indirectly) uses compare/exchange to guarantee
atomic writes on platforms where compare/exchange is available, but
64bit writes aren't atomic (yes, those exist). That leads to a
harmless read of the initial value of variable.

9 years agoImprove logical decoding log messages
Peter Eisentraut [Fri, 14 Nov 2014 01:43:55 +0000 (20:43 -0500)]
Improve logical decoding log messages

suggestions from Robert Haas

9 years agoAdapt valgrind.supp to the XLogInsert() split.
Andres Freund [Thu, 13 Nov 2014 23:59:40 +0000 (00:59 +0100)]
Adapt valgrind.supp to the XLogInsert() split.

The CRC computation now happens in XLogInsertRecord(), not
XLogInsert() itself anymore.

9 years agoFix pg_dumpall to restore its ability to dump from ancient servers.
Tom Lane [Thu, 13 Nov 2014 23:19:26 +0000 (18:19 -0500)]
Fix pg_dumpall to restore its ability to dump from ancient servers.

Fix breakage induced by commits d8d3d2a4f37f6df5d0118b7f5211978cca22091a
and 463f2625a5fb183b6a8925ccde98bb3889f921d9: pg_dumpall has crashed when
attempting to dump from pre-8.1 servers since then, due to faulty
construction of the query used for dumping roles from older servers.
The query was erroneous as of the earlier commit, but it wasn't exposed
unless you tried to use --binary-upgrade, which you presumably wouldn't
with a pre-8.1 server.  However commit 463f2625a made it fail always.

In HEAD, also fix additional breakage induced in the same query by
commit 491c029dbc4206779cf659aa0ff986af7831d2ff, which evidently wasn't
tested against pre-8.1 servers either.

The bug is only latent in 9.1 because 463f2625a hadn't landed yet, but
it seems best to back-patch all branches containing the faulty query.

Gilles Darold

9 years agoFix and improve cache invalidation logic for logical decoding.
Andres Freund [Thu, 13 Nov 2014 18:06:43 +0000 (19:06 +0100)]
Fix and improve cache invalidation logic for logical decoding.

There are basically three situations in which logical decoding needs
to perform cache invalidation. During/After replaying a transaction
with catalog changes, when skipping a uninteresting transaction that
performed catalog changes and when erroring out while replaying a
transaction. Unfortunately these three cases were all done slightly
differently - partially because 8de3e410fa, which greatly simplifies
matters, got committed in the midst of the development of logical
decoding.

The actually problematic case was when logical decoding skipped
transaction commits (and thus processed invalidations). When used via
the SQL interface cache invalidation could access the catalog - bad,
because we didn't set up enough state to allow that correctly. It'd
not be hard to setup sufficient state, but the simpler solution is to
always perform cache invalidation outside a valid transaction.

Also make the different cache invalidation cases look as similar as
possible, to ease code review.

This fixes the assertion failure reported by Antonin Houska in
53EE02D9.7040702@gmail.com. The presented testcase has been expanded
into a regression test.

Backpatch to 9.4, where logical decoding was introduced.

9 years agoFix xmin/xmax horizon computation during logical decoding initialization.
Andres Freund [Thu, 13 Nov 2014 18:06:43 +0000 (19:06 +0100)]
Fix xmin/xmax horizon computation during logical decoding initialization.

When building the initial historic catalog snapshot there were
scenarios where snapbuild.c would use incorrect xmin/xmax values when
starting from a xl_running_xacts record. The values used were always a
bit suspect, but happened to be correct in the easy to test
cases. Notably the values used when the the initial snapshot was
computed while no other transactions were running were correct.

This is likely to be the cause of the occasional buildfarm failures on
animals markhor and tick; but it's quite possible to reproduce
problems without CLOBBER_CACHE_ALWAYS.

Backpatch to 9.4, where logical decoding was introduced.

9 years agoFix race condition between hot standby and restoring a full-page image.
Heikki Linnakangas [Thu, 13 Nov 2014 17:47:44 +0000 (19:47 +0200)]
Fix race condition between hot standby and restoring a full-page image.

There was a window in RestoreBackupBlock where a page would be zeroed out,
but not yet locked. If a backend pinned and locked the page in that window,
it saw the zeroed page instead of the old page or new page contents, which
could lead to missing rows in a result set, or errors.

To fix, replace RBM_ZERO with RBM_ZERO_AND_LOCK, which atomically pins,
zeroes, and locks the page, if it's not in the buffer cache already.

In stable branches, the old RBM_ZERO constant is renamed to RBM_DO_NOT_USE,
to avoid breaking any 3rd party extensions that might use RBM_ZERO. More
importantly, this avoids renumbering the other enum values, which would
cause even bigger confusion in extensions that use ReadBufferExtended, but
haven't been recompiled.

Backpatch to all supported versions; this has been racy since hot standby
was introduced.

9 years agoTweak row-level locking documentation
Alvaro Herrera [Thu, 13 Nov 2014 17:45:55 +0000 (14:45 -0300)]
Tweak row-level locking documentation

Move the meat of locking levels to mvcc.sgml, leaving only a link to it
in the SELECT reference page.

Michael Paquier, with some tweaks by Álvaro

9 years agoMove the guts of our Levenshtein implementation into core.
Robert Haas [Thu, 13 Nov 2014 17:25:10 +0000 (12:25 -0500)]
Move the guts of our Levenshtein implementation into core.

The hope is that we can use this to produce better diagnostics in
some cases.

Peter Geoghegan, reviewed by Michael Paquier, with some further
changes by me.

9 years agodoc: Add index entry for "hypothetical-set aggregate"
Peter Eisentraut [Thu, 13 Nov 2014 16:57:16 +0000 (11:57 -0500)]
doc: Add index entry for "hypothetical-set aggregate"

9 years agoFix XLogReadBufferForRedoExtended to get cleanup lock when asked to do so.
Heikki Linnakangas [Thu, 13 Nov 2014 15:54:20 +0000 (17:54 +0200)]
Fix XLogReadBufferForRedoExtended to get cleanup lock when asked to do so.

9 years agoRename pending_list_cleanup_size to gin_pending_list_limit.
Fujii Masao [Thu, 13 Nov 2014 03:14:48 +0000 (12:14 +0900)]
Rename pending_list_cleanup_size to gin_pending_list_limit.

Since this parameter is only for GIN index, it's better to
add "gin" to the parameter name for easier understanding.

9 years agoExplicitly support the case that a plancache's raw_parse_tree is NULL.
Tom Lane [Wed, 12 Nov 2014 20:58:37 +0000 (15:58 -0500)]
Explicitly support the case that a plancache's raw_parse_tree is NULL.

This only happens if a client issues a Parse message with an empty query
string, which is a bit odd; but since it is explicitly called out as legal
by our FE/BE protocol spec, we'd probably better continue to allow it.

Fix by adding tests everywhere that the raw_parse_tree field is passed to
functions that don't or shouldn't accept NULL.  Also make it clear in the
relevant comments that NULL is an expected case.

This reverts commits a73c9dbab0165b3395dfe8a44a7dfd16166963c4 and
2e9650cbcff8c8fb0d9ef807c73a44f241822eee, which fixed specific crash
symptoms by hacking things at what now seems to be the wrong end, ie the
callee functions.  Making the callees allow NULL is superficially more
robust, but it's not always true that there is a defensible thing for the
callee to do in such cases.  The caller has more context and is better
able to decide what the empty-query case ought to do.

Per followup discussion of bug #11335.  Back-patch to 9.2.  The code
before that is sufficiently different that it would require development
of a separate patch, which doesn't seem worthwhile for what is believed
to be an essentially cosmetic change.

9 years agoFix several weaknesses in slot and logical replication on-disk serialization.
Andres Freund [Wed, 12 Nov 2014 17:52:49 +0000 (18:52 +0100)]
Fix several weaknesses in slot and logical replication on-disk serialization.

Heikki noticed in 544E23C0.8090605@vmware.com that slot.c and
snapbuild.c were missing the FIN_CRC32 call when computing/checking
checksums of on disk files. That doesn't lower the the error detection
capabilities of the checksum, but is inconsistent with other usages.

In a followup mail Heikki also noticed that, contrary to a comment,
the 'version' and 'length' struct fields of replication slot's on disk
data where not covered by the checksum. That's not likely to lead to
actually missed corruption as those fields are cross checked with the
expected version and the actual file length. But it's wrong
nonetheless.

As fixing these issues makes existing on disk files unreadable, bump
the expected versions of on disk files for both slots and logical
decoding historic catalog snapshots.  This means that loading old
files will fail with
ERROR: "replication slot file ... has unsupported version 1"
and
ERROR: "snapbuild state file ... has unsupported version 1 instead of
2" respectively. Given the low likelihood of anybody already using
these new features in a production setup that seems acceptable.

Fixing these issues made me notice that there's no regression test
covering the loading of historic snapshot from disk - so add one.

Backpatch to 9.4 where these features were introduced.

9 years agoAdd interrupt checks to contrib/pg_prewarm.
Andres Freund [Wed, 12 Nov 2014 17:52:49 +0000 (18:52 +0100)]
Add interrupt checks to contrib/pg_prewarm.

Currently the extension's pg_prewarm() function didn't check
interrupts once it started "warming" data. Since individual calls can
take a long while it's important for them to be interruptible.

Backpatch to 9.4 where pg_prewarm was introduced.

9 years agoUse just one database connection in the "tablespace" test.
Noah Misch [Wed, 12 Nov 2014 12:33:17 +0000 (07:33 -0500)]
Use just one database connection in the "tablespace" test.

On Windows, DROP TABLESPACE has a race condition when run concurrently
with other processes having opened files in the tablespace.  This led to
a rare failure on buildfarm member frogmouth.  Back-patch to 9.4, where
the reconnection was introduced.

9 years agoMessage improvements
Peter Eisentraut [Wed, 12 Nov 2014 01:00:58 +0000 (20:00 -0500)]
Message improvements

9 years agoRemove incorrect comment.
Robert Haas [Tue, 11 Nov 2014 23:36:20 +0000 (18:36 -0500)]
Remove incorrect comment.

This was introduced by commit 5ea86e6e65dd2da3e9a3464484985d48328e7fe3.

Peter Geoghegan

9 years agoLoop when necessary in contrib/pgcrypto's pktreader_pull().
Tom Lane [Tue, 11 Nov 2014 22:22:15 +0000 (17:22 -0500)]
Loop when necessary in contrib/pgcrypto's pktreader_pull().

This fixes a scenario in which pgp_sym_decrypt() failed with "Wrong key
or corrupt data" on messages whose length is 6 less than a power of 2.

Per bug #11905 from Connor Penhale.  Fix by Marko Tiikkaja, regression
test case from Jeff Janes.

9 years agoFix dependency searching for case where column is visited before table.
Tom Lane [Tue, 11 Nov 2014 22:00:11 +0000 (17:00 -0500)]
Fix dependency searching for case where column is visited before table.

When the recursive search in dependency.c visits a column and then later
visits the whole table containing the column, it needs to propagate the
drop-context flags for the table to the existing target-object entry for
the column.  Otherwise we might refuse the DROP (if not CASCADE) on the
incorrect grounds that there was no automatic drop pathway to the column.
Remarkably, this has not been reported before, though it's possible at
least when an extension creates both a datatype and a table using that
datatype.

Rather than just marking the column as allowed to be dropped, it might
seem good to skip the DROP COLUMN step altogether, since the later DROP
of the table will surely get the job done.  The problem with that is that
the datatype would then be dropped before the table (since the whole
situation occurred because we visited the datatype, and then recursed to
the dependent column, before visiting the table).  That seems pretty risky,
and the case is rare enough that it doesn't seem worth expending a lot of
effort or risk to make the drops happen in a safe order.  So we just play
dumb and delete the column separately according to the existing drop
ordering rules.

Per report from Petr Jelinek, though this is different from his proposed
patch.

Back-patch to 9.1, where extensions were introduced.  There's currently
no evidence that such cases can arise before 9.1, and in any case we would
also need to back-patch cb5c2ba2d82688d29b5902d86b993a54355cad4d to 9.0
if we wanted to back-patch this.

9 years agoAdd generate_series(numeric, numeric).
Fujii Masao [Tue, 11 Nov 2014 12:44:46 +0000 (21:44 +0900)]
Add generate_series(numeric, numeric).

Платон Малюгин
Reviewed by Michael Paquier, Ali Akbar and Marti Raudsepp

9 years agoAdd GUC and storage parameter to set the maximum size of GIN pending list.
Fujii Masao [Tue, 11 Nov 2014 12:08:21 +0000 (21:08 +0900)]
Add GUC and storage parameter to set the maximum size of GIN pending list.

Previously the maximum size of GIN pending list was controlled only by
work_mem. But the reasonable value of work_mem and the reasonable size
of the list are basically not the same, so it was not appropriate to
control both of them by only one GUC, i.e., work_mem. This commit
separates new GUC, pending_list_cleanup_size, from work_mem to allow
users to control only the size of the list.

Also this commit adds pending_list_cleanup_size as new storage parameter
to allow users to specify the size of the list per index. This is useful,
for example, when users want to increase the size of the list only for
the GIN index which can be updated heavily, and decrease it otherwise.

Reviewed by Etsuro Fujita.

9 years agoReally fix compilation failure on MIPS.
Heikki Linnakangas [Tue, 11 Nov 2014 08:25:22 +0000 (10:25 +0200)]
Really fix compilation failure on MIPS.

I missed an additional colon in previous patch. Oops. to make that mistake
less likely in the future, add comments as placeholders for unused inputs
and outputs in inline assembly.

9 years agoFix compilation failure on MIPS.
Heikki Linnakangas [Mon, 10 Nov 2014 23:04:57 +0000 (01:04 +0200)]
Fix compilation failure on MIPS.

Rémi Zara

9 years agoBRIN: fix bug in xlog backup block counting
Alvaro Herrera [Mon, 10 Nov 2014 21:13:49 +0000 (18:13 -0300)]
BRIN: fix bug in xlog backup block counting

The code that generates the BRIN_XLOG_UPDATE removes the buffer
reference when the page that's target for the updated tuple is freshly
initialized.  This is a pretty usual optimization, but was breaking the
case where the revmap buffer, which is referenced in the same WAL
record, is getting a backup block: the replay code was using backup
block index 1, which is not valid when the update target buffer gets
pruned; the revmap buffer gets assigned 0 instead.  Make sure to use the
correct backup block index for revmap when replaying.

Bug reported by Fujii Masao.

9 years agoFix potential NULL-pointer dereference.
Robert Haas [Mon, 10 Nov 2014 20:19:56 +0000 (15:19 -0500)]
Fix potential NULL-pointer dereference.

Commit 2781b4bea7db357be59f9a5fd73ca1eb12ff5a79 arranged to defer
the setup of after-trigger-related data structures, but
AfterTriggerPendingOnRel didn't get the memo.

9 years agoEnsure that RowExprs and whole-row Vars produce the expected column names.
Tom Lane [Mon, 10 Nov 2014 20:21:09 +0000 (15:21 -0500)]
Ensure that RowExprs and whole-row Vars produce the expected column names.

At one time it wasn't terribly important what column names were associated
with the fields of a composite Datum, but since the introduction of
operations like row_to_json(), it's important that looking up the rowtype
ID embedded in the Datum returns the column names that users would expect.
That did not work terribly well before this patch: you could get the column
names of the underlying table, or column aliases from any level of the
query, depending on minor details of the plan tree.  You could even get
totally empty field names, which is disastrous for cases like row_to_json().

To fix this for whole-row Vars, look to the RTE referenced by the Var, and
make sure its column aliases are applied to the rowtype associated with
the result Datums.  This is a tad scary because we might have to return
a transient RECORD type even though the Var is declared as having some
named rowtype.  In principle it should be all right because the record
type will still be physically compatible with the named rowtype; but
I had to weaken one Assert in ExecEvalConvertRowtype, and there might be
third-party code containing similar assumptions.

Similarly, RowExprs have to be willing to override the column names coming
from a named composite result type and produce a RECORD when the column
aliases visible at the site of the RowExpr differ from the underlying
table's column names.

In passing, revert the decision made in commit 398f70ec070fe601 to add
an alias-list argument to ExecTypeFromExprList: better to provide that
functionality in a separate function.  This also reverts most of the code
changes in d68581483564ec0f, which we don't need because we're no longer
depending on the tupdesc found in the child plan node's result slot to be
blessed.

Back-patch to 9.4, but not earlier, since this solution changes the results
in some cases that users might not have realized were buggy.  We'll apply a
more restricted form of this patch in older branches.

9 years agoFurther code and wording tweaks in BRIN
Alvaro Herrera [Mon, 10 Nov 2014 18:56:08 +0000 (15:56 -0300)]
Further code and wording tweaks in BRIN

Besides a couple of typo fixes, per David Rowley, Thom Brown, and Amit
Langote, and mentions of BRIN in the general CREATE INDEX page again per
David, this includes silencing MSVC compiler warnings (thanks Microsoft)
and an additional variable initialization per Coverity scanner.

9 years agoFix compiler warning for non-assert builds.
Kevin Grittner [Mon, 10 Nov 2014 15:42:46 +0000 (09:42 -0600)]
Fix compiler warning for non-assert builds.

Reported by Peter Geoghegan
David Rowley

9 years agoTab complete second argument to \c with role names.
Robert Haas [Mon, 10 Nov 2014 13:15:17 +0000 (08:15 -0500)]
Tab complete second argument to \c with role names.

Ian Barwick

9 years agoC comment: mention 1500-02-29 as an invalid date
Bruce Momjian [Mon, 10 Nov 2014 01:50:15 +0000 (20:50 -0500)]
C comment:  mention 1500-02-29 as an invalid date

It is invalid because the Gregorian calendar is used for all years.

9 years agoFix some coding issues in BRIN
Alvaro Herrera [Sat, 8 Nov 2014 03:31:03 +0000 (00:31 -0300)]
Fix some coding issues in BRIN

Reported by David Rowley: variadic macros are a problem.  Get rid of
them using a trick suggested by Tom Lane: add extra parentheses where
needed.  In the future we might decide we don't need the calls at all
and remove them, but it seems appropriate to keep them while this code
is still new.

Also from David Rowley: brininsert() was trying to use a variable before
initializing it.  Fix by moving the brin_form_tuple call (which
initializes the variable) to within the locked section.

Reported by Peter Eisentraut: can't use "new" as a struct member name,
because C++ compilers will choke on it, as reported by cpluspluscheck.

9 years agopg_basebackup: Adjust tests for long file name issues
Peter Eisentraut [Sat, 8 Nov 2014 01:47:38 +0000 (20:47 -0500)]
pg_basebackup: Adjust tests for long file name issues

Work around accidental test failures because the working directory path
is too long by creating a temporary directory in the (hopefully shorter)
system location, symlinking that to the working directory, and creating
the tablespaces using the shorter path.

9 years agodoc: Update pg_receivexlog note
Peter Eisentraut [Sat, 8 Nov 2014 01:15:22 +0000 (20:15 -0500)]
doc: Update pg_receivexlog note

The old note about how to use pg_receivexlog as an alternative to
archive_command was obsoleted by replication slots.

9 years agoIntroduce custom path and scan providers.
Robert Haas [Fri, 7 Nov 2014 22:26:02 +0000 (17:26 -0500)]
Introduce custom path and scan providers.

This allows extension modules to define their own methods for
scanning a relation, and get the core code to use them.  It's
unclear as yet how much use this capability will find, but we
won't find out if we never commit it.

KaiGai Kohei, reviewed at various times and in various levels
of detail by Shigeru Hanada, Tom Lane, Andres Freund, Álvaro
Herrera, and myself.

9 years agoFix building with WAL_DEBUG.
Heikki Linnakangas [Fri, 7 Nov 2014 21:04:53 +0000 (23:04 +0200)]
Fix building with WAL_DEBUG.

Now that the backup blocks are appended to the WAL record in xloginsert.c,
XLogInsert doesn't see them anymore and cannot remove them from the version
reconstructed for xlog_outdesc. This makes running with wal_debug=on more
expensive, as we now make (unnecessary) temporary copies of the backup
blocks, but it doesn't seem worth convoluting the code to keep that
optimization.

Reported by Alvaro Herrera.

9 years agoUse the sortsupport infrastructure in more cases.
Robert Haas [Fri, 7 Nov 2014 20:50:09 +0000 (15:50 -0500)]
Use the sortsupport infrastructure in more cases.

This removes some fmgr overhead from cases such as btree index builds.

Peter Geoghegan, reviewed by Andreas Karlsson and me.