summaryrefslogtreecommitdiff
path: root/src/backend/optimizer
Commit message (Collapse)AuthorAgeFilesLines
* Fix relative path references so that make knowns which dependencies referPeter Eisentraut2000-08-316-33/+22
| | | | | to one another. Sort out builddir vs srcdir variable namings. Remove some now obsoleted make variables.
* SQL-language functions are now callable in ordinary fmgr contexts ...Tom Lane2000-08-242-7/+4
| | | | | | for example, an SQL function can be used in a functional index. (I make no promises about speed, but it'll work ;-).) Clean up and simplify handling of functions returning sets.
* Move pg_checkretval out of the planner (where it never belonged) intoTom Lane2000-08-211-135/+1
| | | | | | pg_proc.c (where it's actually used). Fix it to correctly handle tlists that contain resjunk target items, and improve error messages. This addresses bug reported by Krupnikov 6-July-00.
* fmgr interface mopup work. Use new DatumGetBool and BoolGetDatumTom Lane2000-08-211-17/+23
| | | | | | | | macros where appropriate (the code used to have several different ways of doing that, including Int32, Int8, UInt8, ...). Remove last few references to float32 and float64 typedefs --- it's all float4/float8 now. The typedefs themselves should probably stay in c.h for a release or two, though, to avoid breaking user-written C functions.
* Clean up handling of variable-free qual clauses. System now does theTom Lane2000-08-136-93/+293
| | | | | | | | | | right thing with variable-free clauses that contain noncachable functions, such as 'WHERE random() < 0.5' --- these are evaluated once per potential output tuple. Expressions that contain only Params are now candidates to be indexscan quals --- for example, 'var = ($1 + 1)' can now be indexed. Cope with RelabelType nodes atop potential indexscan variables --- this oversight prevents 7.0.* from recognizing some potentially indexscanable situations.
* Remove 'func_tlist' from Func expression nodes, likewise 'param_tlist'Tom Lane2000-08-088-41/+27
| | | | | | | | from Param nodes, per discussion a few days ago on pghackers. Add new expression node type FieldSelect that implements the functionality where it's actually needed. Clean up some other unused fields in Func nodes as well. NOTE: initdb forced due to change in stored expression trees for rules.
* Clean up bogosities in use of random(3) and srandom(3) --- do not assumeTom Lane2000-08-071-3/+3
| | | | | | | that RAND_MAX applies to them, since it doesn't. Instead add a config.h parameter MAX_RANDOM_VALUE. This is currently set at 2^31-1 but could be auto-configured if that ever proves necessary. Also fix some outright bugs like calling srand() where srandom() is appropriate.
* Copy sub-Query nodes to avoid trouble when same sub-Query is linked toTom Lane2000-08-061-4/+15
| | | | | | | | multiple times in the parsetree (can happen in COALESCE or BETWEEN contexts, for example). This is a pretty grotty solution --- it will do for now, but perhaps we can do better when we redesign querytrees. What we need is a consistent policy about whether querytrees should be considered read-only structures or not ...
* More functions updated to new fmgr style --- money, name, tid datatypes.Tom Lane2000-08-031-2/+2
| | | | | We're reaching the mopup stage here (good thing too, this is getting tedious).
* Remove <values.h> inclusions, no-longer-needed MAXINT definitions.Tom Lane2000-07-281-4/+1
|
* Make planner safe for recursive calls --- needed for cases whereTom Lane2000-07-273-54/+32
| | | | eval_const_expressions tries to simplify an SQL function.
* Arrange to free planning memory (or most of it, anyway) at completionTom Lane2000-07-271-5/+50
| | | | of planning. This should reduce memory requirements for large joins.
* When dealing with OR-of-ANDs quals, extract multiple subclauses of an ANDTom Lane2000-07-261-26/+54
| | | | | | to use with a multiple-key index. Formerly we would only extract clauses that had to do with the first key of the index, which was correct but didn't exploit the index fully.
* Update comments.Tom Lane2000-07-251-4/+6
|
* Deduce equality constraints that are implied by transitivity ofTom Lane2000-07-244-156/+393
| | | | | | | | mergejoinable qual clauses, and add them to the query quals. For example, WHERE a = b AND b = c will cause us to add AND a = c. This is necessary to ensure that it's safe to use these variables as interchangeable sort keys, which is something 7.0 knows how to do. Should provide a useful improvement in planning ability, too.
* Make update lists like 'UPDATE tab SET foo[1] = bar, foo[3] = baz'Tom Lane2000-07-221-49/+101
| | | | | | | | work as expected. THe underlying implementation is essentially 'SET foo = array_set(foo, 1, bar)', so we have to turn the items into nested invocations of array_set() to make it work correctly. Side effect: we now complain about 'UPDATE tab SET foo = bar, foo = baz' which is illegal per SQL92 but we didn't detect it before.
* Repair parallel make in backend tree (and make it really parallel).Peter Eisentraut2000-07-131-18/+16
| | | | Make Gen_fmgrtab.sh reasonably robust against concurrent invocation.
* Planner did the wrong thing with index-scan-backward plans: generatedTom Lane2000-07-131-3/+3
| | | | | | them, but forgot to attach relevant restriction clauses, so that the plan represented a scan over the whole table with restrictions applied as qpquals not indexquals. Another day, another bug...
* Remove a bunch of unused configure tests, in particular cases wherePeter Eisentraut2000-07-121-4/+1
| | | | | | | | | | * the result is not recorded anywhere * the result is not used anywhere * the result is only used in some places, whereas others have been getting away with it * the result is used improperly Also make command line options handling a little better (e.g., --disable-locale, while redundant, should really still *dis*able).
* First stage of reclaiming memory in executor by resetting short-termTom Lane2000-07-123-15/+29
| | | | | | memory contexts. Currently, only leaks in expressions executed as quals or projections are handled. Clean up some old dead cruft in executor while at it --- unused fields in state nodes, that sort of thing.
* Update textin() and textout() to new fmgr style. This is just phaseTom Lane2000-07-052-11/+18
| | | | | one of updating the whole text datatype, but there are so dang many calls of these two routines that it seems worth a separate commit.
* First phase of memory management rewrite (see backend/utils/mmgr/READMETom Lane2000-06-282-49/+23
| | | | | | | | | | | | | for details). It doesn't really do that much yet, since there are no short-term memory contexts in the executor, but the infrastructure is in place and long-term contexts are handled reasonably. A few long- standing bugs have been fixed, such as 'VACUUM; anything' in a single query string crashing. Also, out-of-memory is now considered a recoverable ERROR, not FATAL. Eliminate a large amount of crufty, now-dead code in and around memory management. Fix problem with holding off SIGTRAP, SIGSEGV, etc in postmaster and backend startup.
* Make inheritance planning logic a little simpler and clearer,Tom Lane2000-06-203-112/+139
| | | | hopefully even a little faster.
* Reimplement nodeMaterial to use a temporary BufFile (or even memory, if theTom Lane2000-06-185-207/+137
| | | | | | | | | | materialized tupleset is small enough) instead of a temporary relation. This was something I was thinking of doing anyway for performance, and Jan says he needs it for TOAST because he doesn't want to cope with toasting noname relations. With this change, the 'noname table' support in heap.c is dead code, and I have accordingly removed it. Also clean up 'noname' plan handling in planner --- nonames are either sort or materialize plans, and it seems less confusing to handle them separately under those names.
* Fix performance problems with pg_index lookups (see, for example,Tom Lane2000-06-171-26/+34
| | | | | | | | | | discussion of 5/19/00). pg_index is now searched for indexes of a relation using an indexscan. Moreover, this is done once and cached in the relcache entry for the relation, in the form of a list of OIDs for the indexes. This list is used by the parser and executor to drive lookups in the pg_index syscache when they want to know the properties of the indexes. Net result: index information will be fully cached for repetitive operations such as inserts.
* Clean up #include's.Bruce Momjian2000-06-153-4/+7
|
* Cause inheritance patch to meet minimum coding standards (no gccTom Lane2000-06-092-9/+15
| | | | warnings).
* Inheritance overhaul by Chris Bitmead <chris@bitmead.com>Bruce Momjian2000-06-092-2/+40
|
* Mark functions as static and ifdef NOT_USED as appropriate.Bruce Momjian2000-06-085-10/+21
|
* Repair bug reported by ldm@apartia.com: Append nodes, which don'tTom Lane2000-06-041-39/+52
| | | | | | | | | | | | actually use their targetlist, are given a targetlist that is just a pointer to the first appended plan's targetlist. This is OK, but what is not OK is that any sub-select expressions in said tlist were being entered in the subPlan lists of both the Append and the first appended plan. That led to two startup and two shutdown calls for the same plan node at exec time, which led to crashes. Fix is to not generate a list of subPlans for an Append node. Same problem and fix apply to other node types that don't have a real, functioning targetlist: Material, Sort, Unique, Hash.
* Tweak recognition of range-clause pairs so that 'var > $1 AND var < $2'Tom Lane2000-05-311-37/+46
| | | | | | | (ie, parameters instead of consts) will be treated as a range query. We do not know the actual selectivities involved, but it seems like a good idea to use a smaller estimate than we would use for two unrelated inequalities.
* The heralded `Grand Unified Configuration scheme' (GUC)Peter Eisentraut2000-05-316-445/+86
| | | | | | | | | | | | | That means you can now set your options in either or all of $PGDATA/configuration, some postmaster option (--enable-fsync=off), or set a SET command. The list of options is in backend/utils/misc/guc.c, documentation will be written post haste. pg_options is gone, so is that pq_geqo config file. Also removed were backend -K, -Q, and -T options (no longer applicable, although -d0 does the same as -Q). Added to configure an --enable-syslog option. changed all callers from TPRINTF to elog(DEBUG)
* Third round of fmgr updates: eliminate calls using fmgr() andTom Lane2000-05-302-36/+36
| | | | | fmgr_faddr() in favor of new-style calls. Lots of cleanup of sloppy casts to use XXXGetDatum and DatumGetXXX ...
* Remove unused include files. Do not touch /port or includes used by defines.Bruce Momjian2000-05-3019-70/+19
|
* Generated header files parse.h and fmgroids.h are now copied intoTom Lane2000-05-295-15/+5
| | | | | the src/include tree, so that -I backend is no longer necessary anywhere. Also, clean up some bit rot in contrib tree.
* Constant-expression simplifier now knows how to simplify strict functionsTom Lane2000-05-281-13/+47
| | | | | that have at least one constant-NULL input, even if other inputs are not constants.
* First round of changes for new fmgr interface. fmgr itself and theTom Lane2000-05-283-4/+8
| | | | | | | key call sites are changed, but most called functions are still oldstyle. An exception is that the PL managers are updated (so, for example, NULL handling now behaves as expected in plperl and plpgsql functions). NOTE initdb is forced due to added column in pg_proc.
* Fix problem in which sloppily-coded test in ExecInitIndexScan wouldTom Lane2000-05-231-14/+19
| | | | | | | | | | | | think that both sides of indexqual look like index keys. An example is create table inside (f1 float8 primary key); create table outside (g1 float8, g2 float8); select * from inside,outside where f1 = atan2(g1+1, g2); ERROR: ExecInitIndexScan: both left and right ops are rel-vars (note that failure is potentially platform-dependent). Solution is a cleanup I had had in mind to make anyway: functional index keys should be represented as Var nodes in the fixed indexqual, just like regular index keys.
* Repair problem noted by Elphick: make_rels_by_joins failed to handleTom Lane2000-04-271-2/+51
| | | | | | | | cases where joinclauses were present but some joins have to be made by cartesian-product join anyway. An example is SELECT * FROM a,b,c WHERE (a.f1 + b.f2 + c.f3) = 0; Even though all the rels have joinclauses, we must join two of them in cartesian style before we can use the join clause...
* Repair coredump seen when a view refers to an inheritance groupTom Lane2000-04-181-8/+3
| | | | | | (SELECT FROM table*). Cause was reference to 'eref' field of an RTE, which is null in an RTE loaded from a stored rule parsetree. There wasn't any good reason to be touching the refname anyway...
* Correct oversight in hashjoin cost estimation: nodeHash sizes its hashTom Lane2000-04-181-5/+11
| | | | | | table for an average of NTUP_PER_BUCKET tuples/bucket, but cost_hashjoin was assuming a target load of one tuple/bucket. This was causing a noticeable underestimate of hashjoin costs.
* Add new selectivity estimation functions for pattern-matching operatorsTom Lane2000-04-161-255/+22
| | | | | | | | (LIKE and regexp matches). These are not yet referenced in pg_operator, so by default the system will continue to use eqsel/neqsel. Also, tweak convert_to_scalar() logic so that common prefixes of strings are stripped off, allowing better accuracy when all strings in a table share a common prefix.
* get_relattval() should treat a NULL constant as a non-constant expression,Tom Lane2000-04-161-2/+3
| | | | | | since it has no way to indicate to its caller that the constant is actually NULL. This prevents coredump in cases like WHERE textfield < null::text;
* Repair bug reported by Wickstrom: backend would crash if WHERE clauseTom Lane2000-04-142-11/+51
| | | | | | | | | | | | contained a sub-SELECT nested within an AND/OR tree that cnfify() thought it should rearrange. Same physical sub-SELECT node could end up linked into multiple places in resulting expression tree. This is harmless for most node types, but not for SubLink. Repair bug by making physical copies of subexpressions that get logically duplicated by cnfify(). Also, tweak the heuristic that decides whether it's a good idea to do cnfify() --- we don't really want that to happen when it would cause multiple copies of a subselect to be generated, I think.
* Ye-old pgindent run. Same 4-space tabs.Bruce Momjian2000-04-1226-1551/+1926
|
* Further tweaking of indexscan cost estimates.Tom Lane2000-04-091-3/+6
|
* Fix extremely nasty little bug observed when a sub-SELECT appears inTom Lane2000-04-044-125/+157
| | | | | | | | | | | | | | | | | | | | WHERE in a place where it can be part of a nestloop inner indexqual. As the code stood, it put the same physical sub-Plan node into both indxqual and indxqualorig of the IndexScan plan node. That confused later processing in the optimizer (which expected that tracing the subPlan list would visit each subplan node exactly once), and would probably have blown up in the executor if the planner hadn't choked first. Fix by making the 'fixed' indexqual be a complete deep copy of the original indexqual, rather than trying to share nodes below the topmost operator node. This had further ramifications though, because we were making the aforesaid list of sub-Plan nodes during SS_process_sublinks which is run before construction of the 'fixed' indexqual, meaning that the copy of the sub-Plan didn't show up in that list. Fix by rearranging logic so that the sub-Plan list is built by the final set_plan_references pass, not in SS_process_sublinks. This may sound like a mess, but it's actually a good deal cleaner now than it was before, because we are no longer dependent on the assumption that planning will never make a copy of a sub-Plan node.
* Tweak indexscan cost estimation: round estimated # of tuples visited upTom Lane2000-03-301-5/+5
| | | | | | | to next integer. Previously, if selectivity was small, we could compute very tiny scan cost on the basis of estimating that only 0.001 tuple would be fetched, which is silly. This naturally led to some rather silly plans...
* Save a few cycles in simple cases: no need to call cost_sort() when thereTom Lane2000-03-241-8/+8
| | | | is no presorted path to compare with.
* A little further tweaking of the range-query selectivity logic:Tom Lane2000-03-231-13/+25
| | | | | | | to avoid undue sensitivity to roundoff error, believe that a zero or slightly negative range estimate should represent a small positive selectivity, rather than falling back on a generic default estimate.