Commit Graph

7158 Commits

Author SHA1 Message Date
Neil Conway 406a942820 Minor code cleanup: remove a variable that was assigned to but never
subsequently referenced.

Found by: Coverity
Fixed by: Sean Chittenden
2005-02-23 23:27:54 +00:00
Neil Conway 3350b3740e This patch optimizes the md5_text() function (which is used to
implement the md5() SQL-level function). The old code did the
following:

1. de-toast the datum
2. convert it to a cstring via textout()
3. get the length of the cstring via strlen()

Since we are treating the datum context as a blob of binary data,
the latter two steps are unnecessary. Once the data has been
detoasted, we can just use it as-is, and derive its length from
the varlena metadata.

This patch improves some run-of-the-mill md5() computations by
just under 10% in my limited tests, and passes the regression tests.

I also noticed that md5_text() wasn't checking the return value
of md5_hash(); encountering OOM at precisely the right moment
could result in returning a random md5 hash. This patch corrects
that. A better fix would be to make md5_hash() only return on
success (and/or allocate via palloc()), but since it's used in
the frontend as well I don't see an easy way to do that.
2005-02-23 22:46:17 +00:00
Bruce Momjian 0542b1e2fe Use _() macro consistently rather than gettext(). Add translation
macros around strings that were missing them.
2005-02-22 04:43:23 +00:00
Tom Lane bb0aed591f Use SnapshotNow instead of SnapshotSelf for reading the catalogs
during flat-file writing.  The only difference is that SnapshotSelf
would consider tuples of the 'current command' within the current
transaction as valid, where SnapshotNow wouldn't.  We can eliminate
the need for this with one extra CommandCounterIncrement call before
we start reading the catalogs.
2005-02-20 22:02:19 +00:00
Tom Lane 4aefe75553 Remove some no-longer-needed kluges for bootstrapping, in particular
the AMI_OVERRIDE flag.  The fact that TransactionLogFetch treats
BootstrapTransactionId as always committed is sufficient to make
bootstrap work, and getting rid of extra tests in heavily used code
paths seems like a win.  The files produced by initdb are demonstrably
the same after this change.
2005-02-20 21:46:50 +00:00
Bruce Momjian 57e3b0c9db Rename macro to MAKE_EXPIRED_TUPLES_VISIBLE. 2005-02-20 15:01:42 +00:00
Bruce Momjian f6a7bef915 Fix MAKE_ALL_TUPLES_VISIBLE define. 2005-02-20 15:00:16 +00:00
Bruce Momjian 5845bfb8bf Move define MAKE_ALL_TUPLES_VISIBLE to a more logical place. 2005-02-20 14:57:47 +00:00
Bruce Momjian 59191b2245 I have added a define, MAKE_ALL_TUPLES_VISIBLE, to help people recover
deleted tuples. Of course it is only to be used for disaster recovery.
2005-02-20 04:56:00 +00:00
Tom Lane 3f9aec50e7 Flat file cleanup phase 2: make it work for pg_group. The flat group
file now identifies group members by usesysid not name; this avoids
needing to depend on SearchSysCache which we can't use during startup.
(The old representation was entirely broken anyway, since we did not
regenerate the file following RENAME USER.)  It's only a 95% solution
because if the group membership list is big enough to be toasted out
of line, we cannot read it during startup.  I think this will do for
the moment, until we have time to implement the planned pg_role
replacement for pg_group.
2005-02-20 04:45:59 +00:00
Tom Lane 60b2444cc3 Add code to prevent transaction ID wraparound by enforcing a safe limit
in GetNewTransactionId().  Since the limit value has to be computed
before we run any real transactions, this requires adding code to database
startup to scan pg_database and determine the oldest datfrozenxid.
This can conveniently be combined with the first stage of an attack on
the problem that the 'flat file' copies of pg_shadow and pg_group are
not properly updated during WAL recovery.  The code I've added to
startup resides in a new file src/backend/utils/init/flatfiles.c, and
it is responsible for rewriting the flat files as well as initializing
the XID wraparound limit value.  This will eventually allow us to get
rid of GetRawDatabaseInfo too, but we'll need an initdb so we can add
a trigger to pg_database.
2005-02-20 02:22:07 +00:00
Tom Lane 617d16f4ff New arrangement to always let the bgwriter do checkpoints broke
CHECKPOINT and some other commands in the context of a standalone
backend.  Allow a standalone backend to do its own checkpoints.
2005-02-19 23:16:15 +00:00
Tom Lane 9650d6c7e6 Ensure that the resolved datatype of any unknown Param is propagated
into the sub-SELECT targetlist when it appears in the context
INSERT INTO foo SELECT $1 ...  Per report from Abhijit Menon-Sen.
2005-02-19 19:33:08 +00:00
Tom Lane a8593a3463 Convert MemoryContextSwitchTo() into an inline function when using GCC. 2005-02-18 21:52:34 +00:00
Bruce Momjian 3110cd237c Update comment on VACUUM FULL.
Manfred Koizar
2005-02-15 03:50:07 +00:00
Bruce Momjian d73e0410bd Improve documentation of signal usage for HAVE_SIGPROCMASK and
non-HAVE_SIGPROCMASK cases in pqinitmask().
2005-02-14 23:02:35 +00:00
Bruce Momjian ad4f06aeb2 Improve documentation of signal usage for HAVE_SIGPROCMASK and
non-HAVE_SIGPROCMASK cases in pqinitmask().
2005-02-14 23:02:03 +00:00
Tom Lane db58ee5be9 ALTER LANGUAGE RENAME has never worked. Per Sergey Yatskevich. 2005-02-14 06:17:44 +00:00
Bruce Momjian 7c44e57331 Move plpgsql DEBUG from DEBUG2 to DEBUG1 because it is a user-requested
DEBUG.

Fix a few places where DEBUG1 crept in that should have been DEBUG2.
2005-02-12 23:53:42 +00:00
Neil Conway 975e27377a Adjust input routines for float4, float8 and oid to reject the empty string
as valid input (it was previously treated as 0). This input was deprecated
in 8.0 (and a warning was emitted). Regression tests updated.
2005-02-11 04:09:05 +00:00
Tom Lane 4db84f0880 Fix ANALYZE to accumulate some minimal statistics for an all-null column.
Per gripes from Mike Mascari and Bernd Heller.
2005-02-11 00:41:12 +00:00
Tom Lane 42599b322d Fix SPI cursor support to allow scanning the results of utility commands
that return tuples (such as EXPLAIN).  Per gripe from Michael Fuhr.
Side effect: fix an old bug that unintentionally disabled backward scans
for all SPI-created cursors.
2005-02-10 20:36:28 +00:00
Neil Conway 3df9abd1a5 ALTER TABLE ADD COLUMN exhibits a significant memory leak when adding a
column with a default expression. In that situation, we need to rewrite
the heap relation. To evaluate the new default expression, we use
ExecEvalExpr(); however, this can allocate memory in the current memory
context, and ATRewriteTable() does not switch out of the active portal's
heap memory context. The end result is a rather large memory leak (on
the order of gigabytes for a reasonably sized table).

This patch changes ATRewriteTable() to switch to the per-tuple memory
context before beginning the per-tuple loop. It also removes an explicit
heap_freetuple() in the loop, since that is no longer needed.

In an unrelated change, I noticed the code was scanning through the
attributes of the new tuple descriptor for each tuple of the old table.
I changed this to use precomputation, which should slightly speed up
the loop.

Thanks to steve@deefs.net for reporting the leak.
2005-02-09 23:17:26 +00:00
Tom Lane 2a6c032503 Repair CLUSTER failure after ALTER TABLE SET WITHOUT OIDS. Turns out
there are corner cases involving dropping toasted columns in which the
previous coding would fail, too: the new version of the table might not
have any TOAST table, but we'd still propagate possibly-wide values of
dropped columns forward.
2005-02-06 20:19:08 +00:00
Tom Lane 4f82112473 Fix bit-rot in ipc_test.c; it didn't include some stuff that pg_shmem.c
now depends on.
2005-02-05 20:07:16 +00:00
Tom Lane 12179c99b1 Marginal hack to merge adjacent ReleaseBuffer/ReadBuffer calls into
ReleaseAndReadBuffer during GIST index searches.  We already did this
in btree and rtree, might as well do it here too.
2005-02-05 19:38:58 +00:00
Neil Conway 11635c3f6f Refactor some duplicated code in lock.c: create UnGrantLock(), move code
from LockRelease() and LockReleaseAll() into it. From Heikki Linnakangas.
2005-02-04 02:04:53 +00:00
Tom Lane cc4f58f4cd Ensure that all details of the ARC algorithm are hidden within freelist.c.
This refactoring does not change any algorithms or data structures, just
remove visibility of the ARC datastructures from other source files.
2005-02-03 23:29:19 +00:00
Tom Lane ad476170e9 Improve performance of fmgr.c calling routines for cases with more than
two arguments.  Per suggestions from A. Ogawa.
2005-02-02 22:40:04 +00:00
Tom Lane fffb5819ca Adjust constant-folding of CASE expressions so that the simple comparison
form of CASE (eg, CASE 0 WHEN 1 THEN ...) can be constant-folded as it
was in 7.4.  Also, avoid constant-folding result expressions that are
certainly unreachable --- the former coding was a bit cavalier about this
and could generate unexpected results for all-constant CASE expressions.
Add regression test cases.  Per report from Vlad Marchenko.
2005-02-02 21:49:09 +00:00
Neil Conway 73f630500b Add support for temporary views, including documentation and regression
tests. Contributed by Koju Iijima, review from Neil Conway, Gavin Sherry
and Tom Lane.

Also, fix error in description of WITH CHECK OPTION clause in the CREATE
VIEW reference page: it should be "CASCADED", not "CASCADE".
2005-02-02 06:36:02 +00:00
Neil Conway f94197ef35 Fix a bug induced by the list-rewrite that resulted in incrementing the
command counter more than necessary. Per report from Michael Fuhr.
2005-02-01 23:28:40 +00:00
Tom Lane a3f945a1b2 Adjust estimate_num_groups() to not clamp per-relation group count
estimate to less than the number of values estimated for any one grouping
Var, as suggested by Manfred.  This is intuitively right, and what's
more it puts the plan choices in the subselect regression test back the
way they were before ...
2005-02-01 23:08:13 +00:00
Tom Lane 0a92c58b7c Sync inet formatting code with recent BIND releases. In particular,
fix bug with inconsistent selection of default mask length for
"class D" addresses.  Per report from Steve Atkins.
2005-02-01 00:59:09 +00:00
Tom Lane 875b0c62fa When dealing with multiple grouping columns coming from the same table,
clamp the estimated number of groups to table row count over 10, instead
of table row count; this reflects a heuristic that people probably won't
group over a near-unique set of columns, and the knowledge that we don't
currently have any way to estimate the correlation of the columns better
than guessing.  This change creates a trivial plan change in one of the
regression tests.
2005-01-28 20:34:27 +00:00
Tom Lane 0bf2587df4 Improve planner's estimation of the space needed for HashAgg plans:
look at the actual aggregate transition datatypes and the actual overhead
needed by nodeAgg.c, instead of using pessimistic round numbers.
Per a discussion with Michael Tiemann.
2005-01-28 19:34:28 +00:00
Tom Lane 5ae5e3bfe6 Check that aggregate creator has the right to execute the transition
functions of the aggregate, at both aggregate creation and execution times.
2005-01-27 23:42:18 +00:00
Neil Conway f76730e35a Small patch to move get_grosysid() from catalog/aclchk.c to
utils/cache/lsyscache.c where it can be used by other things.  Also
cleans up both get_usesysid() and get_grosysid() a bit. From Stephen
Frost.
2005-01-27 23:36:15 +00:00
Neil Conway a885ecd6ef Change heap_modifytuple() to require a TupleDesc rather than a
Relation. Patch from Alvaro Herrera, minor editorializing by
Neil Conway.
2005-01-27 23:24:11 +00:00
Neil Conway ffaaf27eb4 Provide a more descriptive error message when the return type of an SRF
does not match what the query expected. From Brendan Jurd, minor
editorializing by Neil Conway.
2005-01-27 06:36:42 +00:00
Tom Lane f07b9689c9 Generalize TRUNCATE to support truncating multiple tables in one
command.  This is useful because we can allow truncation of tables
referenced by foreign keys, so long as the referencing table is
truncated in the same command.

Alvaro Herrera
2005-01-27 03:19:37 +00:00
Tom Lane aba691b728 Close all cursors created during a failed subtransaction. This is needed
to avoid problems when a cursor depends on objects created or changed in
the same subtransaction.  We'd like to do better someday, but this seems
the only workable answer for 8.0.1.
2005-01-26 23:20:21 +00:00
Tom Lane bf7737a938 On Windows, set the postmaster executable's stack size to 4MB, so that
it agrees with the default value of max_stack_depth.
2005-01-26 21:55:26 +00:00
Tom Lane beaf5ae623 Fix ALTER TABLE ADD COLUMN so that constraints of domain types are
enforced properly when there is no explicit default value for the new
column.  Per report from Craig Perras.
2005-01-24 23:21:57 +00:00
Tom Lane ad538d8bcd Disallow LOAD to non-superusers. Per report from John Heasman. 2005-01-24 17:46:16 +00:00
Tom Lane 0ffe9f7946 Fix memory leak in rtdosplit, per report from Clive Page. 2005-01-24 02:47:26 +00:00
Tom Lane 94e4778a31 The result of a FULL or RIGHT join can't be assumed to be sorted by the
left input's sorting, because null rows may be inserted at various points.
Per report from Ferenc Lutischá¸n.
2005-01-23 02:21:36 +00:00
Neil Conway a341a96c01 Refactor transformExpr() by creating separate functions for most of the
expression types.
2005-01-19 23:45:24 +00:00
Neil Conway b4297c177c This patch makes some improvements to the rtree index implementation:
(1) Keep a pin on the scan's current buffer and mark buffer. This
avoids the need to do a ReadBuffer() for each tuple produced by the
scan. Since ReadBuffer() is expensive, this is a significant win.

(2) Convert a ReleaseBuffer(); ReadBuffer() pair into
ReleaseAndReadBuffer(). Surely not a huge win, but it saves a lock
acquire/release...

(3) Remove a bunch of duplicated code in rtget.c; make rtnext() handle
both the "initial result" and "subsequent result" cases.

(4) Add support for index tuple killing

(5) Remove rtscancache(): it is dead code, for the same reason that
gistscancache() is dead code (an index scan ought not be invoked with
NoMovementScanDirection).

The end result is about a 10% improvement in rtree index scan perf,
according to contrib/rtree_gist/bench.
2005-01-18 23:25:55 +00:00
Neil Conway 1f5299bc3f Replace the use of "0" with "NULL" where appropriate in dllist.c, for
good style and to satisfy sparse. From Alvaro Herrera.
2005-01-18 22:59:32 +00:00