summaryrefslogtreecommitdiff
path: root/src/backend/commands
Commit message (Collapse)AuthorAgeFilesLines
* Move BufferGetPageSize and BufferGetPage from bufpage.h to bufmgr.h. It isAlvaro Herrera2008-06-081-1/+2
| | | | | | | | | | more logical that way, and also it reduces the amount of unnecessary includes in bufpage.h, which is widely used. Zdenek Kotala. My previous patch to bufpage.h should also have credited him as author, but I forgot (sorry about that).
* ALTER AGGREGATE OWNER seems to have been missed by the last couple ofTom Lane2008-06-081-51/+3
| | | | | | | patches that dealt with object ownership. It wasn't updating pg_shdepend nor adjusting the aggregate's ACL. In 8.2 and up, fix this permanently by making it use AlterFunctionOwner_oid. In 8.1, the function code wasn't factored that way, so just copy and paste.
* Modify vacuum() to accept a single relation OID instead of a list (which weAlvaro Herrera2008-06-051-15/+18
| | | | always pass as a single element anyway.) In passing, fix an outdated comment.
* Coercion sanity check in ri_HashCompareOp failed to allow for enums, as perTom Lane2008-05-191-6/+6
| | | | | example from Rod Taylor. On reflection the correct test here is for any polymorphic type, not specifically ANYARRAY as in the original coding.
* Allow ALTER SEQUENCE START WITH to change the recorded start_value of aTom Lane2008-05-171-44/+36
| | | | | sequence. This seems an obvious extension to the recent patch, and it makes the code noticeably cleaner and more orthogonal.
* Add a RESTART (without parameter) option to ALTER SEQUENCE, allowing aTom Lane2008-05-162-30/+156
| | | | | | | | | | | | | | sequence to be reset to its original starting value. This requires adding the original start value to the set of parameters (columns) of a sequence object, which is a user-visible change with potential compatibility implications; it also forces initdb. Also add hopefully-SQL-compatible RESTART/CONTINUE IDENTITY options to TRUNCATE TABLE. RESTART IDENTITY executes ALTER SEQUENCE RESTART for all sequences "owned by" any of the truncated relations. CONTINUE IDENTITY is a no-op option. Zoltan Boszormenyi
* Add support for tracking call counts and elapsed runtime for user-definedTom Lane2008-05-152-3/+9
| | | | | | | | | | functions. Note that because this patch changes FmgrInfo, any external C functions you might be testing with 8.4 will need to be recompiled. Patch by Martin Pihlak, some editorialization by me (principally, removing tracking of getrusage() numbers)
* Move the "instr_time" typedef and associated macros into a new headerTom Lane2008-05-141-14/+2
| | | | | | | | | file portability/instr_time.h, and add a couple more macros to eliminate some abstraction leakage we formerly had. Also update psql to use this header instead of its own copy of nearly the same code. This commit in itself is just code cleanup and shouldn't change anything. It lays some groundwork for the upcoming function-stats patch, though.
* Improve snapshot manager by keeping explicit track of snapshots.Alvaro Herrera2008-05-129-42/+76
| | | | | | | | | | | | | There are two ways to track a snapshot: there's the "registered" list, which is used for arbitrary long-lived snapshots; and there's the "active stack", which is used for the snapshot that is considered "active" at any time. This also allows users of snapshots to stop worrying about snapshot memory allocation and freeing, and about using PG_TRY blocks around ActiveSnapshot assignment. This is all done automatically now. As a consequence, this allows us to reset MyProc->xmin when there are no more snapshots registered in the current backend, reducing the impact that long-running transactions have on VACUUM.
* Put back bufmgr.h in bufpage.h -- it is needed by some macros.Alvaro Herrera2008-05-121-2/+1
| | | | | Remove #include bufmgr.h from (most?) source files which already include bufpage.h.
* Restructure some header files a bit, in particular heapam.h, by removing someAlvaro Herrera2008-05-1214-15/+35
| | | | | | | | | | | | unnecessary #include lines in it. Also, move some tuple routine prototypes and macros to htup.h, which allows removal of heapam.h inclusion from some .c files. For this to work, a new header file access/sysattr.h needed to be created, initially containing attribute numbers of system columns, for pg_dump usage. While at it, make contrib ltree, intarray and hstore header files more consistent with our header style.
* Change the rules for inherited CHECK constraints to be essentially the sameTom Lane2008-05-093-265/+598
| | | | | | | | | | | | | | | | as those for inherited columns; that is, it's no longer allowed for a child table to not have a check constraint matching one that exists on a parent. This satisfies the principle of least surprise (rows selected from the parent will always appear to meet its check constraints) and eliminates some longstanding bogosity in pg_dump, which formerly had to guess about whether check constraints were really inherited or not. The implementation involves adding conislocal and coninhcount columns to pg_constraint (paralleling attislocal and attinhcount in pg_attribute) and refactoring various ALTER TABLE actions to be more like those for columns. Alex Hunsaker, Nikhil Sontakke, Tom Lane
* Fix REASSIGN OWNED so that it works on procedural languages too.Alvaro Herrera2008-04-291-5/+44
| | | | | | | The capability for changing language owners is new in 8.3, so that's how far back this needs to be backpatched. Per bug #4132 by Kirill Simonov.
* Fix ALTER TABLE ADD COLUMN ... PRIMARY KEY so that the new column is correctlyTom Lane2008-04-241-1/+6
| | | | | | | | | | checked to see if it's been initialized to all non-nulls. The implicit NOT NULL constraint was not being checked during the ALTER (in fact, not even if there was an explicit NOT NULL too), because ATExecAddColumn neglected to set the flag needed to make the test happen. This has been broken since the capability was first added, in 8.0. Brendan Jurd, per a report from Kaloyan Iliev.
* Allow float8, int8, and related datatypes to be passed by value on machinesTom Lane2008-04-211-2/+2
| | | | | | | | | | where Datum is 8 bytes wide. Since this will break old-style C functions (those still using version 0 calling convention) that have arguments or results of these types, provide a configure option to disable it and retain the old pass-by-reference behavior. Likewise, provide a configure option to disable the recently-committed float4 pass-by-value change. Zoltan Boszormenyi, plus configurability stuff by me.
* Modify the float4 datatype to be pass-by-val. Along the way, remove the lastAlvaro Herrera2008-04-181-2/+2
| | | | | | | | | | | | | | | uses of the long-deprecated float32 in contrib/seg; the definitions themselves are still there, but no longer used. fmgr/README updated to match. I added a CREATE FUNCTION to account for existing seg_center() code in seg.c too, and some tests for it and the neighbor functions. At the same time, remove checks for NULL which are not needed (because the functions are declared STRICT). I had to do some adjustments to contrib's btree_gist too. The choices for representation there are not ideal for changing the underlying types :-( Original patch by Zoltan Boszormenyi, with some adjustments by me.
* Fix rmtree() so that it keeps going after failure to remove any individualTom Lane2008-04-181-4/+4
| | | | | | file; the idea is that we should clean up as much as we can, even if there's some problem removing one file. Make the error messages a bit less misleading, too. In passing, const-ify function arguments.
* Fix two race conditions between the pending unlink mechanism that was put inHeikki Linnakangas2008-04-181-7/+9
| | | | | | | | | | | | | | | | | | | | | place to prevent reusing relation OIDs before next checkpoint, and DROP DATABASE. First, if a database was dropped, bgwriter would still try to unlink the files that the rmtree() call by the DROP DATABASE command has already deleted, or is just about to delete. Second, if a database is dropped, and another database is created with the same OID, bgwriter would in the worst case delete a relation in the new database that happened to get the same OID as a dropped relation in the old database. To fix these race conditions: - make rmtree() ignore ENOENT errors. This fixes the 1st race condition. - make ForgetDatabaseFsyncRequests forget unlink requests as well. - force checkpoint on in dropdb on all platforms Since ForgetDatabaseFsyncRequests() is asynchronous, the 2nd change isn't enough on its own to fix the problem of dropping and creating a database with same OID, but forcing a checkpoint on DROP DATABASE makes it sufficient. Per Tom Lane's bug report and proposal. Backpatch to 8.3.
* Cause EXPLAIN's VERBOSE option to print the target list (output column list)Tom Lane2008-04-181-26/+5
| | | | | | | | | | of each plan node, instead of its former behavior of dumping the internal representation of the plan tree. The latter display is still available for those who really want it (see debug_print_plan), but uses for it are certainly few and and far between. Per discussion. This patch also removes the explain_pretty_print GUC, which is obsoleted by the change.
* Add some code to EXPLAIN to show the targetlist (ie, output columns)Tom Lane2008-04-171-2/+57
| | | | | | of each plan node. For the moment this is debug support only and is not enabled unless EXPLAIN_PRINT_TLISTS is defined at build time. Later I'll see about the idea of letting EXPLAIN VERBOSE do it.
* Repair two places where SIGTERM exit could leave shared memory stateTom Lane2008-04-161-13/+32
| | | | | | | | | | | | | | corrupted. (Neither is very important if SIGTERM is used to shut down the whole database cluster together, but there's a problem if someone tries to SIGTERM individual backends.) To do this, introduce new infrastructure macros PG_ENSURE_ERROR_CLEANUP/PG_END_ENSURE_ERROR_CLEANUP that take care of transiently pushing an on_shmem_exit cleanup hook. Also use this method for createdb cleanup --- that wasn't a shared-memory-corruption problem, but SIGTERM abort of createdb could leave orphaned files lying around. Backpatch as far as 8.2. The shmem corruption cases don't exist in 8.1, and the createdb usage doesn't seem important enough to risk backpatching further.
* Push index operator lossiness determination down to GIST/GIN opclassTom Lane2008-04-141-5/+1
| | | | | | | | | | | "consistent" functions, and remove pg_amop.opreqcheck, as per recent discussion. The main immediate benefit of this is that we no longer need 8.3's ugly hack of requiring @@@ rather than @@ to test weight-using tsquery searches on GIN indexes. In future it should be possible to optimize some other queries better than is done now, by detecting at runtime whether the index match is exact or not. Tom Lane, after an idea of Heikki's, and with some help from Teodor.
* Phase 2 of project to make index operator lossiness be determined at runtimeTom Lane2008-04-131-1/+5
| | | | | | | | | | | | instead of plan time. Extend the amgettuple API so that the index AM returns a boolean indicating whether the indexquals need to be rechecked, and make that rechecking happen in nodeIndexscan.c (currently the only place where it's expected to be needed; other callers of index_getnext are just erroring out for now). For the moment, GIN and GIST have stub logic that just always sets the recheck flag to TRUE --- I'm hoping to get Teodor to handle pushing that control down to the opclass consistent() functions. The planner no longer pays any attention to amopreqcheck, and that catalog column will go away in due course.
* Teach ANALYZE to distinguish dead and in-doubt tuples, which it formerlyTom Lane2008-04-031-30/+110
| | | | | | | | | | | | | | | classed all as "dead"; also get it to count DEAD item pointers as dead rows, instead of ignoring them as before. Also improve matters so that tuples previously inserted or deleted by our own transaction are handled nicely: the stats collector's live-tuple and dead-tuple counts will end up correct after our transaction ends, regardless of whether we end in commit or abort. While there's more work that could be done to improve the counting of in-doubt tuples in both VACUUM and ANALYZE, this commit is enough to alleviate some known bad behaviors in 8.3; and the other stuff that's been discussed seems like research projects anyway. Pavan Deolasee and Tom Lane
* Revert my bad decision of about a year ago to make PortalDefineQueryTom Lane2008-04-022-3/+10
| | | | | | | | | | | | | | responsible for copying the query string into the new Portal. Such copying is unnecessary in the common code path through exec_simple_query, and in this case it can be enormously expensive because the string might contain a large number of individual commands; we were copying the entire, long string for each command, resulting in O(N^2) behavior for N commands. (This is the cause of bug #4079.) A second problem with it is that PortalDefineQuery really can't risk error, because if it elog's before having set up the Portal, we will leak the plancache refcount that the caller is trying to hand off to the portal. So go back to the design in which the caller is responsible for making sure everything is copied into the portal if necessary.
* Fix my brain fade in TRUNCATE triggers patch: can't release relcache refcountsTom Lane2008-03-311-3/+9
| | | | | | while EState still contains pointers to those relations. Exposed by the CLOBBER_CACHE_ALWAYS tests that buildfarm member jaguar is running (I knew those cycles would pay off...)
* Support statement-level ON TRUNCATE triggers. Simon RiggsTom Lane2008-03-282-2/+157
|
* Reduce the need for frontend programs to include "postgres.h" by refactoringTom Lane2008-03-275-5/+11
| | | | | | | | | | | | inclusions in src/include/catalog/*.h files. The main idea here is to push function declarations for src/backend/catalog/*.c files into separate headers, rather than sticking them into the corresponding catalog definition file as has been done in the past. This commit only carries out that idea fully for pg_proc, pg_type and pg_conversion, but that's enough for the moment --- if pg_list.h ever becomes unsafe for frontend code to include, we'll need to work a bit more. Zdenek Kotala
* Move the HTSU_Result enum definition into snapshot.h, to avoid includingAlvaro Herrera2008-03-2617-18/+35
| | | | | | tqual.h into heapam.h. This makes all inclusion of tqual.h explicit. I also sorted alphabetically the includes on some source files.
* Rename snapmgmt.c/h to snapmgr.c/h, for consistency with other files.Alvaro Herrera2008-03-2610-20/+20
| | | | Per complaint from Tom Lane.
* Separate snapshot management code from tuple visibility code, create aAlvaro Herrera2008-03-2610-11/+20
| | | | | | | | | | | | | snapmgmt.c file for the former. The header files have also been reorganized in three parts: the most basic snapshot definitions are now in a new file snapshot.h, and the also new snapmgmt.h keeps the definitions for snapmgmt.c. tqual.h has been reduced to the bare minimum. This patch is just a first step towards managing live snapshots within a transaction; there is no functionality change. Per my proposal to pgsql-patches on 20080318191940.GB27458@alvh.no-ip.org and subsequent discussion.
* Simplify and standardize conversions between TEXT datums and ordinary CTom Lane2008-03-259-44/+33
| | | | | | | | | | | | | | | | | | | | strings. This patch introduces four support functions cstring_to_text, cstring_to_text_with_len, text_to_cstring, and text_to_cstring_buffer, and two macros CStringGetTextDatum and TextDatumGetCString. A number of existing macros that provided variants on these themes were removed. Most of the places that need to make such conversions now require just one function or macro call, in place of the multiple notational layers that used to be needed. There are no longer any direct calls of textout or textin, and we got most of the places that were using handmade conversions via memcpy (there may be a few still lurking, though). This commit doesn't make any serious effort to eliminate transient memory leaks caused by detoasting toasted text objects before they reach text_to_cstring. We changed PG_GETARG_TEXT_P to PG_GETARG_TEXT_PP in a few places where it was easy, but much more could be done. Brendan Jurd and Tom Lane
* Add a new tuplestore API function, tuplestore_putvalues(). This isNeil Conway2008-03-251-5/+2
| | | | | | | identical to tuplestore_puttuple(), except it operates on arrays of Datums + nulls rather than a fully-formed HeapTuple. In several places that use the tuplestore API, this means we can avoid creating a HeapTuple altogether, saving a copy.
* Use new errdetail_log() mechanism to provide a less klugy way of reportingTom Lane2008-03-241-3/+6
| | | | | large numbers of dependencies on a role that couldn't be dropped. Per a comment from Alvaro.
* Fix various infelicities that have snuck into usage of errdetail() andTom Lane2008-03-241-5/+5
| | | | | | friends. Avoid double translation of some messages, ensure other messages are exposed for translation (and make them follow the style guidelines), avoid unsafe passing of an unpredictable message text as a format string.
* Add a couple of missing FreeQueryDesc calls. Noticed while testing aAlvaro Herrera2008-03-201-1/+3
| | | | framework to keep track of snapshots in use.
* Support ALTER TYPE RENAME. Petr JelinekTom Lane2008-03-193-27/+128
|
* We no longer need a snapshot set after opening the finishing transaction: thisAlvaro Herrera2008-03-191-10/+1
| | | | | is redundant because autovacuum now always analyzes a single table per transaction.
* Fix vacuum so that autovacuum is really not cancelled when doing an emergencyAlvaro Herrera2008-03-141-6/+17
| | | | | | job (i.e. to prevent Xid wraparound problems.) Bug reported by ITAGAKI Takahiro in 20080314103837.63D3.52131E4D@oss.ntt.co.jp, though I didn't use his patch.
* Fix LISTEN/NOTIFY race condition reported by Laurent Birtz, by postponingTom Lane2008-03-121-282/+339
| | | | | | | | | | | | | | | | | | pg_listener modifications commanded by LISTEN and UNLISTEN until the end of the current transaction. This allows us to hold the ExclusiveLock on pg_listener until after commit, with no greater risk of deadlock than there was before. Aside from fixing the race condition, this gets rid of a truly ugly kludge that was there before, namely having to ignore HeapTupleBeingUpdated failures during NOTIFY. There is a small potential incompatibility, which is that if a transaction issues LISTEN or UNLISTEN and then looks into pg_listener before committing, it won't see any resulting row insertion or deletion, where before it would have. It seems unlikely that anyone would be depending on that, though. This patch also disallows LISTEN and UNLISTEN inside a prepared transaction. That case had some pretty undesirable properties already, such as possibly allowing pg_listener entries to be made for PIDs no longer present, so disallowing it seems like a better idea than trying to maintain the behavior.
* Reduce memory consumption during VACUUM of large relations, by usingTom Lane2008-03-102-33/+34
| | | | | | | FSMPageData (6 bytes) instead of PageFreeSpaceInfo (8 or 16 bytes) for the temporary array of page-free-space information. Itagaki Takahiro
* Improve efficiency of attribute scanning in CopyReadAttributesCSV.Andrew Dunstan2008-03-081-50/+64
| | | | | | The loop is split into two parts, inside quotes, and outside quotes, saving some instructions in both parts. Heikki Linnakangas
* Improve error messages emitted when VACUUM and ANALYZE skip a table.Alvaro Herrera2008-02-202-8/+30
| | | | | Per gripe from Clodoaldo Pinto Neto on Message-ID: <a595de7a0801060326qbfc790ax2a60573043c2e2be@mail.gmail.com>
* Refactor backend makefiles to remove lots of duplicate codePeter Eisentraut2008-02-191-8/+2
|
* Repair VACUUM FULL bug introduced by HOT patch: the original way ofTom Lane2008-02-111-7/+26
| | | | | | | | | | | | | | | | | | | 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.
* Some variants of ALTER OWNER tried to make the "object" field of theTom Lane2008-02-071-5/+5
| | | | | | | | | | 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.
* Fix CREATE TABLE ... LIKE ... INCLUDING INDEXES to not cause unwantedTom Lane2008-02-072-4/+4
| | | | | | | | | | | 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.)
* Add checks to TRUNCATE, CLUSTER, and REINDEX to prevent performing theseTom Lane2008-01-302-60/+62
| | | | | | | | | | | | | | | | | | 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.
* Fix ALTER INDEX RENAME so that if the index belongs to a unique or primary keyTom Lane2008-01-171-3/+14
| | | | | | | | 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.
* Prevent CLUSTER from decreasing a relation's relfrozenxid. BugTom Lane2008-01-151-1/+8
| | | | introduced in rewrite to make CLUSTER MVCC-safe.