summaryrefslogtreecommitdiff
path: root/src/backend/optimizer
AgeCommit message (Collapse)Author
2006-03-14Improve parser so that we can show an error cursor position for errorsTom Lane
during parse analysis, not only errors detected in the flex/bison stages. This is per my earlier proposal. This commit includes all the basic infrastructure, but locations are only tracked and reported for errors involving column references, function calls, and operators. More could be done later but this seems like a good set to start with. I've also moved the ReportSyntaxErrorPosition logic out of psql and into libpq, which should make it available to more people --- even within psql this is an improvement because warnings weren't handled by ReportSyntaxErrorPosition.
2006-03-07Remove the stub support we had for UNION JOIN; per discussion, this isTom Lane
not likely ever to be implemented seeing it's been removed from SQL2003. This allows getting rid of the 'filter' version of yylex() that we had in parser.c, which should save at least a few microseconds in parsing.
2006-03-05Update copyright for 2006. Update scripts.Bruce Momjian
2006-02-19Improve tuplesort.c to support variable merge order. The original codingTom Lane
with fixed merge order (fixed number of "tapes") was based on obsolete assumptions, namely that tape drives are expensive. Since our "tapes" are really just a couple of buffers, we can have a lot of them given adequate workspace. This allows reduction of the number of merge passes with consequent savings of I/O during large sorts. Simon Riggs with some rework by Tom Lane
2006-02-13Fix qual_is_pushdown_safe to not try to push down quals involving a whole-rowTom Lane
Var referencing the subselect output. While this case could possibly be made to work, it seems not worth expending effort on. Per report from Magnus Naeslund(f).
2006-02-06Improve the tests to see if ScalarArrayOpExpr is strict. Original codingTom Lane
would basically punt in all cases for 'foo <> ALL (array)', which resulted in a performance regression for NOT IN compared to what we were doing in 8.1 and before. Per report from Pavel Stehule.
2006-02-05Improve my initial, rather hacky implementation of joins to appendTom Lane
relations: fix the executor so that we can have an Append plan on the inside of a nestloop and still pass down outer index keys to index scans within the Append, then generate such plans as if they were regular inner indexscans. This avoids the need to evaluate the outer relation multiple times.
2006-02-04Fix constraint exclusion to work in inherited UPDATE/DELETE queriesTom Lane
... in fact, it will be applied now in any query whatsoever. I'm still a bit concerned about the cycles that might be expended in failed proof attempts, but given that CE is turned off by default, it's the user's choice whether to expend those cycles or not. (Possibly we should change the simple bool constraint_exclusion parameter to something more fine-grained?)
2006-02-03Teach planner to convert simple UNION ALL subqueries into append relations,Tom Lane
thereby sharing code with the inheritance case. This puts the UNION-ALL-view approach to partitioned tables on par with inheritance, so far as constraint exclusion is concerned: it works either way. (Still need to update the docs to say so.) The definition of "simple UNION ALL" is a little simpler than I would like --- basically the union arms can only be SELECT * FROM foo --- but it's good enough for partitioned-table cases.
2006-01-31Restructure planner's handling of inheritance. Rather than processingTom Lane
inheritance trees on-the-fly, which pretty well constrained us to considering only one way of planning inheritance, expand inheritance sets during the planner prep phase, and build a side data structure that can be consulted later to find which RTEs are members of which inheritance sets. As proof of concept, use the data structure to plan joins against inheritance sets more efficiently: we can now use indexes on the set members in inner-indexscan joins. (The generated plans could be improved further, but it'll take some executor changes.) This data structure will also support handling UNION ALL subqueries in the same way as inheritance sets, but that aspect of it isn't finished yet.
2006-01-29When building a bitmap scan, must copy the bitmapqualorig expression treeTom Lane
to avoid sharing substructure with the lower-level indexquals. This is currently only an issue if there are SubPlans in the indexquals, which is uncommon but not impossible --- see bug #2218 reported by Nicholas Vinen. We use the same kluge for indexqual vs indexqualorig in the index scans themselves ... would be nice to clean this up someday.
2006-01-29Fix Assert that's no longer correct now that RowCompareExpr is indexable.Tom Lane
2006-01-29Fix code that checks to see if an index can be considered to match the query'sTom Lane
requested sort order. It was assuming that build_index_pathkeys always generates a pathkey per index column, which was not true if implied equality deduction had determined that two index columns were effectively equated to each other. Simplest fix seems to be to install an option that causes build_index_pathkeys to support this behavior as well as the original one. Per report from Brian Hirt.
2006-01-26Clean up the INET-vs-CIDR situation. Get rid of the internal is_cidr flagTom Lane
and rely exclusively on the SQL type system to tell the difference between the types. Prevent creation of invalid CIDR values via casting from INET or set_masklen() --- both of these operations now silently zero any bits to the right of the netmask. Remove duplicate CIDR comparison operators, letting the type rely on the INET operators instead.
2006-01-25Allow row comparisons to be used as indexscan qualifications.Tom Lane
This completes the project to upgrade our handling of row comparisons.
2006-01-14Add selectivity-calculation code for RowCompareExpr nodes. Simplistic,Tom Lane
but a lot better than nothing at all ...
2006-01-05Make all command-line options of postmaster and postgres the same. SeePeter Eisentraut
http://archives.postgresql.org/pgsql-hackers/2006-01/msg00151.php for the complete plan.
2005-12-28Implement SQL-compliant treatment of row comparisons for < <= > >= casesTom Lane
(previously we only did = and <> correctly). Also, allow row comparisons with any operators that are in btree opclasses, not only those with these specific names. This gets rid of a whole lot of indefensible assumptions about the behavior of particular operators based on their names ... though it's still true that IN and NOT IN expand to "= ANY". The patch adds a RowCompareExpr expression node type, and makes some changes in the representation of ANY/ALL/ROWCOMPARE SubLinks so that they can share code with RowCompareExpr. I have not yet done anything about making RowCompareExpr an indexable operator, but will look at that soon. initdb forced due to changes in stored rules.
2005-12-20Teach planner how to rearrange join order for some classes of OUTER JOIN.Tom Lane
Per my recent proposal. I ended up basing the implementation on the existing mechanism for enforcing valid join orders of IN joins --- the rules for valid outer-join orders are somewhat similar.
2005-12-06In a nestloop inner indexscan, it's OK to use pushed-down baserestrictinfoTom Lane
clauses even if it's an outer join. This is a corner case since such clauses could only arise from weird OUTER JOIN ON conditions, but worth fixing. Per example from Ron at cheapcomplexdevices.com.
2005-11-30Tweak choose_bitmap_and() heuristics in the light of example provided in bugTom Lane
#2075: consider an index redundant if any of its index conditions were already used, rather than if all of them were. Also, make the selectivity comparison a bit fuzzy, so that very small differences in estimated selectivities don't skew the results.
2005-11-27Teach predtest.c how to reason about ScalarArrayOpExpr clauses as thoughTom Lane
they were broken-out AND or OR lists. The least grotty way to do this seemed to be to set up a general mechanism for handling nodes as though they were ANDs or ORs. There's no other immediate use for it, but perhaps we might want to use the mechanism someday for things like BETWEEN SYMMETRIC.
2005-11-26Teach tid-scan code to make use of "ctid = ANY (array)" clauses, so thatTom Lane
"ctid IN (list)" will still work after we convert IN to ScalarArrayOpExpr. Make some minor efficiency improvements while at it, such as ensuring that multiple TIDs are fetched in physical heap order. And fix EXPLAIN so that it shows what's really going on for a TID scan.
2005-11-26Teach push_nots() how to negate a ScalarArrayOpExpr. In passing, saveTom Lane
a palloc or two in the OpExpr case.
2005-11-25Teach planner and executor to handle ScalarArrayOpExpr as an indexableTom Lane
qualification when the underlying operator is indexable and useOr is true. That is, indexkey op ANY (ARRAY[...]) is effectively translated into an OR combination of one indexscan for each array element. This only works for bitmap index scans, of course, since regular indexscans no longer support OR'ing of scans. There are still some loose ends to clean up before changing 'x IN (list)' to translate as a ScalarArrayOpExpr; for instance predtest.c ought to be taught about it. But this gets the basic functionality in place.
2005-11-22Re-run pgindent, fixing a problem where comment lines after a blankBruce Momjian
comment line where output as too long, and update typedefs for /lib directory. Also fix case where identifiers were used as variable names in the backend, but as typedefs in ecpg (favor the backend for indenting). Backpatch to 8.1.X.
2005-11-17Make SQL arrays support null elements. This commit fixes the core arrayTom Lane
functionality, but I still need to make another pass looking at places that incidentally use arrays (such as ACL manipulation) to make sure they are null-safe. Contrib needs work too. I have not changed the behaviors that are still under discussion about array comparison and what to do with lower bounds.
2005-11-16make_restrictinfo() failed to attach the specified required_relids toTom Lane
its result when the clause was an OR clause. Brain fade exposed by example from Sebastian BÎck.
2005-11-14Restore the former RestrictInfo field valid_everywhere (but invert the flagTom Lane
sense and rename to "outerjoin_delayed" to more clearly reflect what it means). I had decided that it was redundant in 8.1, but the folly of this is exposed by a bug report from Sebastian Böck. The place where it's needed is to prevent orindxpath.c from cherry-picking arms of an outer-join OR clause to form a relation restriction that isn't actually legal to push down to the relation scan level. There may be some legal cases that this forbids optimizing, but we'd need much closer analysis to determine it.
2005-11-03Thinking further, it seems we had better also copy down resorigtbl/resorigcolTom Lane
to ensure that SubqueryScan elimination doesn't change the behavior of reporting of original column sources.
2005-11-03Fix the recently-added code that eliminates unnecessary SubqueryScan nodesTom Lane
from a finished plan tree. We have to copy the output column names (resname fields) from the SubqueryScan down to its child plan node; else, if this is the topmost level of the plan, the wrong column names will be delivered to the client. Per bug #2017 reported by Jolly Chen.
2005-10-25Fix longstanding bug that would sometimes let the planner generate a bad planTom Lane
for an outer join; symptom is bogus error "RIGHT JOIN is only supported with merge-joinable join conditions". Problem was that select_mergejoin_clauses did its tests in the wrong order. We need to force left join not right join for a merge join when there are non-mergeable join clauses; but the test for this only accounted for mergejoinability of the clause operator, and not whether the left and right Vars were of the proper relations. Per report from Jean-Pierre Pelletier.
2005-10-19Fix oversight in recent changes to enable the 'physical tlist'Tom Lane
optimization for subquery and function scan nodes: we can't just do it unconditionally, we still have to check whether there is any need for a whole-row Var. I had been thinking that these node types couldn't have any system columns, which is true, but that loop is also checking for attno zero, ie, whole-row Var. Fix comment to not be so misleading. Per test case from Richard Huxton.
2005-10-15Standard pgindent run for 8.1.Bruce Momjian
2005-10-13Don't try to remove duplicate OR-subclauses in create_bitmap_subplan andTom Lane
make_restrictinfo_from_bitmapqual. The likelihood of finding duplicates seems much less than in the AND-subclause case, and the cost much higher, because OR lists with hundreds or even thousands of subclauses are not uncommon. Per discussion with Ilia Kantor and andrew@supernews.
2005-10-11Fix oversight in 8.0 modification of RestrictInfo data structures.Tom Lane
A RestrictInfo representing an OR clause now contains two versions of the contained expression, one with sub-RestrictInfos and one without. clause_selectivity() should descend to the version with sub-RestrictInfos so that it has a chance of caching its results for the OR's sub-clauses. Failing to do so resulted in redundant planner effort.
2005-10-06Fix oversight in indexscan plan creation. I recently added code to useTom Lane
predicate_implied_by() to detect redundant filter conditions, but forgot that predicate_implied_by() assumes its first argument contains only immutable functions. Add a check to guarantee that. Also, test to see if filter conditions can be discarded because they are redundant with the predicate of a partial index.
2005-10-05Make set_function_size_estimates() marginally smarter: per originalTom Lane
comment, it can at least test whether the expression returns set.
2005-09-28Repair planning bug introduced in 7.4: outer-join ON clauses that referencedTom Lane
only the inner-side relation would be considered as potential equijoin clauses, which is wrong because the condition doesn't necessarily hold above the point of the outer join. Per test case from Kevin Grittner (bug#1916).
2005-09-24Clean up possibly-uninitialized-variable warnings reported by gcc 4.x.Tom Lane
2005-09-22Fix bug introduced into indexable_outerrelids() by an ill-consideredTom Lane
"optimization". When we find a potentially useful joinclause, we have to add all its other required_relids to the result, not only the other clause_relids. They are different in the case of a joinclause whose applicability has to be postponed due to outer join. We have to include the extra rels because otherwise, after best_inner_indexscan masks the join rels with index_outer_relids, it will always fail to find the joinclause as applicable. Per report from Husam Tomeh.
2005-09-21optimize_minmax_aggregates() neglected to check for inherited tables.Tom Lane
Per report from Cesar Paipilla.
2005-09-05Back out prior patch and instead just suppress SubqueryScan eliminationTom Lane
when there are extra resjunk columns in the child node. I found some additional cases involving Append nodes that weren't handled by the prior patch, and it's not clear how to fix them in the same way without breaking inheritance cases. So the prudent path seems to be to narrow the scope of the optimization.
2005-09-05For non-projecting plan node types such as Limit, set_plan_referencesTom Lane
has to recopy the input plan node's targetlist if it removes a SubqueryScan node just below the non-projecting node. For simplicity I made it recopy always. Per bug report from Allan Wang and Michael Fuhr.
2005-08-28Tweak nodeBitmapAnd to stop evaluating sub-plan scans if it finds it'sTom Lane
got an empty bitmap after any step; the remaining subplans can no longer affect the result. Per a suggestion from Ilia Kantor.
2005-08-27cost_agg really ought to charge something per output tuple; else thereTom Lane
are cases where it appears to have zero run cost.
2005-08-27Change the division of labor between grouping_planner and query_plannerTom Lane
so that the latter estimates the number of groups that grouping will produce. This is needed because it is primarily query_planner that makes the decision between fast-start and fast-finish plans, and in the original coding it was unable to make more than a crude rule-of-thumb choice when the query involved grouping. This revision helps us make saner choices for queries like SELECT ... GROUP BY ... LIMIT, as in a recent example from Mark Kirkwood. Also move the responsibility for canonicalizing sort_pathkeys and group_pathkeys into query_planner; this information has to be available anyway to support the first change, and doing it this way lets us get rid of compare_noncanonical_pathkeys entirely.
2005-08-27Fix two separate bugs in setrefs.c. set_subqueryscan_references needsTom Lane
to copy the whole plan tree before invoking adjust_plan_varnos(); else if there is any multiply-linked substructure, the latter might increment some Var's varno twice. Previously there were some retail copyObject calls inside adjust_plan_varnos, but it seems a lot safer to just dup the whole tree first. Also, set_inner_join_references was trying to avoid work by not recursing if a BitmapHeapScan's bitmapqualorig contained no outer references; which was OK at the time the code was written, I think, but now that create_bitmap_scan_plan removes duplicate clauses from bitmapqualorig it is possible for that field to be NULL while outer references still remain in the qpqual and/or contained indexscan nodes. For safety, always recurse even if the BitmapHeapScan looks to be outer reference free. Per reports from Michael Fuhr and Oleg Bartunov.
2005-08-23Clean up some very old and crufty code for TID scan planning. Not muchTom Lane
functional difference really, but make use of stuff added to the planner since this code was touched last.
2005-08-22enable_constraint_exclusion => constraint_exclusionBruce Momjian
Also improve wording.