summaryrefslogtreecommitdiff
path: root/src/backend/optimizer
AgeCommit message (Collapse)Author
2002-01-03Shouldn't try to copy null datums with datumCopy.Tom Lane
2001-12-10Suppress subquery pullup and pushdown when the subquery has anyTom Lane
set-returning functions in its target list. This ensures that we won't rewrite the query in a way that places set-returning functions into quals (WHERE clauses). Cf. bug reports from Joe Conway.
2001-11-30Repair failure to mark an inserted Materialize node with the appropriateTom Lane
extParam/locParam lists. Per bug #526.
2001-11-12If the inputs of a UNION/INTERSECT/EXCEPT construct all agree on theTom Lane
typmod of a particular column, mark the output with that same typmod, not -1 as formerly. -1 is still used if there is any disagreement. Part of response to bug#513.
2001-11-11In find_mergeclauses_for_pathkeys, it's okay to return multiple mergeTom Lane
clauses per path key. Indeed, we *must* do so or we will be unable to form a valid plan for FULL JOIN with overlapping join conditions, eg select * from a full join b on a.v1 = b.v1 and a.v2 = b.v2 and a.v1 = b.v2.
2001-11-11sort_inner_and_outer needs a check to ensure that it's consumed all theTom Lane
mergeclauses in RIGHT/FULL join cases, just like the other routines have. I'm not quite sure why I thought it didn't need one --- but Nick Fankhauser's recent bug report proves that it does.
2001-11-05New pgindent run with fixes suggested by Tom. Patch manually reviewed,Bruce Momjian
initdb/regression tests pass.
2001-11-02Add default expressions to INSERTs during planning, not during parseTom Lane
analysis. This keeps stored rules from prematurely absorbing default information, which is necessary for ALTER TABLE SET DEFAULT to work unsurprisingly with rules. See pgsql-bugs discussion 24-Oct-01.
2001-10-30Fix problems with subselects used in GROUP BY expressions, per gripeTom Lane
from Philip Warner. Side effect of change is that GROUP BY expressions will not be re-evaluated at multiple plan levels anymore, whereas this sometimes happened with old code.
2001-10-30Fix small problem Tom Lane found with pgindent run.Bruce Momjian
2001-10-28Another pgindent run. Fixes enum indenting, and improves #endifBruce Momjian
spacing. Also adds space for one-line comments.
2001-10-25pgindent run on all C files. Java run to follow. initdb/regressionBruce Momjian
tests pass.
2001-10-18Extend code that deduces implied equality clauses to detect whether aTom Lane
clause being added to a particular restriction-clause list is redundant with those already in the list. This avoids useless work at runtime, and (perhaps more importantly) keeps the selectivity estimation routines from generating too-small estimates of numbers of output rows. Also some minor improvements in OPTIMIZER_DEBUG displays.
2001-09-21Produce slightly saner-looking EXPLAIN output for a Result node.Tom Lane
2001-09-06Fix handling of pg_type.typdefault per bug report from Dave Blasby.Tom Lane
If there's anyone out there who's actually using datatype-defined default values, this will be an incompatible change in behavior ... but the old behavior was so broken that I doubt anyone was using it.
2001-08-21Restructure pg_opclass, pg_amop, and pg_amproc per previous discussions inTom Lane
pgsql-hackers. pg_opclass now has a row for each opclass supported by each index AM, not a row for each opclass name. This allows pg_opclass to show directly whether an AM supports an opclass, and furthermore makes it possible to store additional information about an opclass that might be AM-dependent. pg_opclass and pg_amop now store "lossy" and "haskeytype" information that we previously expected the user to remember to provide in CREATE INDEX commands. Lossiness is no longer an index-level property, but is associated with the use of a particular operator in a particular index opclass. Along the way, IndexSupportInitialize now uses the syscaches to retrieve pg_amop and pg_amproc entries. I find this reduces backend launch time by about ten percent, at the cost of a couple more special cases in catcache.c's IndexScanOK. Initial work by Oleg Bartunov and Teodor Sigaev, further hacking by Tom Lane. initdb forced.
2001-08-14Fix brokenness of nested EXCEPT/INTERSECT queries. prepunion was beingTom Lane
a tad sloppy about generating the targetlist for some nodes, by generating a tlist entry that claimed to be a constant when the value wasn't actually constant. This caused setrefs.c to do the wrong thing later on.
2001-08-06Modify partial-index-predicate applicability tester to test whetherTom Lane
clauses are equal(), before trying to match them up using btree opclass inference rules. This allows it to recognize many simple cases involving non-btree operations, for example 'x IS NULL'. Clean up code a little.
2001-07-31Further thought shows that has_distinct_on_clause() needs to take muchTom Lane
more care with resjunk tlist entries than it was doing. The original coding ignored resjunk entries entirely, but a resjunk entry that is in either the distinctClause or sortClause lists indicates that DISTINCT ON was used. It's important for ruleutils.c to get this right, else we may dump views using DISTINCT ON incorrectly.
2001-07-31Fix optimizer to not try to push WHERE clauses down into a sub-SELECT thatTom Lane
has a DISTINCT ON clause, per bug report from Anthony Wood. While at it, improve the DISTINCT-ON-clause recognizer routine to not be fooled by out- of-order DISTINCT lists.
2001-07-16Do not push down quals into subqueries that have LIMIT/OFFSET clauses,Tom Lane
since the added qual could change the set of rows that get past the LIMIT. Per discussion on pgsql-sql 7/15/01.
2001-07-16Partial indexes work again, courtesy of Martijn van Oosterhout.Tom Lane
Note: I didn't force an initdb, figuring that one today was enough. However, there is a new function in pg_proc.h, and pg_dump won't be able to dump partial indexes until you add that function.
2001-07-15Restructure index AM interface for index building and index tuple deletion,Tom Lane
per previous discussion on pghackers. Most of the duplicate code in different AMs' ambuild routines has been moved out to a common routine in index.c; this means that all index types now do the right things about inserting recently-dead tuples, etc. (I also removed support for EXTEND INDEX in the ambuild routines, since that's about to go away anyway, and it cluttered the code a lot.) The retail indextuple deletion routines have been replaced by a "bulk delete" routine in which the indexscan is inside the access method. I haven't pushed this change as far as it should go yet, but it should allow considerable simplification of the internal bookkeeping for deletions. Also, add flag columns to pg_am to eliminate various hardcoded tests on AM OIDs, and remove unused pg_am columns. Fix rtree and gist index types to not attempt to store NULLs; before this, gist usually crashed, while rtree managed not to crash but computed wacko bounding boxes for NULL entries (which might have had something to do with the performance problems we've heard about occasionally). Add AtEOXact routines to hash, rtree, and gist, all of which have static state that needs to be reset after an error. We discovered this need long ago for btree, but missed the other guys. Oh, one more thing: concurrent VACUUM is now the default.
2001-06-25Optimizer can now estimate selectivity of IS NULL, IS NOT NULL,Tom Lane
IS TRUE, etc, with some degree of verisimilitude. Split out selectivity support functions from builtins.h into a new header file selfuncs.h, so as to reduce the number of header files builtins.h must depend on. Fix a few missing inclusions exposed thereby. From Joe Conway, with some kibitzing from Tom Lane.
2001-06-19Add IS UNKNOWN, IS NOT UNKNOWN boolean tests, fix the existing booleanTom Lane
tests to return the correct results per SQL9x when given NULL inputs. Reimplement these tests as well as IS [NOT] NULL to have their own expression node types, instead of depending on special functions. From Joe Conway, with a little help from Tom Lane.
2001-06-17Make inet/cidr << and <<= operators indexable. From Alex Pilosov ↵Tom Lane
<alex@pilosoft.com>.
2001-06-11Make planner compute the number of hash buckets the same way thatTom Lane
nodeHash.c will compute it (by sharing code).
2001-06-10Fix thinko in hash cost estimation: average frequencyTom Lane
should be computed from total number of distinct values in whole relation, not # distinct values we expect to have after restriction clauses are applied.
2001-06-05Improve planning of OR indexscan plans: for quals likeTom Lane
WHERE (a = 1 or a = 2) and b = 42 and an index on (a,b), include the clause b = 42 in the indexquals generated for each arm of the OR clause. Essentially this is an index- driven conversion from CNF to DNF. Implementation is a bit klugy, but better than not exploiting the extra quals at all ...
2001-06-05Further work on making use of new statistics in planner. Adjust APIsTom Lane
of costsize.c routines to pass Query root, so that costsize can figure more things out by itself and not be so dependent on its callers to tell it everything it needs to know. Use selectivity of hash or merge clause to estimate number of tuples processed internally in these joins (this is more useful than it would've been before, since eqjoinsel is somewhat more accurate than before).
2001-06-03Mark many strings in backend not covered by elog for translation. Also,Peter Eisentraut
make strings in xlog.c look more like English and less like binary noise.
2001-05-20Modify optimizer data structures so that IndexOptInfo lists built forTom Lane
create_index_paths are not immediately discarded, but are available for subsequent planner work. This allows avoiding redundant syscache lookups in several places. Change interface to operator selectivity estimation procedures to allow faster and more flexible estimation. Initdb forced due to change of pg_proc entries for selectivity functions!
2001-05-14Current implementation of FOR UPDATE has no hope of working correctlyTom Lane
for relations on the nullable side of an OUTER JOIN. For now I think we'd better refuse such queries.
2001-05-09First cut at making indexscan cost estimates depend on correlationTom Lane
between index order and table order.
2001-05-09Cause planner to make use of average-column-width statistic that is nowTom Lane
collected by ANALYZE. Also, add some modest amount of intelligence to guesses that are used for varlena columns in the absence of any ANALYZE statistics. The 'width' reported by EXPLAIN is finally something less than totally bogus for varlena columns ... and, in consequence, hashjoin estimating should be a little better ...
2001-05-08Add newlines around debug output in optimizer showing total costs.Bruce Momjian
2001-05-07Rewrite of planner statistics-gathering code. ANALYZE is now available asTom Lane
a separate statement (though it can still be invoked as part of VACUUM, too). pg_statistic redesigned to be more flexible about what statistics are stored. ANALYZE now collects a list of several of the most common values, not just one, plus a histogram (not just the min and max values). Random sampling is used to make the process reasonably fast even on very large tables. The number of values and histogram bins collected is now user-settable via an ALTER TABLE command. There is more still to do; the new stats are not being used everywhere they could be in the planner. But the remaining changes for this project should be localized, and the behavior is already better than before. A not-very-related change is that sorting now makes use of btree comparison routines if it can find one, rather than invoking '<' twice.
2001-04-30Suppress pull-up of subqueries that are in the nullable side of an outerTom Lane
join. This is needed to avoid improper evaluation of expressions that should be nulled out, as in Victor Wagner's bug report of 4/27/01. Pretty ugly solution, but no time to do anything better for 7.1.1.
2001-04-25Tweak nestloop costing to weight restart cost of inner path more heavily.Tom Lane
Without this, it was making some pretty silly decisions about whether an expensive sub-SELECT should be the inner or outer side of a join...
2001-04-18Make the world safe for passing whole rows of views to functions. ThisTom Lane
already worked fine for whole rows of tables, but not so well for views...
2001-04-16Avoid reversing user-given order of WHERE clauses while attaching clausesTom Lane
to specific base or join RelOptInfo nodes during planning. This preserves the more-intuitive behavior of 7.0.* --- if you write an expensive clause (such as a sub-select) last, it should get evaluated last. Someday we ought to try to have some intelligence about the order of evaluation of WHERE clauses, but for now we should not override what the user wrote.
2001-04-15Prevent generation of invalid plans for RIGHT or FULL joins with multipleTom Lane
join clauses. The mergejoin executor wants all the join clauses to appear as merge quals, not as extra joinquals, for these kinds of joins. But the planner would consider plans in which partially-sorted input paths were used, leading to only some of the join clauses becoming merge quals. This is fine for inner/left joins, not fine for right/full joins.
2001-04-01Planner wasn't correctly handling adjustment of tuple_fraction for theTom Lane
case of LIMIT in a sub-select.
2001-03-27Quick hack to fix Oliver Elphick's problem with subselects in anTom Lane
inheritance query: make duplicate copies of subplans in adjust_inherited_attrs. When we redesign querytrees we really gotta do something about this issue of whether querytrees are read-only and can share substructure or not.
2001-03-27Repair pgindent damage to comments.Tom Lane
2001-03-23Fix comments that were mis-wrapped, for Tom Lane.Bruce Momjian
2001-03-22Remove dashes in comments that don't need them, rewrap with pgindent.Bruce Momjian
2001-03-22pgindent run. Make it all clean.Bruce Momjian
2001-03-08A subplan invoked within an aggregate function's argument shouldTom Lane
be allowed to receive ungrouped variables of the current query level. Curious that no one reported this bug before...
2001-02-16Clean up two rather nasty bugs in operator selection code.Tom Lane
1. If there is exactly one pg_operator entry of the right name and oprkind, oper() and related routines would return that entry whether its input type had anything to do with the request or not. This is just premature optimization: we shouldn't return the single candidate until after we verify that it really is a valid candidate, ie, is at least coercion-compatible with the given types. 2. oper() and related routines only promise a coercion-compatible result. Unfortunately, there were quite a few callers that assumed the returned operator is binary-compatible with the given datatype; they would proceed to call it without making any datatype coercions. These callers include sorting, grouping, aggregation, and VACUUM ANALYZE. In general I think it is appropriate for these callers to require an exact or binary-compatible match, so I've added a new routine compatible_oper() that only succeeds if it can find an operator that doesn't require any run-time conversions. Callers now call oper() or compatible_oper() depending on whether they are prepared to deal with type conversion or not. The upshot of these bugs is revealed by the following silliness in PL/Tcl's selftest: it creates an operator @< on int4, and then tries to use it to sort a char(N) column. The system would let it do that :-( (and evidently has done so since 6.3 :-( :-(). The result in this case was just a silly sort order, but the reverse combination would've provoked coredump from trying to dereference integers. With this fix you get more reasonable behavior: pltcl_test=# select * from T_pkey1 order by key1, key2 using @<; ERROR: Unable to identify an operator '@<' for types 'bpchar' and 'bpchar' You will have to retype this query using an explicit cast