summaryrefslogtreecommitdiff
path: root/src/backend/utils/mmgr
Commit message (Collapse)AuthorAgeFilesLines
* Run pgindent on 9.2 source tree in preparation for first 9.3Bruce Momjian2012-06-101-1/+1
| | | | commit-fest.
* Run a portal's cleanup hook immediately when pushing it to FAILED state.Tom Lane2012-02-151-7/+46
| | | | | | | | | | | | | | | | This extends the changes of commit 6252c4f9e201f619e5eebda12fa867acd4e4200e so that we run the cleanup hook earlier for failure cases as well as success cases. As before, the point is to avoid an assertion failure from an Assert I added in commit a874fe7b4c890d1fe3455215a83ca777867beadd, which was meant to check that no user-written code can be called during portal cleanup. This fixes a case reported by Pavan Deolasee in which the Assert could be triggered during backend exit (see the new regression test case), and also prevents the possibility that the cleanup hook is run after portions of the portal's state have already been recycled. That doesn't really matter in current usage, but it foreseeably could matter in the future. Back-patch to 9.1 where the Assert in question was added.
* Update copyright notices for year 2012.Bruce Momjian2012-01-013-3/+3
|
* Redesign the plancache mechanism for more flexibility and efficiency.Tom Lane2011-09-162-3/+15
| | | | | | | | | | | | | | | | | | | Rewrite plancache.c so that a "cached plan" (which is rather a misnomer at this point) can support generation of custom, parameter-value-dependent plans, and can make an intelligent choice between using custom plans and the traditional generic-plan approach. The specific choice algorithm implemented here can probably be improved in future, but this commit is all about getting the mechanism in place, not the policy. In addition, restructure the API to greatly reduce the amount of extraneous data copying needed. The main compromise needed to make that possible was to split the initial creation of a CachedPlanSource into two steps. It's worth noting in particular that SPI_saveplan is now deprecated in favor of SPI_keepplan, which accomplishes the same end result with zero data copying, and no need to then spend even more cycles throwing away the original SPIPlan. The risk of long-term memory leaks while manipulating SPIPlans has also been greatly reduced. Most of this improvement is based on use of the recently-added MemoryContextSetParent primitive.
* Invent a new memory context primitive, MemoryContextSetParent.Tom Lane2011-09-111-19/+63
| | | | | | | This function will be useful for altering the lifespan of a context after creation (for example, by creating it under a transient context and later reparenting it to belong to a long-lived context). It costs almost no new code, since we can refactor what was there. Per my proposal of yesterday.
* Move Timestamp/Interval typedefs and basic macros into datatype/timestamp.h.Tom Lane2011-09-091-0/+1
| | | | | | | | | | | As per my recent proposal, this refactors things so that these typedefs and macros are available in a header that can be included in frontend-ish code. I also changed various headers that were undesirably including utils/timestamp.h to include datatype/timestamp.h instead. Unsurprisingly, this showed that half the system was getting utils/timestamp.h by way of xlog.h. No actual code changes here, just header refactoring.
* Cleanup for pull-up-isReset patch.Tom Lane2011-05-242-11/+12
| | | | | | | | Clear isReset before, not after, calling the context-specific alloc method, so as to preserve the option to do a tail call in MemoryContextAlloc (and also so this code isn't assuming that a failed alloc call won't have changed the context's state before failing). Fix missed direct invocation of reset method. Reformat a comment.
* Pull up isReset flag from AllocSetContext to MemoryContext struct. ThisHeikki Linnakangas2011-05-212-25/+18
| | | | | | | | | avoids the overhead of one function call when calling MemoryContextReset(), and it seems like the isReset optimization would be applicable to any new memory context we might invent in the future anyway. This buys back the overhead I just added in previous patch to always call MemoryContextReset() in ExecScan, even when there's no quals or projections.
* Improve aset.c's space management in contexts with small maxBlockSize.Tom Lane2011-05-021-8/+17
| | | | | | | | | | | | | | | | | The previous coding would allow requests up to half of maxBlockSize to be treated as "chunks", but when that actually did happen, we'd waste nearly half of the space in the malloc block containing the chunk, if no smaller requests came along to fill it. Avoid this scenario by limiting the maximum size of a chunk to 1/8th maxBlockSize, so that we can waste no more than 1/8th of the allocated space. This will not change the behavior at all for the default context size parameters (with large maxBlockSize), but it will change the behavior when using ALLOCSET_SMALL_MAXSIZE. In particular, there's no longer a need for spell.c to be overly concerned about the request size parameters it uses, so remove a rather unhelpful comment about that. Merlin Moncure, per an idea of Tom Lane's
* pgindent run before PG 9.1 beta 1.Bruce Momjian2011-04-102-9/+9
|
* Run a portal's cleanup hook immediately when pushing it to DONE state.Tom Lane2011-03-031-0/+26
| | | | | | | | | This works around the problem noted by Yamamoto Takashi in bug #5906, that there were code paths whereby we could reach AtCleanup_Portals with a portal's cleanup hook still unexecuted. The changes I made a few days ago were intended to prevent that from happening, and I think that on balance it's still a good thing to avoid, so I don't want to remove the Assert in AtCleanup_Portals. Hence do this instead.
* Refactor the executor's API to support data-modifying CTEs better.Tom Lane2011-02-271-99/+82
| | | | | | | | | | | | | | | | | | | | | | The originally committed patch for modifying CTEs didn't interact well with EXPLAIN, as noted by myself, and also had corner-case problems with triggers, as noted by Dean Rasheed. Those problems show it is really not practical for ExecutorEnd to call any user-defined code; so split the cleanup duties out into a new function ExecutorFinish, which must be called between the last ExecutorRun call and ExecutorEnd. Some Asserts have been added to these functions to help verify correct usage. It is no longer necessary for callers of the executor to call AfterTriggerBeginQuery/AfterTriggerEndQuery for themselves, as this is now done by ExecutorStart/ExecutorFinish respectively. If you really need to suppress that and do it for yourself, pass EXEC_FLAG_SKIP_TRIGGERS to ExecutorStart. Also, refactor portal commit processing to allow for the possibility that PortalDrop will invoke user-defined code. I think this is not actually necessary just yet, since the portal-execution-strategy logic forces any non-pure-SELECT query to be run to completion before we will consider committing. But it seems like good future-proofing.
* Stamp copyrights for year 2011.Bruce Momjian2011-01-013-3/+3
|
* Remove useless whitespace at end of linesPeter Eisentraut2010-11-231-1/+1
|
* Remove cvs keywords from all files.Magnus Hagander2010-09-205-5/+5
|
* Oops, in the previous fix to prevent a cursor that's being used in a FORHeikki Linnakangas2010-07-131-1/+12
| | | | | | | | | loop from being dropped, I missed subtransaction cleanup. Pinned portals must be dropped at subtransaction cleanup just as they are at main transaction cleanup. Per bug #5556 by Robert Walker. Backpatch to 8.0, 7.4 didn't have subtransactions.
* pgindent run for 9.0, second runBruce Momjian2010-07-061-4/+4
|
* The previous fix in CVS HEAD and 8.4 for handling the case where a cursorHeikki Linnakangas2010-07-051-5/+49
| | | | | | | | | | | being used in a PL/pgSQL FOR loop is closed was inadequate, as Tom Lane pointed out. The bug affects FOR statement variants too, because you can close an implicitly created cursor too by guessing the "<unnamed portal X>" name created for it. To fix that, "pin" the portal to prevent it from being dropped while it's being used in a PL/pgSQL FOR loop. Backpatch all the way to 7.4 which is the oldest supported version.
* pgindent run for 9.0Bruce Momjian2010-02-262-18/+18
|
* Force READY portals into FAILED state when a transaction or subtransactionTom Lane2010-02-181-48/+38
| | | | | | | | | | | is aborted, if they were created within the failed xact. This prevents ExecutorEnd from being run on them, which is a good idea because they may contain references to tables or other objects that no longer exist. In particular this is hazardous when auto_explain is active, but it's really rather surprising that nobody has seen an issue with this before. I'm back-patching this to 8.4, since that's the first version that contains auto_explain or an ExecutorEnd hook, but I wonder whether we shouldn't back-patch further.
* Support inlining various small performance-critical functions on non-GCCTom Lane2010-02-131-6/+5
| | | | | | | | | compilers, by applying a configure check to see if the compiler will accept an unreferenced "static inline foo ..." function without warnings. It is believed that such warnings are the only reason not to declare inlined functions in headers, if the compiler understands "inline" at all. Kurt Harriman
* Fix portalmem.c to avoid keeping a dangling pointer to a cached plan listTom Lane2010-01-181-9/+12
| | | | | | | after it's released its reference count for the cached plan. There are code paths that might try to examine the plan list before noticing that the portal is already in aborted state. Report and diagnosis by Tatsuo Ishii, though this isn't exactly his proposed patch.
* Update copyright for the year 2010.Bruce Momjian2010-01-023-6/+6
|
* Silence compiler warning on 64-bit windows buildMagnus Hagander2010-01-011-3/+3
|
* Previous fix for temporary file management broke returning a set fromHeikki Linnakangas2009-12-291-8/+4
| | | | | | | | | | | | | | PL/pgSQL function within an exception handler. Make sure we use the right resource owner when we create the tuplestore to hold returned tuples. Simplify tuplestore API so that the caller doesn't need to be in the right memory context when calling tuplestore_put* functions. tuplestore.c automatically switches to the memory context used when the tuplestore was created. Tuplesort was already modified like this earlier. This patch also removes the now useless MemoryContextSwitch calls from callers. Report by Aleksei on pgsql-bugs on Dec 22 2009. Backpatch to 8.1, like the previous patch that broke this.
* Speed up AllocSetFreeIndex, which is a significant cost in palloc and pfree,Tom Lane2009-07-211-9/+32
| | | | | | | | | | 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.
* Make backend header files C++ safePeter Eisentraut2009-07-161-2/+2
| | | | | | | | | | | This alters various incidental uses of C++ key words to use other similar identifiers, so that a C++ compiler won't choke outright. You still (probably) need extern "C" { }; around the inclusion of backend headers. based on a patch by Kurt Harriman <harriman@acm.org> Also add a script cpluspluscheck to check for C++ compatibility in the future. As of right now, this passes without error for me.
* 8.4 pgindent run, with new combined Linux/FreeBSD/MinGW typedef listBruce Momjian2009-06-111-3/+2
| | | | provided by Andrew.
* Update copyright for 2009.Bruce Momjian2009-01-013-6/+6
|
* Be more tense about not creating tuplestores with randomAccess = true unlessTom Lane2008-10-291-5/+13
| | | | | | | | backwards scan could actually happen. In particular, pass a flag to materialize-mode SRFs that tells them whether they need to require random access. In passing, also suppress unneeded backward-scan overhead for a Portal's holdStore tuplestore. Per my proposal about reducing I/O costs for tuplestores.
* Adjust things so that the query_string of a cached plan and the sourceText ofTom Lane2008-07-181-8/+10
| | | | | | | | | | | | | | | | | | | | | | | | a portal are never NULL, but reliably provide the source text of the query. It turns out that there was only one place that was really taking a short-cut, which was the 'EXECUTE' utility statement. That doesn't seem like a sufficiently critical performance hotspot to justify not offering a guarantee of validity of the portal source text. Fix it to copy the source text over from the cached plan. Add Asserts in the places that set up cached plans and portals to reject null source strings, and simplify a bunch of places that formerly needed to guard against nulls. There may be a few places that cons up statements for execution without having any source text at all; I found one such in ConvertTriggerToFK(). It seems sufficient to inject a phony source string in such a case, for instance ProcessUtility((Node *) atstmt, "(generated ALTER TABLE ADD FOREIGN KEY command)", NULL, false, None_Receiver, NULL); We should take a second look at the usage of debug_query_string, particularly the recently added current_query() SQL function. ITAGAKI Takahiro and Tom Lane
* If pnstrdup is going to be promoted to a generally available function,Tom Lane2008-06-281-13/+16
| | | | it ought to conform to the rest of palloc.h in using Size for sizes.
* Move wchar2char() and char2wchar() from tsearch into /mb to be easier toBruce Momjian2008-06-181-1/+13
| | | | | | use for other modules; also move pnstrdup(). Clean up code slightly.
* Restructure some header files a bit, in particular heapam.h, by removing someAlvaro Herrera2008-05-121-2/+1
| | | | | | | | | | | | 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.
* Add some debug support code to try to catch future mistakes in the area ofTom Lane2008-04-111-1/+52
| | | | | | | | | | input functions that include garbage bytes in their results. Provide a compile-time option RANDOMIZE_ALLOCATED_MEMORY to make palloc fill returned blocks with variable contents. This option also makes the parser perform conversions of literal constants twice and compare the results, emitting a WARNING if they don't match. (This is the code I used to catch the input function bugs fixed in the previous commit.) For the moment, I've set it to be activated automatically by --enable-cassert.
* Small wording improvements for source code READMEs.Bruce Momjian2008-04-091-4/+4
|
* Revert README cleanups.Bruce Momjian2008-04-091-4/+4
|
* Revert sentence removal from nickname in FAQ.Bruce Momjian2008-04-091-4/+4
|
* Revert my bad decision of about a year ago to make PortalDefineQueryTom Lane2008-04-021-8/+12
| | | | | | | | | | | | | | 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.
* Simplify and standardize conversions between TEXT datums and ordinary CTom Lane2008-03-251-4/+3
| | | | | | | | | | | | | | | | | | | | 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.
* Make source code READMEs more consistent. Add CVS tags to all README files.Bruce Momjian2008-03-201-12/+12
|
* Refactor backend makefiles to remove lots of duplicate codePeter Eisentraut2008-02-191-8/+2
|
* Update copyrights in source tree to 2008.Bruce Momjian2008-01-013-6/+6
|
* Re-run pgindent with updated list of typedefs. (Updated README shouldBruce Momjian2007-11-151-2/+2
| | | | avoid this problem in the future.)
* pgindent run for 8.3.Bruce Momjian2007-11-152-19/+20
|
* Remove an "optimization" I installed in 2001, to make repalloc() attempt toTom Lane2007-08-121-49/+10
| | | | | | | | | | | | enlarge the memory chunk in-place when it was feasible to do so. This turns out to not work well at all for scenarios involving repeated cycles of palloc/repalloc/pfree: the eventually freed chunks go into the wrong freelist for the next initial palloc request, and so we consume memory indefinitely. While that could be defended against, the number of cases where the optimization can still be applied drops significantly, and adjusting the initial sizes of StringInfo buffers makes it drop to almost nothing. Seems better to just remove the extra complexity. Per recent discussion and testing.
* Adjust the output of MemoryContextStats() so that the stats for aNeil Conway2007-08-072-7/+19
| | | | | | child memory contexts is indented two spaces to the right of its parent context. This should make it easier to deduce the memory context hierarchy from the output of MemoryContextStats().
* Rename DLLIMPORT macro to PGDLLIMPORT to avoid conflict withMagnus Hagander2007-07-251-4/+4
| | | | third party includes (like tcl) that define DLLIMPORT.
* mmgr README tweak: "either" is no longer correct. The previous wordingNeil Conway2007-05-291-2/+2
| | | | compared PortalContext with QueryContext, but the latter no longer exists.