Commit Graph

28616 Commits

Author SHA1 Message Date
Tom Lane 25d9bf2e3e Support deferrable uniqueness constraints.
The current implementation fires an AFTER ROW trigger for each tuple that
looks like it might be non-unique according to the index contents at the
time of insertion.  This works well as long as there aren't many conflicts,
but won't scale to massive unique-key reassignments.  Improving that case
is a TODO item.

Dean Rasheed
2009-07-29 20:56:21 +00:00
Tom Lane 8504905793 Fix a thinko introduced into CountActiveBackends by a recent patch:
we should ignore NULL array entries, not non-NULL ones.  This had the
effect of disabling commit_delay, and could have caused a crash in the
rare race condition the patch was intended to fix.

Bug report and diagnosis by Jeff Janes, in bug #4952.
2009-07-29 15:57:11 +00:00
Teodor Sigaev 49475aab8d Correct calculations of overlap and contains operations over polygons. 2009-07-28 09:48:00 +00:00
Teodor Sigaev 1f4b046c18 Fix incorrect cleanup of tsquery in ts_rewrite(). Per bug #4933 by
Aaron Marcuse-Kubitza <aaronmk@blackducksoftware.com>
2009-07-28 09:31:55 +00:00
Tom Lane c1b9ec24ef Add system catalog columns pg_constraint.conindid and pg_trigger.tgconstrindid.
conindid is the index supporting a constraint.  We can use this not only for
unique/primary-key constraints, but also foreign-key constraints, which
depend on the unique index that constrains the referenced columns.
tgconstrindid is just copied from the constraint's conindid field, or is
zero for triggers not associated with constraints.

This is mainly intended as infrastructure for upcoming patches, but it has
some virtue in itself, since it exposes a relationship that you formerly
had to grovel in pg_depend to determine.  I simplified one information_schema
view accordingly.  (There is a pg_dump query that could also use conindid,
but I left it alone because it wasn't clear it'd get any faster.)
2009-07-28 02:56:31 +00:00
Magnus Hagander 36942504fc Fix minor memory leak in Win32 SID handling functions. Not a big issue
since it's only called during process startup, thus no backpatch.

Found by TAKATSUKA Haruka, patch by Magnus Hagander and
Andrew Chernow
2009-07-27 08:46:10 +00:00
Magnus Hagander 220e36c97f Enable the use of multiple CPUs/cores when building on MSVC. This only
affects the C compiler step - we still only build one target at a
time.
2009-07-27 07:11:15 +00:00
Tom Lane aac3c301b5 Add s_lock support for SuperH architecture.
After a patch originally submitted by Nobuhiro Iwamatsu, but corrected
(I think) to match our guidelines for safe use of asm fragments.
This should be considered untested ...
2009-07-27 05:31:05 +00:00
Tom Lane cfbd2af95c Improve comment, per gripe from Alvaro. 2009-07-27 04:09:55 +00:00
Tom Lane e4b9e65393 Fix pg_stat_statements for EXEC_BACKEND case.
We should not try to load old statistics when re-attaching to existing
shared memory.  Per bug #4941.

Itagaki Takahiro
2009-07-27 03:34:40 +00:00
Tom Lane 8835d63b27 Experiment with using EXPLAIN COSTS OFF in regression tests.
This is a simple test to see whether COSTS OFF will help much with getting
EXPLAIN output that's sufficiently platform-independent for use in the
regression tests.  The planner does have some freedom of choice in these
examples (plain via bitmap indexscan), so I'm not sure what will happen.
2009-07-27 00:26:03 +00:00
Tom Lane d4382c4ae7 Extend EXPLAIN to allow generic options to be specified.
The original syntax made it difficult to add options without making them
into reserved words.  This change parenthesizes the options to avoid that
problem, and makes provision for an explicit (and perhaps non-Boolean)
value for each option.  The original syntax is still supported, but only
for the two original options ANALYZE and VERBOSE.

As a test case, add a COSTS option that can suppress the planner cost
estimates.  This may be useful for including EXPLAIN output in the regression
tests, which are otherwise unable to cope with cross-platform variations in
cost estimates.

Robert Haas
2009-07-26 23:34:18 +00:00
Tom Lane a07e5acebb Code review for FORCE QUOTE * patch: fix error checking to consider FORCE
QUOTE * as a variety of FORCE QUOTE, and update psql documentation to include
the option.  (The actual psql code doesn't seem to need any changes.)
2009-07-25 17:04:19 +00:00
Andrew Dunstan fd9df11f81 Small stylistic improvement in recent FORCE QUOTE * code - use a bool instead of a magic value. 2009-07-25 13:35:32 +00:00
Andrew Dunstan de7531a971 Allow * as parameter for FORCE QUOTE for COPY CSV. Itagaki Takahiro. 2009-07-25 00:07:14 +00:00
Tom Lane 8af12bca3b Assorted minor refactoring in EXPLAIN.
This is believed to not change the output at all, with one known exception:
"Subquery Scan foo" becomes "Subquery Scan on foo".  (We can fix that if
anyone complains, but it would be a wart, because the old code was clearly
inconsistent.)  The main intention is to remove duplicate coding and
provide a cleaner base for subsequent EXPLAIN patching.

Robert Haas
2009-07-24 21:08:42 +00:00
Magnus Hagander a7e587863c Reserve the shared memory region during backend startup on Windows, so
that memory allocated by starting third party DLLs doesn't end up
conflicting with it.

Hopefully this solves the long-time issue with "could not reattach
to shared memory" errors on Win32.

Patch from Tsutomu Yamada and me, based on idea from Trevor Talbot.
2009-07-24 20:12:42 +00:00
Peter Eisentraut 5e22994127 Document \dg+ and \du+
The fact that \dg and \du take the + option was missing in the documentation.

backpatched to 8.4

Author: Andreas Wenk <a.wenk@netzmeister-st-pauli.de>
2009-07-24 19:35:44 +00:00
Tom Lane cea80e726e Avoid extra system calls to block SIGPIPE if the platform provides either
sockopt(SO_NOSIGPIPE) or the MSG_NOSIGNAL flag to send().

We assume these features are available if (1) the symbol is defined at
compile time and (2) the kernel doesn't reject the call at runtime.
It might turn out that there are some platforms where (1) and (2) are
true and yet the signal isn't really blocked, in which case applications
would die on server crash.  If that sort of thing gets reported, then
we'll have to add additional defenses of some kind.

Jeremy Kerr
2009-07-24 17:58:31 +00:00
Tom Lane 655473a7cd Add commentary about Cygwin's broken erand48, per report from Andrew Dunstan. 2009-07-24 15:03:07 +00:00
Andrew Dunstan dc7aa36521 Force use of our erand48 on Cygwin 2009-07-23 23:50:29 +00:00
Tom Lane 0d6909eaba Teach pg_dump to dump comments attached to the columns of a composite type.
Taro Minowa (Higepon)
2009-07-23 22:59:40 +00:00
Tom Lane adfa04293b Save a few cycles in EXPLAIN and related commands by not bothering to form
a physical tuple in do_tup_output().  A virtual tuple is easier to set up
and also easier for most tuple receivers to process.  Per my comment on
Robert Haas' recent patch in this code.
2009-07-23 21:27:10 +00:00
Tom Lane 6a0865e4bb In a non-hashed Agg node, reset the "aggcontext" at group boundaries, instead
of individually pfree'ing pass-by-reference transition values.  This should
be at least as fast as the prior coding, and it has the major advantage of
clearing out any working data an aggregate function may have stored in or
underneath the aggcontext.  This avoids memory leakage when an aggregate
such as array_agg() is used in GROUP BY mode.  Per report from Chris Spotts.

Back-patch to 8.4.  In principle the problem could arise in prior versions,
but since they didn't have array_agg the issue seems not critical.
2009-07-23 20:45:27 +00:00
Tom Lane 1ca695db38 Fix another thinko in join_is_legal's handling of semijoins: we have to test
for the case that the semijoin was implemented within either input by
unique-ifying its RHS before we test to see if it appears to match the current
join situation.  The previous coding would select semijoin logic in situations
where we'd already unique-ified the RHS and joined it to some unrelated
relation(s), and then came to join it to the semijoin's LHS.  That still gave
the right answer as far as the semijoin itself was concerned, but would lead
to incorrectly examining only an arbitrary one of the matchable rows from the
unrelated relation(s).  The cause of this thinko was incorrect unification of
the pre-8.4 logic for IN joins and OUTER joins --- the comparable case for
outer joins can be handled after making the match test, but that's because
there is nothing like the unique-ification escape hatch for outer joins.
Per bug #4934 from Benjamin Reed.
2009-07-23 17:42:06 +00:00
Andrew Dunstan 00f0b47539 Update location to download flex for building on Windows. 2009-07-23 17:06:48 +00:00
Peter Eisentraut 2afa73a9e8 Clarify NULLIF example
found by "Vesa-Matti J Kari" <vmkari@cc.helsinki.fi>
2009-07-22 18:07:26 +00:00
Tom Lane 846c364dd4 Change do_tup_output() to take Datum/isnull arrays instead of a char * array,
so it doesn't go through BuildTupleFromCStrings.  This is more or less a
wash for current uses, but will avoid inefficiency for planned changes to
EXPLAIN.

Robert Haas
2009-07-22 17:00:23 +00:00
Magnus Hagander ea382424ee Fix mismatch in const:ness of parameters. 2009-07-22 11:07:02 +00:00
Joe Conway 6cf9f31908 Replace PLpgSQL_dstring by StringInfo.
Replace redundant PLpgSQL_dstring functionality with StringInfo.
Patch by Pavel Stehule. Review by Joe Conway.
2009-07-22 02:31:38 +00:00
Tom Lane ca7c8168de Tweak TOAST code so that columns marked with MAIN storage strategy are
not forced out-of-line unless that is necessary to make the row fit on a
page.  Previously, they were forced out-of-line if needed to get the row
down to the default target size (1/4th page).

Kevin Grittner
2009-07-22 01:21:22 +00:00
Tom Lane a5375bf903 Make pg_dump/pg_restore --clean options drop large objects too.
In passing, make invocations of lo_xxx functions a bit more schema-safe.

Itagaki Takahiro
2009-07-21 21:46:10 +00:00
Peter Eisentraut 5dedce6770 Change pg_listener attribute number constants to match the usual pattern
It appears that, for no particularly good reason, pg_listener.h deviates from
the usual convention for declaring attribute number constants.  Normally, it's

#define Anum_{catalog-name}_{column-name}  {attribute-number}

pg_listener.h, however substitutes a different string that is similar, but not
the same as, the column name.  This change fixes that.

Author: Robert Haas <robertmhaas@gmail.com>
2009-07-21 20:24:51 +00:00
Tom Lane ab5b4e2f9e Speed up AllocSetFreeIndex, which is a significant cost in palloc and pfree,
by using a lookup table instead of a naive shift-and-count loop.  Based on
code originally posted by Sean Eron Anderson at
http://graphics.stanford.edu/%7eseander/bithacks.html.
Greg Stark did the research and benchmarking to show that this is what
we should use.  Jeremy Kerr first noticed that this is a hotspot that
could be optimized, though we ended up not using his suggestion of
platform-specific bit-searching code.
2009-07-21 19:53:12 +00:00
Peter Eisentraut f3f45c87d2 Remove translated FAQs
The English FAQ has been moved to the wiki, so the translated versions should
have been removed at that point as well.

The FAQ_MINGW.html should have been removed when the platform FAQs were
integrated into the documentation (or earlier).

applied to both 8.4 and 8.5
2009-07-21 19:20:33 +00:00
Peter Eisentraut f7ad9cab30 Add a further customization to the SGML Emacs mode to prevent the use of
tabs in the documentation source.
2009-07-21 19:07:24 +00:00
Tom Lane b2c51e6eba Fix another semijoin-ordering bug. We already knew that we couldn't
reorder a semijoin into or out of the righthand side of another semijoin,
but actually it doesn't work to reorder it into or out of the righthand
side of a left or antijoin, either.  Per bug #4906 from Mathieu Fenniak.

This was sloppy thinking on my part.  This identity does work:

	( A left join B on (Pab) ) semijoin C on (Pac)
==
	( A semijoin C on (Pac) ) left join B on (Pab)

but I failed to see that that doesn't mean this does:

	( A left join B on (Pab) ) semijoin C on (Pbc)
!=
	A left join ( B semijoin C on (Pbc) ) on (Pab)
2009-07-21 02:02:44 +00:00
Bruce Momjian 4e03b827ee Properly restore pg_largeobject.relfozenxid in binary upgrade mode.
Backpatch to 8.4.X.
2009-07-20 20:53:40 +00:00
Alvaro Herrera 396a493c17 Install src/include/utils/fmgroids.h on VPATH builds too.
The original coding was not dealing specially with this file being a symlink,
with the end result that it was not installed in VPATH builds.  Oddly enough,
the clean target does know about it ...
2009-07-20 20:38:55 +00:00
Peter Eisentraut 7405f2cc85 Small additional clean from the rearrangement of the HTML index build rules 2009-07-20 18:34:58 +00:00
Peter Eisentraut 5106bdc450 Use errcontext mechanism in PL/Python
Error messages from PL/Python now always mention the function name in the
CONTEXT: field.  This also obsoletes the few places that tried to do the
same manually.

Regression test files are updated to work with Python 2.4-2.6.  I don't have
access to older versions right now.
2009-07-20 08:01:07 +00:00
Tom Lane 888d3335b1 Remove unnecessary and version-sensitive dependence on the exact set of
column names to be found in a sequence.  Per gripe from Bruce.
2009-07-20 03:46:45 +00:00
Andrew Dunstan e73131a16a DROP IF EXISTS for columns and constraints. Andres Freund. 2009-07-20 02:42:28 +00:00
Tom Lane 31d1f23302 Teach simplify_boolean_equality to simplify the forms foo <> true and
foo <> false, along with its previous duties of simplifying foo = true
and foo = false.  (All of these are equivalent to just foo or NOT foo
as the case may be.)  It's not clear how often this is really useful;
but it costs almost nothing to do, and it seems some people think we
should be smart about such cases.  Per recent bug report.
2009-07-20 00:24:30 +00:00
Tom Lane 400e2c9344 Rewrite GEQO's gimme_tree function so that it always finds a legal join
sequence, even when the input "tour" doesn't lead directly to such a sequence.
The stack logic that was added in 2004 only supported cases where relations
that had to be joined to each other (due to join order restrictions) were
adjacent in the tour.  However, relying on a random search to figure that out
is tremendously inefficient in large join problems, and could even fail
completely (leading to "failed to make a valid plan" errors) if
random_init_pool ran out of patience.  It seems better to make the
tour-to-plan transformation a little bit fuzzier so that every tour can form
a legal plan, even though this means that apparently different tours will
sometimes yield the same plan.

In the same vein, get rid of the logic that knew that tours (a,b,c,d,...)
are the same as tours (b,a,c,d,...), and therefore insisted the latter
are invalid.  The chance of generating two tours that differ only in
this way isn't that high, and throwing out 50% of possible tours to
avoid such duplication seems more likely to waste valuable genetic-
refinement generations than to do anything useful.

This leaves us with no cases in which geqo_eval will deem a tour invalid,
so get rid of assorted kluges that tried to deal with such cases, in
particular the undocumented assumption that DBL_MAX is an impossible
plan cost.

This is all per testing of Robert Haas' lets-remove-the-collapse-limits
patch.  That idea has crashed and burned, at least for now, but we still
got something useful out of it.

It's possible we should back-patch this change, since the "failed to make a
valid plan" error can happen in existing releases; but I'd rather not until
it has gotten more testing.
2009-07-19 21:00:43 +00:00
Tom Lane a43b190e3c Fix a thinko in join_is_legal: when we decide we can implement a semijoin
by unique-ifying the RHS and then inner-joining to some other relation,
that is not grounds for violating the RHS of some other outer join.
Noticed while regression-testing new GEQO code, which will blindly follow
any path that join_is_legal says is legal, and then complain later if that
leads to a dead end.

I'm not certain that this can result in any visible failure in 8.4: the
mistake may always be masked by the fact that subsequent attempts to join
the rest of the RHS of the other join will fail.  But I'm not certain it
can't, either, and it's definitely not operating as intended.  So back-patch.

The added regression test depends on the new no-failures-allowed logic
that I'm about to commit in GEQO, so no point back-patching that.
2009-07-19 20:32:48 +00:00
Tom Lane 011eae60ef Fix error cleanup failure caused by 8.4 changes in plpgsql to try to avoid
memory leakage in error recovery.  We were calling FreeExprContext, and
therefore invoking ExprContextCallback callbacks, in both normal and error
exits from subtransactions.  However this isn't very safe, as shown in
recent trouble report from Frank van Vugt, in which releasing a tupledesc
refcount failed.  It's also unnecessary, since the resources that callbacks
might wish to release should be cleaned up by other error recovery mechanisms
(ie the resource owners).  We only really want FreeExprContext to release
memory attached to the exprcontext in the error-exit case.  So, add a bool
parameter to FreeExprContext to tell it not to call the callbacks.

A more general solution would be to pass the isCommit bool parameter on to
the callbacks, so they could do only safe things during error exit.  But
that would make the patch significantly more invasive and possibly break
third-party code that registers ExprContextCallback callbacks.  We might want
to do that later in HEAD, but for now I'll just do what seems reasonable to
back-patch.
2009-07-18 19:15:42 +00:00
Tom Lane fb18055998 Repair bug #4926 "too few pathkeys for mergeclauses". This example shows
that the sanity checking I added to create_mergejoin_plan() in 8.3 was a
few bricks shy of a load: the mergeclauses could reference pathkeys in a
noncanonical order such as x,y,x, not only cases like x,x,y which is all
that the code had allowed for.  The odd cases only turn up when using
redundant clauses in an outer join condition, which is why no one had
noticed before.
2009-07-17 23:19:34 +00:00
Tom Lane f5bc74192d Make GEQO's planning deterministic by having it start from a predictable
random number seed each time.  This is how it used to work years ago, but
we got rid of the seed reset because it was resetting the main random()
sequence and thus having undesirable effects on the rest of the system.
To fix, establish a private random number state for each execution of
geqo(), and initialize the state using the new GUC variable geqo_seed.
People who want to experiment with different random searches can do so
by changing geqo_seed, but you'll always get the same plan for the same
value of geqo_seed (if holding all other planner inputs constant, of course).

The new state is kept in PlannerInfo by adding a "void *" field reserved
for use by join_search hooks.  Most of the rather bulky code changes in
this commit are just arranging to pass PlannerInfo around to all the GEQO
functions (many of which formerly didn't receive it).

Andres Freund, with some editorialization by Tom
2009-07-16 20:55:44 +00:00
Tom Lane c43feefa80 Add erand48() to the set of functions supported by our src/port/ library,
and extend configure to test for it properly instead of hard-wiring
an assumption that everybody but Windows has the rand48 functions.
(We do cheat to the extent of assuming that probing for erand48 will do
for the entire rand48 family.)

erand48() is unused as of this commit, but a followon patch will cause
GEQO to depend on it.

Andres Freund, additional hacking by Tom
2009-07-16 17:43:52 +00:00