Commit Graph

9486 Commits

Author SHA1 Message Date
Tom Lane e67867b26c Allow AS to be omitted when specifying an output column name in SELECT
(or RETURNING), but only when the output name is not any SQL keyword.
This seems as close as we can get to the standard's syntax without a
great deal of thrashing.  Original patch by Hiroshi Saito, amended by me.
2008-02-15 22:17:06 +00:00
Tom Lane cc80f0a340 Remove ancient restriction that LIMIT/OFFSET can't contain a sub-select.
This was probably protecting some implementation limitation when it was
put in, but as far as I can tell the planner and executor have no such
assumption anymore; the case seems to work fine.  Per a gripe from
Grzegorz Jaskiewicz.
2008-02-15 17:19:46 +00:00
Tom Lane df1e965e12 Sync our regex code with upstream changes since last time we did this, which
was Tcl 8.4.8.  The main changes are to remove the never-fully-implemented
code for multi-character collating elements, and to const-ify some stuff a
bit more fully.  In combination with the recent security patch, this commit
brings us into line with Tcl 8.5.0.

Note that I didn't make any effort to duplicate a lot of cosmetic changes
that they made to bring their copy into line with their own style
guidelines, such as adding braces around single-line IF bodies.  Most of
those we either had done already (such as ANSI-fication of function headers)
or there is no point because pgindent would undo the change anyway.
2008-02-14 17:33:37 +00:00
Tom Lane 745e6edaae Fix SPI_cursor_open() and SPI_is_cursor_plan() to push the SPI stack before
doing anything interesting, such as calling RevalidateCachedPlan().  The
necessity of this is demonstrated by an example from Willem Buitendyk:
during a replan, the planner might try to evaluate SPI-using functions,
and so we'd better be in a clean SPI context.

A small downside of this fix is that these two functions will now fail
outright if called when not inside a SPI-using procedure (ie, a
SPI_connect/SPI_finish pair).  The documentation never promised or suggested
that that would work, though; and they are normally used in concert with
other functions, mainly SPI_prepare, that always have failed in such a case.
So the odds of breaking something seem pretty low.

In passing, make SPI_is_cursor_plan's error handling convention clearer,
and fix documentation's erroneous claim that SPI_cursor_open would
return NULL on error.

Before 8.3 these functions could not invoke replanning, so there is probably
no need for back-patching.
2008-02-12 04:09:44 +00:00
Tom Lane c931c07124 Repair VACUUM FULL bug introduced by HOT patch: the original way of
calculating a page's initial free space was fine, and should not have been
"improved" by letting PageGetHeapFreeSpace do it.  VACUUM FULL is going to
reclaim LP_DEAD line pointers later, so there is no need for a guard
against the page being too full of line pointers, and having one risks
rejecting pages that are perfectly good move destinations.

This also exposed a second bug, which is that the empty_end_pages logic
assumed that any page with no live tuples would get entered into the
fraged_pages list automatically (by virtue of having more free space than
the threshold in the do_frag calculation).  This assumption certainly
seems risky when a low fillfactor has been chosen, and even without
tunable fillfactor I think it could conceivably fail on a page with many
unused line pointers.  So fix the code to force do_frag true when notup
is true, and patch this part of the fix all the way back.

Per report from Tomas Szepe.
2008-02-11 19:14:30 +00:00
Tom Lane 082aca9ec2 Fix PageGetExactFreeSpace() so that it actually behaves sensibly
if pd_lower > pd_upper, rather than merely claiming to.  This would
only matter if the page header were corrupt, which shouldn't occur,
but ...
2008-02-10 20:39:08 +00:00
Tom Lane 81e770857d Since GSSAPI and SSPI authentication don't work in protocol version 2,
issue a helpful error message instead of sending unparsable garbage.
(It is clearly a design error that this doesn't work, but fixing it
is not worth the trouble at this point.)  Per discussion.
2008-02-08 17:58:46 +00:00
Tom Lane 9b43c245e3 Avoid misbehavior in foreign key checks when casting to a datatype for which
the parser supplies a default typmod that can result in data loss (ie,
truncation).  Currently that appears to be only CHARACTER and BIT.
We can avoid the problem by specifying the type's internal name instead
of using SQL-spec syntax.  Since the queries generated here are only used
internally, there's no need to worry about portability.  This problem is
new in 8.3; before we just let the parser do whatever it wanted to resolve
the operator, but 8.3 is trying to be sure that the semantics of FK checks
are consistent.  Per report from Harald Fuchs.
2008-02-07 22:58:35 +00:00
Tom Lane 1ab19a36a5 Some variants of ALTER OWNER tried to make the "object" field of the
statement be a list of bare C strings, rather than String nodes, which is
what they need to be for copyfuncs/equalfuncs to work.  Fortunately these
node types never go out to disk (if they did, we'd likely have noticed the
problem sooner), so we can just fix it without creating a need for initdb.
This bug has been there since 8.0, but 8.3 exposes it in a more common
code path (Parse messages) than prior releases did.  Per bug #3940 from
Vladimir Kokovic.
2008-02-07 21:07:55 +00:00
Tom Lane 49a730128c Add missing copyfuncs/equalfuncs support for AlterTSDictionaryStmt and
AlterTSConfigurationStmt.  All utility statement node types are expected
to be supported here, though they do not have to have outfuncs/readfuncs
support.  Found by running regression tests with COPY_PARSE_PLAN_TREES
enabled.
2008-02-07 20:19:47 +00:00
Tom Lane 09bb6f6ed0 Fix silly mistake in expand_indexqual_rowcompare --- in converting a forboth()
into an iteration over three parallel lists, I had accidentally put the lnext
steps outside the loop.  Sigh.  Per bug #3938.
2008-02-07 17:53:53 +00:00
Tom Lane b7fe5f70d3 Fix CREATE TABLE ... LIKE ... INCLUDING INDEXES to not cause unwanted
tablespace permissions failures when copying an index that is in the
database's default tablespace.  A side-effect of the change is that explicitly
specifying the default tablespace no longer triggers a permissions check;
this is not how it was done in pre-8.3 releases but is argued to be more
consistent.  Per bug #3921 from Andrew Gilligan.  (Note: I argued in the
subsequent discussion that maybe LIKE shouldn't copy index tablespaces
at all, but since no one indicated agreement with that idea, I've refrained
from doing it.)
2008-02-07 17:09:51 +00:00
Tom Lane 6f906905b1 Fix WaitOnLock() to ensure that the process's "waiting" flag is reset after
erroring out of a wait.  We can use a PG_TRY block for this, but add a comment
explaining why it'd be a bad idea to use it for any other state cleanup.

Back-patch to 8.2.  Prior releases had the same issue, but only with respect
to the process title, which is likely to get reset almost immediately anyway
after the transaction aborts, so it seems not worth changing them.  In 8.2
and HEAD, the pg_stat_activity "waiting" flag could remain set incorrectly
for a long time.

Per report from Gurjeet Singh.
2008-02-02 22:26:17 +00:00
Peter Eisentraut 3c9ae7300d Translation updates 2008-01-31 18:04:52 +00:00
Magnus Hagander 0ace923ce8 Add pid to the pgident event name on win32.
Should fix a problem where two clusters are running under
two different service accounts and get colliding names,
causing only the first cluster to contain the pgident
event description.

Per report from Stephen Denne.
2008-01-31 09:21:17 +00:00
Tom Lane 0688d84041 Add checks to TRUNCATE, CLUSTER, and REINDEX to prevent performing these
operations when the current transaction has any open references to the
target relation or index (implying it has an active query using the relation).
The need for this was previously recognized in connection with ALTER TABLE,
but anything that summarily eliminates tuples or moves them around would
confuse an active scan.

While this patch does not in itself fix bug #3883 (the deadlock would happen
before the new check fires), it will discourage people from attempting the
sequence of operations that creates a deadlock risk, so it's at least a
partial response to that problem.

In passing, add a previously-missing check to REINDEX to prevent trying to
reindex another backend's temp table.  This isn't a security problem since
only a superuser would get past the schema permission checks, but if we are
testing for this in other utility commands then surely REINDEX should too.
2008-01-30 19:46:48 +00:00
Tom Lane 47df4f6688 Add a GUC variable "synchronize_seqscans" to allow clients to disable the new
synchronized-scanning behavior, and make pg_dump disable sync scans so that
it will reliably preserve row ordering.  Per recent discussions.
2008-01-30 18:35:55 +00:00
Peter Eisentraut 6dfa40d69f Translation updates 2008-01-30 11:05:41 +00:00
Tom Lane b58d8c9a53 Don't putenv() a string that is allocated in a context that will go away
soon.  I suspect this explains bug #3902, though I'm still not able to
reproduce that.
2008-01-30 04:11:19 +00:00
Tom Lane b5518c8e88 Minor editorial improvements in documentation of session_replication_role;
in particular correct the obsolete claim that it can't be changed once
any plans have been cached.
2008-01-27 19:12:28 +00:00
Tom Lane 6322e84430 Change StatementCancelHandler() to check the DoingCommandRead flag to decide
whether to execute an immediate interrupt, rather than testing whether
LockWaitCancel() cancelled a lock wait.  The old way misclassified the case
where we were blocked in ProcWaitForSignal(), and arguably would misclassify
any other future additions of new ImmediateInterruptOK states too.  This
allows reverting the old kluge that gave LockWaitCancel() a return value,
since no callers care anymore.  Improve comments in the various
implementations of PGSemaphoreLock() to explain that on some platforms, the
assumption that semop() exits after a signal is wrong, and so we must ensure
that the signal handler itself throws elog if we want cancel or die interrupts
to be effective.  Per testing related to bug #3883, though this patch doesn't
solve those problems fully.

Perhaps this change should be back-patched, but since pre-8.3 branches aren't
really relying on autovacuum to respond to SIGINT, it doesn't seem critical
for them.
2008-01-26 19:55:08 +00:00
Tom Lane ace1b29b04 Fix two different copy-and-paste-os in CSV log rotation logic; one that led to
a double-pfree crash and another that effectively disabled size-based rotation
for CSV logs.  Also suppress a memory leak and make some trivial cosmetic
improvements.  Per bug #3901 from Chris Hoover and additional code-reading.
2008-01-25 20:42:10 +00:00
Tom Lane 353a1cca9f Release any detoasted copies of arrays that are made temporarily in
ri_FetchConstraintInfo, to avoid a query-duration memory leak when that
routine is called by RI_FKey_keyequal_upd_fk (which isn't executed in a
short-lived context).  This problem was latent when the routine was added
in February, but it didn't become serious until the varvarlena patch made
it quite likely that the fields being examined would be "toasted" (ie, have
short headers).  Per report from Stephen Denne.
2008-01-25 04:46:07 +00:00
Alvaro Herrera 8984c8bbe2 Improve lock level choices in pg_shdepend.c. Noticed by Tom Lane. 2008-01-23 15:36:38 +00:00
Peter Eisentraut 6f8f8d2daa Provide a clearer error message if the pg_control version number looks
wrong because of mismatched byte ordering.
2008-01-21 11:17:46 +00:00
Tom Lane 716e8b8374 Fix RS_isRegis() to agree exactly with RS_compile()'s idea of what's a valid
regis.  Correct the latter's oversight that a bracket-expression needs to be
terminated.  Reduce the ereports to elogs, since they are now not expected to
ever be hit (thus addressing Alvaro's original complaint).
In passing, const-ify the string argument to RS_compile.
2008-01-21 02:46:11 +00:00
Alvaro Herrera 000666bbfe Split error message. 2008-01-20 17:50:41 +00:00
Tom Lane a44174cf90 Fix subselect.c to avoid assuming that a SubLink's testexpr references each
subquery output column exactly once left-to-right.  Although this is the case
in the original parser output, it might not be so after rewriting and
constant-folding, as illustrated by bug #3882 from Jan Mate.  Instead
scan the subquery's target list to obtain needed per-column information;
this is duplicative of what the parser did, but only a couple dozen lines
need be copied, and we can clean up a couple of notational uglinesses.
Bug was introduced in 8.2 as part of revision of SubLink representation.
2008-01-17 20:35:27 +00:00
Tom Lane 0df7717faa Fix ALTER INDEX RENAME so that if the index belongs to a unique or primary key
constraint, the constraint is renamed as well.  This avoids inconsistent
situations that could confuse pg_dump (not to mention humans).  We might at
some point provide ALTER TABLE RENAME CONSTRAINT as a more general solution,
but there seems no reason not to allow doing it this way too.  Per bug #3854
and related discussions.
2008-01-17 18:56:54 +00:00
Teodor Sigaev cd42dd5a17 Fix core dump with buffer-overrun by too long infinitive. Add checking of using
fixed length arrays to prevent array's overrun. Per report by
Hannes Dorbath <light@theendofthetunnel.de> and comments by Tom.
2008-01-16 13:01:03 +00:00
Tom Lane 14e2a260a5 Prevent CLUSTER from decreasing a relation's relfrozenxid. Bug
introduced in rewrite to make CLUSTER MVCC-safe.
2008-01-15 21:20:28 +00:00
Tom Lane ac12412ede Revise memory management for libxml calls. Instead of keeping libxml's data
in whichever context happens to be current during a call of an xml.c function,
use a dedicated context that will not go away until we explicitly delete it
(which we do at transaction end or subtransaction abort).  This makes recovery
after an error much simpler --- we don't have to individually delete the data
structures created by libxml.  Also, we need to initialize and cleanup libxml
only once per transaction (if there's no error) instead of once per function
call, so it should be a bit faster.  We'll need to keep an eye out for
intra-transaction memory leaks, though.  Alvaro and Tom.
2008-01-15 18:57:00 +00:00
Tom Lane deb7deda26 Tweak new error message to conform to style guidelines. 2008-01-15 18:22:47 +00:00
Teodor Sigaev f7807f1de8 Add check of headline method presence. Per report by Yoshiyuki Asaba <y-asaba@sraoss.co.jp> 2008-01-15 17:16:01 +00:00
Tom Lane 98c0ebca80 Avoid cluttering the postmaster log with bogus complaints
during transaction abort, per my note from a couple days ago.
2008-01-14 19:18:53 +00:00
Alvaro Herrera 7aa4164363 Mark autovacuum entries in pg_stat_activity so that they can be easily
distinguished from user-invoked commands.  Per suggestion from Tom Lane.
2008-01-14 13:39:25 +00:00
Tom Lane d3b1b1f9d8 Fix CREATE INDEX CONCURRENTLY so that it won't use synchronized scan for
its second pass over the table.  It has to start at block zero, else the
"merge join" logic for detecting which TIDs are already in the index
doesn't work.  Hence, extend heapam.c's API so that callers can enable or
disable syncscan.  (I put in an option to disable buffer access strategy,
too, just in case somebody needs it.)  Per report from Hannes Dorbath.
2008-01-14 01:39:09 +00:00
Tom Lane 1bbf8706ae It turns out the LIBXML_TEST_VERSION macro calls xmlInitParser().
Therefore we must xmlCleanupParser(), or we risk leaving behind
dangling pointers to whatever memory context is current when xml_init()
is called.  This seems to fix bug #3860, though we might still want
the more invasive solution being worked on by Alvaro.
2008-01-12 21:14:08 +00:00
Neil Conway 5217663372 Fix two places in xml.c that neglected to check the return values of
SPI_prepare() and SPI_cursor_open(), to silence a Coverity warning.
2008-01-12 10:50:03 +00:00
Neil Conway 25b7583f67 Minor perf tweak for _SPI_strdup(): if we're going to call strlen()
anyway, it is faster to memcpy() than to strcpy().
2008-01-12 10:38:32 +00:00
Tom Lane 208d0a2321 Fix logical errors in constraint exclusion: we cannot assume that a CHECK
constraint yields TRUE for every row of its table, only that it does not
yield FALSE (a NULL result isn't disallowed).  This breaks a couple of
implications that would be true in two-valued logic.  I had put in one such
mistake in an 8.2.5 patch: foo IS NULL doesn't refute a strict operator
on foo.  But there was another in the original 8.2 release: NOT foo doesn't
refute an expression whose truth would imply the truth of foo.
Per report from Rajesh Kumar Mallah.

To preserve the ability to do constraint exclusion with one partition
holding NULL values, extend relation_excluded_by_constraints() to check
for attnotnull flags, and add col IS NOT NULL expressions to the set of
constraints we hope to refute.
2008-01-12 00:11:39 +00:00
Tom Lane 89c0a87fda The original implementation of polymorphic aggregates didn't really get the
checking of argument compatibility right; although the problem is only exposed
with multiple-input aggregates in which some arguments are polymorphic and
some are not.  Per bug #3852 from Sokolov Yura.
2008-01-11 18:39:41 +00:00
Tom Lane df62977d00 Fix an old error in clause_selectivity: the default selectivity estimate
for unhandled clause types ought to be 0.5, not 1.0.  I fear I introduced
this silliness due to misreading the intent of the very-poorly-structured
code that was there when we inherited the file from Berkeley.  The lack
of sanity in this behavior was exposed by an example from Sim Zacks.
(Arguably this is a bug fix and should be back-patched, but I'm a bit
hesitant to introduce a possible planner behavior change in the back
branches; it might detune queries that worked acceptably in the past.)

While at it, make estimation for DistinctExpr do something marginally
realistic, rather than just defaulting.
2008-01-11 17:00:45 +00:00
Tom Lane 59fc64acee Fix a conceptual error in my patch of 2007-10-26 that avoided considering
clauseless joins of relations that have unexploited join clauses.  Rather
than looking at every other base relation in the query, the correct thing is
to examine the other relations in the "initial_rels" list of the current
make_rel_from_joinlist() invocation, because those are what we actually have
the ability to join against.  This might be a subset of the whole query in
cases where join_collapse_limit or from_collapse_limit or full joins have
prevented merging the whole query into a single join problem.  This is a bit
untidy because we have to pass those rels down through a new PlannerInfo
field, but it's necessary.  Per bug #3865 from Oleg Kharin.
2008-01-11 04:02:18 +00:00
Tom Lane e6a442c71b Restructure the shutdown procedure for the archiver process to allow it to
finish archiving everything (when there's no error), and to eliminate various
hazards as best we can.  This fixes a previous 8.3 patch that caused the
postmaster to kill and then restart the archiver during shutdown (!?).

The new behavior is that the archiver is allowed to run unmolested until
the bgwriter has exited; then it is sent SIGUSR2 to tell it to do a final
archiving cycle and quit.  We only SIGQUIT the archiver if we want a panic
stop; this is important since SIGQUIT will also be sent to any active
archive_command.  The postmaster also now doesn't SIGQUIT the stats collector
until the bgwriter is done, since the bgwriter can send stats messages in 8.3.
The postmaster will not exit until both the archiver and stats collector are
gone; this provides some defense (not too bulletproof) against conflicting
archiver or stats collector processes being started by a new postmaster
instance.  We continue the prior practice that the archiver will check
for postmaster death immediately before issuing any archive_command; that
gives some additional protection against conflicting archivers.

Also, modify the archiver process to notice SIGTERM and refuse to issue any
more archive commands if it gets it.  The postmaster doesn't ever send it
SIGTERM; we assume that any such signal came from init and is a notice of
impending whole-system shutdown.  In this situation it seems imprudent to try
to start new archive commands --- if they aren't extremely quick they're
likely to get SIGKILL'd by init.

All per discussion.
2008-01-11 00:54:09 +00:00
Bruce Momjian 77015b59aa vacuum_cost_limit has a minimum value of 1, not zero; update
postgresql.conf comment to match.
2008-01-10 02:50:01 +00:00
Tom Lane a9742f123c Remove incorrect (and ill-advised anyway) pfree's in pg_convert_from and
pg_convert_to.  Per bug #3866 from Andrew Gilligan.
2008-01-09 23:43:54 +00:00
Tom Lane ceb9360067 Fix CREATE INDEX CONCURRENTLY to not deadlock against an automatic or manual
VACUUM that is blocked waiting to get lock on the table being indexed.
Per report and fix suggestion from Greg Stark.
2008-01-09 21:52:36 +00:00
Tom Lane 6a6522529f Fix some planner issues found while investigating Kevin Grittner's report
of poorer planning in 8.3 than 8.2:

1. After pushing a constant across an outer join --- ie, given
"a LEFT JOIN b ON (a.x = b.y) WHERE a.x = 42", we can deduce that b.y is
sort of equal to 42, in the sense that we needn't fetch any b rows where
it isn't 42 --- loop to see if any additional deductions can be made.
Previous releases did that by recursing, but I had mistakenly thought that
this was no longer necessary given the EquivalenceClass machinery.

2. Allow pushing constants across outer join conditions even if the
condition is outerjoin_delayed due to a lower outer join.  This is safe
as long as the condition is strict and we re-test it at the upper join.

3. Keep the outer-join clause even if we successfully push a constant
across it.  This is *necessary* in the outerjoin_delayed case, but
even in the simple case, it seems better to do this to ensure that the
join search order heuristics will consider the join as reasonable to
make.  Mark such a clause as having selectivity 1.0, though, since it's
not going to eliminate very many rows after application of the constant
condition.

4. Tweak have_relevant_eclass_joinclause to report that two relations
are joinable when they have vars that are equated to the same constant.
We won't actually generate any joinclause from such an EquivalenceClass,
but again it seems that in such a case it's a good idea to consider
the join as worth costing out.

5. Fix a bug in select_mergejoin_clauses that was exposed by these
changes: we have to reject candidate mergejoin clauses if either side was
equated to a constant, because we can't construct a canonical pathkey list
for such a clause.  This is an implementation restriction that might be
worth fixing someday, but it doesn't seem critical to get it done for 8.3.
2008-01-09 20:42:29 +00:00
Neil Conway bbee1c5da8 Fix an omission in the outfuncs.c support for Agg nodes: the grpColIdx
and grpOperators fields were not emitted by _outAgg().
2008-01-09 08:46:44 +00:00