]> granicus.if.org Git - postgresql/log
postgresql
8 years agopostgres_fdw: More preliminary refactoring for upcoming join pushdown.
Robert Haas [Sat, 30 Jan 2016 15:32:38 +0000 (10:32 -0500)]
postgres_fdw: More preliminary refactoring for upcoming join pushdown.

The code that generates a complete SQL query for a given foreign relation
was repeated in two places, and they didn't quite agree: the EXPLAIN case
left out the locking clause.  Centralize the code so we get the same
behavior everywhere, and adjust calling conventions and which functions
are static vs. extern accordingly .  Centralize the code so we get the same
behavior everywhere, and adjust calling conventions and which functions
are static vs. extern accordingly.

Ashutosh Bapat, reviewed and slightly adjusted by me.

8 years agoMigrate replication slot I/O locks into a separate tranche.
Robert Haas [Fri, 29 Jan 2016 14:44:29 +0000 (09:44 -0500)]
Migrate replication slot I/O locks into a separate tranche.

This is following in a long train of similar changes and for the same
reasons - see b319356f0e94a6482c726cf4af96597c211d8d6e and
fe702a7b3f9f2bc5bf6d173166d7d55226af82c8 inter alia.

Author: Amit Kapila
Reviewed-by: Alexander Korotkov, Robert Haas
8 years agoMigrate PGPROC's backendLock into PGPROC itself, using a new tranche.
Robert Haas [Fri, 29 Jan 2016 13:10:47 +0000 (08:10 -0500)]
Migrate PGPROC's backendLock into PGPROC itself, using a new tranche.

Previously, each PGPROC's backendLock was part of the main tranche,
and the PGPROC just contained a pointer.  Now, the actual LWLock is
part of the PGPROC.

As with previous, similar patches, this makes it significantly easier
to identify these lwlocks in LWLOCK_STATS or Trace_lwlocks output
and improves modularity.

Author: Ildus Kurbangaliev
Reviewed-by: Amit Kapila, Robert Haas
8 years agopgbench: refactor handling of stats tracking
Alvaro Herrera [Fri, 29 Jan 2016 12:05:08 +0000 (13:05 +0100)]
pgbench: refactor handling of stats tracking

This doesn't add any functionality but just shuffles things around so
that it can be reused and improved later.

Author: Fabien Coelho
Reviewed-by: Michael Paquier, Álvaro Herrera
8 years agoFix incorrect pattern-match processing in psql's \det command.
Tom Lane [Fri, 29 Jan 2016 09:28:02 +0000 (10:28 +0100)]
Fix incorrect pattern-match processing in psql's \det command.

listForeignTables' invocation of processSQLNamePattern did not match up
with the other ones that handle potentially-schema-qualified names; it
failed to make use of pg_table_is_visible() and also passed the name
arguments in the wrong order.  Bug seems to have been aboriginal in commit
0d692a0dc9f0e532.  It accidentally sort of worked as long as you didn't
inquire too closely into the behavior, although the silliness was later
exposed by inconsistencies in the test queries added by 59efda3e50ca4de6
(which I probably should have questioned at the time, but didn't).

Per bug #13899 from Reece Hart.  Patch by Reece Hart and Tom Lane.
Back-patch to all affected branches.

8 years agoFix syntax descriptions for replication commands in logicaldecoding.sgml
Fujii Masao [Fri, 29 Jan 2016 03:14:56 +0000 (12:14 +0900)]
Fix syntax descriptions for replication commands in logicaldecoding.sgml

Patch-by: Oleksandr Shulgin
Reviewed-by: Craig Ringer and Fujii Masao
Backpatch-through: 9.4 where logical decoding was introduced

8 years agopostgres_fdw: Refactor deparsing code for locking clauses.
Robert Haas [Thu, 28 Jan 2016 21:44:01 +0000 (16:44 -0500)]
postgres_fdw: Refactor deparsing code for locking clauses.

The upcoming patch to allow join pushdown in postgres_fdw needs to use
this code multiple times, which requires moving it to deparse.c.  That
seems like a good idea anyway, so do that now both on general principle
and to simplify the future patch.

Inspired by a patch by Shigeru Hanada and Ashutosh Bapat, but I did
it a little differently than what that patch did.

8 years agoOnly try to push down foreign joins if the user mapping OIDs match.
Robert Haas [Thu, 28 Jan 2016 19:05:36 +0000 (14:05 -0500)]
Only try to push down foreign joins if the user mapping OIDs match.

Previously, the foreign join pushdown infrastructure left the question
of security entirely up to individual FDWs, but it would be easy for
a foreign data wrapper to inadvertently open up subtle security holes
that way.  So, make it the core code's job to determine which user
mapping OID is relevant, and don't attempt join pushdown unless it's
the same for all relevant relations.

Per a suggestion from Tom Lane.  Shigeru Hanada and Ashutosh Bapat,
reviewed by Etsuro Fujita and KaiGai Kohei, with some further
changes by me.

8 years agoAdd missing quotation mark.
Robert Haas [Thu, 28 Jan 2016 17:21:51 +0000 (12:21 -0500)]
Add missing quotation mark.

This fix accidentally got left out of the previous commit.

8 years agoAvoid multiple foreign server connections when all use same user mapping.
Robert Haas [Thu, 28 Jan 2016 17:05:19 +0000 (12:05 -0500)]
Avoid multiple foreign server connections when all use same user mapping.

Previously, postgres_fdw's connection cache was keyed by user OID and
server OID, but this can lead to multiple connections when it's not
really necessary.  In particular, if all relevant users are mapped to
the public user mapping, then their connection options are certainly
the same, so one connection can be used for all of them.

While we're cleaning things up here, drop the "server" argument to
GetConnection(), which isn't really needed.  This saves a few cycles
because callers no longer have to look this up; the function itself
does, but only when establishing a new connection, not when reusing
an existing one.

Ashutosh Bapat, with a few small changes by me.

8 years agoAdd [NO]BYPASSRLS options to CREATE USER and ALTER USER docs.
Robert Haas [Thu, 28 Jan 2016 14:29:04 +0000 (09:29 -0500)]
Add [NO]BYPASSRLS options to CREATE USER and ALTER USER docs.

Patch-by: Filip Rembiałkowski
Reviewed-by: Robert Haas
Backpatch-through: 9.5

8 years agoFix spi_worker mention in bgworker documentation
Alvaro Herrera [Thu, 28 Jan 2016 13:08:21 +0000 (14:08 +0100)]
Fix spi_worker mention in bgworker documentation

The documentation mentioned contrib/ but the module was moved to
src/test/modules/ by commit 22dfd116a127a of 9.5 era.

Problem pointed out by Dickson Guedes in bug #13896
Backpatch-to: 9.5.
8 years agoFix typos in comments and doc
Fujii Masao [Thu, 28 Jan 2016 07:47:36 +0000 (16:47 +0900)]
Fix typos in comments and doc

overriden -> overridden

The misspelling in create_extension.sgml was introduced in b67aaf2,
so no need to backpatch.

8 years agoAdd gin_clean_pending_list function to clean up GIN pending list
Fujii Masao [Thu, 28 Jan 2016 03:57:52 +0000 (12:57 +0900)]
Add gin_clean_pending_list function to clean up GIN pending list

This function cleans up the pending list of the GIN index by
moving entries in it to the main GIN data structure in bulk.
It returns the number of pages cleaned up from the pending list.

This function is useful, for example, when the pending list
needs to be cleaned up *quickly* to improve the performance of
the search using GIN index. VACUUM can do the same thing, too,
but it may take days to run on a large table.

Jeff Janes,
reviewed by Julien Rouhaud, Jaime Casanova, Alvaro Herrera and me.

Discussion: CAMkU=1x8zFkpfnozXyt40zmR3Ub_kHu58LtRmwHUKRgQss7=iQ@mail.gmail.com

8 years agoAssert that create_unique_path returns non-NULL.
Robert Haas [Thu, 28 Jan 2016 03:03:18 +0000 (22:03 -0500)]
Assert that create_unique_path returns non-NULL.

Per off-list discussion with Tom Lane and Michael Paquier, Coverity
gets unhappy if this is not done.

8 years agoFix cross-version pg_dump for aggregate combine functions.
Robert Haas [Thu, 28 Jan 2016 02:45:07 +0000 (21:45 -0500)]
Fix cross-version pg_dump for aggregate combine functions.

Fixes a defect in commit a7de3dc5c346e07e0439275982569996e645b3c2.

David Rowley, per report from Jeff Janes, who also checked that the
fix works.

8 years agoFix volatility marking of pg_size_pretty function
Fujii Masao [Wed, 27 Jan 2016 02:13:31 +0000 (11:13 +0900)]
Fix volatility marking of pg_size_pretty function

pg_size_pretty function should be marked immutable rather than volatile
because it always returns the same result given the same argument.

Pavel Stehule

8 years agopgbench: improve multi-script support
Alvaro Herrera [Wed, 27 Jan 2016 01:54:22 +0000 (02:54 +0100)]
pgbench: improve multi-script support

Previously, it was possible to specify one or several custom scripts to
run, or only one of the builtin scripts.  With this patch it is also
possible to specify to run the builtin scripts multiple times, using the
new -b option.  Also, unify the code for both cases; this eases future
pgbench improvements.

Author: Fabien Coelho
Review: Michaël Paquier, Álvaro Herrera

8 years agoMostly mechanical cleanup of pgbench
Alvaro Herrera [Wed, 27 Jan 2016 01:11:34 +0000 (02:11 +0100)]
Mostly mechanical cleanup of pgbench

pgindent for recent commits; also change some variables from int to
boolean, which is how they are really used.

Mostly submitted by Fabien Coelho; this is in preparation to commit
further patches to the file.

8 years agoFix startup so that log prefix %h works for the log_connections message.
Tom Lane [Tue, 26 Jan 2016 20:38:33 +0000 (15:38 -0500)]
Fix startup so that log prefix %h works for the log_connections message.

We entirely randomly chose to initialize port->remote_host just after
printing the log_connections message, when we could perfectly well do it
just before, allowing %h and %r to work for that message.  Per gripe from
Artem Tomyuk.

8 years agoImprove ResourceOwners' behavior for large numbers of owned objects.
Tom Lane [Tue, 26 Jan 2016 20:20:22 +0000 (15:20 -0500)]
Improve ResourceOwners' behavior for large numbers of owned objects.

The original coding was quite fast so long as objects were always
released in reverse order of addition; otherwise, it degenerated into
O(N^2) behavior due to searching for the array element to delete.
Improve matters by switching to hashed storage when the number of
objects of a given type exceeds 64.  (The cutover point is open to
discussion, of course, but some simple performance testing suggests
that hashing has enough overhead to be a loser below there.)

Also, refactor resowner.c so that we don't need N copies of the array
management code.  Since all the resource IDs the code currently needs
to deal with are either pointers or integers, it seems sufficient to
create a one-size-fits-all infrastructure in which everything is
converted to a Datum for storage.

Aleksander Alekseev, reviewed by Stas Kelvich, further fixes by me

8 years agoVarious fixes to REFRESH MATERIALIZED VIEW tab completion.
Kevin Grittner [Tue, 26 Jan 2016 14:45:08 +0000 (08:45 -0600)]
Various fixes to REFRESH MATERIALIZED VIEW tab completion.

Masahiko Sawada, Fujii Masao, Kevin Grittner

8 years agoRevert "Fix broken multibyte regression tests."
Tatsuo Ishii [Mon, 25 Jan 2016 23:29:15 +0000 (08:29 +0900)]
Revert "Fix broken multibyte regression tests."

This reverts commit efc1610b64b04e7cf08cc1d6c608ede8b7d5ff07.
The commit was plain wrong as pointed out in:
http://www.postgresql.org/message-id/27771.1448736909@sss.pgh.pa.us

8 years agoCorrect comment in GetConflictingVirtualXIDs()
Simon Riggs [Sun, 24 Jan 2016 18:22:11 +0000 (10:22 -0800)]
Correct comment in GetConflictingVirtualXIDs()

We use Share lock because it is safe to do so.

8 years agoYet further adjust degree-based trig functions for more portability.
Tom Lane [Sun, 24 Jan 2016 17:53:03 +0000 (12:53 -0500)]
Yet further adjust degree-based trig functions for more portability.

Buildfarm member cockatiel is still saying that cosd(60) isn't 0.5.
What seems likely is that the subexpression (1.0 - cos(x)) isn't being
rounded to double width before more arithmetic is done on it, so force
that by storing it into a variable.

8 years agoStill further adjust degree-based trig functions for more portability.
Tom Lane [Sat, 23 Jan 2016 23:12:54 +0000 (18:12 -0500)]
Still further adjust degree-based trig functions for more portability.

Indeed, the non-static declaration foreseen in my previous commit message
is necessary.  Per Noah Misch.

8 years agoFurther adjust degree-based trig functions for more portability.
Tom Lane [Sat, 23 Jan 2016 21:17:31 +0000 (16:17 -0500)]
Further adjust degree-based trig functions for more portability.

The last round didn't do it.  Per Noah Misch, the problem on at least
some machines is that the compiler pre-evaluates trig functions having
constant arguments using code slightly different from what will be used
at runtime.  Therefore, we must prevent the compiler from seeing constant
arguments to any of the libm trig functions used in this code.

The method used here might still fail if init_degree_constants() gets
inlined into the call sites.  That probably won't happen given the large
number of call sites; but if it does, we could probably fix it by making
init_degree_constants() non-static.  I'll avoid that till proven
necessary, though.

8 years agoAdjust degree-based trig functions for more portability.
Tom Lane [Sat, 23 Jan 2016 16:26:07 +0000 (11:26 -0500)]
Adjust degree-based trig functions for more portability.

The buildfarm isn't very happy with the results of commit e1bd684a34c11139.
To try to get the expected exact results everywhere:

* Replace M_PI / 180 subexpressions with a precomputed constant, so that
the compiler can't decide to rearrange that division with an adjacent
operation.  Hopefully this will fix failures to get exactly 0.5 from
sind(30) and cosd(60).

* Add scaling to ensure that tand(45) and cotd(45) give exactly 1; there
was nothing particularly guaranteeing that before.

* Replace minus zero by zero when tand() or cotd() would output that;
many machines did so for tand(180) and cotd(270), but not all.  We could
alternatively deem both results valid, but that doesn't seem likely to
be what users will want.

8 years agopsql: Improve completion of FDW DDL commands
Peter Eisentraut [Sat, 23 Jan 2016 11:57:42 +0000 (06:57 -0500)]
psql: Improve completion of FDW DDL commands

Add
- ALTER FOREIGN DATA WRAPPER -> RENAME TO
- ALTER SERVER -> RENAME TO
- ALTER SERVER ... VERSION ... -> OPTIONS
- CREATE FOREIGN DATA WRAPPER -> OPTIONS
- CREATE SERVER -> OPTIONS
- CREATE|ALTER USER MAPPING -> OPTIONS

From: Andreas Karlsson <andreas@proxel.se>

8 years agopg_dump: Fix quoting of domain constraint names
Alvaro Herrera [Fri, 22 Jan 2016 23:04:35 +0000 (20:04 -0300)]
pg_dump: Fix quoting of domain constraint names

The original code was adding double quotes to an already-quoted
identifier, leading to nonsensical results.  Remove the quoting call.

I introduced the broken code in 7eca575d1c of 9.5 era, so backpatch to
9.5.

Report and patch by Elvis Pranskevichus
Reviewed by Michael Paquier

8 years agoAdd trigonometric functions that work in degrees.
Tom Lane [Fri, 22 Jan 2016 20:46:22 +0000 (15:46 -0500)]
Add trigonometric functions that work in degrees.

The implementations go to some lengths to deliver exact results for values
where an exact result can be expected, such as sind(30) = 0.5 exactly.

Dean Rasheed, reviewed by Michael Paquier

8 years agoImprove cross-platform consistency of Inf/NaN handling in trig functions.
Tom Lane [Fri, 22 Jan 2016 19:50:51 +0000 (14:50 -0500)]
Improve cross-platform consistency of Inf/NaN handling in trig functions.

Ensure that the trig functions return NaN for NaN input regardless of what
the underlying C library functions might do.  Also ensure that an error
is thrown for Inf (or otherwise out-of-range) input, except for atan/atan2
which should accept it.

All these behaviors should now conform to the POSIX spec; previously, all
our popular platforms deviated from that in one case or another.

The main remaining platform dependency here is whether the C library might
choose to throw a domain error for sin/cos/tan inputs that are large but
less than infinity.  (Doing so is not unreasonable, since once a single
unit-in-the-last-place exceeds PI, there can be no significance at all in
the result; however there doesn't seem to be any suggestion in POSIX that
such an error is allowed.)  We will report such errors if they are reported
via "errno", but not if they are reported via "fetestexcept" which is the
other mechanism sanctioned by POSIX.  Some preliminary experiments with
fetestexcept indicated that it might also report errors we could do
without, such as complaining about underflow at an unreasonably large
threshold.  So let's skip that complexity for now.

Dean Rasheed, reviewed by Michael Paquier

8 years agoImprove levenshtein() docs.
Tom Lane [Fri, 22 Jan 2016 17:29:07 +0000 (12:29 -0500)]
Improve levenshtein() docs.

Fix chars-vs-bytes confusion here too.  Improve poor grammar and
markup.

8 years agoRemove new coupling between NAMEDATALEN and MAX_LEVENSHTEIN_STRLEN.
Tom Lane [Fri, 22 Jan 2016 16:53:06 +0000 (11:53 -0500)]
Remove new coupling between NAMEDATALEN and MAX_LEVENSHTEIN_STRLEN.

Commit e529cd4ffa605c6f introduced an Assert requiring NAMEDATALEN to be
less than MAX_LEVENSHTEIN_STRLEN, which has been 255 for a long time.
Since up to that instant we had always allowed NAMEDATALEN to be
substantially more than that, this was ill-advised.

It's debatable whether we need MAX_LEVENSHTEIN_STRLEN at all (versus
putting a CHECK_FOR_INTERRUPTS into the loop), or whether it has to be
so tight; but this patch takes the narrower approach of just not applying
the MAX_LEVENSHTEIN_STRLEN limit to calls from the parser.

Trusting the parser for this seems reasonable, first because the strings
are limited to NAMEDATALEN which is unlikely to be hugely more than 256,
and second because the maximum distance is tightly constrained by
MAX_FUZZY_DISTANCE (though we'd forgotten to make use of that limit in one
place).  That means the cost is not really O(mn) but more like O(max(m,n)).

Relaxing the limit for user-supplied calls is left for future research;
given the lack of complaints to date, it doesn't seem very high priority.

In passing, fix confusion between lengths-in-bytes and lengths-in-chars
in comments and error messages.

Per gripe from Kevin Day; solution suggested by Robert Haas.  Back-patch
to 9.5 where the unwanted restriction was introduced.

8 years agoMake extract() do something more reasonable with infinite datetimes.
Tom Lane [Fri, 22 Jan 2016 03:26:20 +0000 (22:26 -0500)]
Make extract() do something more reasonable with infinite datetimes.

Historically, extract() just returned zero for any case involving an
infinite timestamp[tz] input; even cases in which the unit name was
invalid.  This is not very sensible.  Instead, return infinity or
-infinity as appropriate when the requested field is one that is
monotonically increasing (e.g, year, epoch), or NULL when it is not
(e.g., day, hour).  Also, throw the expected errors for bad unit names.

BACKWARDS INCOMPATIBLE CHANGE

Vitaly Burovoy, reviewed by Vik Fearing

8 years agoSuppress compiler warning.
Tom Lane [Fri, 22 Jan 2016 02:14:07 +0000 (21:14 -0500)]
Suppress compiler warning.

Given the limited range of i, these shifts should not cause any
problem, but that apparently doesn't stop some compilers from
whining about them.

David Rowley

8 years agoImprove index AMs' opclass validation procedures.
Tom Lane [Fri, 22 Jan 2016 00:47:15 +0000 (19:47 -0500)]
Improve index AMs' opclass validation procedures.

The amvalidate functions added in commit 65c5fcd353a859da were on the
crude side.  Improve them in a few ways:

* Perform signature checking for operators and support functions.

* Apply more thorough checks for missing operators and functions,
where possible.

* Instead of reporting problems as ERRORs, report most problems as INFO
messages and make the amvalidate function return FALSE.  This allows
more than one problem to be discovered per run.

* Report object names rather than OIDs, and work a bit harder on making
the messages understandable.

Also, remove a few more opr_sanity regression test queries that are
now superseded by the amvalidate checks.

8 years agoAdd defenses against putting expanded objects into Const nodes.
Tom Lane [Thu, 21 Jan 2016 17:55:59 +0000 (12:55 -0500)]
Add defenses against putting expanded objects into Const nodes.

Putting a reference to an expanded-format value into a Const node would be
a bad idea for a couple of reasons.  It'd be possible for the supposedly
immutable Const to change value, if something modified the referenced
variable ... in fact, if the Const's reference were R/W, any function that
has the Const as argument might itself change it at runtime.  Also, because
datumIsEqual() is pretty simplistic, the Const might fail to compare equal
to other Consts that it should compare equal to, notably including copies
of itself.  This could lead to unexpected planner behavior, such as "could
not find pathkey item to sort" errors or inferior plans.

I have not been able to find any way to get an expanded value into a Const
within the existing core code; but Paul Ramsey was able to trigger the
problem by writing a datatype input function that returns an expanded
value.

The best fix seems to be to establish a rule that varlena values being
placed into Const nodes should be passed through pg_detoast_datum().
That will do nothing (and cost little) in normal cases, but it will flatten
expanded values and thereby avoid the above problems.  Also, it will
convert short-header or compressed values into canonical format, which will
avoid possible unexpected lack-of-equality issues for those cases too.
And it provides a last-ditch defense against putting a toasted value into
a Const, which we already knew was dangerous, cf commit 2b0c86b66563cf2f.
(In the light of this discussion, I'm no longer sure that that commit
provided 100% protection against such cases, but this fix should do it.)

The test added in commit 65c3d05e18e7c530 to catch datatype input functions
with unstable results would fail for functions that returned expanded
values; but it seems a bit uncharitable to deem a result unstable just
because it's expressed in expanded form, so revise the coding so that we
check for bitwise equality only after applying pg_detoast_datum().  That's
a sufficient condition anyway given the new rule about detoasting when
forming a Const.

Back-patch to 9.5 where the expanded-object facility was added.  It's
possible that this should go back further; but in the absence of clear
evidence that there's any live bug in older branches, I'll refrain for now.

8 years agoRemove unused argument from ginInsertCleanup()
Fujii Masao [Thu, 21 Jan 2016 16:22:56 +0000 (01:22 +0900)]
Remove unused argument from ginInsertCleanup()

It's an oversight in commit dc943ad.

8 years agoRefactor headers to split out standby defs
Simon Riggs [Thu, 21 Jan 2016 02:51:34 +0000 (18:51 -0800)]
Refactor headers to split out standby defs

Jeff Janes

8 years agoSpeedup 2PC by skipping two phase state files in normal path
Simon Riggs [Thu, 21 Jan 2016 02:40:44 +0000 (18:40 -0800)]
Speedup 2PC by skipping two phase state files in normal path

2PC state info is written only to WAL at PREPARE, then read back from WAL at
COMMIT PREPARED/ABORT PREPARED. Prepared transactions that live past one bufmgr
checkpoint cycle will be written to disk in the same form as previously. Crash
recovery path is not altered. Measured performance gains of 50-100% for short
2PC transactions by completely avoiding writing files and fsyncing. Other
optimizations still available, further patches in related areas expected.

Stas Kelvich and heavily edited by Simon Riggs

Based upon earlier ideas and patches by Michael Paquier and Heikki Linnakangas,
a concrete example of how Postgres-XC has fed back ideas into PostgreSQL.

Reviewed by Michael Paquier, Jeff Janes and Andres Freund
Performance testing by Jesper Pedersen

8 years agopsql: Add tab completion for COPY with query
Peter Eisentraut [Thu, 21 Jan 2016 02:27:46 +0000 (21:27 -0500)]
psql: Add tab completion for COPY with query

From: Andreas Karlsson <andreas@proxel.se>

8 years agoRefactor to create generic WAL page read callback
Simon Riggs [Thu, 21 Jan 2016 01:18:58 +0000 (17:18 -0800)]
Refactor to create generic WAL page read callback

Previously we didn’t have a generic WAL page read callback function,
surprisingly. Logical decoding has logical_read_local_xlog_page(), which was
actually generic, so move that to xlogfunc.c and rename to
read_local_xlog_page().
Maintain logical_read_local_xlog_page() so existing callers still work.

As requested by Michael Paquier, Alvaro Herrera and Andres Freund

8 years agoSupport parallel joins, and make related improvements.
Robert Haas [Wed, 20 Jan 2016 19:29:22 +0000 (14:29 -0500)]
Support parallel joins, and make related improvements.

The core innovation of this patch is the introduction of the concept
of a partial path; that is, a path which if executed in parallel will
generate a subset of the output rows in each process.  Gathering a
partial path produces an ordinary (complete) path.  This allows us to
generate paths for parallel joins by joining a partial path for one
side (which at the baserel level is currently always a Partial Seq
Scan) to an ordinary path on the other side.  This is subject to
various restrictions at present, especially that this strategy seems
unlikely to be sensible for merge joins, so only nested loops and
hash joins paths are generated.

This also allows an Append node to be pushed below a Gather node in
the case of a partitioned table.

Testing revealed that early versions of this patch made poor decisions
in some cases, which turned out to be caused by the fact that the
original cost model for Parallel Seq Scan wasn't very good.  So this
patch tries to make some modest improvements in that area.

There is much more to be done in the area of generating good parallel
plans in all cases, but this seems like a useful step forward.

Patch by me, reviewed by Dilip Kumar and Amit Kapila.

8 years agoSupport multi-stage aggregation.
Robert Haas [Wed, 20 Jan 2016 18:46:50 +0000 (13:46 -0500)]
Support multi-stage aggregation.

Aggregate nodes now have two new modes: a "partial" mode where they
output the unfinalized transition state, and a "finalize" mode where
they accept unfinalized transition states rather than individual
values as input.

These new modes are not used anywhere yet, but they will be necessary
for parallel aggregation.  The infrastructure also figures to be
useful for cases where we want to aggregate local data and remote
data via the FDW interface, and want to bring back partial aggregates
from the remote side that can then be combined with locally generated
partial aggregates to produce the final value.  It may also be useful
even when neither FDWs nor parallelism are in play, as explained in
the comments in nodeAgg.c.

David Rowley and Simon Riggs, reviewed by KaiGai Kohei, Heikki
Linnakangas, Haribabu Kommi, and me.

8 years agoPostgresNode: Add names to nodes
Alvaro Herrera [Wed, 20 Jan 2016 17:13:11 +0000 (14:13 -0300)]
PostgresNode: Add names to nodes

This makes the log files easier to follow when investigating a test
failure.

Author: Michael Paquier
Review: Noah Misch

8 years agoProperly install dynloader.h on MSVC builds
Bruce Momjian [Wed, 20 Jan 2016 04:30:29 +0000 (23:30 -0500)]
Properly install dynloader.h on MSVC builds

This will enable PL/Java to be cleanly compiled, as dynloader.h is a
requirement.

Report by Chapman Flack

Patch by Michael Paquier

Backpatch through 9.1

8 years agoFix assorted inconsistencies in GIN opclass support function declarations.
Tom Lane [Wed, 20 Jan 2016 03:32:19 +0000 (22:32 -0500)]
Fix assorted inconsistencies in GIN opclass support function declarations.

GIN had some minor issues too, mostly using "internal" where something
else would be more appropriate.  I went with the same approach as in
9ff60273e35cad6e, namely preferring the opclass' indexed datatype for
arguments that receive an operator RHS value, even if that's not
necessarily what they really are.

Again, this is with an eye to having a uniform rule for ginvalidate()
to check support function signatures.

8 years agoAdd two HyperLogLog functions
Alvaro Herrera [Tue, 19 Jan 2016 20:40:15 +0000 (17:40 -0300)]
Add two HyperLogLog functions

New functions initHyperLogLogError() and freeHyperLogLog() simplify
using this module from elsewhere.

Author: Tomáš Vondra
Review: Peter Geoghegan

8 years agoFix assorted inconsistencies in GiST opclass support function declarations.
Tom Lane [Tue, 19 Jan 2016 17:04:32 +0000 (12:04 -0500)]
Fix assorted inconsistencies in GiST opclass support function declarations.

The conventions specified by the GiST SGML documentation were widely
ignored.  For example, the strategy-number argument for "consistent" and
"distance" functions is specified to be a smallint, but most of the
built-in support functions declared it as an integer, and for that matter
the core code passed it using Int32GetDatum not Int16GetDatum.  None of
that makes any real difference at runtime, but it's quite confusing for
newcomers to the code, and it makes it very hard to write an amvalidate()
function that checks support function signatures.  So let's try to instill
some consistency here.

Another similar issue is that the "query" argument is not of a single
well-defined type, but could have different types depending on the strategy
(corresponding to search operators with different righthand-side argument
types).  Some of the functions threw up their hands and declared the query
argument as being of "internal" type, which surely isn't right ("any" would
have been more appropriate); but the majority position seemed to be to
declare it as being of the indexed data type, corresponding to a search
operator with both input types the same.  So I've specified a convention
that that's what to do always.

Also, the result of the "union" support function actually must be of the
index's storage type, but the documentation suggested declaring it to
return "internal", and some of the functions followed that.  Standardize
on telling the truth, instead.

Similarly, standardize on declaring the "same" function's inputs as
being of the storage type, not "internal".

Also, somebody had forgotten to add the "recheck" argument to both
the documentation of the "distance" support function and all of their
SQL declarations, even though the C code was happily using that argument.
Clean that up too.

Fix up some other omissions in the docs too, such as documenting that
union's second input argument is vestigial.

So far as the errors in core function declarations go, we can just fix
pg_proc.h and bump catversion.  Adjusting the erroneous declarations in
contrib modules is more debatable: in principle any change in those
scripts should involve an extension version bump, which is a pain.
However, since these changes are purely cosmetic and make no functional
difference, I think we can get away without doing that.

8 years agoRemove Cygwin-specific code from pg_ctl
Andrew Dunstan [Tue, 19 Jan 2016 12:31:18 +0000 (07:31 -0500)]
Remove Cygwin-specific code from pg_ctl

This code has been there for a long time, but it's never really been
needed. Cygwin has its own utility for registering, unregistering,
stopping and starting Windows services, and that's what's used in the
Cygwin postgres packages. So now pg_ctl for Cygwin looks like it is for
any Unix platform.

Michael Paquier and me

8 years agoFix typo.
Tatsuo Ishii [Mon, 18 Jan 2016 12:26:30 +0000 (21:26 +0900)]
Fix typo.

Reported by KOIZUMI Satoru.

8 years agoAdd explicit cast to amcostestimate call.
Tom Lane [Mon, 18 Jan 2016 03:56:16 +0000 (22:56 -0500)]
Add explicit cast to amcostestimate call.

My compiler doesn't complain here, but David Rowley's does ...

8 years agoRestructure index access method API to hide most of it at the C level.
Tom Lane [Mon, 18 Jan 2016 00:36:59 +0000 (19:36 -0500)]
Restructure index access method API to hide most of it at the C level.

This patch reduces pg_am to just two columns, a name and a handler
function.  All the data formerly obtained from pg_am is now provided
in a C struct returned by the handler function.  This is similar to
the designs we've adopted for FDWs and tablesample methods.  There
are multiple advantages.  For one, the index AM's support functions
are now simple C functions, making them faster to call and much less
error-prone, since the C compiler can now check function signatures.
For another, this will make it far more practical to define index access
methods in installable extensions.

A disadvantage is that SQL-level code can no longer see attributes
of index AMs; in particular, some of the crosschecks in the opr_sanity
regression test are no longer possible from SQL.  We've addressed that
by adding a facility for the index AM to perform such checks instead.
(Much more could be done in that line, but for now we're content if the
amvalidate functions more or less replace what opr_sanity used to do.)
We might also want to expose some sort of reporting functionality, but
this patch doesn't do that.

Alexander Korotkov, reviewed by Petr Jelínek, and rather heavily
editorialized on by me.

8 years agoRe-pgindent a few files.
Tom Lane [Mon, 18 Jan 2016 00:13:18 +0000 (19:13 -0500)]
Re-pgindent a few files.

In preparation for landing index AM interface changes.

8 years agoRemove dead code in pg_dump.
Tom Lane [Sun, 17 Jan 2016 16:38:40 +0000 (11:38 -0500)]
Remove dead code in pg_dump.

Coverity quite reasonably complained that this check for fout==NULL
occurred after we'd already dereferenced fout.  However, the check
is just dead code since there is no code path by which CreateArchive
can return a null pointer.  Errors such as can't-open-that-file are
reported down inside CreateArchive, and control doesn't return.
So let's silence the warning by removing the dead code, rather than
continuing to pretend it does something.

Coverity didn't complain about this before 5b5fea2a1, so back-patch
to 9.5 like that patch.

8 years agopsql: Add completion support for DROP INDEX CONCURRENTLY
Peter Eisentraut [Sun, 17 Jan 2016 01:46:14 +0000 (20:46 -0500)]
psql: Add completion support for DROP INDEX CONCURRENTLY

based on patch by Kyotaro Horiguchi

8 years agoFix minor typo in comment
Magnus Hagander [Fri, 15 Jan 2016 09:24:37 +0000 (10:24 +0100)]
Fix minor typo in comment

Tatsuro Yamada

8 years agoFix spelling mistakes.
Robert Haas [Fri, 15 Jan 2016 04:12:05 +0000 (23:12 -0500)]
Fix spelling mistakes.

Same patch submitted independently by David Rowley and Peter Geoghegan.

8 years agoFix build_grouping_chain() to not clobber its input lists.
Tom Lane [Thu, 14 Jan 2016 16:51:57 +0000 (11:51 -0500)]
Fix build_grouping_chain() to not clobber its input lists.

There's no good reason for stomping on the input data; it makes the logic
in this function no simpler, in fact probably the reverse.  And it makes
it impossible to separate path generation from plan generation, as I'm
working towards doing; that will require more than one traversal of these
lists.

8 years agoProperly close token in sspi authentication
Magnus Hagander [Thu, 14 Jan 2016 12:06:03 +0000 (13:06 +0100)]
Properly close token in sspi authentication

We can never leak more than one token, but we shouldn't do that. We
don't bother closing it in the error paths since the process will
exit shortly anyway.

Christian Ullrich

8 years agoHandle extension members when first setting object dump flags in pg_dump.
Tom Lane [Wed, 13 Jan 2016 23:55:27 +0000 (18:55 -0500)]
Handle extension members when first setting object dump flags in pg_dump.

pg_dump's original approach to handling extension member objects was to
run around and clear (or set) their dump flags rather late in its data
collection process.  Unfortunately, quite a lot of code expects those flags
to be valid before that; which was an entirely reasonable expectation
before we added extensions.  In particular, this explains Karsten Hilbert's
recent report of pg_upgrade failing on a database in which an extension
has been installed into the pg_catalog schema.  Its objects are initially
marked as not-to-be-dumped on the strength of their schema, and later we
change them to must-dump because we're doing a binary upgrade of their
extension; but we've already skipped essential tasks like making associated
DO_SHELL_TYPE objects.

To fix, collect extension membership data first, and incorporate it in the
initial setting of the dump flags, so that those are once again correct
from the get-go.  This has the undesirable side effect of slightly
lengthening the time taken before pg_dump acquires table locks, but testing
suggests that the increase in that window is not very much.

Along the way, get rid of ugly special-case logic for deciding whether
to dump procedural languages, FDWs, and foreign servers; dump decisions
for those are now correct up-front, too.

In 9.3 and up, this also fixes erroneous logic about when to dump event
triggers (basically, they were *always* dumped before).  In 9.5 and up,
transform objects had that problem too.

Since this problem came in with extensions, back-patch to all supported
versions.

8 years agoAccess pg_dump's options structs through Archive struct, not directly.
Tom Lane [Wed, 13 Jan 2016 22:48:33 +0000 (17:48 -0500)]
Access pg_dump's options structs through Archive struct, not directly.

Rather than passing around DumpOptions and RestoreOptions as separate
arguments, add fields to struct Archive to carry pointers to these objects,
and access them through those fields when needed.  There already was a
RestoreOptions pointer in Archive, though for no obvious reason it was part
of the "private" struct rather than out where pg_dump.c could see it.

Doing this allows reversion of quite a lot of parameter-addition changes
made in commit 0eea8047bf, which is a good thing IMO because this will
reduce the code delta between 9.4 and 9.5, probably easing a few future
back-patch efforts.  Moreover, the previous commit only added a DumpOptions
argument to functions that had to have it at the time, which means we could
anticipate still more code churn (and more back-patch hazard) as the
requirement spread further.  I'd hit exactly that problem in my upcoming
patch to fix extension membership marking, which is what motivated me to
do this.

8 years agoRun pgindent on src/bin/pg_dump/*
Tom Lane [Wed, 13 Jan 2016 20:48:54 +0000 (15:48 -0500)]
Run pgindent on src/bin/pg_dump/*

To ease doing indent fixups on a couple of patches I have in progress.

8 years agopsql: Improve CREATE INDEX CONCURRENTLY tab completion
Peter Eisentraut [Wed, 13 Jan 2016 01:31:43 +0000 (20:31 -0500)]
psql: Improve CREATE INDEX CONCURRENTLY tab completion

The completion of CREATE INDEX CONCURRENTLY was lacking in several ways
compared to a plain CREATE INDEX command:

- CREATE INDEX <name> ON completes table names, but didn't with
  CONCURRENTLY.

- CREATE INDEX completes ON and existing index names, but with
  CONCURRENTLY it only completed ON.

- CREATE INDEX <name> completes ON, but didn't with CONCURRENTLY.

These are now all fixed.

8 years agopsql: Fix CREATE INDEX tab completion
Peter Eisentraut [Sun, 10 Jan 2016 16:43:27 +0000 (11:43 -0500)]
psql: Fix CREATE INDEX tab completion

The previous code supported a syntax like CREATE INDEX name
CONCURRENTLY, which never existed.  Mistake introduced in commit
37ec19a15ce452ee94f32ebc3d6a9a45868e82fd.  Remove the addition of
CONCURRENTLY at that point.

8 years agopsql: Update tab completion comment
Peter Eisentraut [Sun, 10 Jan 2016 16:24:51 +0000 (11:24 -0500)]
psql: Update tab completion comment

This just updates a comment to match the code.

from Michael Paquier

8 years agoAdd new user fn pg_current_xlog_flush_location()
Simon Riggs [Tue, 12 Jan 2016 07:54:52 +0000 (07:54 +0000)]
Add new user fn pg_current_xlog_flush_location()

Tomas Vondra, reviewed by Michael Paquier and Amit Kapila
Minor edits by me

8 years agoMaintain local LogwrtResult consistently
Simon Riggs [Tue, 12 Jan 2016 07:33:20 +0000 (07:33 +0000)]
Maintain local LogwrtResult consistently

Teach GetFlushRecPtr() to update LogwrtResult cache as performed by all other
functions in xlog.c

8 years agoRemove no-longer-needed old-style check for incompatible plpythons.
Tom Lane [Tue, 12 Jan 2016 01:13:31 +0000 (20:13 -0500)]
Remove no-longer-needed old-style check for incompatible plpythons.

Commit 866566a690bb9916 introduced a new mechanism for incompatible
plpythons to detect each other.  I left the old mechanism in place,
because it seems possible that a plpython predating that commit might be
used with one postdating it.  (This would require updating plpython3 but
not plpython2 or vice versa, but that seems well within the realm of
possibility.)  However, surely it will not be able to happen in 9.6 or
later, so we can delete the old mechanism in HEAD.

8 years agoUse LOAD not actual code execution to pull in plpython library.
Tom Lane [Tue, 12 Jan 2016 01:06:36 +0000 (20:06 -0500)]
Use LOAD not actual code execution to pull in plpython library.

Commit 866566a690bb9916 is insufficient to prevent dump/reload failures
when using transform modules in a database with both plpython2 and
plpython3 installed.  The reason is that the transform extension scripts
use DO blocks as a mechanism to pull in the libpython library before
creating the transform function.  It's necessary to preload the library
because the dynamic loader won't do it for us on every platform, leading
to "unresolved symbol" failures when the transform library is loaded.
But it's *not* necessary to execute Python code, and doing so will
provoke a multiple-Pythons-are-loaded error even after the preceding
commit.

To fix, use LOAD instead of a DO block.  That requires superuser privilege,
but creation of a C function does anyway.  It also embeds knowledge of
the underlying library name for each PL language; but that's wired into
the initdb-time contents of pg_pltemplate too, so that doesn't seem like
a large problem either.  Note that CREATE TRANSFORM as such doesn't call
the language module at all.

Per a report from Paul Jones.  Back-patch to 9.5 where transform modules
were introduced.

8 years agoAvoid dump/reload problems when using both plpython2 and plpython3.
Tom Lane [Tue, 12 Jan 2016 00:55:39 +0000 (19:55 -0500)]
Avoid dump/reload problems when using both plpython2 and plpython3.

Commit 803716013dc1350f installed a safeguard against loading plpython2
and plpython3 at the same time, but asserted that both could still be
used in the same database, just not in the same session.  However, that's
not actually all that practical because dumping and reloading will fail
(since both libraries necessarily get loaded into the restoring session).
pg_upgrade is even worse, because it checks for missing libraries by
loading every .so library mentioned in the entire installation into one
session, so that you can have only one across the whole cluster.

We can improve matters by not throwing the error immediately in _PG_init,
but only when and if we're asked to do something that requires calling
into libpython.  This ameliorates both of the above situations, since
while execution of CREATE LANGUAGE, CREATE FUNCTION, etc will result in
loading plpython, it isn't asked to do anything interesting (at least
not if check_function_bodies is off, as it will be during a restore).

It's possible that this opens some corner-case holes in which a crash
could be provoked with sufficient effort.  However, since plpython
only exists as an untrusted language, any such crash would require
superuser privileges, making it "don't do that" not a security issue.
To reduce the hazards in this area, the error is still FATAL when it
does get thrown.

Per a report from Paul Jones.  Back-patch to 9.2, which is as far back
as the patch applies without work.  (It could be made to work in 9.1,
but given the lack of previous complaints, I'm disinclined to expend
effort so far back.  We've been pretty desultory about support for
Python 3 in 9.1 anyway.)

8 years agoRemove obsolete comment.
Robert Haas [Mon, 11 Jan 2016 02:35:33 +0000 (21:35 -0500)]
Remove obsolete comment.

Noted while reviewing a question from Dickson S. Guedes.

8 years agodoc: Fix typo in logical decoding documentation
Peter Eisentraut [Mon, 11 Jan 2016 01:12:27 +0000 (20:12 -0500)]
doc: Fix typo in logical decoding documentation

From: Petr Jelinek <petr@2ndquadrant.com>

8 years agoRemove a useless PG_GETARG_DATUM() call from jsonb_build_array.
Tom Lane [Sat, 9 Jan 2016 22:39:45 +0000 (17:39 -0500)]
Remove a useless PG_GETARG_DATUM() call from jsonb_build_array.

This loop uselessly fetched the argument after the one it's currently
looking at.  No real harm is done since we couldn't possibly fetch off
the end of memory, but it's confusing to the reader.

Also remove a duplicate (and therefore confusing) PG_ARGISNULL check in
jsonb_build_object.

I happened to notice these things while trolling for missed null-arg
checks earlier today.  Back-patch to 9.5, not because there is any
real bug, but just because 9.5 and HEAD are still in sync in this
file and we might as well keep them so.

In passing, re-pgindent.

8 years agoAdd some checks on "char"-type columns to type_sanity and opr_sanity.
Tom Lane [Sat, 9 Jan 2016 22:20:58 +0000 (17:20 -0500)]
Add some checks on "char"-type columns to type_sanity and opr_sanity.

I noticed that the sanity checks in the regression tests omitted to
check a couple of "poor man's enum" columns that you'd reasonably
expect them to check.

There are other "char"-type columns in system catalogs that are not
covered by either type_sanity or opr_sanity, e.g. pg_rewrite.ev_type.
However, those catalogs are not populated with any manually-created
data during bootstrap, so it seems less necessary to check them
this way.

8 years agoClean up some lack-of-STRICT issues in the core code, too.
Tom Lane [Sat, 9 Jan 2016 21:58:32 +0000 (16:58 -0500)]
Clean up some lack-of-STRICT issues in the core code, too.

A scan for missed proisstrict markings in the core code turned up
these functions:

brin_summarize_new_values
pg_stat_reset_single_table_counters
pg_stat_reset_single_function_counters
pg_create_logical_replication_slot
pg_create_physical_replication_slot
pg_drop_replication_slot

The first three of these take OID, so a null argument will normally look
like a zero to them, resulting in "ERROR: could not open relation with OID
0" for brin_summarize_new_values, and no action for the pg_stat_reset_XXX
functions.  The other three will dump core on a null argument, though this
is mitigated by the fact that they won't do so until after checking that
the caller is superuser or has rolreplication privilege.

In addition, the pg_logical_slot_get/peek[_binary]_changes family was
intentionally marked nonstrict, but failed to make nullness checks on all
the arguments; so again a null-pointer-dereference crash is possible but
only for superusers and rolreplication users.

Add the missing ARGISNULL checks to the latter functions, and mark the
former functions as strict in pg_proc.  Make that change in the back
branches too, even though we can't force initdb there, just so that
installations initdb'd in future won't have the issue.  Since none of these
bugs rise to the level of security issues (and indeed the pg_stat_reset_XXX
functions hardly misbehave at all), it seems sufficient to do this.

In addition, fix some order-of-operations oddities in the slot_get_changes
family, mostly cosmetic, but not the part that moves the function's last
few operations into the PG_TRY block.  As it stood, there was significant
risk for an error to exit without clearing historical information from
the system caches.

The slot_get_changes bugs go back to 9.4 where that code was introduced.
Back-patch appropriate subsets of the pg_proc changes into all active
branches, as well.

8 years agoClean up code for widget_in() and widget_out().
Tom Lane [Sat, 9 Jan 2016 18:44:27 +0000 (13:44 -0500)]
Clean up code for widget_in() and widget_out().

Given syntactically wrong input, widget_in() could call atof() with an
indeterminate pointer argument, typically leading to a crash; or if it
didn't do that, it might return a NULL pointer, which again would lead
to a crash since old-style C functions aren't supposed to do things
that way.  Fix that by correcting the off-by-one syntax test and
throwing a proper error rather than just returning NULL.

Also, since widget_in and widget_out have been marked STRICT for a
long time, their tests for null inputs are just dead code; remove 'em.
In the oldest branches, also improve widget_out to use snprintf not
sprintf, just to be sure.

In passing, get rid of a long-since-useless sprintf into a local buffer
that nothing further is done with, and make some other minor coding
style cleanups.

In the intended regression-testing usage of these functions, none of
this is very significant; but if the regression test database were
left around in a production installation, these bugs could amount
to a minor security hazard.

Piotr Stefaniak, Michael Paquier, and Tom Lane

8 years agoRevoke change to rmgr desc of btree vacuum
Simon Riggs [Sat, 9 Jan 2016 18:31:08 +0000 (18:31 +0000)]
Revoke change to rmgr desc of btree vacuum

Per discussion with Andres Freund

8 years agoAdd STRICT to some C functions created by the regression tests.
Tom Lane [Sat, 9 Jan 2016 18:02:54 +0000 (13:02 -0500)]
Add STRICT to some C functions created by the regression tests.

These functions readily crash when passed a NULL input value.  The tests
themselves do not pass NULL values to them; but when the regression
database is used as a basis for fuzz testing, they cause a lot of noise.
Also, if someone were to leave a regression database lying about in a
production installation, these would create a minor security hazard.

Andreas Seltenreich

8 years agoAvoid pin scan for replay of XLOG_BTREE_VACUUM
Simon Riggs [Sat, 9 Jan 2016 10:10:08 +0000 (10:10 +0000)]
Avoid pin scan for replay of XLOG_BTREE_VACUUM
Replay of XLOG_BTREE_VACUUM during Hot Standby was previously thought to require
complex interlocking that matched the requirements on the master. This required
an O(N) operation that became a significant problem with large indexes, causing
replication delays of seconds or in some cases minutes while the
XLOG_BTREE_VACUUM was replayed.

This commit skips the “pin scan” that was previously required, by observing in
detail when and how it is safe to do so, with full documentation. The pin scan
is skipped only in replay; the VACUUM code path on master is not touched here.

The current commit still performs the pin scan for toast indexes, though this
can also be avoided if we recheck scans on toast indexes. Later patch will
address this.

No tests included. Manual tests using an additional patch to view WAL records
and their timing have shown the change in WAL records and their handling has
successfully reduced replication delay.

8 years agoRevert "Blind attempt at a Cygwin fix"
Alvaro Herrera [Fri, 8 Jan 2016 16:18:40 +0000 (13:18 -0300)]
Revert "Blind attempt at a Cygwin fix"

This reverts commit e9282e953205a2f3125fc8d1052bc01cb77cd2a3, which blew
up in a pretty spectacular way.  Re-introduce the original code while we
search for a real fix.

8 years agoBlind attempt at a Cygwin fix
Alvaro Herrera [Fri, 8 Jan 2016 14:48:39 +0000 (11:48 -0300)]
Blind attempt at a Cygwin fix

Further portability fix for a967613911f7.  Mingw- and MSVC-based builds
appear to be working fine, but Cygwin needs an extra tweak whereby the
new win32security.c file is explicitely added to the list of files to
build in pgport, per Cygwin members brolga and lorikeet.

Author: Michael Paquier

8 years agoFix typo in comment
Magnus Hagander [Fri, 8 Jan 2016 07:54:40 +0000 (08:54 +0100)]
Fix typo in comment

Tatsuro Yamada

8 years agoRemove reundand include of TestLib
Magnus Hagander [Fri, 8 Jan 2016 07:53:00 +0000 (08:53 +0100)]
Remove reundand include of TestLib

Kyotaro HORIGUCHI

8 years agoMarginal cleanup of GROUPING SETS code in grouping_planner().
Tom Lane [Fri, 8 Jan 2016 01:32:35 +0000 (20:32 -0500)]
Marginal cleanup of GROUPING SETS code in grouping_planner().

Improve comments and make it a shade less messy.  I think we might want
to move all of this somewhere else later, but it needs to be more
readable first.

In passing, re-pgindent the file, affecting some recently-added comments
concerning parallel query planning.

8 years agoDelay creation of subplan tlist until after create_plan().
Tom Lane [Fri, 8 Jan 2016 01:23:57 +0000 (20:23 -0500)]
Delay creation of subplan tlist until after create_plan().

Once upon a time it was necessary for grouping_planner() to determine
the tlist it wanted from the scan/join plan subtree before it called
query_planner(), because query_planner() would actually make a Plan using
that.  But we refactored things a long time ago to delay construction of
the Plan tree till later, so there's no need to build that tlist until
(and indeed unless) we're ready to plaster it onto the Plan.  The only
thing query_planner() cares about is what Vars are going to be needed for
the tlist, and it can perfectly well get that by looking at the real tlist
rather than some masticated version.

Well, actually, there is one minor glitch in that argument, which is that
make_subplanTargetList also adds Vars appearing only in HAVING to the
tlist it produces.  So now we have to account for HAVING explicitly in
build_base_rel_tlists.  But that just adds a few lines of code, and
I doubt it moves the needle much on processing time; we might be doing
pull_var_clause() twice on the havingQual, but before we had it scanning
dummy tlist entries instead.

This is a very small down payment on rationalizing grouping_planner
enough so it can be refactored.

8 years agoFix order of arguments to va_start()
Alvaro Herrera [Thu, 7 Jan 2016 23:32:14 +0000 (20:32 -0300)]
Fix order of arguments to va_start()

8 years agoFix unobvious interaction between -X switch and subdirectory creation.
Tom Lane [Thu, 7 Jan 2016 23:20:57 +0000 (18:20 -0500)]
Fix unobvious interaction between -X switch and subdirectory creation.

Turns out the only reason initdb -X worked is that pg_mkdir_p won't
whine if you point it at something that's a symlink to a directory.
Otherwise, the attempt to create pg_xlog/ just like all the other
subdirectories would have failed.  Let's be a little more explicit
about what's happening.  Oversight in my patch for bug #13853
(mea culpa for not testing -X ...)

8 years agoAdd win32security to LIBOBJS
Alvaro Herrera [Thu, 7 Jan 2016 21:50:28 +0000 (18:50 -0300)]
Add win32security to LIBOBJS

This seems to fix Mingw's compile that was broken in a967613911f7e, as
evidenced by buildfarm.

8 years agoUse plain mkdir() not pg_mkdir_p() to create subdirectories of PGDATA.
Tom Lane [Thu, 7 Jan 2016 20:22:01 +0000 (15:22 -0500)]
Use plain mkdir() not pg_mkdir_p() to create subdirectories of PGDATA.

When we're creating subdirectories of PGDATA during initdb, we know darn
well that the parent directory exists (or should exist) and that the new
subdirectory doesn't (or shouldn't).  There is therefore no need to use
anything more complicated than mkdir().  Using pg_mkdir_p() just opens us
up to unexpected failure modes, such as the one exhibited in bug #13853
from Nuri Boardman.  It's not very clear why pg_mkdir_p() went wrong there,
but it is clear that we didn't need to be trying to create parent
directories in the first place.  We're not even saving any code, as proven
by the fact that this patch nets out at minus five lines.

Since this is a response to a field bug report, back-patch to all branches.

8 years agopgstat: add WAL receiver status view & SRF
Alvaro Herrera [Thu, 7 Jan 2016 19:21:19 +0000 (16:21 -0300)]
pgstat: add WAL receiver status view & SRF

This new view provides insight into the state of a running WAL receiver
in a HOT standby node.
The information returned includes the PID of the WAL receiver process,
its status (stopped, starting, streaming, etc), start LSN and TLI, last
received LSN and TLI, timestamp of last message send and receipt, latest
end-of-WAL LSN and time, and the name of the slot (if any).

Access to the detailed data is only granted to superusers; others only
get the PID.

Author: Michael Paquier
Reviewer: Haribabu Kommi

8 years agoRemove vestigial CHECK_FOR_INTERRUPTS call.
Tom Lane [Thu, 7 Jan 2016 16:26:54 +0000 (11:26 -0500)]
Remove vestigial CHECK_FOR_INTERRUPTS call.

Commit e710b65c inserted code in md5_crypt_verify to disable and later
re-enable interrupts, with a CHECK_FOR_INTERRUPTS call as part of the
second step, to process any interrupts that had been held off.  Commit
6647248e removed the interrupt disable/re-enable code, but left behind
the CHECK_FOR_INTERRUPTS, even though this is now an entirely random,
pointless place for one.  md5_crypt_verify doesn't run long enough to
need such a check, and if it did, this would still be the wrong place
to put one.

8 years agoProvide more detail in postmaster log for password authentication failures.
Tom Lane [Thu, 7 Jan 2016 16:19:33 +0000 (11:19 -0500)]
Provide more detail in postmaster log for password authentication failures.

We tell people to examine the postmaster log if they're unsure why they are
getting auth failures, but actually only a few relatively-uncommon failure
cases were given their own log detail messages in commit 64e43c59b817a78d.
Expand on that so that every failure case detected within md5_crypt_verify
gets a specific log detail message.  This should cover pretty much every
ordinary password auth failure cause.

So far I've not noticed user demand for a similar level of auth detail
for the other auth methods, but sooner or later somebody might want to
work on them.  This is not that patch, though.

8 years agoWindows: Make pg_ctl reliably detect service status
Alvaro Herrera [Thu, 7 Jan 2016 14:59:08 +0000 (11:59 -0300)]
Windows: Make pg_ctl reliably detect service status

pg_ctl is using isatty() to verify whether the process is running in a
terminal, and if not it sends its output to Windows' Event Log ... which
does the wrong thing when the output has been redirected to a pipe, as
reported in bug #13592.

To fix, make pg_ctl use the code we already have to detect service-ness:
in the master branch, move src/backend/port/win32/security.c to src/port
(with suitable tweaks so that it runs properly in backend and frontend
environments); pg_ctl already has access to pgport so it Just Works.  In
older branches, that's likely to cause trouble, so instead duplicate the
required code in pg_ctl.c.

Author: Michael Paquier
Bug report and diagnosis: Egon Kocjan
Backpatch: all supported branches

8 years agoIn initdb's post-bootstrap phase, drop temp tables explicitly.
Tom Lane [Wed, 6 Jan 2016 17:25:32 +0000 (12:25 -0500)]
In initdb's post-bootstrap phase, drop temp tables explicitly.

Although these temp tables will get removed from template1 at the end of
the standalone-backend run, that's too late to keep them from getting
copied into the template0 and postgres databases, now that we use only a
single backend run for the whole sequence.  While no real harm is done
by the extra copies (since they'd be deleted on first use of the temp
schema), it's still unsightly, and it would mean some wasted cycles for
every database creation for the life of the installation.

Oversight in commit c4a8812cf64b1426.  Noticed by Amit Langote.

8 years agoComment typo fix.
Tom Lane [Wed, 6 Jan 2016 16:06:42 +0000 (11:06 -0500)]
Comment typo fix.

Per Amit Langote.

8 years agoFix typo in create_transform.sgml.
Tatsuo Ishii [Tue, 5 Jan 2016 23:01:40 +0000 (08:01 +0900)]
Fix typo in create_transform.sgml.

8 years agoAdd scale(numeric)
Alvaro Herrera [Tue, 5 Jan 2016 22:02:13 +0000 (19:02 -0300)]
Add scale(numeric)

Author: Marko Tiikkaja

8 years agoRemove some ancient and unmaintained encoding-conversion test cruft.
Tom Lane [Tue, 5 Jan 2016 21:43:40 +0000 (16:43 -0500)]
Remove some ancient and unmaintained encoding-conversion test cruft.

In commit 921191912c48a68d I claimed that we weren't testing encoding
conversion functions, but further poking around reveals that we did
have an equivalent though hard-wired set of tests in conversion.sql.
AFAICS there is no advantage to doing it like that as compared to letting
the catalog contents drive the test, so let the opr_sanity addition stand
and remove the now-redundant tests in conversion.sql.

Also, remove some infrastructure in src/backend/utils/mb/conversion_procs
for building conversion.sql's list of tests.  That was unmaintained, and
had not corresponded to the actual contents of conversion.sql since 2007
or perhaps even further back.