Commit Graph

419 Commits

Author SHA1 Message Date
Tom Lane 9c38a8d296 Further tweaking of indexscan cost estimates. 2000-04-09 04:31:37 +00:00
Tom Lane 1c72a8a37a Fix extremely nasty little bug observed when a sub-SELECT appears in
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.
2000-04-04 01:21:48 +00:00
Tom Lane e55985d3be Tweak indexscan cost estimation: round estimated # of tuples visited up
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...
2000-03-30 00:53:30 +00:00
Tom Lane 8cbeb5f131 Save a few cycles in simple cases: no need to call cost_sort() when there
is no presorted path to compare with.
2000-03-24 21:40:43 +00:00
Tom Lane 7177bbac29 A little further tweaking of the range-query selectivity logic:
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.
2000-03-23 23:35:47 +00:00
Tom Lane 1afaa2557a If we cannot get a real estimate for the selectivity of a range query,
use a default value that's fairly small.  We were generating a result
of about 0.1, but I think 0.01 is probably better --- want to encourage
use of an indexscan in this situation.
2000-03-23 00:58:36 +00:00
Tom Lane 1d5e7a6f46 Repair logic flaw in cost estimator: cost_nestloop() was estimating CPU
costs using the inner path's parent->rows count as the number of tuples
processed per inner scan iteration.  This is wrong when we are using an
inner indexscan with indexquals based on join clauses, because the rows
count in a Relation node reflects the selectivity of the restriction
clauses for that rel only.  Upshot was that if join clause was very
selective, we'd drastically overestimate the true cost of the join.
Fix is to calculate correct output-rows estimate for an inner indexscan
when the IndexPath node is created and save it in the path node.
Change of path node doesn't require initdb, since path nodes don't
appear in saved rules.
2000-03-22 22:08:35 +00:00
Tom Lane 3ee8f7e207 Restructure planning code so that preprocessing of targetlist and quals
to simplify constant expressions and expand SubLink nodes into SubPlans
is done in a separate routine subquery_planner() that calls union_planner().
We formerly did most of this work in query_planner(), but that's the
wrong place because it may never see the real targetlist.  Splitting
union_planner into two routines also allows us to avoid redundant work
when union_planner is invoked recursively for UNION and inheritance
cases.  Upshot is that it is now possible to do something like
select float8(count(*)) / (select count(*) from int4_tbl)  from int4_tbl
group by f1;
which has never worked before.
2000-03-21 05:12:12 +00:00
Tom Lane d6429e552d Minor code rearrangement & doc improvement in eval_const_expressions(). 2000-03-19 18:20:38 +00:00
Tom Lane 341b328b18 Fix a bunch of minor portability problems and maybe-bugs revealed by
running gcc and HP's cc with warnings cranked way up.  Signed vs unsigned
comparisons, routines declared static and then defined not-static,
that kind of thing.  Tedious, but perhaps useful...
2000-03-17 02:36:41 +00:00
Thomas G. Lockhart 6456810078 Implement column aliases on views "CREATE VIEW name (collist)".
Implement TIME WITH TIME ZONE type (timetz internal type).
Remap length() for character strings to CHAR_LENGTH() for SQL92
 and to remove the ambiguity with geometric length() functions.
Keep length() for character strings for backward compatibility.
Shrink stored views by removing internal column name list from visible rte.
Implement min(), max() for time and timetz data types.
Implement conversion of TIME to INTERVAL.
Implement abs(), mod(), fac() for the int8 data type.
Rename some math functions to generic names:
 round(), sqrt(), cbrt(), pow(), etc.
Rename NUMERIC power() function to pow().
Fix int2 factorial to calculate result in int4.
Enhance the Oracle compatibility function translate() to work with string
 arguments (from Edwin Ramirez).
Modify pg_proc system table to remove OID holes.
2000-03-14 23:06:59 +00:00
Tom Lane 6217a8c7ba Fix some bogosities in the code that deals with estimating the fraction
of tuples we are going to retrieve from a sub-SELECT.  Must have been
half asleep when I did this code the first time :-(
2000-03-14 02:23:15 +00:00
Tom Lane 1879175b18 Fix performance bug in constant-expression simplifier. After finding
that the inputs to a given operator can be recursively simplified to
constants, it was evaluating the operator using the op's *original*
(unsimplified) arg list, so that any subexpressions had to be evaluated
again.  A constant subexpression at depth N got evaluated N times.
Probably not very important in practical situations, but it made us look
real slow in MySQL's 'crashme' test...
2000-03-12 19:32:06 +00:00
Tom Lane e8be8ffaf0 Further tweaking of logic that decides when to materialize an uncorrelated
subplan: do it if subplan has subplans itself, and always do it if the
subplan is an indexscan.  (I originally set it to materialize an indexscan
only if the indexqual is fairly selective, but I dunno what I was
thinking ... an unselective indexscan is still expensive ...)
2000-03-11 23:53:41 +00:00
Hiroshi Inoue fd9ff86bd9 Trial implementation of ALTER DROP COLUMN.
They are #ifdef'd.
Add -D_DROP_COLUMN_HACK__ compile option
to evaluate it.
2000-03-09 05:00:26 +00:00
Tom Lane 0eb5ab8250 Apply a MATERIAL node to the result of an uncorrelated subplan, if it
looks like it will save computation to do so.
2000-03-02 04:08:16 +00:00
Tom Lane 84ccfdf087 Avoid a little bit of unnecessary computation in canonicalize_qual. 2000-02-27 19:45:44 +00:00
Tom Lane be05edd812 Tweak planner to use OFFSET+LIMIT, not just LIMIT, as estimate of the
portion of the query result that will be retrieved.  As far as I could
tell, the consensus was that we should let the planner do the best it
can with a LIMIT query, and require the user to add ORDER BY if he
wants consistent results from different LIMIT values.
2000-02-21 01:13:04 +00:00
Tom Lane 57b30e8e22 Create a new expression node type RelabelType, which exists solely to
represent the result of a binary-compatible type coercion.  At runtime
it just evaluates its argument --- but during type resolution, exprType
will pick up the output type of the RelabelType node instead of the type
of the argument.  This solves some longstanding problems with dropped
type coercions, an example being 'select now()::abstime::int4' which
used to produce date-formatted output, not an integer, because the
coercion to int4 was dropped on the floor.
2000-02-20 21:32:16 +00:00
Tom Lane 3cbcb78a3d Plug some more memory leaks in the planner. It still leaks like a sieve,
but this is as good as it'll get for this release...
2000-02-18 23:47:31 +00:00
Hiroshi Inoue e3a97b370c Implement reindex command 2000-02-18 09:30:20 +00:00
Tom Lane 598ea2c359 Finish repairing 6.5's problems with r-tree indexes: create appropriate
selectivity functions and make the r-tree operators use them.  The
estimation functions themselves are just stubs, unfortunately, but
perhaps someday someone will make them compute realistic estimates.
Change pg_am so that the optimizer can reliably tell the difference
between ordered and unordered indexes --- before it would think that
an r-tree index can be scanned in '<<' order, which is not right AFAIK.
Repair broken negator links for network_sup and related ops.
Initdb forced.  This might be my last initdb force for 7.0 ... hope so
anyway ...
2000-02-17 03:40:02 +00:00
Tom Lane 47dde30222 Remove long-dead code. 2000-02-15 23:12:26 +00:00
Tom Lane b1577a7c78 New cost model for planning, incorporating a penalty for random page
accesses versus sequential accesses, a (very crude) estimate of the
effects of caching on random page accesses, and cost to evaluate WHERE-
clause expressions.  Export critical parameters for this model as SET
variables.  Also, create SET variables for the planner's enable flags
(enable_seqscan, enable_indexscan, etc) so that these can be controlled
more conveniently than via PGOPTIONS.

Planner now estimates both startup cost (cost before retrieving
first tuple) and total cost of each path, so it can optimize queries
with LIMIT on a reasonable basis by interpolating between these costs.
Same facility is a win for EXISTS(...) subqueries and some other cases.

Redesign pathkey representation to achieve a major speedup in planning
(I saw as much as 5X on a 10-way join); also minor changes in planner
to reduce memory consumption by recycling discarded Path nodes and
not constructing unnecessary lists.

Minor cleanups to display more-plausible costs in some cases in
EXPLAIN output.

Initdb forced by change in interface to index cost estimation
functions.
2000-02-15 20:49:31 +00:00
Thomas G. Lockhart a344a6e7b5 Carry column aliases from the parser frontend. Enables queries like
SELECT a FROM t1 tx (a);
Allow join syntax, including queries like
  SELECT * FROM t1 NATURAL JOIN t2;
Update RTE structure to hold column aliases in an Attr structure.
2000-02-15 03:38:29 +00:00
Tom Lane d8733ce674 Repair planning bugs caused by my misguided removal of restrictinfo link
fields in JoinPaths --- turns out that we do need that after all :-(.
Also, rearrange planner so that only one RelOptInfo is created for a
particular set of joined base relations, no matter how many different
subsets of relations it can be created from.  This saves memory and
processing time compared to the old method of making a bunch of RelOptInfos
and then removing the duplicates.  Clean up the jointree iteration logic;
not sure if it's better, but I sure find it more readable and plausible
now, particularly for the case of 'bushy plans'.
2000-02-07 04:41:04 +00:00
Tom Lane 81fc1d5edb Rename same() to sameseti() to have a slightly less generic name. Move
nonoverlap_sets() and is_subset() to list.c, where they should have lived
to begin with, and rename to nonoverlap_setsi and is_subseti since they
only work on integer lists.
2000-02-06 03:27:35 +00:00
Tom Lane 78296c2797 Further cleanup for OR-of-AND WHERE-clauses. orindxpath can now handle
extracting from an AND subclause just those opclauses that are relevant
for a particular index.  For example, we can now consider using an index
on x to process WHERE (x = 1 AND y = 2) OR (x = 2 AND y = 4) OR ...
2000-02-05 18:26:09 +00:00
Tom Lane d24ef0d08f Make EXPLAIN results for Append, Group, Agg, Unique nodes more plausible.
Group and Unique use an arbitrary assumption that there will be about
10% as many groups as input tuples --- perhaps someday we can refine this.
2000-02-03 06:12:19 +00:00
Tom Lane 003dd965d2 Apply the heuristic proposed by Taral (see pgsql-general archives for
2-Oct-98 or TODO.detail/cnfify) to decide whether we want to reduce
WHERE clause to CNF form, DNF form, or neither.  This is a HUGE win.
The heuristic conditions could probably still use a little tweaking to
make sure we don't pick CNF when DNF would be better, or vice versa,
but the risk of exponential explosion in cnfify() is gone.  I was able
to run ten-thousand-AND-subclause queries through the planner in a
reasonable amount of time.
2000-01-28 03:22:36 +00:00
Tom Lane dd979f66be Redesign DISTINCT ON as discussed in pgsql-sql 1/25/00: syntax is now
SELECT DISTINCT ON (expr [, expr ...]) targetlist ...
and there is a check to make sure that the user didn't specify an ORDER BY
that's incompatible with the DISTINCT operation.
Reimplement nodeUnique and nodeGroup to use the proper datatype-specific
equality function for each column being compared --- they used to do
bitwise comparisons or convert the data to text strings and strcmp().
(To add insult to injury, they'd look up the conversion functions once
for each tuple...)  Parse/plan representation of DISTINCT is now a list
of SortClause nodes.
initdb forced by querytree change...
2000-01-27 18:11:50 +00:00
Bruce Momjian 5c25d60244 Add:
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc

to all files copyright Regents of Berkeley.  Man, that's a lot of files.
2000-01-26 05:58:53 +00:00
Tom Lane 0dbffa704a First cut at making useful selectivity estimates for range queries
(ie, WHERE x > lowbound AND x < highbound).  It's not very bright yet
but it does something useful.  Also, rename intltsel/intgtsel to
scalarltsel/scalargtsel to reflect usage better.  Extend convert_to_scalar
to do something a little bit useful with string data types.  Still need
to make it do something with date/time datatypes, but I'll wait for
Thomas's datetime unification dust to settle first.  Eventually the
routine ought not have any type-specific knowledge at all; it ought to
be calling a type-dependent routine found via a pg_type column; but
that's a task for another day.
2000-01-24 07:16:52 +00:00
Tom Lane 8449df8a67 First cut at unifying regular selectivity estimation with indexscan
selectivity estimation wasn't right.  This is better...
2000-01-23 02:07:00 +00:00
Tom Lane 71ed7eb494 Revise handling of index-type-specific indexscan cost estimation, per
pghackers discussion of 5-Jan-2000.  The amopselect and amopnpages
estimators are gone, and in their place is a per-AM amcostestimate
procedure (linked to from pg_am, not pg_amop).
2000-01-22 23:50:30 +00:00
Peter Eisentraut 1cd4c14116 Fixed all elog related warnings, as well as a few others. 2000-01-15 02:59:43 +00:00
Tom Lane 421d4f9bd7 Put back erroneously removed zeroing of sentinel elements
in indexkeys, classlist arrays.
2000-01-12 00:53:21 +00:00
Bruce Momjian bd52f4bffd More cleanups. Still doesn't work. 2000-01-11 03:33:14 +00:00
Tom Lane 166b5c1def Another round of planner/optimizer work. This is just restructuring and
code cleanup; no major improvements yet.  However, EXPLAIN does produce
more intuitive outputs for nested loops with indexscans now...
2000-01-09 00:26:47 +00:00
Tom Lane d8f3752133 Generate double-sided LIKE indexquals that work even in weird locales,
by continuing to increment the rightmost character until we get a string
that is demonstrably greater than the pattern prefix.
1999-12-31 05:38:25 +00:00
Tom Lane 5f68d5c38f Clean up loose end in LIKE optimization fix: parser's code would generate
<= and >= indexquals from a LIKE even if the index in question didn't
support those operators.  (As, for example, a hash index does not.)
1999-12-31 03:41:03 +00:00
Tom Lane 7431796b46 fix_parsetree_attnums was not nearly smart enough about walking parse
trees.  Also rewrite find_all_inheritors() in a more intelligible style.
1999-12-14 03:35:28 +00:00
Bruce Momjian a82f9ffde6 New LDOUT makefile variable for QNX os. 1999-12-13 22:35:27 +00:00
Tom Lane a8ae19ec3d aggregate(DISTINCT ...) works, per SQL spec.
Note this forces initdb because of change of Aggref node in stored rules.
1999-12-13 01:27:21 +00:00
Bruce Momjian 3ffd3d82db Make LD -r as macros that can be changed for QNX. 1999-12-09 19:15:45 +00:00
Tom Lane f7f41c7c8c Replace generic 'Illegal use of aggregates' error message with one that
shows the specific ungrouped variable being complained of.  Perhaps this
will reduce user confusion...
1999-12-09 05:58:56 +00:00
Bruce Momjian 6f9ff92cc0 Tid access method feature from Hiroshi Inoue, Inoue@tpf.co.jp 1999-11-23 20:07:06 +00:00
Bruce Momjian fc955b14ea Add system indexes to match all caches.
Make all system indexes unique.
Make all cache loads use system indexes.
Rename *rel to *relid in inheritance tables.
Rename cache names to be clearer.
1999-11-22 17:56:41 +00:00
Tom Lane 610dfa6d55 Combine index_info and find_secondary_indexes into a single routine that
returns a list of RelOptInfos, eliminating the need for static state
in index_info.  That static state was a direct cause of coredumps; if
anything decided to elog(ERROR) partway through an index_info search of
pg_index, the next query would try to close a scan pointer that was
pointing at no-longer-valid memory.  Another example of the reasons to
avoid static state variables...
1999-11-21 23:25:47 +00:00
Tom Lane f68e11f373 Implement subselects in target lists. Also, relax requirement that
subselects can only appear on the righthand side of a binary operator.
That's still true for quantified predicates like x = ANY (SELECT ...),
but a subselect that delivers a single result can now appear anywhere
in an expression.  This is implemented by changing EXPR_SUBLINK sublinks
to represent just the (SELECT ...) expression, without any 'left hand
side' or combining operator --- so they're now more like EXISTS_SUBLINK.
To handle the case of '(x, y, z) = (SELECT ...)', I added a new sublink
type MULTIEXPR_SUBLINK, which acts just like EXPR_SUBLINK used to.
But the grammar will only generate one for a multiple-left-hand-side
row expression.
1999-11-15 02:00:15 +00:00