]> git.ipfire.org Git - thirdparty/postgresql.git/log
thirdparty/postgresql.git
13 years agoAdd missing format argument to ecpg_log() call
Peter Eisentraut [Thu, 8 Sep 2011 19:09:08 +0000 (22:09 +0300)] 
Add missing format argument to ecpg_log() call

13 years agoFix corner case bug in numeric to_char().
Tom Lane [Wed, 7 Sep 2011 21:06:44 +0000 (17:06 -0400)] 
Fix corner case bug in numeric to_char().

Trailing-zero stripping applied by the FM specifier could strip zeroes
to the left of the decimal point, for a format with no digit positions
after the decimal point (such as "FM999.").

Reported and diagnosed by Marti Raudsepp, though I didn't use his patch.

13 years agoAvoid possibly accessing off the end of memory in examine_attribute().
Tom Lane [Tue, 6 Sep 2011 18:36:01 +0000 (14:36 -0400)] 
Avoid possibly accessing off the end of memory in examine_attribute().

Since the last couple of columns of pg_type are often NULL,
sizeof(FormData_pg_type) can be an overestimate of the actual size of the
tuple data part.  Therefore memcpy'ing that much out of the catalog cache,
as analyze.c was doing, poses a small risk of copying past the end of
memory and incurring SIGSEGV.  No such crash has been identified in the
field, but we've certainly seen the equivalent happen in other code paths,
so patch this one all the way back.

Per valgrind testing by Noah Misch, though this is not his proposed patch.
I chose to use SearchSysCacheCopy1 rather than inventing special-purpose
infrastructure for copying only the minimal part of a pg_type tuple.

13 years agoUpdate type-conversion documentation for long-ago changes.
Tom Lane [Tue, 6 Sep 2011 16:14:51 +0000 (12:14 -0400)] 
Update type-conversion documentation for long-ago changes.

This example wasn't updated when we changed the behavior of bpcharlen()
in 8.0, nor when we changed the number of parameters taken by the bpchar()
cast function in 7.3.  Per report from lsliang.

13 years agoUpdate time zone data files to tzdata release 2011i.
Tom Lane [Mon, 5 Sep 2011 18:46:31 +0000 (14:46 -0400)] 
Update time zone data files to tzdata release 2011i.

DST law changes in Canada, Egypt, Russia, Samoa, South Sudan.

13 years agoFix typo in pg_srand48 (srand48 in older branches).
Tom Lane [Sat, 3 Sep 2011 20:18:01 +0000 (16:18 -0400)] 
Fix typo in pg_srand48 (srand48 in older branches).

">" should be ">>".  This typo results in failure to use all of the bits
of the provided seed.

This might rise to the level of a security bug if we were relying on
srand48 for any security-critical purposes, but we are not --- in fact,
it's not used at all unless the platform lacks srandom(), which is
improbable.  Even on such a platform the exposure seems minimal.

Reported privately by Andres Freund.

13 years agoReplace obsolete AC_LANG_FUNC_LINK_TRY autoconf macro.
Tom Lane [Mon, 29 Aug 2011 23:52:13 +0000 (19:52 -0400)] 
Replace obsolete AC_LANG_FUNC_LINK_TRY autoconf macro.

The version of this macro used in autoconf 2.59 is capable of incorrectly
succeeding (ie, reporting that a library function is available when it
isn't), if the compiler performs link-time optimization and decides that
it can optimize the function reference away entirely.  Replace it with the
coding used in autoconf 2.61 and later, which forces the program result to
depend on the function's result so that it cannot be optimized away.  This
should fix build failures currently being seen on buildfarm member anchovy.

This patch affects the 8.2 and 8.3 branches only, since later branches are
using autoconf versions that don't have this problem.

13 years agoDon't assume that "E" response to NEGOTIATE_SSL_CODE means pre-7.0 server.
Tom Lane [Sat, 27 Aug 2011 20:37:22 +0000 (16:37 -0400)] 
Don't assume that "E" response to NEGOTIATE_SSL_CODE means pre-7.0 server.

These days, such a response is far more likely to signify a server-side
problem, such as fork failure.  Reporting "server does not support SSL"
(in sslmode=require) could be quite misleading.  But the results could
be even worse in sslmode=prefer: if the problem was transient and the
next connection attempt succeeds, we'll have silently fallen back to
protocol version 2.0, possibly disabling features the user needs.

Hence, it seems best to just eliminate the assumption that backing off
to non-SSL/2.0 protocol is the way to recover from an "E" response, and
instead treat the server error the same as we would in non-SSL cases.

I tested this change against a pre-7.0 server, and found that there
was a second logic bug in the "prefer" path: the test to decide whether
to make a fallback connection attempt assumed that we must have opened
conn->ssl, which in fact does not happen given an "E" response.  After
fixing that, the code does indeed connect successfully to pre-7.0,
as long as you didn't set sslmode=require.  (If you did, you get
"Unsupported frontend protocol", which isn't completely off base
given the server certainly doesn't support SSL.)

Since there seems no reason to believe that pre-7.0 servers exist anymore
in the wild, back-patch to all supported branches.

13 years agoEnsure we discard unread/unsent data when abandoning a connection attempt.
Tom Lane [Sat, 27 Aug 2011 18:16:39 +0000 (14:16 -0400)] 
Ensure we discard unread/unsent data when abandoning a connection attempt.

There are assorted situations wherein PQconnectPoll() will abandon a
connection attempt and try again with different parameters (eg, SSL versus
not SSL).  However, the code forgot to discard any pending data in libpq's
I/O buffers when doing this.  In at least one case (server returns E
message during SSL negotiation), there is unread input data which bollixes
the next connection attempt.  I have not checked to see whether this is
possible in the other cases where we close the socket and retry, but it
seems like a matter of good defensive programming to add explicit
buffer-flushing code to all of them.

This is one of several issues exposed by Daniel Farina's report of
misbehavior after a server-side fork failure.

This has been wrong since forever, so back-patch to all supported branches.

13 years agoFix pgstatindex() to give consistent results for empty indexes.
Tom Lane [Thu, 25 Aug 2011 03:50:36 +0000 (23:50 -0400)] 
Fix pgstatindex() to give consistent results for empty indexes.

For an empty index, the pgstatindex() function would compute 0.0/0.0 for
its avg_leaf_density and leaf_fragmentation outputs.  On machines that
follow the IEEE float arithmetic standard with any care, that results in
a NaN.  However, per report from Rushabh Lathia, Microsoft couldn't
manage to get this right, so you'd get a bizarre error on Windows.

Fix by forcing the results to be NaN explicitly, rather than relying on
the division operator to give that or the snprintf function to print it
correctly.  I have some doubts that this is really the most useful
definition, but it seems better to remain backward-compatible with
those platforms for which the behavior wasn't completely broken.

Back-patch to 8.2, since the code is like that in all current releases.

13 years agoFix performance problem when building a lossy tidbitmap.
Tom Lane [Sat, 20 Aug 2011 18:51:02 +0000 (14:51 -0400)] 
Fix performance problem when building a lossy tidbitmap.

As pointed out by Sergey Koposov, repeated invocations of tbm_lossify can
make building a large tidbitmap into an O(N^2) operation.  To fix, make
sure we remove more than the minimum amount of information per call, and
add a fallback path to behave sanely if we're unable to fit the bitmap
within the requested amount of memory.

This has been wrong since the tidbitmap code was written, so back-patch
to all supported branches.

13 years agoFix race condition in relcache init file invalidation.
Tom Lane [Tue, 16 Aug 2011 17:12:29 +0000 (13:12 -0400)] 
Fix race condition in relcache init file invalidation.

The previous code tried to synchronize by unlinking the init file twice,
but that doesn't actually work: it leaves a window wherein a third process
could read the already-stale init file but miss the SI messages that would
tell it the data is stale.  The result would be bizarre failures in catalog
accesses, typically "could not read block 0 in file ..." later during
startup.

Instead, hold RelCacheInitLock across both the unlink and the sending of
the SI messages.  This is more straightforward, and might even be a bit
faster since only one unlink call is needed.

This has been wrong since it was put in (in 2002!), so back-patch to all
supported releases.

13 years agoAvoid integer overflow when LIMIT + OFFSET >= 2^63.
Heikki Linnakangas [Tue, 2 Aug 2011 07:47:17 +0000 (10:47 +0300)] 
Avoid integer overflow when LIMIT + OFFSET >= 2^63.

This fixes bug #6139 reported by Hitoshi Harada.

13 years agoFix pg_restore's direct-to-database mode for standard_conforming_strings.
Tom Lane [Thu, 28 Jul 2011 18:07:28 +0000 (14:07 -0400)] 
Fix pg_restore's direct-to-database mode for standard_conforming_strings.

pg_backup_db.c contained a mini SQL lexer with which it tried to identify
boundaries between SQL commands, but that code was not designed to cope
with standard_conforming_strings, and would get the wrong answer if a
backslash immediately precedes a closing single quote in such a string,
as per report from Julian Mehnle.  The bug only affects direct-to-database
restores from archive files made with standard_conforming_strings = on.

Rather than complicating the code some more to try to fix that, let's just
rip it all out.  The only reason it was needed was to cope with COPY data
embedded into ordinary archive entries, which was a layout that was used
only for about the first three weeks of the archive format's existence,
and never in any production release of pg_dump.  Instead, just rely on the
archive file layout to tell us whether we're printing COPY data or not.

This bug represents a data corruption hazard in all releases in which
standard_conforming_strings can be turned on, ie 8.2 and later, so
back-patch to all supported branches.

13 years agoAdd missing newlines at end of error messages
Peter Eisentraut [Tue, 26 Jul 2011 20:24:57 +0000 (23:24 +0300)] 
Add missing newlines at end of error messages

13 years agoUse OpenSSL's SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER flag.
Tom Lane [Sun, 24 Jul 2011 19:18:16 +0000 (15:18 -0400)] 
Use OpenSSL's SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER flag.

This disables an entirely unnecessary "sanity check" that causes failures
in nonblocking mode, because OpenSSL complains if we move or compact the
write buffer.  The only actual requirement is that we not modify pending
data once we've attempted to send it, which we don't.  Per testing and
research by Martin Pihlak, though this fix is a lot simpler than his patch.

I put the same change into the backend, although it's less clear whether
it's necessary there.  We do use nonblock mode in some situations in
streaming replication, so seems best to keep the same behavior in the
backend as in libpq.

Back-patch to all supported releases.

13 years agoAdapted expected result for latest change to ecpglib.
Michael Meskes [Mon, 18 Jul 2011 17:22:03 +0000 (19:22 +0200)] 
Adapted expected result for latest change to ecpglib.

13 years agoMade ecpglib write double with a precision of 15 digits.
Michael Meskes [Mon, 18 Jul 2011 14:30:51 +0000 (16:30 +0200)] 
Made ecpglib write double with a precision of 15 digits.

Patch by Akira Kurosawa <kurosawa-akira@mxc.nes.nec.co.jp>.

13 years agoFix two ancient bugs in GiST code to re-find a parent after page split:
Heikki Linnakangas [Fri, 15 Jul 2011 07:54:56 +0000 (10:54 +0300)] 
Fix two ancient bugs in GiST code to re-find a parent after page split:

First, when following a right-link, we incorrectly marked the current page
as the parent of the right sibling. In reality, the parent of the right page
is the same as the parent of the current page (or some page to the right of
it, gistFindCorrectParent() will sort that out).

Secondly, when we follow a right-link, we must prepend, not append, the right
page to our list of pages to visit. That's because we assume that once we
hit a leaf page in the list, all the rest are leaf pages too, and give up.

To hit these bugs, you need concurrent actions and several unlucky accidents.
Another backend must split the root page, while you're in process of
splitting a lower-level page. Furthermore, while you scan the internal nodes
to re-find the parent, another backend needs to again split some more internal
pages. Even then, the bugs don't necessarily manifest as user-visible errors
or index corruption.

While we're at it, make the error reporting a bit better if gistFindPath()
fails to re-find the parent. It used to be an assertion, but an elog() seems
more appropriate.

Backpatch to all supported branches.

13 years agoRemove excessively backpatched gitignore files
Peter Eisentraut [Mon, 11 Jul 2011 16:07:26 +0000 (19:07 +0300)] 
Remove excessively backpatched gitignore files

These caused directories from future releases to appear in the
backbranch tree.

14 years agoFix psql's counting of script file line numbers during COPY.
Tom Lane [Tue, 5 Jul 2011 16:04:40 +0000 (12:04 -0400)] 
Fix psql's counting of script file line numbers during COPY.

handleCopyIn incremented pset.lineno for each line of COPY data read from
a file.  This is correct when reading from the current script file (i.e.,
we are doing COPY FROM STDIN followed by in-line data), but it's wrong if
the data is coming from some other file.  Per bug #6083 from Steve Haslam.
Back-patch to all supported versions.

14 years agoBack-patch creation of tar.bz2 tarball during "make dist".
Tom Lane [Sun, 3 Jul 2011 20:40:37 +0000 (16:40 -0400)] 
Back-patch creation of tar.bz2 tarball during "make dist".

Since commit a4d03bbcdaf7739d7e9073ee76bb186f68ddc163, "make dist" has
built both gzip- and bzip2-compressed tarballs.  However, this was
pretty useless, because our tarball build script didn't know about it
and proceeded to overwrite the bz2 file with new data.  Back-patch the
change to all active branches, so that creation of the tar.bz2 file
can be removed from the build script.

14 years agoApply upstream fix for blowfish signed-character bug (CVE-2011-2483).
Tom Lane [Tue, 21 Jun 2011 18:41:05 +0000 (14:41 -0400)] 
Apply upstream fix for blowfish signed-character bug (CVE-2011-2483).

A password containing a character with the high bit set was misprocessed
on machines where char is signed (which is most).  This could cause the
preceding one to three characters to fail to affect the hashed result,
thus weakening the password.  The result was also unportable, and failed
to match some other blowfish implementations such as OpenBSD's.

Since the fix changes the output for such passwords, upstream chose
to provide a compatibility hack: password salts beginning with $2x$
(instead of the usual $2a$ for blowfish) are intentionally processed
"wrong" to give the same hash as before.  Stored password hashes can
thus be modified if necessary to still match, though it'd be better
to change any affected passwords.

In passing, sync a couple other upstream changes that marginally improve
performance and/or tighten error checking.

Back-patch to all supported branches.  Since this issue is already
public, no reason not to commit the fix ASAP.

14 years agoFix missed use of "cp -i" in an example, per Fujii Masao.
Tom Lane [Mon, 20 Jun 2011 20:27:51 +0000 (16:27 -0400)] 
Fix missed use of "cp -i" in an example, per Fujii Masao.

Also be more careful about markup: use &amp; not just &.

14 years agoDon't use "cp -i" in the example WAL archive_command.
Tom Lane [Fri, 17 Jun 2011 23:13:25 +0000 (19:13 -0400)] 
Don't use "cp -i" in the example WAL archive_command.

This is a dangerous example to provide because on machines with GNU cp,
it will silently do the wrong thing and risk archive corruption.  Worse,
during the 9.0 cycle somebody "improved" the discussion by removing the
warning that used to be there about that, and instead leaving the
impression that the command would work as desired on most Unixen.
It doesn't.  Try to rectify the damage by providing an example that is safe
most everywhere, and then noting that you can try cp -i if you want but
you'd better test that.

In back-patching this to all supported branches, I also added an example
command for Windows, which wasn't provided before 9.0.

14 years agoObtain table locks as soon as practical during pg_dump.
Tom Lane [Fri, 17 Jun 2011 22:19:31 +0000 (18:19 -0400)] 
Obtain table locks as soon as practical during pg_dump.

For some reason, when we (I) added table lock acquisition to pg_dump,
we didn't think about making it happen as soon as possible after the
start of the transaction.  What with subsequent additions, there was
actually quite a lot going on before we got around to that; which sort
of defeats the purpose.  Rearrange the order of calls in dumpSchema()
to close the risk window as much as we easily can.  Back-patch to all
supported branches.

14 years agoAdd overflow checks to int4 and int8 versions of generate_series().
Robert Haas [Fri, 17 Jun 2011 18:28:45 +0000 (14:28 -0400)] 
Add overflow checks to int4 and int8 versions of generate_series().

The previous code went into an infinite loop after overflow.  In fact,
an overflow is not really an error; it just means that the current
value is the last one we need to return.  So, just arrange to stop
immediately when overflow is detected.

Back-patch all the way.

14 years agoSuppress -arch switches in the output of ExtUtils::Embed.
Tom Lane [Tue, 14 Jun 2011 21:14:11 +0000 (17:14 -0400)] 
Suppress -arch switches in the output of ExtUtils::Embed.

We previously found out that OS X's standard perl installation tries to put
-arch switches into Perl link commands, evidently in hopes of building
universal binaries.  But it doesn't work to add such switches in plperl's
link step if they weren't being used earlier, so this is basically
unworkable.  When using gcc the result is only some warnings; but LLVM
fails entirely, so this issue isn't as cosmetic as we originally thought.
Hence, back-patch commit d69a419e682c2d39c2355105a7e5e2b90357c8f0 into
pre-9.0 branches.

14 years agoFix assorted issues with build and install paths containing spaces.
Tom Lane [Tue, 14 Jun 2011 20:39:47 +0000 (16:39 -0400)] 
Fix assorted issues with build and install paths containing spaces.

Apparently there is no buildfarm critter exercising this case after all,
because it fails in several places.  With this patch, build, install,
check-world, and installcheck-world pass for me on OS X.

14 years agoFix aboriginal copy-paste mistake in error message
Alvaro Herrera [Mon, 13 Jun 2011 21:50:30 +0000 (17:50 -0400)] 
Fix aboriginal copy-paste mistake in error message

Spotted by Jaime Casanova

14 years agoWork around gcc 4.6.0 bug that breaks WAL replay.
Tom Lane [Fri, 10 Jun 2011 21:03:27 +0000 (17:03 -0400)] 
Work around gcc 4.6.0 bug that breaks WAL replay.

ReadRecord's habit of using both direct references to tmpRecPtr and
references to *RecPtr (which is pointing at tmpRecPtr) triggers an
optimization bug in gcc 4.6.0, which apparently has forgotten about
aliasing rules.  Avoid the compiler bug, and make the code more readable
to boot, by getting rid of the direct references.  Improve the comments
while at it.

Back-patch to all supported versions, in case they get built with 4.6.0.

Tom Lane, with some cosmetic suggestions from Alex Hunsaker

14 years agoFix documentation of information_schema.element_types
Peter Eisentraut [Thu, 9 Jun 2011 04:24:14 +0000 (07:24 +0300)] 
Fix documentation of information_schema.element_types

The documentation of the columns collection_type_identifier and
dtd_identifier was wrong.  This effectively reverts commits
8e1ccad51901e83916dae297cd9afa450957a36c and
57352df66d3a0885899d39c04c067e63c7c0ba30 and updates the name
array_type_identifier (the name in SQL:1999) to
collection_type_identifier.

closes bug #5926

14 years agoAllow building with perl 5.14.
Andrew Dunstan [Sat, 4 Jun 2011 23:37:50 +0000 (19:37 -0400)] 
Allow building with perl 5.14.

Patch from Alex Hunsaker.

14 years agoECPG documentation fixes
Peter Eisentraut [Sat, 4 Jun 2011 19:29:26 +0000 (22:29 +0300)] 
ECPG documentation fixes

Marc Cousin

14 years agoExpose the "*VALUES*" alias that we generate for a stand-alone VALUES list.
Tom Lane [Sat, 4 Jun 2011 19:48:41 +0000 (15:48 -0400)] 
Expose the "*VALUES*" alias that we generate for a stand-alone VALUES list.

We were trying to make that strictly an internal implementation detail,
but it turns out that it's exposed anyway when dumping a view defined
like
CREATE VIEW test_view AS VALUES (1), (2), (3) ORDER BY 1;
This comes out as
CREATE VIEW ... ORDER BY "*VALUES*".column1;
which fails to parse when reloading the dump.

Hacking ruleutils.c to suppress the column qualification looks like it'd
be a risky business, so instead promote the RTE alias to full-fledged
usability.

Per bug #6049 from Dylan Adams.  Back-patch to all supported branches.

14 years agoClean up after erroneous SELECT FOR UPDATE/SHARE on a sequence.
Tom Lane [Thu, 2 Jun 2011 19:31:28 +0000 (15:31 -0400)] 
Clean up after erroneous SELECT FOR UPDATE/SHARE on a sequence.

My previous commit disallowed this operation, but did nothing about
cleaning up the damage if one had already been done.  With the operation
disallowed, it's okay to just forcibly clear xmax in a sequence's tuple,
since any value seen there could not represent a live transaction's lock.
So, any sequence-specific operation will repair the problem automatically,
whether or not the user has already seen "could not access status of
transaction" failures.

14 years agoDisallow SELECT FOR UPDATE/SHARE on sequences.
Tom Lane [Thu, 2 Jun 2011 18:46:37 +0000 (14:46 -0400)] 
Disallow SELECT FOR UPDATE/SHARE on sequences.

We can't allow this because such an operation stores its transaction XID
into the sequence tuple's xmax.  Because VACUUM doesn't process sequences
(and we don't want it to start doing so), such an xmax value won't get
frozen, meaning it will eventually refer to nonexistent pg_clog storage,
and even wrap around completely.  Since the row lock is ignored by nextval
and setval, the usefulness of the operation is highly debatable anyway.
Per reports of trouble with pgpool 3.0, which had ill-advisedly started
using such commands as a form of locking.

In HEAD, also disallow SELECT FOR UPDATE/SHARE on toast tables.  Although
this does work safely given the current implementation, there seems no
good reason to allow it.  I refrained from changing that behavior in
back branches, however.

14 years agoProtect GIST logic that assumes penalty values can't be negative.
Tom Lane [Tue, 31 May 2011 21:54:11 +0000 (17:54 -0400)] 
Protect GIST logic that assumes penalty values can't be negative.

Apparently sane-looking penalty code might return small negative values,
for example because of roundoff error.  This will confuse places like
gistchoose().  Prevent problems by clamping negative penalty values to
zero.  (Just to be really sure, I also made it force NaNs to zero.)
Back-patch to all supported branches.

Alexander Korotkov

14 years agoFix portability bugs in use of credentials control messages for peer auth.
Tom Lane [Mon, 30 May 2011 23:16:28 +0000 (19:16 -0400)] 
Fix portability bugs in use of credentials control messages for peer auth.

Even though our existing code for handling credentials control messages has
been basically unchanged since 2001, it was fundamentally wrong: it did not
ensure proper alignment of the supplied buffer, and it was calculating
buffer sizes and message sizes incorrectly.  This led to failures on
platforms where alignment padding is relevant, for instance FreeBSD on
64-bit platforms, as seen in a recent Debian bug report passed on by
Martin Pitt (http://bugs.debian.org//cgi-bin/bugreport.cgi?bug=612888).

Rewrite to do the message-whacking using the macros specified in RFC 2292,
following a suggestion from Theo de Raadt in that thread.  Tested by me
on Debian/kFreeBSD-amd64; since OpenBSD and NetBSD document the identical
CMSG API, it should work there too.

Back-patch to all supported branches.

14 years agoMake decompilation of optimized CASE constructs more robust.
Tom Lane [Thu, 26 May 2011 23:25:19 +0000 (19:25 -0400)] 
Make decompilation of optimized CASE constructs more robust.

We had some hacks in ruleutils.c to cope with various odd transformations
that the optimizer could do on a CASE foo WHEN "CaseTestExpr = RHS" clause.
However, the fundamental impossibility of covering all cases was exposed
by Heikki, who pointed out that the "=" operator could get replaced by an
inlined SQL function, which could contain nearly anything at all.  So give
up on the hacks and just print the expression as-is if we fail to recognize
it as "CaseTestExpr = RHS".  (We must cover that case so that decompiled
rules print correctly; but we are not under any obligation to make EXPLAIN
output be 100% valid SQL in all cases, and already could not do so in some
other cases.)  This approach requires that we have some printable
representation of the CaseTestExpr node type; I used "CASE_TEST_EXPR".

Back-patch to all supported branches, since the problem case fails in all.

14 years agoInstall defenses against overflow in BuildTupleHashTable().
Tom Lane [Mon, 23 May 2011 16:53:05 +0000 (12:53 -0400)] 
Install defenses against overflow in BuildTupleHashTable().

The planner can sometimes compute very large values for numGroups, and in
cases where we have no alternative to building a hashtable, such a value
will get fed directly to BuildTupleHashTable as its nbuckets parameter.
There were two ways in which that could go bad.  First, BuildTupleHashTable
declared the parameter as "int" but most callers were passing "long"s,
so on 64-bit machines undetected overflow could occur leading to a bogus
negative value.  The obvious fix for that is to change the parameter to
"long", which is what I've done in HEAD.  In the back branches that seems a
bit risky, though, since third-party code might be calling this function.
So for them, just put in a kluge to treat negative inputs as INT_MAX.
Second, hash_create can go nuts with extremely large requested table sizes
(notably, my_log2 becomes an infinite loop for inputs larger than
LONG_MAX/2).  What seems most appropriate to avoid that is to bound the
initial table size request to work_mem.

This fixes bug #6035 reported by Daniel Schreiber.  Although the reported
case only occurs back to 8.4 since it involves WITH RECURSIVE, I think
it's a good idea to install the defenses in all supported branches.

14 years agoReplace strdup() with pstrdup(), to avoid leaking memory.
Heikki Linnakangas [Thu, 19 May 2011 02:30:24 +0000 (22:30 -0400)] 
Replace strdup() with pstrdup(), to avoid leaking memory.

It's been like this since the seg module was introduced, so backpatch to
8.2 which is the oldest supported version.

14 years agoFix write-past-buffer-end in ldapServiceLookup().
Tom Lane [Thu, 12 May 2011 15:56:38 +0000 (11:56 -0400)] 
Fix write-past-buffer-end in ldapServiceLookup().

The code to assemble ldap_get_values_len's output into a single string
wrote the terminating null one byte past where it should.  Fix that,
and make some other cosmetic adjustments to make the code a trifle more
readable and more in line with usual Postgres coding style.

Also, free the "result" string when done with it, to avoid a permanent
memory leak.

Bug report and patch by Albe Laurenz, cosmetic adjustments by me.

14 years agoCatch errors in for loop in makefile
Peter Eisentraut [Sun, 1 May 2011 21:54:02 +0000 (00:54 +0300)] 
Catch errors in for loop in makefile

Add "|| exit" so that the rule aborts when a command fails.

This is the minimal backpatch version.  The fix in head is more
elaborate.

14 years agoRewrite pg_size_pretty() to avoid compiler bug.
Tom Lane [Fri, 29 Apr 2011 05:45:27 +0000 (01:45 -0400)] 
Rewrite pg_size_pretty() to avoid compiler bug.

Convert it to use successive shifts right instead of increasing a divisor.
This is probably a tad more efficient than the original coding, and it's
nicer-looking than the previous patch because we don't need a special case
to avoid overflow in the last branch.  But the real reason to do it is to
avoid a Solaris compiler bug, as per results from buildfarm member moa.

14 years agoThe arguments to pg_ctl kill are not optional - remove brackets in the docs.
Heikki Linnakangas [Thu, 28 Apr 2011 09:51:02 +0000 (12:51 +0300)] 
The arguments to pg_ctl kill are not optional - remove brackets in the docs.

Fujii Masao

14 years agoFix array- and path-creating functions to ensure padding bytes are zeroes.
Tom Lane [Wed, 27 Apr 2011 17:58:59 +0000 (13:58 -0400)] 
Fix array- and path-creating functions to ensure padding bytes are zeroes.

Per recent discussion, it's important for all computed datums (not only the
results of input functions) to not contain any ill-defined (uninitialized)
bits.  Failing to ensure that can result in equal() reporting that
semantically indistinguishable Consts are not equal, which in turn leads to
bizarre and undesirable planner behavior, such as in a recent example from
David Johnston.  We might eventually try to fix this in a general manner by
allowing datatypes to define identity-testing functions, but for now the
path of least resistance is to expect datatypes to force all unused bits
into consistent states.

Per some testing by Noah Misch, array and path functions seem to be the
only ones presenting risks at the moment, so I looked through all the
functions in adt/array*.c and geo_ops.c and fixed them as necessary.  In
the array functions, the easiest/safest fix is to allocate result arrays
with palloc0 instead of palloc.  Possibly in future someone will want to
look into whether we can just zero the padding bytes, but that looks too
complex for a back-patchable fix.  In the path functions, we already had a
precedent in path_in for just zeroing the one known pad field, so duplicate
that code as needed.

Back-patch to all supported branches.

14 years agoFix pg_size_pretty() to avoid overflow for inputs close to INT64_MAX.
Tom Lane [Mon, 25 Apr 2011 20:22:28 +0000 (16:22 -0400)] 
Fix pg_size_pretty() to avoid overflow for inputs close to INT64_MAX.

The expression that tried to round the value to the nearest TB could
overflow, leading to bogus output as reported in bug #5993 from Nicola
Cossu.  This isn't likely to ever happen in the intended usage of the
function (if it could, we'd be needing to use a wider datatype instead);
but it's not hard to give the expected output, so let's do so.

14 years agoTag 8.2.21. REL8_2_21
Marc G. Fournier [Fri, 15 Apr 2011 03:19:01 +0000 (00:19 -0300)] 
Tag 8.2.21.

14 years agoTranslation updates
Peter Eisentraut [Thu, 14 Apr 2011 19:29:44 +0000 (22:29 +0300)] 
Translation updates

14 years agoUpdate release notes for releases 9.0.4, 8.4.8, 8.3.15, and 8.2.21.
Tom Lane [Thu, 14 Apr 2011 19:51:55 +0000 (15:51 -0400)] 
Update release notes for releases 9.0.4, 8.4.8, 8.3.15, and 8.2.21.

14 years agoUpdate time zone data files to tzdata release 2011f.
Tom Lane [Wed, 13 Apr 2011 22:03:23 +0000 (18:03 -0400)] 
Update time zone data files to tzdata release 2011f.

DST law changes in Chile, Cuba, Falkland Islands, Morocco, Samoa, Turkey.
Historical corrections for South Australia, Alaska, Hawaii.

14 years agoOn IA64 architecture, we check the depth of the register stack in addition
Heikki Linnakangas [Wed, 13 Apr 2011 08:43:22 +0000 (11:43 +0300)] 
On IA64 architecture, we check the depth of the register stack in addition
to the regular stack. The code to do that is platform and compiler specific,
add support for the HP-UX native compiler.

14 years agoModernize dlopen interface code for FreeBSD and OpenBSD.
Tom Lane [Thu, 7 Apr 2011 19:15:00 +0000 (15:15 -0400)] 
Modernize dlopen interface code for FreeBSD and OpenBSD.

Remove the hard-wired assumption that __mips__ (and only __mips__) lacks
dlopen in FreeBSD and OpenBSD.  This assumption is outdated at least for
OpenBSD, as per report from an anonymous 9.1 tester.  We can perfectly well
use HAVE_DLOPEN instead to decide which code to use.

Some other cosmetic adjustments to make freebsd.c, netbsd.c, and openbsd.c
exactly alike.

14 years agoFix SortTocFromFile() to cope with lines that are too long for its buffer.
Tom Lane [Thu, 7 Apr 2011 15:40:44 +0000 (11:40 -0400)] 
Fix SortTocFromFile() to cope with lines that are too long for its buffer.

The original coding supposed that a dump TOC file could never contain lines
longer than 1K.  The folly of that was exposed by a recent report from
Per-Olov Esgard.  We only really need to see the first dozen or two bytes
of each line, since we're just trying to read off the numeric ID at the
start of the line; so there's no need for a particularly huge buffer.
What there is a need for is logic to not process continuation bufferloads.

Back-patch to all supported branches, since it's always been like this.

14 years agoCorrect "characters" to "bytes" in createdb docs.
Robert Haas [Mon, 28 Mar 2011 01:28:15 +0000 (21:28 -0400)] 
Correct "characters" to "bytes" in createdb docs.

Susanne Ebrecht

14 years agoImprove user-defined-aggregates documentation.
Tom Lane [Wed, 23 Mar 2011 20:57:41 +0000 (16:57 -0400)] 
Improve user-defined-aggregates documentation.

On closer inspection, that two-element initcond value seems to have been
a little white lie to avoid explaining the full behavior of float8_accum.
But if people are going to expect the examples to be exactly correct,
I suppose we'd better explain.  Per comment from Thom Brown.

14 years agoFix ancient typo in user-defined-aggregates documentation.
Tom Lane [Wed, 23 Mar 2011 16:33:14 +0000 (12:33 -0400)] 
Fix ancient typo in user-defined-aggregates documentation.

The description of the initcond value for the built-in avg(float8)
aggregate has been wrong since it was written.  Noted by Disc Magnet.

14 years agoAvoid potential deadlock in InitCatCachePhase2().
Tom Lane [Tue, 22 Mar 2011 17:01:23 +0000 (13:01 -0400)] 
Avoid potential deadlock in InitCatCachePhase2().

Opening a catcache's index could require reading from that cache's own
catalog, which of course would acquire AccessShareLock on the catalog.
So the original coding here risks locking index before heap, which could
deadlock against another backend trying to get exclusive locks in the
normal order.  Because InitCatCachePhase2 is only called when a backend
has to start up without a relcache init file, the deadlock was seldom seen
in the field.  (And by the same token, there's no need to worry about any
performance disadvantage; so not much point in trying to distinguish
exactly which catalogs have the risk.)

Bug report, diagnosis, and patch by Nikhil Sontakke.  Additional commentary
by me.  Back-patch to all supported branches.

14 years agoFix PL/Python memory leak involving array slices
Alvaro Herrera [Thu, 17 Mar 2011 15:49:38 +0000 (12:49 -0300)] 
Fix PL/Python memory leak involving array slices

Report and patch from Daniel Popowich, bug #5842
(with some debugging help from Alex Hunsaker)

14 years agoUse correct PATH separator for Cygwin in pg_regress.c.
Andrew Dunstan [Thu, 17 Mar 2011 04:24:04 +0000 (00:24 -0400)] 
Use correct PATH separator for Cygwin in pg_regress.c.

This has been broken for years, and I'm not sure why it has not been
noticed before, but now a very modern Cygwin breaks on it, and the fix
is clearly correct. Backpatching to all live branches.

14 years agoOn further reflection, we'd better do the same in int.c.
Tom Lane [Sat, 12 Mar 2011 00:04:18 +0000 (19:04 -0500)] 
On further reflection, we'd better do the same in int.c.

We previously heard of the same problem in int24div(), so there's not a
good reason to suppose the problem is confined to cases involving int8.

14 years agoPut in some more safeguards against executing a division-by-zero.
Tom Lane [Fri, 11 Mar 2011 23:19:11 +0000 (18:19 -0500)] 
Put in some more safeguards against executing a division-by-zero.

Add dummy returns before every potential division-by-zero in int8.c,
because apparently further "improvements" in gcc's optimizer have
enabled it to break functions that weren't broken before.

Aurelien Jarno, via Martin Pitt

14 years agoFix dangling-pointer problem in before-row update trigger processing.
Tom Lane [Tue, 22 Feb 2011 02:18:30 +0000 (21:18 -0500)] 
Fix dangling-pointer problem in before-row update trigger processing.

ExecUpdate checked for whether ExecBRUpdateTriggers had returned a new
tuple value by seeing if the returned tuple was pointer-equal to the old
one.  But the "old one" was in estate->es_junkFilter's result slot, which
would be scribbled on if we had done an EvalPlanQual update in response to
a concurrent update of the target tuple; therefore we were comparing a
dangling pointer to a live one.  Given the right set of circumstances we
could get a false match, resulting in not forcing the tuple to be stored in
the slot we thought it was stored in.  In the case reported by Maxim Boguk
in bug #5798, this led to "cannot extract system attribute from virtual
tuple" failures when trying to do "RETURNING ctid".  I believe there is a
very-low-probability chance of more serious errors, such as generating
incorrect index entries based on the original rather than the
trigger-modified version of the row.

In HEAD, change all of ExecBRInsertTriggers, ExecIRInsertTriggers,
ExecBRUpdateTriggers, and ExecIRUpdateTriggers so that they continue to
have similar APIs.  In the back branches I just changed
ExecBRUpdateTriggers, since there is no bug in the ExecBRInsertTriggers
case.

14 years agoAdd CheckTableNotInUse calls in DROP TABLE and DROP INDEX.
Tom Lane [Tue, 15 Feb 2011 20:50:17 +0000 (15:50 -0500)] 
Add CheckTableNotInUse calls in DROP TABLE and DROP INDEX.

Recent releases had a check on rel->rd_refcnt in heap_drop_with_catalog,
but failed to cover the possibility of pending trigger events at DROP time.
(Before 8.4 we didn't even check the refcnt.)  When the trigger events were
eventually fired, you'd get "could not open relation with OID nnn" errors,
as in recent report from strk.  Better to throw a suitable error when the
DROP is attempted.

Also add a similar check in DROP INDEX.

Back-patch to all supported branches.

14 years agoFix wrong error reports in 'number of array dimensions exceeds the
Itagaki Takahiro [Tue, 1 Feb 2011 06:48:08 +0000 (15:48 +0900)] 
Fix wrong error reports in 'number of array dimensions exceeds the
maximum allowed' messages, that have reported one-less dimensions.

Alexey Klyukin

14 years agoTag 8.2.20 REL8_2_20
Marc G. Fournier [Fri, 28 Jan 2011 02:25:42 +0000 (22:25 -0400)] 
Tag 8.2.20

14 years agoUpdate release notes.
Tom Lane [Thu, 27 Jan 2011 22:45:55 +0000 (17:45 -0500)] 
Update release notes.

Security: CVE-2010-4015

14 years agoPrevent buffer overrun while parsing an integer in a "query_int" value.
Tom Lane [Thu, 27 Jan 2011 22:42:00 +0000 (17:42 -0500)] 
Prevent buffer overrun while parsing an integer in a "query_int" value.

contrib/intarray's gettoken() uses a fixed-size buffer to collect an
integer's digits, and did not guard against overrunning the buffer.
This is at least a backend crash risk, and in principle might allow
arbitrary code execution.  The code didn't check for overflow of the
integer value either, which while not presenting a crash risk was still
bad.

Thanks to Apple Inc's security team for reporting this issue and supplying
the fix.

Security: CVE-2010-4015

14 years agoDon't include <asm/ia64regs.h> unnecessarily.
Tom Lane [Thu, 27 Jan 2011 21:27:27 +0000 (16:27 -0500)] 
Don't include <asm/ia64regs.h> unnecessarily.

We only need that header when compiling with icc, since the gcc variant of
ia64_get_bsp() uses in-line assembly code.  Per report from Frank Brendel,
the header doesn't exist on all IA64 platforms; so don't include it unless
we need it.

14 years agoTranslation updates for release 8.2.20
Peter Eisentraut [Thu, 27 Jan 2011 19:15:18 +0000 (21:15 +0200)] 
Translation updates for release 8.2.20

14 years agoUpdate release notes for releases 9.0.3, 8.4.7, 8.3.14, and 8.2.20.
Tom Lane [Thu, 27 Jan 2011 21:10:15 +0000 (16:10 -0500)] 
Update release notes for releases 9.0.3, 8.4.7, 8.3.14, and 8.2.20.

14 years agoFix pg_restore to do the right thing when escaping large objects.
Tom Lane [Fri, 21 Jan 2011 21:22:35 +0000 (16:22 -0500)] 
Fix pg_restore to do the right thing when escaping large objects.

Specifically, this makes the workflow pg_dump -Fc -> pg_restore -> file
produce correct output for BLOBs when the source database has
standard_conforming_strings turned on.  It was already okay when that was
off, or if pg_restore was told to restore directly into a database.

This is a back-port of commit b1732111f233bbb72788e92a627242ec28a85631 of
2009-08-04, with additional changes to emit old-style escaped bytea data
instead of hex-style.  At the time, we had not heard of anyone encountering
the problem in the field, so I judged it not worth the risk of changing
back branches.  Now we do have a report, from Bosco Rama, so back-patch
into 8.2 through 8.4.  9.0 and up are okay already.

14 years agoFix miscalculation of itemsafter in array_set_slice().
Tom Lane [Mon, 17 Jan 2011 17:38:52 +0000 (12:38 -0500)] 
Fix miscalculation of itemsafter in array_set_slice().

If the slice to be assigned to was before the existing array lower bound
(requiring at least one null element to spring into existence to fill the
gap), the code miscalculated how many entries needed to be copied from
the old array's null bitmap.  This could result in trashing the array's
data area (as seen in bug #5840 from Karsten Loesing), or worse.

This has been broken since we first allowed the behavior of assigning to
non-adjacent slices, in 8.2.  Back-patch to all affected versions.

14 years agoAllow older branches to be built with Visual Studio 2008. This is a backport of commi...
Andrew Dunstan [Tue, 4 Jan 2011 21:07:05 +0000 (16:07 -0500)] 
Allow older branches to be built with Visual Studio 2008. This is a backport of commit df0cdd53 to the 8.2, 8.3 and 8.4 branches.

14 years agoWork around header misdefines in modern Windows SDK when _WIN32_WINNT is less than...
Andrew Dunstan [Tue, 4 Jan 2011 14:41:18 +0000 (09:41 -0500)] 
Work around header misdefines in modern Windows SDK when _WIN32_WINNT is less than 0x0501. Only required for versions 8.2, 8.3 and 8.4., as we defined _WIN32_WINNT as 0x0501 after that.

14 years agoOoops, no DATE_IS_NOBEGIN/DATE_IS_NOEND in 8.3 or 8.2 ...
Tom Lane [Wed, 29 Dec 2010 04:01:33 +0000 (23:01 -0500)] 
Ooops, no DATE_IS_NOBEGIN/DATE_IS_NOEND in 8.3 or 8.2 ...

I heard the siren call of git cherry-pick, but should have lashed myself
to the mast.

14 years agoAvoid unexpected conversion overflow in planner for distant date values.
Tom Lane [Wed, 29 Dec 2010 03:49:57 +0000 (22:49 -0500)] 
Avoid unexpected conversion overflow in planner for distant date values.

The "date" type supports a wider range of dates than int64 timestamps do.
However, there is pre-int64-timestamp code in the planner that assumes that
all date values can be converted to timestamp with impunity.  Fortunately,
what we really need out of the conversion is always a double (float8)
value; so even when the date is out of timestamp's range it's possible to
produce a sane answer.  All we need is a code path that doesn't try to
force the result into int64.  Per trouble report from David Rericha.

Back-patch to all supported versions.  Although this is surely a corner
case, there's not much point in advertising a date range wider than
timestamp's if we will choke on such values in unexpected places.

14 years agoFix up handling of simple-form CASE with constant test expression.
Tom Lane [Sun, 19 Dec 2010 20:30:44 +0000 (15:30 -0500)] 
Fix up handling of simple-form CASE with constant test expression.

eval_const_expressions() can replace CaseTestExprs with constants when
the surrounding CASE's test expression is a constant.  This confuses
ruleutils.c's heuristic for deparsing simple-form CASEs, leading to
Assert failures or "unexpected CASE WHEN clause" errors.  I had put in
a hack solution for that years ago (see commit
514ce7a331c5bea8e55b106d624e55732a002295 of 2006-10-01), but bug #5794
from Peter Speck shows that that solution failed to cover all cases.

Fortunately, there's a much better way, which came to me upon reflecting
that Peter's "CASE TRUE WHEN" seemed pretty redundant: we can "simplify"
the simple-form CASE to the general form of CASE, by simply omitting the
constant test expression from the rebuilt CASE construct.  This is
intuitively valid because there is no need for the executor to evaluate
the test expression at runtime; it will never be referenced, because any
CaseTestExprs that would have referenced it are now replaced by constants.
This won't save a whole lot of cycles, since evaluating a Const is pretty
cheap, but a cycle saved is a cycle earned.  In any case it beats kluging
ruleutils.c still further.  So this patch improves const-simplification
and reverts the previous change in ruleutils.c.

Back-patch to all supported branches.  The bug exists in 8.1 too, but it's
out of warranty.

14 years agoFix erroneous parsing of tsquery input "... & !(subexpression) | ..."
Tom Lane [Sun, 19 Dec 2010 17:48:58 +0000 (12:48 -0500)] 
Fix erroneous parsing of tsquery input "... & !(subexpression) | ..."

After parsing a parenthesized subexpression, we must pop all pending
ANDs and NOTs off the stack, just like the case for a simple operand.
Per bug #5793.

Also fix clones of this routine in contrib/intarray and contrib/ltree,
where input of types query_int and ltxtquery had the same problem.

Back-patch to all supported versions.

14 years agoDocument unavailable parameters in some configurations
Magnus Hagander [Sat, 18 Dec 2010 15:30:00 +0000 (16:30 +0100)] 
Document unavailable parameters in some configurations

Add a note to user-facing parameters that can be removed completely
(and not just empty) by #ifdef's depending on build configuration.

14 years agoWork around make changes on modern Mingw to allow release 8.2 regression tests to...
Andrew Dunstan [Sat, 18 Dec 2010 00:49:31 +0000 (19:49 -0500)] 
Work around make changes on modern Mingw to allow release 8.2 regression tests to work.

14 years agoBackpatch plperl GNUmakefile fixes to allow building release 8.2 on Mingw with a...
Andrew Dunstan [Fri, 17 Dec 2010 16:51:32 +0000 (11:51 -0500)] 
Backpatch plperl GNUmakefile fixes to allow building release 8.2 on Mingw with a modern perl.

14 years agoFix up getopt() reset management so it works on recent mingw.
Tom Lane [Thu, 16 Dec 2010 04:51:07 +0000 (23:51 -0500)] 
Fix up getopt() reset management so it works on recent mingw.

The mingw people don't appear to care about compatibility with non-GNU
versions of getopt, so force use of our own copy of getopt on Windows.
Also, ensure that we make use of optreset when using our own copy.

Per report from Andrew Dunstan.  Back-patch to all versions supported
on Windows.

14 years agoFix contrib/seg's GiST picksplit method.
Tom Lane [Thu, 16 Dec 2010 02:22:38 +0000 (21:22 -0500)] 
Fix contrib/seg's GiST picksplit method.

Fix the same size_alpha versus size_beta typo that was recently fixed
in contrib/cube.  Noted by Alexander Korotkov.

Back-patch to all supported branches (there is a more invasive fix in
HEAD).

14 years agoTag 8.2.19. REL8_2_19
Marc G. Fournier [Tue, 14 Dec 2010 03:03:33 +0000 (23:03 -0400)] 
Tag 8.2.19.

14 years agoUpdate release notes for releases 9.0.2, 8.4.6, 8.3.13, 8.2.19, and 8.1.23.
Tom Lane [Tue, 14 Dec 2010 01:22:09 +0000 (20:22 -0500)] 
Update release notes for releases 9.0.2, 8.4.6, 8.3.13, 8.2.19, and 8.1.23.

14 years agoTranslation updates for release 8.2.19
Peter Eisentraut [Mon, 13 Dec 2010 20:31:56 +0000 (22:31 +0200)] 
Translation updates for release 8.2.19

14 years agoUpdate time zone data files to tzdata release 2010o: DST law changes in
Tom Lane [Mon, 13 Dec 2010 17:41:57 +0000 (12:41 -0500)] 
Update time zone data files to tzdata release 2010o: DST law changes in
Fiji and Samoa.  Historical corrections for Hong Kong.

14 years agoForce default wal_sync_method to be fdatasync on Linux.
Tom Lane [Thu, 9 Dec 2010 01:01:29 +0000 (20:01 -0500)] 
Force default wal_sync_method to be fdatasync on Linux.

Recent versions of the Linux system header files cause xlogdefs.h to
believe that open_datasync should be the default sync method, whereas
formerly fdatasync was the default on Linux.  open_datasync is a bad
choice, first because it doesn't actually outperform fdatasync (in fact
the reverse), and second because we try to use O_DIRECT with it, causing
failures on certain filesystems (e.g., ext4 with data=journal option).
This part of the patch is largely per a proposal from Marti Raudsepp.
More extensive changes are likely to follow in HEAD, but this is as much
change as we want to back-patch.

Also clean up confusing code and incorrect documentation surrounding the
fsync_writethrough option.  Those changes shouldn't result in any actual
behavioral change, but I chose to back-patch them anyway to keep the
branches looking similar in this area.

In 9.0 and HEAD, also do some copy-editing on the WAL Reliability
documentation section.

Back-patch to all supported branches, since any of them might get used
on modern Linux versions.

14 years agoAdd a stack overflow check to copyObject().
Tom Lane [Tue, 7 Dec 2010 03:56:07 +0000 (22:56 -0500)] 
Add a stack overflow check to copyObject().

There are some code paths, such as SPI_execute(), where we invoke
copyObject() on raw parse trees before doing parse analysis on them.  Since
the bison grammar is capable of building heavily nested parsetrees while
itself using only minimal stack depth, this means that copyObject() can be
the front-line function that hits stack overflow before anything else does.
Accordingly, it had better have a check_stack_depth() call.  I did a bit of
performance testing and found that this slows down copyObject() by only a
few percent, so the hit ought to be negligible in the context of complete
processing of a query.

Per off-list report from Toshihide Katayama.  Back-patch to all supported
branches.

14 years agoPrevent inlining a SQL function with multiple OUT parameters.
Tom Lane [Wed, 1 Dec 2010 05:53:39 +0000 (00:53 -0500)] 
Prevent inlining a SQL function with multiple OUT parameters.

There were corner cases in which the planner would attempt to inline such
a function, which would result in a failure at runtime due to loss of
information about exactly what the result record type is.  Fix by disabling
inlining when the function's recorded result type is RECORD.  There might
be some sub-cases where inlining could still be allowed, but this is a
simple and backpatchable fix, so leave refinements for another day.
Per bug #5777 from Nate Carson.

Back-patch to all supported branches.  8.1 happens to avoid a core-dump
here, but it still does the wrong thing.

14 years agoFix significant memory leak in contrib/xml2 functions.
Tom Lane [Fri, 26 Nov 2010 20:21:08 +0000 (15:21 -0500)] 
Fix significant memory leak in contrib/xml2 functions.

Most of the functions that execute XPath queries leaked the data structures
created by libxml2.  This memory would not be recovered until end of
session, so it mounts up pretty quickly in any serious use of the feature.
Per report from Pavel Stehule, though this isn't his patch.

Back-patch to all supported branches.

14 years agoDon't raise "identifier will be truncated" messages in dblink
Itagaki Takahiro [Thu, 25 Nov 2010 11:12:20 +0000 (20:12 +0900)] 
Don't raise "identifier will be truncated" messages in dblink
except creating new connections.

14 years agoThe GiST scan algorithm uses LSNs to detect concurrent pages splits, but
Heikki Linnakangas [Tue, 16 Nov 2010 09:02:11 +0000 (11:02 +0200)] 
The GiST scan algorithm uses LSNs to detect concurrent pages splits, but
temporary indexes are not WAL-logged. We used a constant LSN for temporary
indexes, on the assumption that we don't need to worry about concurrent page
splits in temporary indexes because they're only visible to the current
session. But that assumption is wrong, it's possible to insert rows and
split pages in the same session, while a scan is in progress. For example,
by opening a cursor and fetching some rows, and INSERTing new rows before
fetching some more.

Fix by generating fake increasing LSNs, used in place of real LSNs in
temporary GiST indexes.

14 years agoFix aboriginal mistake in plpython's set-returning-function support.
Tom Lane [Mon, 15 Nov 2010 19:27:12 +0000 (14:27 -0500)] 
Fix aboriginal mistake in plpython's set-returning-function support.

We must stay in the function's SPI context until done calling the iterator
that returns the set result.  Otherwise, any attempt to invoke SPI features
in the python code called by the iterator will malfunction.  Diagnosis and
patch by Jan Urbanski, per bug report from Jean-Baptiste Quenot.

Back-patch to 8.2; there was no support for SRFs in previous versions of
plpython.

14 years agoFix bug in cube picksplit algorithm.
Robert Haas [Mon, 15 Nov 2010 02:27:34 +0000 (21:27 -0500)] 
Fix bug in cube picksplit algorithm.

Alexander Korotkov

14 years agoAdd missing outfuncs.c support for struct InhRelation.
Tom Lane [Sat, 13 Nov 2010 05:35:08 +0000 (00:35 -0500)] 
Add missing outfuncs.c support for struct InhRelation.

This is needed to support debug_print_parse, per report from Jon Nelson.
Cursory testing via the regression tests suggests we aren't missing
anything else.

14 years agoFix old oversight in const-simplification of COALESCE() expressions.
Tom Lane [Fri, 12 Nov 2010 20:14:51 +0000 (15:14 -0500)] 
Fix old oversight in const-simplification of COALESCE() expressions.

Once we have found a non-null constant argument, there is no need to
examine additional arguments of the COALESCE.  The previous coding got it
right only if the constant was in the first argument position; otherwise
it tried to simplify following arguments too, leading to unexpected
behavior like this:

regression=# select coalesce(f1, 42, 1/0) from int4_tbl;
ERROR:  division by zero

It's a minor corner case, but a bug is a bug, so back-patch all the way.

14 years agoFix bug introduced by the recent patch to check that the checkpoint redo
Heikki Linnakangas [Thu, 11 Nov 2010 17:21:49 +0000 (19:21 +0200)] 
Fix bug introduced by the recent patch to check that the checkpoint redo
location read from backup label file can be found: wasShutdown was set
incorrectly when a backup label file was found.

Jeff Davis, with a little tweaking by me.