]> granicus.if.org Git - postgresql/log
postgresql
8 years agoImprove internationalization of messages involving type names
Alvaro Herrera [Mon, 28 Mar 2016 17:12:00 +0000 (14:12 -0300)]
Improve internationalization of messages involving type names

Change the slightly different variations of the message
  function FOO must return type BAR
to a single wording, removing the variability in type name so that they
all create a single translation entry; since the type name is not to be
translated, there's no point in it being part of the message anyway.

Also, change them all to use the same quoting convention, namely that
the function name is not to be quoted but the type name is.  (I'm not
quite sure why this is so, but it's the clear majority.)

Some similar messages such as "encoding conversion function FOO must ..."
are also changed.

8 years agopsql tab-complete for CREATE/DROP ACCESS METHOD
Teodor Sigaev [Mon, 28 Mar 2016 16:32:13 +0000 (19:32 +0300)]
psql tab-complete for CREATE/DROP ACCESS METHOD

Alexander Korotkov

8 years agoFix comment in pg_dump.
Teodor Sigaev [Mon, 28 Mar 2016 16:17:28 +0000 (19:17 +0300)]
Fix comment in pg_dump.

It was missed in 473b93287040b20017cc25a157cffdc5b978c254,
CREATE ACCESS METHOD

Alexander Korotkov

8 years agoLast-minute updates for release notes.
Tom Lane [Mon, 28 Mar 2016 15:32:17 +0000 (11:32 -0400)]
Last-minute updates for release notes.

Security: CVE-2016-2193, CVE-2016-3065

8 years agoAdd missing checks to some of pageinspect's BRIN functions
Alvaro Herrera [Mon, 28 Mar 2016 13:57:42 +0000 (10:57 -0300)]
Add missing checks to some of pageinspect's BRIN functions

brin_page_type() and brin_metapage_info() did not enforce being called
by superuser, like other pageinspect functions that take bytea do.
Since they don't verify the passed page thoroughly, it is possible to
use them to read the server memory with a carefully crafted bytea value,
up to a file kilobytes from where the input bytea is located.

Have them throw errors if called by a non-superuser.

Report and initial patch: Andreas Seltenreich

Security: CVE-2016-3065

8 years agoReset plan->row_security_env and planUserId
Stephen Frost [Mon, 28 Mar 2016 13:03:20 +0000 (09:03 -0400)]
Reset plan->row_security_env and planUserId

In the plancache, we check if the environment we planned the query under
has changed in a way which requires us to re-plan, such as when the user
for whom the plan was prepared changes and RLS is being used (and,
therefore, there may be different policies to apply).

Unfortunately, while those values were set and checked, they were not
being reset when the query was re-planned and therefore, in cases where
we change role, re-plan, and then change role again, we weren't
re-planning again.  This leads to potentially incorrect policies being
applied in cases where role-specific policies are used and a given query
is planned under one role and then executed under other roles, which
could happen under security definer functions or when a common user and
query is planned initially and then re-used across multiple SET ROLEs.

Further, extensions which made use of CopyCachedPlan() may suffer from
similar issues as the RLS-related fields were not properly copied as
part of the plan and therefore RevalidateCachedQuery() would copy in the
current settings without invalidating the query.

Fix by using the same approach used for 'search_path', where we set the
correct values in CompleteCachedPlan(), check them early on in
RevalidateCachedQuery() and then properly reset them if re-planning.
Also, copy through the values during CopyCachedPlan().

Pointed out by Ashutosh Bapat.  Reviewed by Michael Paquier.

Back-patch to 9.5 where RLS was introduced.

Security: CVE-2016-2193

8 years agoCode and docs review for commit 3187d6de0e5a9e805b27c48437897e8c39071d45.
Tom Lane [Mon, 28 Mar 2016 05:00:30 +0000 (01:00 -0400)]
Code and docs review for commit 3187d6de0e5a9e805b27c48437897e8c39071d45.

Fix up check for high-bit-set characters, which provoked "comparison is
always true due to limited range of data type" warnings on some compilers,
and was unlike the way we do it elsewhere anyway.  Fix omission of "$"
from the set of valid identifier continuation characters.  Get rid of
sanitize_text(), which was utterly inconsistent with any other error report
anywhere in the system, and wasn't even well designed on its own terms
(double-quoting the result string without escaping contained double quotes
doesn't seem very well thought out).  Fix up error messages, which didn't
follow the message style guidelines very well, and were overly specific in
situations where the actual mistake might not be what they said.  Improve
documentation.

(I started out just intending to fix the compiler warning, but the more
I looked at the patch the less I liked it.)

8 years agoRelease notes for 9.5.2, 9.4.7, 9.3.12, 9.2.16, 9.1.21.
Tom Lane [Sun, 27 Mar 2016 23:26:26 +0000 (19:26 -0400)]
Release notes for 9.5.2, 9.4.7, 9.3.12, 9.2.16, 9.1.21.

8 years agoGuard against zero vardata.rel->tuples in estimate_hash_bucketsize().
Tom Lane [Sun, 27 Mar 2016 22:21:03 +0000 (18:21 -0400)]
Guard against zero vardata.rel->tuples in estimate_hash_bucketsize().

If the referenced rel was proven empty, we'd compute 0/0 here, which
results in the function returning NaN.  That's a bit more serious
than the other zero-divide case.  Still, it only seems to be possible
in HEAD, so no back-patch.

Per report from Piotr Stefaniak.  I looked through the rest of selfuncs.c
and found no other likely trouble spots.

8 years agoClamp adjusted ndistinct to positive integer in estimate_hash_bucketsize().
Tom Lane [Sun, 27 Mar 2016 22:06:53 +0000 (18:06 -0400)]
Clamp adjusted ndistinct to positive integer in estimate_hash_bucketsize().

This avoids a possible divide-by-zero in the following calculation,
and rounding the number to an integer seems like saner behavior anyway.
Assuming IEEE math, the division would yield +Infinity which would get
replaced by 1.0 at the bottom of the function, so nothing really
interesting would ensue; but avoiding divide-by-zero seems like a
good idea on general principles.

Per report from Piotr Stefaniak.  No back-patch since this seems
mostly cosmetic.

8 years agopg_rewind: fsync target data directory.
Andres Freund [Sun, 27 Mar 2016 21:46:25 +0000 (23:46 +0200)]
pg_rewind: fsync target data directory.

Previously pg_rewind did not fsync any files. That's problematic, given
that the target directory is modified. If the database was started
afterwards, 2ce439f33 luckily already caused the data directory to be
synced to disk at postmaster startup; reducing the scope of the problem.

To fix, use initdb -S, at the end of the pg_rewind run. It doesn't seem
worthwhile to duplicate the code into pg_rewind, and initdb -S is
already used that way by pg_upgrade.

Reported-By: Andres Freund
Author: Michael Paquier, somewhat edited by me
Discussion: 20160310034352.iuqgvpmg5qmnxtkz@alap3.anarazel.de
    CAB7nPqSytVG1o4S3S2pA1O=692ekurJ+fckW2PywEG3sNw54Ow@mail.gmail.com
Backpatch: 9.5, where pg_rewind was introduced

8 years agoFix LWLockReportWaitEnd() parameter list to be (void).
Andres Freund [Sun, 27 Mar 2016 20:53:31 +0000 (22:53 +0200)]
Fix LWLockReportWaitEnd() parameter list to be (void).

Previously it was an "old style" function declaration.

8 years agopg_rewind: Close backup_label file descriptor.
Andres Freund [Sun, 27 Mar 2016 20:48:31 +0000 (22:48 +0200)]
pg_rewind: Close backup_label file descriptor.

This was a relatively harmless leak, as createBackupLabel() is only
called once per pg_rewind invocation.

Author: Michael Paquier
Reported-By: Michael Paquier
Discussion: CAB7nPqRnOw30gOXe2_SPLjh37bgm4V+txbYAPwoXb97nGQ297w@mail.gmail.com
Backpatch: 9.5, where pg_rewind was introduced

8 years agoDon't use !! but != 0/NULL to force boolean evaluation.
Andres Freund [Sun, 27 Mar 2016 15:17:00 +0000 (17:17 +0200)]
Don't use !! but != 0/NULL to force boolean evaluation.

I introduced several uses of !! to force bit arithmetic to be boolean,
but per discussion the project prefers != 0/NULL.

Discussion: CA+TgmoZP5KakLGP6B4vUjgMBUW0woq_dJYi0paOz-My0Hwt_vQ@mail.gmail.com

8 years agoChange various Gin*Is* macros to return 0/1.
Andres Freund [Sun, 27 Mar 2016 14:59:58 +0000 (16:59 +0200)]
Change various Gin*Is* macros to return 0/1.

Returning the direct result of bit arithmetic, in a macro intended to be
used in a boolean manner, can be problematic if the return value is
stored in a variable of type 'bool'. If bool is implemented using C99's
_Bool, that can lead to comparison failures if the variable is then
compared again with the expression (see ginStepRight() for an example
that fails), as _Bool forces the result to be 0/1. That happens in some
configurations of newer MSVC compilers.  It's also problematic when
storing the result of such an expression in a narrower type.

Several gin macros have been declared in that style since gin's initial
commit in 8a3631f8d86.

There's a lot more macros like this, but this is the only one causing
regression test failures; and I don't want to commit and backpatch a
larger patch with lots of conflicts just before the next set of minor
releases.

Discussion: 20150811154237.GD17575@awork2.anarazel.de
Backpatch: All supported branches

8 years agoFirst-draft release notes for 9.5.2.
Tom Lane [Sat, 26 Mar 2016 23:27:58 +0000 (19:27 -0400)]
First-draft release notes for 9.5.2.

As usual, the release notes for other branches will be made by cutting
these down, but put them up for community review first.

8 years agoModernize zic's test for valid timezone abbreviations.
Tom Lane [Sat, 26 Mar 2016 19:58:44 +0000 (15:58 -0400)]
Modernize zic's test for valid timezone abbreviations.

We really need to sync all of our IANA-derived timezone code with upstream,
but that's going to be a large patch and I certainly don't care to shove
such a thing into stable branches immediately before a release.  As a
stopgap, copy just the tzcode2016c logic that checks validity of timezone
abbreviations.  This prevents getting multiple "time zone abbreviation
differs from POSIX standard" bleats with tzdata 2014b and later.

8 years agoAvoid a couple of zero-divide scenarios in the planner.
Tom Lane [Sat, 26 Mar 2016 16:03:12 +0000 (12:03 -0400)]
Avoid a couple of zero-divide scenarios in the planner.

cost_subplan() supposed that the given subplan must have plan_rows > 0,
which as far as I can tell was true until recent refactoring of the
code in createplan.c; but now that code allows the Result for a provably
empty subquery to have plan_rows = 0.  Rather than undo that change,
put in a clamp to prevent zero divide.

get_cheapest_fractional_path() likewise supposed that best_path->rows > 0.
This assumption has been wrong for longer.  It's actually harmless given
IEEE float math, because a positive value divided by zero gives +Infinity
and compare_fractional_path_costs() will do the right thing with that.
Still, best not to assume that.

final_cost_nestloop() also seems to have some risks in this area, so
borrow the clamping logic already present in the mergejoin cost functions.

Lastly, remove unnecessary clamp_row_est() in planner.c's calls to
get_number_of_groups().  The only thing that function does with path_rows
is pass it to estimate_num_groups() which already has an internal clamp,
so we don't need the extra call; and if we did, the callers are arguably
the wrong place for it anyway.

First two items reported by Piotr Stefaniak, the others are products
of my nosing around for similar problems.  No back-patch since there's
no evidence that problems arise in the back branches.

8 years agoUpdate time zone data files to tzdata release 2016c.
Tom Lane [Fri, 25 Mar 2016 23:03:08 +0000 (19:03 -0400)]
Update time zone data files to tzdata release 2016c.

DST law changes in Azerbaijan, Chile, Haiti, Palestine, and Russia (Altai,
Astrakhan, Kirov, Sakhalin, Ulyanovsk regions).  Historical corrections
for Lithuania, Moldova, Russia (Kaliningrad, Samara, Volgograd).

As of 2015b, the keepers of the IANA timezone database started to use
numeric time zone abbreviations (e.g., "+04") instead of inventing
abbreviations not found in the wild like "ASTT".  This causes our rather
old copy of zic to whine "warning: time zone abbreviation differs from
POSIX standard" several times during "make install".  This warning is
harmless according to the IANA folk, and I don't see any problems with
these abbreviations in some simple tests; but it seems like now would be
a good time to update our copy of the tzcode stuff.  I'll look into that
soon.

8 years agoFix PL/Tcl for vpath builds.
Tom Lane [Fri, 25 Mar 2016 21:13:03 +0000 (17:13 -0400)]
Fix PL/Tcl for vpath builds.

Commit cd37bb78599dcf24 works for in-tree builds, but not so much for
VPATH.  Per buildfarm.

8 years agoImprove PL/Tcl errorCode facility by providing decoded name for SQLSTATE.
Tom Lane [Fri, 25 Mar 2016 20:54:52 +0000 (16:54 -0400)]
Improve PL/Tcl errorCode facility by providing decoded name for SQLSTATE.

We don't really want to encourage people to write numeric SQLSTATEs in
programs; that's unreadable and error-prone.  Copy plpgsql's infrastructure
for converting between SQLSTATEs and exception names shown in Appendix A,
and modify examples in tests and documentation to do it that way.

8 years agoIn PL/Tcl, make database errors return additional info in the errorCode.
Tom Lane [Fri, 25 Mar 2016 19:52:53 +0000 (15:52 -0400)]
In PL/Tcl, make database errors return additional info in the errorCode.

Tcl has a convention for returning additional info about an error in a
global variable named errorCode.  Up to now PL/Tcl has ignored that,
but this patch causes database errors caught by PL/Tcl to fill in
errorCode with useful information from the ErrorData struct.

Jim Nasby, reviewed by Pavel Stehule and myself

8 years agoFix DROP OPERATOR to reset oprcom/oprnegate links to the dropped operator.
Tom Lane [Fri, 25 Mar 2016 16:33:16 +0000 (12:33 -0400)]
Fix DROP OPERATOR to reset oprcom/oprnegate links to the dropped operator.

This avoids leaving dangling links in pg_operator; which while fairly
harmless are also unsightly.

While we're at it, simplify OperatorUpd, which went through
heap_modify_tuple for no very good reason considering it had already made
a tuple copy it could just scribble on.

Roma Sokolov, reviewed by Tomas Vondra, additional hacking by Robert Haas
and myself.

8 years agoDon't split up SRFs when choosing to postpone SELECT output expressions.
Tom Lane [Fri, 25 Mar 2016 15:19:51 +0000 (11:19 -0400)]
Don't split up SRFs when choosing to postpone SELECT output expressions.

In commit 9118d03a8cca3d97 we taught the planner to postpone evaluation of
set-returning functions in a SELECT's targetlist until after any sort done
to satisfy ORDER BY.  However, if we postpone some SRFs this way while
others do not get postponed (because they're sort or group key columns)
we will break the traditional behavior by which all SRFs in the tlist run
in-step during ExecTargetList(), so that you get the least common multiple
of their periods not the product.  Fix make_sort_input_target() so it will
not split up SRF evaluation in such cases.

There is still a hazard of similar odd behavior if there's a SRF in a
grouping column and another one that isn't, but that was true before
and we're just trying to preserve bug-compatibility with the traditional
behavior.  This whole area is overdue to be rethought and reimplemented,
but we'll try to avoid changing behavior until then.

Per report from Regina Obe.

8 years agoLink libpq after libpgfeutils to satisfy Windows linker.
Tom Lane [Fri, 25 Mar 2016 00:45:31 +0000 (20:45 -0400)]
Link libpq after libpgfeutils to satisfy Windows linker.

Some of the non-MSVC Windows buildfarm members seem to need this to avoid
getting "undefined symbol" errors on libpgfeutils' references to libpq.
I could understand that if libpq were a static library, but surely it is
not?  Oh well, at least the extra reference is no more harmful than it is
for libpgcommon or libpgport.

8 years agoMove psql's psqlscan.l into src/fe_utils.
Tom Lane [Fri, 25 Mar 2016 00:28:47 +0000 (20:28 -0400)]
Move psql's psqlscan.l into src/fe_utils.

This completes (at least for now) the project of getting rid of ad-hoc
linkages among the src/bin/ subdirectories.  Everything they share is now
in src/fe_utils/ and is included from a static library at link time.

A side benefit is that we can restore the FLEX_NO_BACKUP check for
psqlscanslash.l.  We might need to think of another way to do that check
if we ever need to build two lexers with that property in the same source
directory, but there's no foreseeable reason to need that.

8 years agoMove psql's print.c and mbprint.c into src/fe_utils.
Tom Lane [Thu, 24 Mar 2016 22:27:28 +0000 (18:27 -0400)]
Move psql's print.c and mbprint.c into src/fe_utils.

Just turning the crank ...

8 years agoSuppress compiler warning for get_am_type_string().
Tom Lane [Thu, 24 Mar 2016 21:22:24 +0000 (17:22 -0400)]
Suppress compiler warning for get_am_type_string().

Compilers that don't know that elog(ERROR) doesn't return complained
that this function might fail to return a value.  Per buildfarm.

While at it, const-ify the function's declaration, since the intent
is evidently to always return a constant string.

8 years agoAdd missed inclusion requirement in Mkvcbuild.pm.
Tom Lane [Thu, 24 Mar 2016 21:12:40 +0000 (17:12 -0400)]
Add missed inclusion requirement in Mkvcbuild.pm.

Per buildfarm.

8 years agoCreate src/fe_utils/, and move stuff into there from pg_dump's dumputils.
Tom Lane [Thu, 24 Mar 2016 19:55:44 +0000 (15:55 -0400)]
Create src/fe_utils/, and move stuff into there from pg_dump's dumputils.

Per discussion, we want to create a static library and put the stuff into
it that until now has been shared across src/bin/ directories by ad-hoc
methods like symlinking a source file.  This commit creates the library and
populates it with a couple of files that contain the widely-useful portions
of pg_dump's dumputils.c file.  dumputils.c survives, because it has some
stuff that didn't seem appropriate for fe_utils, but it's significantly
smaller and is no longer referenced from any other directory.

Follow-on patches will move more stuff into fe_utils.

The Mkvcbuild.pm hacking here is just a best guess; we'll see how the
buildfarm likes it.

8 years agoImprove documentation for combine functions.
Robert Haas [Thu, 24 Mar 2016 16:59:18 +0000 (12:59 -0400)]
Improve documentation for combine functions.

David Rowley

8 years agoUse correct GetDatum function.
Robert Haas [Thu, 24 Mar 2016 12:57:48 +0000 (08:57 -0400)]
Use correct GetDatum function.

Oops.

8 years agoAvoid PGDLLIMPORT for simple local references in frontend programs.
Tom Lane [Thu, 24 Mar 2016 03:26:44 +0000 (23:26 -0400)]
Avoid PGDLLIMPORT for simple local references in frontend programs.

I was wondering if this would be an issue, and buildfarm member frogmouth
says it is.

8 years agoSupport CREATE ACCESS METHOD
Alvaro Herrera [Thu, 24 Mar 2016 02:01:35 +0000 (23:01 -0300)]
Support CREATE ACCESS METHOD

This enables external code to create access methods.  This is useful so
that extensions can add their own access methods which can be formally
tracked for dependencies, so that DROP operates correctly.  Also, having
explicit support makes pg_dump work correctly.

Currently only index AMs are supported, but we expect different types to
be added in the future.

Authors: Alexander Korotkov, Petr Jelínek
Reviewed-By: Teodor Sigaev, Petr Jelínek, Jim Nasby
Commitfest-URL: https://commitfest.postgresql.org/9/353/
Discussion: https://www.postgresql.org/message-id/CAPpHfdsXwZmojm6Dx+TJnpYk27kT4o7Ri6X_4OSWcByu1Rm+VA@mail.gmail.com

8 years agoMove keywords.c/kwlookup.c into src/common/.
Tom Lane [Thu, 24 Mar 2016 00:22:08 +0000 (20:22 -0400)]
Move keywords.c/kwlookup.c into src/common/.

Now that we have src/common/ for code shared between frontend and backend,
we can get rid of (most of) the klugy ways that the keyword table and
keyword lookup code were formerly shared between different uses.
This is a first step towards a more general plan of getting rid of
special-purpose kluges for sharing code in src/bin/.

I chose to merge kwlookup.c back into keywords.c, as it once was, and
always has been so far as keywords.h is concerned.  We could have
kept them separate, but there is noplace that uses ScanKeywordLookup
without also wanting access to the backend's keyword list, so there
seems little point.

ecpg is still a bit weird, but at least now the trickiness is documented.

I think that the MSVC build script should require no adjustments beyond
what's done here ... but we'll soon find out.

8 years agoDisable abbreviated keys for string-sorting in non-C locales.
Robert Haas [Wed, 23 Mar 2016 19:58:34 +0000 (15:58 -0400)]
Disable abbreviated keys for string-sorting in non-C locales.

Unfortunately, every version of glibc thus far tested has bugs whereby
strcoll() ordering does not match strxfrm() ordering as required by
the standard.  This can result in, for example, corrupted indexes.
Disabling abbreviated keys in these cases slows down non-C-collation
string sorting considerably, but there seems to be no practical
alternative.  Users who are confident that their libc implementations
are solid in this regard can re-enable the optimization by compiling
with TRUST_STRXFRM.

Users who have built indexes using PostgreSQL 9.5 or PostgreSQL 9.5.1
should REINDEX if there is a possibility that they may have been
affected by this problem.

Report by Marc-Olaf Jaschke.  Investigation mostly by Tom Lane, with
help from Peter Geoghegan, Noah Misch, Stephen Frost, and me.  Patch
by me, reviewed by Peter Geoghegan and Tom Lane.

8 years agopostgres_fdw: Fix crash when pushing down multiple joins.
Robert Haas [Wed, 23 Mar 2016 16:28:01 +0000 (12:28 -0400)]
postgres_fdw: Fix crash when pushing down multiple joins.

A join clause might mention multiple relations on either side, so it
need not be the case that a given joinrel's constituent relations are
all on one side of the join clause or all on the other.

Report by Rajkumar Raghuwanshi.  Analysis and fix by Michael Paquier
and Ashutosh Bapat.

8 years agoPartition the freelist for shared dynahash tables.
Robert Haas [Wed, 23 Mar 2016 14:56:23 +0000 (10:56 -0400)]
Partition the freelist for shared dynahash tables.

Without this, contention on the freelist can become a pretty serious
problem on large servers.

Aleksander Alekseev, reviewed by Anastasia Lubennikova, Dilip Kumar,
and me.

8 years agoCode review for error reports in jsonb_set().
Tom Lane [Wed, 23 Mar 2016 15:00:39 +0000 (11:00 -0400)]
Code review for error reports in jsonb_set().

User-facing (even tested by regression tests) error conditions were thrown
with elog(), hence had wrong SQLSTATE and were untranslatable.  And the
error message texts weren't up to project style, either.

8 years agoFix unsafe use of strtol() on a non-null-terminated Text datum.
Tom Lane [Wed, 23 Mar 2016 14:43:13 +0000 (10:43 -0400)]
Fix unsafe use of strtol() on a non-null-terminated Text datum.

jsonb_set() could produce wrong answers or incorrect error reports, or in
the worst case even crash, when trying to convert a path-array element into
an integer for use as an array subscript.  Per report from Vitaly Burovoy.
Back-patch to 9.5 where the faulty code was introduced (in commit
c6947010ceb42143).

Michael Paquier

8 years agoChange comment to describe correct lock level used
Simon Riggs [Wed, 23 Mar 2016 11:32:34 +0000 (11:32 +0000)]
Change comment to describe correct lock level used

8 years agoFix EvalPlanQual bug when query contains both locked and not-locked rels.
Tom Lane [Tue, 22 Mar 2016 21:56:06 +0000 (17:56 -0400)]
Fix EvalPlanQual bug when query contains both locked and not-locked rels.

In commit afb9249d06f47d7a, we (probably I) made ExecLockRows assign
null test tuples to all relations of the query while setting up to do an
EvalPlanQual recheck for a newly-updated locked row.  This was sheerest
brain fade: we should only set test tuples for relations that are lockable
by the LockRows node, and in particular empty test tuples are only sensible
for inheritance child relations that weren't the source of the current
tuple from their inheritance tree.  Setting a null test tuple for an
unrelated table causes it to return NULLs when it should not, as exhibited
in bug #14034 from Bronislav Houdek.  To add insult to injury, doing it the
wrong way required two loops where one would suffice; so the corrected code
is even a bit shorter and faster.

Add a regression test case based on his example, and back-patch to 9.5
where the bug was introduced.

8 years agoImprove docs of pg_trgm changes
Teodor Sigaev [Tue, 22 Mar 2016 14:08:10 +0000 (17:08 +0300)]
Improve docs of pg_trgm changes

Artur Zakirov, per gripe from Jeff Janes

8 years agoFix typo in docs.
Fujii Masao [Tue, 22 Mar 2016 13:04:30 +0000 (22:04 +0900)]
Fix typo in docs.

Jeff Janes

8 years agoAllow the delay in psql's \watch command to be a fractional second.
Tom Lane [Mon, 21 Mar 2016 22:34:18 +0000 (18:34 -0400)]
Allow the delay in psql's \watch command to be a fractional second.

Instead of just "2" seconds, allow eg. "2.5" seconds.  Per request
from Alvaro Herrera.  No docs change since the docs didn't say you
couldn't do this already.

8 years agoImprove header output from psql's \watch command.
Tom Lane [Mon, 21 Mar 2016 22:18:13 +0000 (18:18 -0400)]
Improve header output from psql's \watch command.

Include the \pset title string if there is one, and shorten the prefab
part of the header to be "timestamp (every Ns)".  Per suggestion by
David Johnston.

Michael Paquier and Tom Lane

8 years agoClean up some Coverity complaints about commit 0bf3ae88af330496.
Tom Lane [Mon, 21 Mar 2016 15:59:49 +0000 (11:59 -0400)]
Clean up some Coverity complaints about commit 0bf3ae88af330496.

The two get_tle_by_resno() calls introduced by this commit lacked any
check for a NULL return, unlike any other calls of that function anywhere
in our tree.  Coverity quite properly complained about it.  Also fix a
misindented line in process_query_params(), which Coverity also complained
about on the grounds that the bad indentation suggested possible programmer
misinterpretation.

8 years agoMake max_parallel_degree PGC_USERSET.
Robert Haas [Mon, 21 Mar 2016 14:54:36 +0000 (10:54 -0400)]
Make max_parallel_degree PGC_USERSET.

It was intended to be this way all along, just like other planner
GUCs such as work_mem.  But I goofed.

8 years agoSupport parallel aggregation.
Robert Haas [Mon, 21 Mar 2016 13:20:53 +0000 (09:20 -0400)]
Support parallel aggregation.

Parallel workers can now partially aggregate the data and pass the
transition values back to the leader, which can combine the partial
results to produce the final answer.

David Rowley, based on earlier work by Haribabu Kommi.  Reviewed by
Álvaro Herrera, Tomas Vondra, Amit Kapila, James Sewell, and me.

8 years agoProperly declare FeBeWaitSet.
Andres Freund [Mon, 21 Mar 2016 11:58:18 +0000 (12:58 +0100)]
Properly declare FeBeWaitSet.

Surprising that this worked on a number of systems. Reported by
buildfarm member longfin.

8 years agoIntroduce WaitEventSet API.
Andres Freund [Mon, 21 Mar 2016 08:56:39 +0000 (09:56 +0100)]
Introduce WaitEventSet API.

Commit ac1d794 ("Make idle backends exit if the postmaster dies.")
introduced a regression on, at least, large linux systems. Constantly
adding the same postmaster_alive_fds to the OSs internal datastructures
for implementing poll/select can cause significant contention; leading
to a performance regression of nearly 3x in one example.

This can be avoided by using e.g. linux' epoll, which avoids having to
add/remove file descriptors to the wait datastructures at a high rate.
Unfortunately the current latch interface makes it hard to allocate any
persistent per-backend resources.

Replace, with a backward compatibility layer, WaitLatchOrSocket with a
new WaitEventSet API. Users can allocate such a Set across multiple
calls, and add more than one file-descriptor to wait on. The latter has
been added because there's upcoming postgres features where that will be
helpful.

In addition to the previously existing poll(2), select(2),
WaitForMultipleObjects() implementations also provide an epoll_wait(2)
based implementation to address the aforementioned performance
problem. Epoll is only available on linux, but that is the most likely
OS for machines large enough (four sockets) to reproduce the problem.

To actually address the aforementioned regression, create and use a
long-lived WaitEventSet for FE/BE communication.  There are additional
places that would benefit from a long-lived set, but that's a task for
another day.

Thanks to Amit Kapila, who helped make the windows code I blindly wrote
actually work.

Reported-By: Dmitry Vasilyev Discussion:
CAB-SwXZh44_2ybvS5Z67p_CDz=XFn4hNAD=CnMEF+QqkXwFrGg@mail.gmail.com
20160114143931.GG10941@awork2.anarazel.de

8 years agoCombine win32 and unix latch implementations.
Andres Freund [Mon, 21 Mar 2016 08:56:39 +0000 (09:56 +0100)]
Combine win32 and unix latch implementations.

Previously latches for windows and unix had been implemented in
different files. A later patch introduce an expanded wait
infrastructure, keeping the implementation separate would introduce too
much duplication.

This basically just moves the functions, without too much change. The
reason to keep this separate is that it allows blame to continue working
a little less badly; and to make review a tiny bit easier.

Discussion: 20160114143931.GG10941@awork2.anarazel.de

8 years agoSecond attempt at fixing MSVC build for 68ab8e8ba4a471d9.
Andres Freund [Mon, 21 Mar 2016 09:49:45 +0000 (10:49 +0100)]
Second attempt at fixing MSVC build for 68ab8e8ba4a471d9.

After the previous fix in 6f1f34c9 msvc ended up looking for psqlscan.c
in the wrong directory.

David's fix just forces the path to be adjusted. That's not a
particularly pretty fix, but it hopefully will make the buildfarm green
again.

Author: David Rowley
Discussion: CAKJS1f_9CCi_t+LEgV5GWoCj3wjavcMoDc5qfcf_A0UwpQoPoA@mail.gmail.com

8 years agoUse %option bison-bridge in psql/pgbench lexers.
Tom Lane [Mon, 21 Mar 2016 01:59:03 +0000 (21:59 -0400)]
Use %option bison-bridge in psql/pgbench lexers.

The point of this change is to use %pure-parser in pgbench's exprparse.y.
The immediate reason is that it turns out very ancient versions of bison
have a bug with the combination of a reentrant lexer and non-reentrant
parser.  We could consider dropping support for such ancient bisons; but
considering that we might well need exprparse.y to be reentrant some day,
it seems better to make it so right now than to move the portability
goalposts.  (AFAICT there's no particular performance consequence to this
change, either, so there's no good reason not to do it.)

Now, %pure-parser assumes that the called lexer is built with %option
bison-bridge.  Because we're assuming bitwise compatibility of yyscan_t
(yyguts_t) data structures among all the psql/pgbench lexers, that
requirement propagates back to psql's lexers as well.  But it's just a
few lines of change on that side too; and if psqlscan.l is to set the
baseline for a possibly-large family of lexers, it should err on the
side of including not omitting useful features.

8 years agoBest-guess attempt at fixing MSVC build for 68ab8e8ba4a471d9.
Tom Lane [Sun, 20 Mar 2016 21:51:54 +0000 (17:51 -0400)]
Best-guess attempt at fixing MSVC build for 68ab8e8ba4a471d9.

pgbench now needs to use src/bin/psql/psqlscan.l, but it's not very clear
how to fit that into the MSVC build system.  If this doesn't work I'm going
to need some help from somebody who actually understands those scripts ...

8 years agoSQL commands in pgbench scripts are now ended by semicolons, not newlines.
Tom Lane [Sun, 20 Mar 2016 16:58:44 +0000 (12:58 -0400)]
SQL commands in pgbench scripts are now ended by semicolons, not newlines.

To allow multiline SQL commands in scripts, adopt the same rules psql uses
to decide what is the end of a SQL command, to wit, an unquoted semicolon
not encased in parentheses.  Do this by importing the same flex lexer that
psql uses, since coping with stuff like dollar-quoted literals is hard to
get right without going the full nine yards.

This makes use of the infrastructure added in commit 0ea9efbe9ec1bf07 to
support independently-written flex lexers scanning the same PsqlScanState
input-buffer data structure.  Since that infrastructure isn't very
friendly to ad-hoc parsing code such as strtok(), improve exprscan.l
so that it can parse either whitespace-separated words or expression
tokens, on demand, and rewrite pgbench.c's backslash-command parsing
code to always use the lexer to fetch tokens.

It's still the case that pgbench backslash commands extend to the end
of the line, no more and no less.  That could be changed in a fairly
localized way now, and there was some interest in doing so, but it
seems like material for a separate patch.

In passing, make some marginal cleanups in syntax error reporting,
const-ify a few data structures that could use it, and run some of
this code through pgindent.

I can't tell whether the MSVC build scripts need to be taught explicitly
about the changes here or not, but the buildfarm will soon tell us.

Kyotaro Horiguchi and Tom Lane

8 years agoRemove dependency on psed for MSVC builds.
Andrew Dunstan [Sat, 19 Mar 2016 22:36:35 +0000 (18:36 -0400)]
Remove dependency on psed for MSVC builds.

Modern Perl has removed psed from its core distribution, so it might not
be readily available on some build platforms. We therefore replace its
use with a Perl script generated by s2p, which is equivalent to the sed
script. The latter is retained for non-MSVC builds to avoid creating a
new hard dependency on Perl for non-Windows tarball builds.

Backpatch to all live branches.

Michael Paquier and me.

8 years agoFix phony .PHONY.
Tom Lane [Sat, 19 Mar 2016 21:19:37 +0000 (17:19 -0400)]
Fix phony .PHONY.

A couple makefiles had misspelled the magic .PHONY target as PHONY.

8 years agoMake pgbench's expression lexer reentrant.
Tom Lane [Sat, 19 Mar 2016 20:35:41 +0000 (16:35 -0400)]
Make pgbench's expression lexer reentrant.

This is a necessary preliminary step for making it play with psqlscan.l
given the way I set up the lexer input-buffer sharing mechanism in commit
0ea9efbe9ec1bf07.

I've not tried to make it *actually* reentrant; there's still some static
variables laying about.  But flex thinks it's reentrant, and that's what
counts.

In support of that, fix exprparse.y to pass through the yyscan_t from the
caller.  Also do some minor code beautification, like not casting away
const.

8 years agopgbench: Silence new compiler warnings
Alvaro Herrera [Sat, 19 Mar 2016 19:14:37 +0000 (16:14 -0300)]
pgbench: Silence new compiler warnings

The original coding in 7bafffea647 and previous wasn't all that great
anyway.

Reported by Jeff Janes and Tom Lane

8 years agoTypo fix.
Tom Lane [Sat, 19 Mar 2016 18:36:52 +0000 (14:36 -0400)]
Typo fix.

8 years agoSync backend/parser/scan.l with bin/psql/psqlscan.l.
Tom Lane [Sat, 19 Mar 2016 18:36:22 +0000 (14:36 -0400)]
Sync backend/parser/scan.l with bin/psql/psqlscan.l.

Make some minor formatting adjustments to make it easier to diff these
files and see that they indeed implement the same flex rules (at least
to the extent that we want them to be the same).

(Someday it'd be nice to make ecpg's pgc.l more easily diff'able too,
but today is not that day.)

Also run relevant parts of these files and psqlscanslash.l through
pgindent.

No actual behavioral changes here, just obsessive neatnik-ism.

8 years agoBuild backend/parser/scan.l and interfaces/ecpg/preproc/pgc.l standalone.
Tom Lane [Sat, 19 Mar 2016 16:07:16 +0000 (12:07 -0400)]
Build backend/parser/scan.l and interfaces/ecpg/preproc/pgc.l standalone.

Now that we know about the %top{} trick, we can revert to building flex
lexers as separate .o files.  This is worth doing for a couple of reasons
besides sheer cleanliness.  We can narrow the scope of the -Wno-error flag
that's forced on scan.c.  Also, since these grammar and lexer files are
so large, splitting them into separate build targets should have some
advantages in build speed, particularly in parallel or ccache'd builds.

We have quite a few other .l files that could be changed likewise, but the
above arguments don't apply to them, so the benefit of fixing them seems
pretty minimal.  Leave the rest for some other day.

8 years agopgbench: Allow changing weights for scripts
Alvaro Herrera [Sat, 19 Mar 2016 15:32:42 +0000 (12:32 -0300)]
pgbench: Allow changing weights for scripts

Previously, all scripts had the same probability of being chosen when
multiple of them were specified via -b, -f, -N, -S.  With this commit,
-b and -f now search for an "@" in the script name and use the integer
found after it as the drawing probability for that script.

(One disadvantage is that if you have script whose names contain @, you
are now forced to specify "@1" at the end; otherwise the name's @ is
confused with a weight separator.  We don't expect many pgbench script
with @ in their names in the wild, so this shouldn't be too serious a
problem.)

While at it, rework the interface between addScript, process_file,
process_builtin, and findBuiltin.  It had gotten a bit out of hand with
recent commits.

Author: Fabien Coelho
Reviewed-By: Andres Freund, Robert Haas, Álvaro Herrera, Michaël Paquier
Discussion: http://www.postgresql.org/message-id/alpine.DEB.2.10.1603160721240.1666@sto

8 years agoWith ancient gcc, skip pg_attribute_printf() on function pointer.
Tom Lane [Sat, 19 Mar 2016 14:59:20 +0000 (10:59 -0400)]
With ancient gcc, skip pg_attribute_printf() on function pointer.

Buildfarm results show that the ability to attach pg_attribute_printf
decoration to a function pointer appeared somewhere between gcc 2.95.3
and gcc 4.0.1.  Guess that it was there in 4.0.

8 years agoAllow SSL server key file to have group read access if owned by root
Peter Eisentraut [Sat, 19 Mar 2016 10:03:22 +0000 (11:03 +0100)]
Allow SSL server key file to have group read access if owned by root

We used to require the server key file to have permissions 0600 or less
for best security.  But some systems (such as Debian) have certificate
and key files managed by the operating system that can be shared with
other services.  In those cases, the "postgres" user is made a member of
a special group that has access to those files, and the server key file
has permissions 0640.  To accommodate that kind of setup, also allow the
key file to have permissions 0640 but only if owned by root.

From: Christoph Berg <myon@debian.org>
Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org>
8 years agoFix stupid omission in c4901a1e.
Andres Freund [Sat, 19 Mar 2016 05:35:43 +0000 (22:35 -0700)]
Fix stupid omission in c4901a1e.

Reported-By: Jeff Janes
Discussion: CAMkU=1zGxREwoyaCrp_CHadEB+dPgpVyKBysCJ+6xP9gCOvAuw@mail.gmail.com

8 years agoFix missed update in _readForeignScan().
Tom Lane [Sat, 19 Mar 2016 05:20:34 +0000 (01:20 -0400)]
Fix missed update in _readForeignScan().

Blatant fail in 0bf3ae88af330496517722e391e7c975e6bad219.
Caught by buildfarm member mandrill.

8 years agoUse yylex_init not yylex_init_extra().
Tom Lane [Sat, 19 Mar 2016 05:02:18 +0000 (01:02 -0400)]
Use yylex_init not yylex_init_extra().

Older versions of flex don't have the latter.  Per buildfarm.

8 years agoSuppress FLEX_NO_BACKUP check for psqlscanslash.l.
Tom Lane [Sat, 19 Mar 2016 04:43:46 +0000 (00:43 -0400)]
Suppress FLEX_NO_BACKUP check for psqlscanslash.l.

The existing infrastructure for FLEX_NO_BACKUP doesn't work reliably
when two lexers are built in parallel in the same directory.  We can
probably fix that, but as a short-term workaround, just don't make
the check for psqlscanslash.l.

Per buildfarm.

8 years agoSplit psql's lexer into two separate .l files for SQL and backslash cases.
Tom Lane [Sat, 19 Mar 2016 04:24:55 +0000 (00:24 -0400)]
Split psql's lexer into two separate .l files for SQL and backslash cases.

This gets us to a point where psqlscan.l can be used by other frontend
programs for the same purpose psql uses it for, ie to detect when it's
collected a complete SQL command from input that is divided across
line boundaries.  Moreover, other programs can supply their own lexers
for backslash commands of their own choosing.  A follow-on patch will
use this in pgbench.

The end result here is roughly the same as in Kyotaro Horiguchi's
0001-Make-SQL-parser-part-of-psqlscan-independent-from-ps.patch, although
the details of the method for switching between lexers are quite different.
Basically, in this patch we share the entire PsqlScanState, YY_BUFFER_STATE
stack, *and* yyscan_t between different lexers.  The only thing we need
to do to switch to a different lexer is to make sure the start_state is
valid for the new lexer.  This works because flex doesn't keep any other
persistent state that depends on the specific lexing tables generated for
a particular .l file.  (We are assuming that both lexers are built with
the same flex version, or at least versions that are compatible with
respect to the contents of yyscan_t; but that doesn't seem likely to
be a big problem in practice, considering how slowly flex changes.)

Aside from being more efficient than Horiguchi-san's original solution,
this avoids possible corner-case changes in semantics: the original code
was capable of popping the input buffer stack while still staying in
backslash-related parsing states.  I'm not sure that that equates to any
useful user-visible behaviors, but I'm not sure it doesn't either, so
I'm loath to assume that we only need to consider the topmost buffer when
parsing a backslash command.

I've attempted to update the MSVC build scripts for the added .l file,
but will rely on the buildfarm to see if I missed anything.

Kyotaro Horiguchi and Tom Lane

8 years agoConvert psql's flex lexer to be re-entrant, and make it compile standalone.
Tom Lane [Sat, 19 Mar 2016 01:21:52 +0000 (21:21 -0400)]
Convert psql's flex lexer to be re-entrant, and make it compile standalone.

Change psqlscan.l to specify '%option reentrant', adjust internal APIs
to match, and get rid of its internal static variables.  While this is
good cleanup in an abstract sense, the reason to do it right now is that
it seems the only practical way to support use of separate flex lexers
with common PsqlScanState infrastructure.  If we build two non-reentrant
lexers then we are going to have problems with dangling buffer pointers
in whichever lexer isn't active when we transition from one buffer to
another, as well as curious side-effects if we try to share any code
between the files.  (Horiguchi-san had a different solution to that in his
pending patch, but I find it ugly and probably broken for corner cases.)

Depending on which version of flex you're using, this may result in getting
a "warning: unused variable 'yyg'" warning from psqlscan, similar to the
one you'd have seen for a long time in backend/parser/scan.l.  I put a
local -Wno-error into CFLAGS for the file, for the convenience of those
who compile with -Werror.

Also, stop compiling psqlscan as part of mainloop.c, and make it a
standalone build target instead.  This is a lot cleaner than before, though
it doesn't really change much in practice as of this commit.  (I'm not sure
whether the MSVC build scripts will need some help with this part, but the
buildfarm will soon tell us.)

8 years agoMerge wal_level "archive" and "hot_standby" into new name "replica"
Peter Eisentraut [Tue, 1 Mar 2016 01:01:54 +0000 (20:01 -0500)]
Merge wal_level "archive" and "hot_standby" into new name "replica"

The distinction between "archive" and "hot_standby" existed only because
at the time "hot_standby" was added, there was some uncertainty about
stability.  This is now a long time ago.  We would like to move forward
with simplifying the replication configuration, but this distinction is
in the way, because a primary server cannot tell (without asking a
standby or predicting the future) which one of these would be the
appropriate level.

Pick a new name for the combined setting to make it clearer that it
covers all (non-logical) backup and replication uses.  The old values
are still accepted but are converted internally.

Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
Reviewed-by: David Steele <david@pgmasters.net>
8 years agoDecouple psqlscan.l from surrounding program.
Tom Lane [Fri, 18 Mar 2016 19:05:49 +0000 (15:05 -0400)]
Decouple psqlscan.l from surrounding program.

Remove assorted external references from psqlscan.l in preparation for
making it usable by other frontend programs.  This mostly involves
getting rid of direct calls to psql_error() and GetVariable() in favor
of introducing a callback-functions struct to encapsulate variable
fetching and error printing.  In addition, pass the current encoding
and standard-strings status as additional parameters to psql_scan_setup
instead of looking directly at "pset" or calling additional functions.

I did not bother to change some references to psql_error that are in
functions that will soon migrate to a psql-specific backslash-command
lexer.  Other than that, this version of psqlscan.l is capable of
compiling standalone.  It still depends on assorted src/common functions
as well as some encoding-related libpq functions, but we expect that
all programs using it will be happy with those dependencies.

Kyotaro Horiguchi, somewhat editorialized on by me

8 years agoUse INT64_FORMAT instead of %ld for int64.
Robert Haas [Fri, 18 Mar 2016 18:53:06 +0000 (14:53 -0400)]
Use INT64_FORMAT instead of %ld for int64.

Commit 0011c0091e886b874e485a46ff2c94222ffbf550 introduced this
mistake.

Patch by me.  Reported by Andres Freund, who also reviewed the
patch.

8 years agoOnly clear latch self-pipe/event if there is a pending notification.
Andres Freund [Fri, 18 Mar 2016 18:43:59 +0000 (11:43 -0700)]
Only clear latch self-pipe/event if there is a pending notification.

This avoids a good number of, individually quite fast, system calls in
scenarios with many quick queries. Besides the aesthetic benefit of
seing fewer superflous system calls with strace, it also improves
performance by ~2% measured by pgbench -M prepared -c 96 -j 8 -S (scale
100).

Without having benchmarked it, this patch also adjust the windows code,
as that makes it easier to unify the unix/windows codepaths in a later
patch. There's little reason to diverge in behaviour between the
platforms.

Discussion: CA+TgmoYc1Zm+Szoc_Qbzi92z2c1vRHZmjhfPn5uC=w8bXv6Avg@mail.gmail.com
Reviewed-By: Robert Haas
8 years agoMake it easier to choose the used waiting primitive in unix_latch.c.
Andres Freund [Fri, 18 Mar 2016 18:43:59 +0000 (11:43 -0700)]
Make it easier to choose the used waiting primitive in unix_latch.c.

This allows for easier testing of the different primitives; in
preparation for adding a new primitive.

Discussion: 20160114143931.GG10941@awork2.anarazel.de
Reviewed-By: Robert Haas
8 years agoError out if waiting on socket readiness without a specified socket.
Andres Freund [Fri, 18 Mar 2016 18:43:59 +0000 (11:43 -0700)]
Error out if waiting on socket readiness without a specified socket.

Previously we just ignored such an attempt, but that seems to serve no
purpose but making things harder to debug.

Discussion: 20160114143931.GG10941@awork2.anarazel.de
    20151230173734.hx7jj2fnwyljfqek@alap3.anarazel.de
Reviewed-By: Robert Haas
8 years agoRemove unused, and dangerous, TestLatch() macro.
Andres Freund [Fri, 18 Mar 2016 18:43:59 +0000 (11:43 -0700)]
Remove unused, and dangerous, TestLatch() macro.

The macro has not seen any in-tree use since latches had been introduced
in 2746e5f, in 2010.

8 years agoDirectly modify foreign tables.
Robert Haas [Fri, 18 Mar 2016 17:48:58 +0000 (13:48 -0400)]
Directly modify foreign tables.

postgres_fdw can now sent an UPDATE or DELETE statement directly to
the foreign server in simple cases, rather than sending a SELECT FOR
UPDATE statement and then updating or deleting rows one-by-one.

Etsuro Fujita, reviewed by Rushabh Lathia, Shigeru Hanada, Kyotaro
Horiguchi, Albe Laurenz, Thom Brown, and me.

8 years agoClean up some misplaced #includes.
Tom Lane [Fri, 18 Mar 2016 17:43:13 +0000 (13:43 -0400)]
Clean up some misplaced #includes.

Random .h files have no business including postgres-fe.h (or postgres.h).
If that wasn't the first #include done by the calling .c file, it's the
.c file that's broken.  Noted while prepping Kyotaro Horiguchi's psql
lexer refactoring patch.

8 years agoFix a typo
Teodor Sigaev [Fri, 18 Mar 2016 15:49:24 +0000 (18:49 +0300)]
Fix a typo

Erik Rijkers

8 years agoIntroduce parse_ident()
Teodor Sigaev [Fri, 18 Mar 2016 15:16:14 +0000 (18:16 +0300)]
Introduce parse_ident()

SQL-layer function to split qualified identifier into array parts.

Author: Pavel Stehule with minor editorization by me and Jim Nasby

8 years agoPush scan/join target list beneath Gather when possible.
Robert Haas [Fri, 18 Mar 2016 13:46:40 +0000 (09:46 -0400)]
Push scan/join target list beneath Gather when possible.

This means that, for example, "SELECT expensive_func(a) FROM bigtab
WHERE something" can compute expensive_func(a) in the workers rather
than the leader if it happens to be parallel-safe, which figures to be
a big win in some practical cases.

Currently, we can only do this if the entire target list is
parallel-safe.  If we worked harder, we might be able to evaluate
parallel-safe targets in the worker and any parallel-restricted
targets in the leader, but that would be more complicated, and there
aren't that many parallel-restricted functions that people are likely
to use in queries anyway.  I think.  So just do the simple thing for
the moment.

Robert Haas, Amit Kapila, and Tom Lane

8 years agoVarious minor corrections of and improvements to comments.
Robert Haas [Fri, 18 Mar 2016 13:38:59 +0000 (09:38 -0400)]
Various minor corrections of and improvements to comments.

Aleksander Alekseev

8 years agopg_trgm's set_limit() now uses SetConfigOption()
Teodor Sigaev [Fri, 18 Mar 2016 09:26:27 +0000 (12:26 +0300)]
pg_trgm's set_limit() now uses SetConfigOption()

Deprecated set_limit() is modified to use SetConfigOption() to set
similarity_threshold which is actually an instance of
pg_trgm.similarity_threshold GUC variable. Previous coding directly sets
similarity_threshold what could cause an inconsistency between states of
actual variable and GUC representation.

Per gripe from Tom Lane

8 years agodocs: Fix typo'd brin_summarize_new_values
Alvaro Herrera [Thu, 17 Mar 2016 23:17:04 +0000 (20:17 -0300)]
docs: Fix typo'd brin_summarize_new_values

I wrote "brin_summarize_new_pages" instead, in docs as well as in the
commit message of commit ac443d1034d9.

Bug: #14030
Reported-By: Chris Pacejo
8 years agoRemove useless double calls of make_parsestate().
Tom Lane [Thu, 17 Mar 2016 20:46:23 +0000 (16:46 -0400)]
Remove useless double calls of make_parsestate().

Aleksander Alekseev

8 years agoUpdate tuplesort.c comments for memory mangement improvements.
Robert Haas [Thu, 17 Mar 2016 20:11:14 +0000 (16:11 -0400)]
Update tuplesort.c comments for memory mangement improvements.

I'm committing these changes separately so that it's clear what is
Peter's original work versus what I changed.  This is a followup to
commit 0011c0091e886b874e485a46ff2c94222ffbf550, and these changes
are all by me.

8 years agoImprove memory management for external sorts.
Robert Haas [Thu, 17 Mar 2016 20:05:05 +0000 (16:05 -0400)]
Improve memory management for external sorts.

Introduce a new memory context which stores tuple data, and reset it
at the end of each merge pass; this helps avoid memory fragmentation
and, consequently, overallocation.  Also, for the final merge patch,
eliminate memory context chunk header overhead entirely by allocating
all of the memory used for buffering tuples during the merge in a
single chunk.  Since this modestly increases the number of tuples we
can store, grow the memtuples array a bit so that we're less likely to
run short of slots there.

Peter Geoghegan.  Review and testing of patches in this series by
Jeff Janes, Greg Stark, Mithun Cy, and me.

8 years agoFix assorted breakage in to_char()'s OF format option.
Tom Lane [Thu, 17 Mar 2016 19:50:33 +0000 (15:50 -0400)]
Fix assorted breakage in to_char()'s OF format option.

In HEAD, fix incorrect field width for hours part of OF when tm_gmtoff is
negative.  This was introduced by commit 2d87eedc1d4468d3 as a result of
falsely applying a pattern that's correct when + signs are omitted, which
is not the case for OF.

In 9.4, fix missing abs() call that allowed a sign to be attached to the
minutes part of OF.  This was fixed in 9.5 by 9b43d73b3f9bef27, but for
inscrutable reasons not back-patched.

In all three versions, ensure that the sign of tm_gmtoff is correctly
reported even when the GMT offset is less than 1 hour.

Add regression tests, which evidently we desperately need here.

Thomas Munro and Tom Lane, per report from David Fetter

8 years agoImprove support of Hunspell
Teodor Sigaev [Thu, 17 Mar 2016 14:23:38 +0000 (17:23 +0300)]
Improve support of Hunspell

- allow to use non-ascii characters as affix flag. Non-numeric affix flags now
  are stored as string instead of numeric value of character.
- allow to use 0 as affix flag in numeric encoded affixes

That adds support for arabian, hungarian, turkish and
brazilian portuguese languages.

Author: Artur Zakirov with heavy editorization by me

8 years agoFix typos.
Robert Haas [Thu, 17 Mar 2016 11:26:20 +0000 (07:26 -0400)]
Fix typos.

Jim Nasby

8 years agoAdd syslog_split_messages parameter
Peter Eisentraut [Wed, 16 Mar 2016 02:48:53 +0000 (22:48 -0400)]
Add syslog_split_messages parameter

Reviewed-by: Andreas Karlsson <andreas@proxel.se>
8 years agoAdd syslog_sequence_numbers parameter
Peter Eisentraut [Sat, 27 Feb 2016 03:34:30 +0000 (22:34 -0500)]
Add syslog_sequence_numbers parameter

Reviewed-by: Andreas Karlsson <andreas@proxel.se>
8 years agoFix "pg_bench -C -M prepared".
Tom Lane [Thu, 17 Mar 2016 03:18:07 +0000 (23:18 -0400)]
Fix "pg_bench -C -M prepared".

This didn't work because when we dropped and re-established a database
connection, we did not bother to reset session-specific state such as
the statements-are-prepared flags.

The st->prepared[] array certainly needs to be flushed, and I cleared a
couple of other fields as well that couldn't possibly retain meaningful
state for a new connection.

In passing, fix some bogus comments and strange field order choices.

Per report from Robins Tharakan.

8 years agoFix j2day() to behave sanely for negative Julian dates.
Tom Lane [Thu, 17 Mar 2016 00:57:45 +0000 (20:57 -0400)]
Fix j2day() to behave sanely for negative Julian dates.

Somebody had apparently once figured that casting to unsigned int would
produce the right output for negative inputs, but that would only be
true if 2^32 were a multiple of 7, which of course it ain't.  We need
to use a signed division and then correct the sign of the remainder.

AFAICT, the only case where this would arise currently is when doing
ISO-week calculations for dates in 4714BC, where we'd compute a
negative Julian date representing 4714-01-04BC and then do some
arithmetic with it.  Since we don't even really document support for
such dates, this is not of much consequence.  But we may as well
get it right.

Per report from Vitaly Burovoy.

8 years agoBe more careful about out-of-range dates and timestamps.
Tom Lane [Wed, 16 Mar 2016 23:09:04 +0000 (19:09 -0400)]
Be more careful about out-of-range dates and timestamps.

Tighten the semantics of boundary-case timestamptz so that we allow
timestamps >= '4714-11-24 00:00+00 BC' and < 'ENDYEAR-01-01 00:00+00 AD'
exactly, no more and no less, but it is allowed to enter timestamps
within that range using non-GMT timezone offsets (which could make the
nominal date 4714-11-23 BC or ENDYEAR-01-01 AD).  This eliminates
dump/reload failure conditions for timestamps near the endpoints.
To do this, separate checking of the inputs for date2j() from the
final range check, and allow the Julian date code to handle a range
slightly wider than the nominal range of the datatypes.

Also add a bunch of checks to detect out-of-range dates and timestamps
that formerly could be returned by operations such as date-plus-integer.
All C-level functions that return date, timestamp, or timestamptz should
now be proof against returning a value that doesn't pass IS_VALID_DATE()
or IS_VALID_TIMESTAMP().

Vitaly Burovoy, reviewed by Anastasia Lubennikova, and substantially
whacked around by me

8 years agoAnother comment update.
Robert Haas [Wed, 16 Mar 2016 18:28:25 +0000 (14:28 -0400)]
Another comment update.

I thought this was in my last commit, but I goofed.

8 years agoFix problems in commit c16dc1aca5e01e6acaadfcf38f5fc964a381dc62.
Robert Haas [Wed, 16 Mar 2016 17:54:04 +0000 (13:54 -0400)]
Fix problems in commit c16dc1aca5e01e6acaadfcf38f5fc964a381dc62.

Vinayak Pokale provided a patch for a copy-and-paste error in a
comment.  I noticed that I'd use the word "automatically" nearby where
I meant to talk about things being "atomic".  Rahila Syed spotted a
misplaced counter update.  Fix all that stuff.