summaryrefslogtreecommitdiff
path: root/src/backend/utils
AgeCommit message (Collapse)Author
2007-09-11Refactor from Heikki Linnakangas <heikki@enterprisedb.com>:Teodor Sigaev
* Defined new struct WordEntryPosVector that holds a uint16 length and a variable size array of WordEntries. This replaces the previous convention of a variable size uint16 array, with the first element implying the length. WordEntryPosVector has the same layout in memory, but is more readable in source code. The POSDATAPTR and POSDATALEN macros are still used, though it would now be more readable to access the fields in WordEntryPosVector directly. * Removed needfree field from DocRepresentation. It was always set to false. * Miscellaneous other commenting and refactoring
2007-09-11Rename recently-added pg_stat_activity column from txn_start to xact_start,Tom Lane
for consistency with other column names such as in pg_stat_database.
2007-09-11Arrange for SET LOCAL's effects to persist until the end of the current topTom Lane
transaction, unless rolled back or overridden by a SET clause for the same variable attached to a surrounding function call. Per discussion, these seem the best semantics. Note that this is an INCOMPATIBLE CHANGE: in 8.0 through 8.2, SET LOCAL's effects disappeared at subtransaction commit (leading to behavior that made little sense at the SQL level). I took advantage of the opportunity to rewrite and simplify the GUC variable save/restore logic a little bit. The old idea of a "tentative" value is gone; it was a hangover from before we had a stack. Also, we no longer need a stack entry for every nesting level, but only for those in which a variable's value actually changed.
2007-09-10Change void* opaque argument to Datum type, add argument'sTeodor Sigaev
name to PushFunction type definition. Per suggestion by Tome Lane <tgl@sss.pgh.pa.us>
2007-09-10Revert temporary patch that made synchronous_commit default to OFF.Tom Lane
2007-09-10Set the correct context (PGC_SIGHUP) for log_autovacuum, per ITAGAKI Takahiro.Tom Lane
Fix grammatical errors in its description.
2007-09-10Code review for GUC revert-values-if-removed-from-postgresql.conf patch;Tom Lane
and in passing, fix some bogosities dating from the custom_variable_classes patch. Fix guc-file.l to correctly check changes in custom_variable_classes that are attempted concurrently with additions/removals of custom variables, and don't allow the new setting to be applied in advance of checking it. Clean up messy and undocumented situation for string variables with NULL boot_val. Fix DefineCustomVariable functions to initialize boot_val correctly. Prevent find_option from inserting bogus placeholders for custom variables that are simply inquired about rather than being set.
2007-09-08Replace the former method of determining snapshot xmax --- to wit, callingTom Lane
ReadNewTransactionId from GetSnapshotData --- with a "latestCompletedXid" variable that is updated during transaction commit or abort. Since latestCompletedXid is written only in places that had to lock ProcArrayLock exclusively anyway, and is read only in places that had to lock ProcArrayLock shared anyway, it adds no new locking requirements to the system despite being cluster-wide. Moreover, removing ReadNewTransactionId from snapshot acquisition eliminates the need to take both XidGenLock and ProcArrayLock at the same time. Since XidGenLock is sometimes held across I/O this can be a significant win. Some preliminary benchmarking suggested that this patch has no effect on average throughput but can significantly improve the worst-case transaction times seen in pgbench. Concept by Florian Pflug, implementation by Tom Lane.
2007-09-07Improvements from Heikki Linnakangas <heikki@enterprisedb.com>Teodor Sigaev
- change the alignment requirement of lexemes in TSVector slightly. Lexeme strings were always padded to 2-byte aligned length to make sure that if there's position array (uint16[]) it has the right alignment. The patch changes that so that the padding is not done when there's no positions. That makes the storage of tsvectors without positions slightly more compact. - added some #include "miscadmin.h" lines I missed in the earlier when I added calls to check_stack_depth(). - Reimplement the send/recv functions, and added a comment above them describing the on-wire format. The CRC is now recalculated in tsquery as well per previous discussion.
2007-09-07Improving various checks by Heikki Linnakangas <heikki@enterprisedb.com>Teodor Sigaev
- add code to check that the query tree is well-formed. It was indeed possible to send malformed queries in binary mode, which produced all kinds of strange results. - make the left-field a uint32. There's no reason to arbitrarily limit it to 16-bits, and it won't increase the disk/memory footprint either now that QueryOperator and QueryOperand are separate structs. - add check_stack_depth() call to all recursive functions I found. Some of them might have a natural limit so that you can't force arbitrarily deep recursions, but check_stack_depth() is cheap enough that seems best to just stick it into anything that might be a problem.
2007-09-07Refactoring by Heikki Linnakangas <heikki@enterprisedb.com> withTeodor Sigaev
small editorization by me - Brake the QueryItem struct into QueryOperator and QueryOperand. Type was really the only common field between them. QueryItem still exists, and is used in the TSQuery struct as before, but it's now a union of the two. Many other changes fell from that, like separation of pushval_asis function into pushValue, pushOperator and pushStop. - Moved some structs that were for internal use only from header files to the right .c-files. - Moved tsvector parser to a new tsvector_parser.c file. Parser code was about half of the size of tsvector.c, it's also used from tsquery.c, and it has some data structures of its own, so it seems better to separate it. Cleaned up the API so that TSVectorParserState is not accessed from outside tsvector_parser.c. - Separated enumerations (#defines, really) used for QueryItem.type field and as return codes from gettoken_query. It was just accidental code sharing. - Removed ParseQueryNode struct used internally by makepol and friends. push*-functions now construct QueryItems directly. - Changed int4 variables to just ints for variables like "i" or "array size", where the storage-size was not significant.
2007-09-05Implement lazy XID allocation: transactions that do not modify any databaseTom Lane
rows will normally never obtain an XID at all. We already did things this way for subtransactions, but this patch extends the concept to top-level transactions. In applications where there are lots of short read-only transactions, this should improve performance noticeably; not so much from removal of the actual XID-assignments, as from reduction of overhead that's driven by the rate of XID consumption. We add a concept of a "virtual transaction ID" so that active transactions can be uniquely identified even if they don't have a regular XID. This is a much lighter-weight concept: uniqueness of VXIDs is only guaranteed over the short term, and no on-disk record is made about them. Florian Pflug, with some editorialization by Tom.
2007-09-04Provide for binary input/output of enums, to fix complaint from Merlin Moncure.Andrew Dunstan
This just provides text values, we're not exposing the underlying Oid representation. Catalog version bumped.
2007-09-03Support SET FROM CURRENT in CREATE/ALTER FUNCTION, ALTER DATABASE, ALTER ROLE.Tom Lane
(Actually, it works as a plain statement too, but I didn't document that because it seems a bit useless.) Unify VariableResetStmt with VariableSetStmt, and clean up some ancient cruft in the representation of same.
2007-09-03Implement function-local GUC parameter settings, as per recent discussion.Tom Lane
There are still some loose ends: I didn't do anything about the SET FROM CURRENT idea yet, and it's not real clear whether we are happy with the interaction of SET LOCAL with function-local settings. The documentation is a bit spartan, too.
2007-09-01Since sort_bounded_heap makes state changes that should be madeTom Lane
regardless of the number of tuples involved, it's incorrect to skip it when memtupcount = 1; the number of cycles saved is minuscule anyway. An alternative solution would be to pull the state changes out to the call site in tuplesort_performsort, but keeping them near the corresponding changes in make_bounded_heap seems marginally cleaner. Noticed by Greg Stark.
2007-08-31Apply a band-aid fix for the problem that 8.2 and up completely misestimateTom Lane
the number of rows likely to be produced by a query such as SELECT * FROM t1 LEFT JOIN t2 USING (key) WHERE t2.key IS NULL; What this is doing is selecting for t1 rows with no match in t2, and thus it may produce a significant number of rows even if the t2.key table column contains no nulls at all. 8.2 thinks the table column's null fraction is relevant and thus may estimate no rows out, which results in terrible plans if there are more joins above this one. A proper fix for this will involve passing much more information about the context of a clause to the selectivity estimator functions than we ever have. There's no time left to write such a patch for 8.3, and it wouldn't be back-patchable into 8.2 anyway. Instead, put in an ad-hoc test to defeat the normal table-stats-based estimation when an IS NULL test is evaluated at an outer join, and just use a constant estimate instead --- I went with 0.5 for lack of a better idea. This won't catch every case but it will catch the typical ways of writing such queries, and it seems unlikely to make things worse for other queries.
2007-08-31Install check_stack_depth() protection in two recursive tsqueryTom Lane
processing routines. Per Heikki.
2007-08-30Fix int8mul so that overflow check is applied correctly for INT64_IS_BUSTEDTom Lane
case, per Florian Pflug. Not back-patched since it's unclear that anyone but me still cares ...
2007-08-29Relax permissions checks on dbsize functions, per discussion. Revert out allTom Lane
checks for individual-table-size functions, since anyone in the database could get approximate values from pg_class.relpages anyway. Allow database-size to users with CONNECT privilege for the target database (note that this is granted by default). Allow tablespace-size if the user has CREATE privilege on the tablespace (which is *not* granted by default), or if the tablespace is the default tablespace for the current database (since we treat that as implicitly allowing use of the tablespace).
2007-08-27Remove the 'not in' operator (!!=). This was a hangover from BerkeleyTom Lane
days that was obsolete the moment we had IN (SELECT ...) capability. It's arguably a security hole since it applied no permissions check to the table it searched, and since it was never documented anywhere, removing it seems more appropriate than fixing it.
2007-08-27Restrict pg_relation_size to relation owner, pg_database_size to DB owner,Tom Lane
and pg_tablespace_size to superusers. Perhaps we could weaken the first case to just require SELECT privilege, but that doesn't work for the other cases, so use ownership as the common concept.
2007-08-27Make currtid() functions require SELECT privileges on the target table.Tom Lane
While it's not clear that TID linkage info is of any great use to a nefarious user, it's certainly unexpected that these functions wouldn't insist on read privileges.
2007-08-23Reduce memory requirements for writing CSVlogs, so it will work with aboutAndrew Dunstan
the same amount of memory in ErrorContext as standard logs.
2007-08-22Simplify the syntax of CREATE/ALTER TEXT SEARCH DICTIONARY by treating theTom Lane
init options of the template as top-level options in the syntax. This also makes ALTER a bit easier to use, since options can be replaced individually. I also made these statements verify that the tmplinit method will accept the new settings before they get stored; in the original coding you didn't find out about mistakes until the dictionary got invoked. Under the hood, init methods now get options as a List of DefElem instead of a raw text string --- that lets tsearch use existing options-pushing code instead of duplicating functionality.
2007-08-21Remove extraneous semicolon --- buildfarm member bear, for one,Tom Lane
objects to it.
2007-08-21Fix cash_mul_int4 and cash_div_int4 for overenthusiastic substitutionTom Lane
of int64 for int32. Per reports from Merlin Moncure and Andrew Chernow.
2007-08-21Fix money type's send/receive functions to conform to recent wideningTom Lane
of the datatype to int64. Per Andrew Chernow.
2007-08-21Fix potential access-off-the-end-of-memory in varbit_out(): it fetched theTom Lane
byte after the last full byte of the bit array, regardless of whether that byte was part of the valid data or not. Found by buildfarm testing. Thanks to Stefan Kaltenbrunner for nailing down the cause.
2007-08-21Fix a small 64-bit problem in tsearch patch.Tom Lane
2007-08-21Tsearch2 functionality migrates to core. The bulk of this work is byTom Lane
Oleg Bartunov and Teodor Sigaev, but I did a lot of editorializing, so anything that's broken is probably my fault. Documentation is nonexistent as yet, but let's land the patch so we can get some portability testing done.
2007-08-19Provide for logfiles in machine readable CSV format. In consequence, renameAndrew Dunstan
redirect_stderr to logging_collector. Original patch from Arul Shaji, subsequently modified by Greg Smith, and then heavily modified by me.
2007-08-15Repair problems occurring when multiple RI updates have to be done to the sameTom Lane
row within one query: we were firing check triggers before all the updates were done, leading to bogus failures. Fix by making the triggers queued by an RI update go at the end of the outer query's trigger event list, thereby effectively making the processing "breadth-first". This was indeed how it worked pre-8.0, so the bug does not occur in the 7.x branches. Per report from Pavel Stehule.
2007-08-14Fix oversight in async-commit patch: there were some places in heapam.cTom Lane
that still thought they could set HEAP_XMAX_COMMITTED immediately after seeing the other transaction commit. Make them use the same logic as tqual.c does to determine if the hint bit can be set yet.
2007-08-13TEMPORARILY make synchronous_commit default to OFF, so that we can get moreTom Lane
thorough testing of async-commit mode from the buildfarm. This patch MUST get reverted before 8.3 release!
2007-08-12Remove an "optimization" I installed in 2001, to make repalloc() attempt toTom Lane
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.
2007-08-11Avoid memory leakage across successive calls of regexp_matches() orTom Lane
regexp_split_to_table() within a single query. This is only a partial solution, as it turns out that with enough matches per string these functions can also tickle a repalloc() misbehavior. But fixing that is a topic for a separate patch.
2007-08-11Code review for regexp_matches/regexp_split patch. Refactor to avoid assumingTom Lane
that cached compiled patterns will still be there when the function is next called. Clean up looping logic, thereby fixing bug identified by Pavel Stehule. Share setup code between the two functions, add some comments, and avoid risky mixing of int and size_t variables. Clean up the documentation a tad, and accept all the flag characters mentioned in table 9-19 rather than just a subset.
2007-08-08Fix thinko in multi-autovac-workers code: validity checks made byTom Lane
GUC assign hooks are supposed to be made whether doit is true or not.
2007-08-07Adjust the output of MemoryContextStats() so that the stats for aNeil Conway
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().
2007-08-04Fix up bad layout of some comments (probably pg_indent's fault), andTom Lane
improve grammar a tad. Per Greg Stark.
2007-08-04Fix crash caused by log_timezone patch if we attempt to emit any elog messagesTom Lane
between the setting of log_line_prefix and the setting of log_timezone. We can't realistically set log_timezone any earlier than we do now, so the best behavior seems to be to use GMT zone if any timestamps are to be logged during early startup. Create a dummy zone variable with a minimal definition of GMT (in particular it will never know about leap seconds), so that we can set it up without reference to any external files.
2007-08-04Switch over to using the src/timezone functions for formatting timestampsTom Lane
displayed in the postmaster log. This avoids Windows-specific problems with localized time zone names that are in the wrong encoding, and generally seems like a good idea to forestall other potential platform-dependent issues. To preserve the existing behavior that all backends will log in the same time zone, create a new GUC variable log_timezone that can only be changed on a system-wide basis, and reference log-related calculations to that zone instead of the TimeZone variable. This fixes the issue reported by Hiroshi Saito that timestamps printed by xlog.c startup could be improperly localized on Windows. We still need a simpler patch for that problem in the back branches, however.
2007-08-02Move session_start out of MyProcPort stucture and make it a global called ↵Andrew Dunstan
MyStartTime, so that we will be able to create a cookie for all processes for CSVlogs. It is set wherever MyProcPid is set. Take the opportunity to remove the now unnecessary session-only restriction on the %s and %c escapes in log_line_prefix.
2007-08-02Fix a memory leak in tuplestore_end(). Unlikely to be significant duringNeil Conway
normal operation, but tuplestore_end() ought to do what it claims to do.
2007-08-01Support an optional asynchronous commit mode, in which we don't flush WALTom Lane
before reporting a transaction committed. Data consistency is still guaranteed (unlike setting fsync = off), but a crash may lose the effects of the last few transactions. Patch by Simon, some editorialization by Tom.
2007-07-31Fix security definer functions with polymorphic arguments. This case hasTom Lane
never worked because fmgr_security_definer() neglected to pass the fn_expr information through. Per report from Viatcheslav Kalinin.
2007-07-25Arrange to put TOAST tables belonging to temporary tables into special schemasTom Lane
named pg_toast_temp_nnn, alongside the pg_temp_nnn schemas used for the temp tables themselves. This allows low-level code such as the relcache to recognize that these tables are indeed temporary, which enables various optimizations such as not WAL-logging changes and using local rather than shared buffers for access. Aside from obvious performance benefits, this provides a solution to bug #3483, in which other backends unexpectedly held open file references to temporary tables. The scheme preserves the property that TOAST tables are not in any schema that's normally in the search path, so they don't conflict with user table names. initdb forced because of changes in system view definitions.
2007-07-25Rename DLLIMPORT macro to PGDLLIMPORT to avoid conflict withMagnus Hagander
third party includes (like tcl) that define DLLIMPORT.
2007-07-24Create a new dedicated Postgres process, "wal writer", which exists to writeTom Lane
and fsync WAL at convenient intervals. For the moment it just tries to offload this work from backends, but soon it will be responsible for guaranteeing a maximum delay before asynchronously-committed transactions will be flushed to disk. This is a portion of Simon Riggs' async-commit patch, committed to CVS separately because a background WAL writer seems like it might be a good idea independently of the async-commit feature. I rebased walwriter.c on bgwriter.c because it seemed like a more appropriate way of handling signals; while the startup/shutdown logic in postmaster.c is more like autovac because we want walwriter to quit before we start the shutdown checkpoint.