summaryrefslogtreecommitdiff
path: root/src/backend/optimizer
AgeCommit message (Collapse)Author
2005-08-18Fix up LIMIT/OFFSET planning so that we cope with non-constant LIMITTom Lane
or OFFSET clauses by using estimate_expression_value(). The main advantage of this is that if the expression is a Param and we have a value for the Param, we'll use that value rather than defaulting. Also, fix some thinkos in the logic for combining LIMIT/OFFSET with an externally supplied tuple fraction (this covers cases like EXISTS(...LIMIT...)). And make sure the results of all this are shown by EXPLAIN. Per a gripe from Merlin Moncure.
2005-08-02Prevent planner from including temp tables of other backends when expandingTom Lane
an inheritance tree. Per recent discussions.
2005-08-01Add NOWAIT option to SELECT FOR UPDATE/SHARE.Tom Lane
Original patch by Hans-Juergen Schoenig, revisions by Karel Zak and Tom Lane.
2005-07-29Fix an oversight I introduced on 2003-12-28: find_nots/push_nots shouldTom Lane
continue to recurse after eliminating a NOT-below-a-NOT, since the contained subexpression will now be part of the top-level AND/OR structure and so deserves to be simplified. The real-world impact of this is probably minimal, since it'd require at least three levels of NOT to make a difference, but it's still a bug. Also remove some redundant tests for NULL subexpressions.
2005-07-28Make use of new list primitives list_append_unique and list_concat_uniqueTom Lane
where applicable.
2005-07-28Fix a bunch of bad interactions between partial indexes and the newTom Lane
planning logic for bitmap indexscans. Partial indexes create corner cases in which a scan might be done with no explicit index qual conditions, and the code wasn't handling those cases nicely. Also be a little tenser about eliminating redundant clauses in the generated plan. Per report from Dmitry Karasik.
2005-07-23Simple constraint exclusion. For now, only child tables of inheritanceTom Lane
scans are candidates for exclusion; this should be fixed eventually. Simon Riggs, with some help from Tom Lane.
2005-07-22Fix compare_fuzzy_path_costs() to behave a bit more sanely. The originalTom Lane
coding would ignore startup cost differences of less than 1% of the estimated total cost; which was OK for normal planning but highly not OK if a very small LIMIT was applied afterwards, so that startup cost becomes the name of the game. Instead, compare startup and total costs fuzzily but independently. This changes the plan selected for two queries in the regression tests; adjust expected-output files for resulting changes in row order. Per reports from Dawid Kuroczko and Sam Mason.
2005-07-15Fix create_unique_plan() so it doesn't generate useless entries in theTom Lane
output targetlist of the Unique or HashAgg plan. This code was OK when written, but subsequent changes to use "physical tlists" where possible had broken it: given an input subplan that has extra variables added to avoid a projection step, it would copy those extra variables into the upper tlist, which is pointless since a projection has to happen anyway.
2005-07-15Fix overenthusiastic optimization of 'x IN (SELECT DISTINCT ...)' and relatedTom Lane
cases: we can't just consider whether the subquery's output is unique on its own terms, we have to check whether the set of output columns we are going to use will be unique. Per complaint from Luca Pireddu and test case from Michael Fuhr.
2005-07-03Don't try to constant-fold functions returning RECORD. We were neverTom Lane
able to do this before, but I had tried to make an exception for functions with OUT parameters. Michael Fuhr found one problem with it already, and I found another, which was it didn't work for strict functions with a NULL input. While both of these could be worked around, the probability that there are more gotchas seems high; I think prudence dictates just reverting to the former behavior for now. Accordingly, remove the kluge added to get_expr_result_type() for Michael's case.
2005-07-03Improve outer-join-deduction logic to be able to propagate equalitiesTom Lane
through multiple join clauses.
2005-07-02Teach planner about some cases where a restriction clause can beTom Lane
propagated inside an outer join. In particular, given LEFT JOIN ON (A = B) WHERE A = constant, we cannot conclude that B = constant at the top level (B might be null instead), but we can nonetheless put a restriction B = constant into the quals for B's relation, since no inner-side rows not meeting that condition can contribute to the final result. Similarly, given FULL JOIN USING (J) WHERE J = constant, we can't directly conclude that either input J variable = constant, but it's OK to push such quals into each input rel. Per recent gripe from Kim Bisgaard. Along the way, remove 'valid_everywhere' flag from RestrictInfo, as on closer analysis it was not being used for anything, and was defined backwards anyway.
2005-06-26Add Oracle-compatible GREATEST and LEAST functions. Pavel StehuleTom Lane
2005-06-14The random selection in function linear() could deliver a value equal to maxTom Lane
if geqo_rand() returns exactly 1.0, resulting in failure due to indexing off the end of the pool array. Also, since this is using inexact float math, it seems wise to guard against roundoff error producing values slightly outside the expected range. Per report from bug@zedware.org.
2005-06-14Teach planner to optionally ignore index columns that have an equalityTom Lane
constraint while determining whether the index sort order matches the query's ORDER BY. This for example allows an index on (x,y) to match ... WHERE x = 42 ORDER BY y; It only works for btree indexes, but since those are the only ones we currently have that are ordered at all, that's good enough for now. Per popular demand.
2005-06-13Change the planner to allow indexscan qualification clauses to useTom Lane
nonconsecutive columns of a multicolumn index, as per discussion around mid-May (pghackers thread "Best way to scan on-disk bitmaps"). This turns out to require only minimal changes in btree, and so far as I can see none at all in GiST. btcostestimate did need some work, but its original assumption that index selectivity == heap selectivity was quite bogus even before this.
2005-06-10Separate predicate-testing code out of indxpath.c, making it a moduleTom Lane
in its own right. As proposed by Simon Riggs, but with some editorializing of my own.
2005-06-10Quick hack to allow the outer query's tuple_fraction to be passed downTom Lane
to a subquery if the outer query is simple enough that the LIMIT can be reflected directly to the subquery. This didn't use to be very interesting, because a subquery that couldn't have been flattened into the upper query was usually not going to be very responsive to tuple_fraction anyway. But with new code that allows UNION ALL subqueries to pay attention to tuple_fraction, this is useful to do. In particular this lets the optimization occur when the UNION ALL is directly inside a view.
2005-06-10If a LIMIT is applied to a UNION ALL query, plan each UNION arm asTom Lane
if the limit were directly applied to it. This does not actually add a LIMIT plan node to the generated subqueries --- that would be useless overhead --- but it does cause the planner to prefer fast- start plans when the limit is small. After an idea from Phil Endecott.
2005-06-10Revise searching of subplan target lists to use something more efficientTom Lane
than tlist_member calls. Building a large join tlist is still O(N^2), but with a much smaller constant factor than before.
2005-06-09Simplify the planner's join clause management by storing join clausesTom Lane
of a relation in a flat 'joininfo' list. The former arrangement grouped the join clauses according to the set of unjoined relids used in each; however, profiling on test cases involving lots of joins proves that that data structure is a net loss. It takes more time to group the join clauses together than is saved by avoiding duplicate tests later. It doesn't help any that there are usually not more than one or two clauses per group ...
2005-06-08Marginal hack to avoid spending a lot of time in find_join_rel duringTom Lane
large planning problems: when the list of join rels gets too long, make an auxiliary hash table that hashes on the identifying Bitmapset.
2005-06-06Nab some low-hanging fruit: replace the planner's base_rel_list andTom Lane
other_rel_list with a single array indexed by rangetable index. This reduces find_base_rel from O(N) to O(1) without any real penalty. While find_base_rel isn't one of the major bottlenecks in any profile I've seen so far, it was starting to creep up on the radar screen for complex queries --- so might as well fix it.
2005-06-05Remove planner's private fields from Query struct, and put them intoTom Lane
a new PlannerInfo struct, which is passed around instead of the bare Query in all the planning code. This commit is essentially just a code-beautification exercise, but it does open the door to making larger changes to the planner data structures without having to muck with the widely-known Query struct.
2005-06-04Change expandRTE() and ResolveNew() back to taking just the singleTom Lane
RTE of interest, rather than the whole rangetable list. This makes the API more understandable and avoids duplicate RTE lookups. This patch reverts no-longer-needed portions of my patch of 2004-08-19.
2005-06-03Revise handling of dropped columns in JOIN alias lists to avoid aTom Lane
performance problem pointed out by phil@vodafone: to wit, we were spending O(N^2) time to check dropped-ness in an N-deep join tree, even in the case where the tree was freshly constructed and couldn't possibly mention any dropped columns. Instead of recursing in get_rte_attribute_is_dropped(), change the data structure definition: the joinaliasvars list of a JOIN RTE must have a NULL Const instead of a Var at any position that references a now-dropped column. This costs nothing during normal parse-rewrite-plan path, and instead we have a linear-time update to make when loading a stored rule that might contain now-dropped columns. While at it, move the responsibility for acquring locks on relations referenced by rules into this separate function (which I therefore chose to call AcquireRewriteLocks). This saves effort --- namely, duplicated lock grabs in parser and rewriter --- in the normal path at a cost of one extra non-locked heap_open() in the stored-rule path; seems a good tradeoff. A fringe benefit is that it is now *much* clearer that we acquire lock on relations referenced in rules before we make any rewriter decisions based on their properties. (I don't know of any bug of that ilk, but it wasn't exactly clear before.)
2005-06-03Just noticed that you can't Query-Cancel a long planner run, becauseTom Lane
no part of the planner did CHECK_FOR_INTERRUPTS(). Add one in a suitably strategic spot.
2005-05-30Add support for FUNCTION RTEs to build_physical_tlist(), so that theTom Lane
physical-tlist optimization can be applied to FunctionScan nodes as well as regular tables and SubqueryScans.
2005-05-30Skip eval_const_expressions when the query is such that the expressionTom Lane
would be evaluated only once anyway (ie, it's just a SELECT with no FROM or an INSERT ... VALUES). The planner can't do it any faster than the executor, so no point in an extra copying of the expression tree.
2005-05-24Previous fix for "x FULL JOIN y ON true" failed to handle the caseTom Lane
where there was also a WHERE-clause restriction that applied to the join. The check on restrictlist == NIL is really unnecessary anyway, because select_mergejoin_clauses already checked for and complained about any unmergejoinable join clauses. So just take it out.
2005-05-23Avoid redundant relation lock grabs during planning, and make sureTom Lane
that we acquire a lock on relations added to the query due to inheritance. Formerly, no such lock was held throughout planning, which meant that a schema change could occur to invalidate the plan before it's even been completed.
2005-05-22Teach the planner to remove SubqueryScan nodes from the plan if theyTom Lane
aren't doing anything useful (ie, neither selection nor projection). Also, extend to SubqueryScan the hacks already in place to avoid unnecessary ExecProject calls when the result would just be the same tuple the subquery already delivered. This saves some overhead in UNION and other set operations, as well as avoiding overhead for unflatten-able subqueries. Per example from Sokolov Yura.
2005-05-06For some reason access/tupmacs.h has been #including utils/memutils.h,Tom Lane
which is neither needed by nor related to that header. Remove the bogus inclusion and instead include the header in those C files that actually need it. Also fix unnecessary inclusions and bad inclusion order in tsearch2 files.
2005-04-28Implement sharable row-level locks, and use them for foreign key referencesTom Lane
to eliminate unnecessary deadlocks. This commit adds SELECT ... FOR SHARE paralleling SELECT ... FOR UPDATE. The implementation uses a new SLRU data structure (managed much like pg_subtrans) to represent multiple- transaction-ID sets. When more than one transaction is holding a shared lock on a particular row, we create a MultiXactId representing that set of transactions and store its ID in the row's XMAX. This scheme allows an effectively unlimited number of row locks, just as we did before, while not costing any extra overhead except when a shared lock actually has to be shared. Still TODO: use the regular lock manager to control the grant order when multiple backends are waiting for a row lock. Alvaro Herrera and Tom Lane.
2005-04-25Avoid rechecking lossy operators twice in a bitmap scan plan.Tom Lane
2005-04-25While determining the filter clauses for an index scan (either plainTom Lane
or bitmap), use pred_test to be a little smarter about cases where a filter clause is logically unnecessary. This may be overkill for the plain indexscan case, but it's definitely useful for OR'd bitmap scans.
2005-04-25Replace slightly klugy create_bitmap_restriction() function with aTom Lane
more efficient routine in restrictinfo.c (which can make use of make_restrictinfo_internal).
2005-04-25Remove support for OR'd indexscans internal to a single IndexScan planTom Lane
node, as this behavior is now better done as a bitmap OR indexscan. This allows considerable simplification in nodeIndexscan.c itself as well as several planner modules concerned with indexscan plan generation. Also we can improve the sharing of code between regular and bitmap indexscans, since they are now working with nigh-identical Plan nodes.
2005-04-23Turns out that my recent elimination of the 'redundant' flatten_andors()Tom Lane
code in prepqual.c had a small drawback: the flatten_andors code was able to cope with deeply nested AND/OR structures (like 10000 ORs in a row), whereas eval_const_expressions tends to recurse until it overruns the stack. Revise eval_const_expressions so that it doesn't choke on deeply nested ANDs or ORs.
2005-04-23Teach choose_bitmap_and() to actually be choosy --- that is, try toTom Lane
make some estimate of which available indexes to AND together, rather than blindly taking 'em all. This could probably stand further improvement, but it seems to do OK in simple tests.
2005-04-23Fix bogus EXPLAIN display of rowcount estimates for BitmapAnd andTom Lane
BitmapOr nodes.
2005-04-22First cut at planner support for bitmap index scans. Lots to do yet,Tom Lane
but the code is basically working. Along the way, rewrite the entire approach to processing OR index conditions, and make it work in join cases for the first time ever. orindxpath.c is now basically obsolete, but I left it in for the time being to allow easy comparison testing against the old implementation.
2005-04-21Rethink original decision to use AND/OR Expr nodes to represent bitmapTom Lane
logic operations during planning. Seems cleaner to create two new Path node types, instead --- this avoids duplication of cost-estimation code. Also, create an enable_bitmapscan GUC parameter to control use of bitmap plans.
2005-04-21Install some slightly realistic cost estimation for bitmap index scans.Tom Lane
2005-04-20Don't try to run clauseless index scans on index types that don't supportTom Lane
it. Per report from Marinos Yannikos.
2005-04-19Create executor and planner-backend support for decoupled heap and indexTom Lane
scans, using in-memory tuple ID bitmaps as the intermediary. The planner frontend (path creation and cost estimation) is not there yet, so none of this code can be executed. I have tested it using some hacked planner code that is far too ugly to see the light of day, however. Committing now so that the bulk of the infrastructure changes go in before the tree drifts under me.
2005-04-14Don't try to constant-fold functions returning RECORD, since the optimizerTom Lane
isn't presently set up to pass them an expected tuple descriptor. Bug has been there since 7.3 but was just recently reported by Thomas Hallgren.
2005-04-14Completion of project to use fixed OIDs for all system catalogs andTom Lane
indexes. Replace all heap_openr and index_openr calls by heap_open and index_open. Remove runtime lookups of catalog OID numbers in various places. Remove relcache's support for looking up system catalogs by name. Bulky but mostly very boring patch ...
2005-04-12Fix oversight in MIN/MAX optimization: must not return NULL entriesTom Lane
from index, since the aggregates ignore NULLs.