Commit Graph

395 Commits

Author SHA1 Message Date
Bruce Momjian 158fd5f1c4 > > Prevent sorting if result is already sorted
> >
> > was implemented by Jan Wieck.
> > His work is for ascending order cases.
> >
> > Here is a patch to prevent sorting also in descending
> > order cases.
> > Because I had already changed _bt_first() to position
> > backward correctly before v6.5,this patch would work.
> >
Hiroshi Inoue
Inoue@tpf.co.jp
1999-08-09 06:20:27 +00:00
Tom Lane 5efe31214a Clean up tlist.c tree-walking routines with
expression_tree_mutator.
1999-08-09 05:34:13 +00:00
Tom Lane 14f84cd821 Store -1 in attdisbursion to signal 'no duplicates in column'.
Centralize att_disbursion readout logic.
1999-08-09 03:16:47 +00:00
Tom Lane 5af4b04f31 Move get_attdisbursion to lsyscache. Clean up get_typdefault. 1999-08-09 03:13:31 +00:00
Tom Lane 10d6d411a8 Rewrite fix_indxqual_references, which was entirely bogus for
multi-scan indexscan plans; it tried to use the same table-to-index
attribute mapping for all the scans, even if they used different indexes.
It would klugily work as long as OR indexquals never used multikey indexes,
but that's not likely to hold up much longer...
1999-08-09 01:01:42 +00:00
Tom Lane ecef2caae9 Clean up routines in setrefs.c by replacing individual tree
walking logic with expression_tree_walker/mutator calls.
1999-08-09 00:56:05 +00:00
Tom Lane 6bc601b648 Create a standardized expression_tree_mutator support routine
to go along with expression_tree_walker.  (_walker is not suitable for
routines that need to alter the tree structure significantly.)  Other minor
cleanups in clauses.c.
1999-08-09 00:51:26 +00:00
Tom Lane e1fad50a5d Revise generation of hashjoin paths: generate one path per
hashjoinable clause, not one path for a randomly-chosen element of each
set of clauses with the same join operator.  That is, if you wrote
   SELECT ... WHERE t1.f1 = t2.f2 and t1.f3 = t2.f4,
and both '=' ops were the same opcode (say, all four fields are int4),
then the system would either consider hashing on f1=f2 or on f3=f4,
but it would *not* consider both possibilities.  Boo hiss.
Also, revise estimation of hashjoin costs to include a penalty when the
inner join var has a high disbursion --- ie, the most common value is
pretty common.  This tends to lead to badly skewed hash bucket occupancy
and way more comparisons than you'd expect on average.
I imagine that the cost calculation still needs tweaking, but at least
it generates a more reasonable plan than before on George Young's example.
1999-08-06 04:00:17 +00:00
Tom Lane 30da344cb1 Update comments about clause selectivity estimation. 1999-07-30 22:34:19 +00:00
Tom Lane 04578a9180 Further cleanups of indexqual processing: simplify control
logic in indxpath.c, avoid generation of redundant indexscan paths for the
same relation and index.
1999-07-30 04:07:25 +00:00
Tom Lane 7d572886d6 Fix coredump seen when doing mergejoin between indexed tables,
for example in the regression test database, try
select * from tenk1 t1, tenk1 t2 where t1.unique1 = t2.unique2;
6.5 has this same bug ...
1999-07-30 00:56:17 +00:00
Tom Lane 161be69544 Update comments for create_indexscan_node(). 1999-07-30 00:44:23 +00:00
Tom Lane ecbfafbe0e Add support for Case exprs to fix_indxqual_references,
so that Case works in WHERE join clauses.  Temporary patch --- this routine
is one of many that ought to be changed to use centralized expression-tree-
walking logic.
1999-07-29 02:48:05 +00:00
Tom Lane b62fdc13f0 Correct bug in best_innerjoin(): it should check all the
rels that the inner path needs to join to, but it was only checking for
the first one.  Failure could only have been observed with an OR-clause
that mentions 3 or more tables, and then only if the bogus path was
actually selected as cheapest ...
1999-07-27 06:23:12 +00:00
Tom Lane 9e7e29e6c9 First cut at doing LIKE/regex indexing optimization in
optimizer rather than parser.  This has many advantages, such as not
getting fooled by chance uses of operator names ~ and ~~ (the operators
are identified by OID now), and not creating useless comparison operations
in contexts where the comparisons will not actually be used as indexquals.
The new code also recognizes exact-match LIKE and regex patterns, and
produces an = indexqual instead of >= and <=.

This change does NOT fix the problem with non-ASCII locales: the code
still doesn't know how to generate an upper bound indexqual for non-ASCII
collation order.  But it's no worse than before, just the same deficiency
in a different place...

Also, dike out loc_restrictinfo fields in Plan nodes.  These were doing
nothing useful in the absence of 'expensive functions' optimization,
and they took a considerable amount of processing to fill in.
1999-07-27 03:51:11 +00:00
Tom Lane 49ed4dd779 Further work on planning of indexscans. Cleaned up interfaces
to index_selectivity so that it can be handed an indexqual clause list
rather than a bunch of assorted derivative data.
1999-07-25 23:07:26 +00:00
Tom Lane 8ae29a1d40 Remove 'restrictinfojoinid' field from RestrictInfo nodes.
The only place it was being used was as temporary storage in indxpath.c,
and the logic was wrong: the same restrictinfo node could get chosen to
carry the info for two different joins.  Right fix is to return a second
list of unjoined-relids parallel to the list of clause groups.
1999-07-25 17:53:27 +00:00
Tom Lane ac4913a0dd Clean up messy clause-selectivity code in clausesel.c; repair bug
identified by Hiroshi (incorrect cost attributed to OR clauses
after multiple passes through set_rest_selec()).  I think the code
was trying to allow selectivities of OR subclauses to be passed in
from outside, but noplace was actually passing any useful data, and
set_rest_selec() was passing wrong data.

Restructure representation of "indexqual" in IndexPath nodes so that
it is the same as for indxqual in completed IndexScan nodes: namely,
a toplevel list with an entry for each pass of the index scan, having
sublists that are implicitly-ANDed index qual conditions for that pass.
You don't want to know what the old representation was :-(

Improve documentation of OR-clause indexscan functions.

Remove useless 'notclause' field from RestrictInfo nodes.  (This might
force an initdb for anyone who has stored rules containing RestrictInfos,
but I do not think that RestrictInfo ever appears in completed plans.)
1999-07-24 23:21:14 +00:00
Tom Lane 348bdbce79 Minor code beautification, extensive improvement of
comments.  This file was full of obsolete and just plain wrong
commentary...
1999-07-23 03:34:49 +00:00
Bruce Momjian 3406901a29 Move some system includes into c.h, and remove duplicates. 1999-07-17 20:18:55 +00:00
Bruce Momjian a71802e12e Final cleanup. 1999-07-16 05:00:38 +00:00
Bruce Momjian 9b645d481c Update #include cleanups 1999-07-16 03:14:30 +00:00
Bruce Momjian a9591ce66a Change #include's to use <> and "" as appropriate. 1999-07-15 23:04:24 +00:00
Bruce Momjian 2e6b1e63a3 Remove unused #includes in *.c files. 1999-07-15 22:40:16 +00:00
Bruce Momjian 4b2c2850bf Clean up #include in /include directory. Add scripts for checking includes. 1999-07-15 15:21:54 +00:00
Tom Lane 8aea617c03 Several routines failed to cope with CASE expressions, and
indeed some of 'em were missing support for more node types than that...
1999-07-15 01:52:09 +00:00
Bruce Momjian 0cf1b79528 Cleanup of /include #include's, for 6.6 only. 1999-07-14 01:20:30 +00:00
Bruce Momjian db15dc05ad Fix for \do and ceil()/float. 1999-07-07 16:09:33 +00:00
Bruce Momjian e9c977da7d Fix spelling of variable name. 1999-07-07 09:36:45 +00:00
Bruce Momjian 9f7ac20e57 Cleanup of min tuple size. 1999-07-07 09:27:28 +00:00
Bruce Momjian 1391098851 Fix misspelling. 1999-07-07 09:11:15 +00:00
Bruce Momjian 97dfff832c Fix to prevent too large tuple from being created. 1999-07-03 00:33:04 +00:00
Tom Lane fd8e580bb7 Clean up problems with sublinks + grouping in planner. Not
sure if they are all fixed, because rewriter is now the stumbling block,
but at least some cases work that did not work before.
1999-06-21 01:20:57 +00:00
Tom Lane 974bdd94f9 On second thought, expression_tree_walker should handle bare
SubLink nodes after all ...
1999-06-21 01:18:02 +00:00
Bruce Momjian 326d8658ad Change form() to varargform() to prevent portability problems. 1999-06-19 04:54:23 +00:00
Tom Lane 86f36719db Create a generic expression-tree-walker subroutine, which
will gradually replace all of the boilerplate tree-walk-recursion code that
currently exists in O(N) slightly different forms in N subroutines.
I've had it with adding missing cases to these subroutines...
1999-06-19 03:41:45 +00:00
Tom Lane aaf2442472 Remove query_planner's overhasty rejection of cases where
tlist and qual are NULL.  It ought to handle these the same as the cases
where tlist contains only constant expressions, ie, be willing to generate
a Result-node plan.  This did not use to matter, but it does now because
union_planner will flatten the tlist when aggregates are present.  Thus,
'select count(1) from table' now causes query_planner to be given a null
tlist, and to duplicate 6.4's behavior we need it to give back a Result
plan rather than refusing the query.  6.4 was arguably doing the Wrong
Thing for this query, but I'm not going to open a semantics issue right
before 6.5 release ... can revisit that problem later.
1999-06-12 19:38:30 +00:00
Tom Lane acf242da97 Plug hole in dike: planner would coredump if query_planner
returned NULL, which it will do in some cases where an elog(ERROR) would
probably be more appropriate.  For the moment, generate a not-very-
informative error message rather than proceeding to certain coredump.
Probably ought to think about making query_planner elog instead of
returning NULL, but this is at least a safe change for now.
1999-06-12 19:27:41 +00:00
Tom Lane c37ecaf8d5 Fix errors in SELECT ... GROUP BY ... UNION SELECT ...
ye proverbial one-line patch (not counting five lines of comment so's
maybe it won't happen again)
1999-06-10 06:55:40 +00:00
Tom Lane b4210ae0f0 Fix problems with grouping/aggregation in queries that use
inheritance ... basically it was completely busted :-(
1999-06-06 17:38:11 +00:00
Tom Lane b325dab67a new_relation_targetlist used to cause about 8 separate (and
redundant) SearchSysCache searches per table column in an INSERT, which
accounted for a good percentage of the CPU time for INSERT ... VALUES().
Now it only does two searches in the typical case.
1999-05-29 01:48:06 +00:00
Bruce Momjian 278bbf4572 Make functions static or NOT_USED as appropriate. 1999-05-26 12:57:23 +00:00
Bruce Momjian fcff1cdf4e Another pgindent run. Sorry folks. 1999-05-25 22:43:53 +00:00
Bruce Momjian 4eadfe8754 Make 0x007f -> (unsigned)0x7f to make pgindent happy. 1999-05-25 22:04:56 +00:00
Bruce Momjian 07842084fe pgindent run over code. 1999-05-25 16:15:34 +00:00
Tom Lane 795f6ca66a Update commentary in sample GEQO config file. 1999-05-22 23:59:59 +00:00
Tom Lane b2f14e11ec Reduce default GEQO 'effort' setting to MEDIUM always.
This agrees with the documentation and seems like a more useful default
anyhow ...
1999-05-22 23:27:19 +00:00
Tom Lane b21005fa7c Allow GEQO effort to be specified numerically, as well as
symbolic LOW/MEDIUM/HIGH values --- needed for experiments with other
effort levels ...
1999-05-22 19:29:01 +00:00
Tom Lane c2f0d565f3 Now that hashjoin is reliable for large joins (knock on wood),
remove optimizer's arbitrary limit on how large a join it will use hashing
for.  (The limit was too large to prevent the problems we'd been seeing,
anyway...)
1999-05-18 21:36:10 +00:00
Tom Lane 353d36f979 Remove no-longer-used fields in Hash and HashJoin nodes. 1999-05-18 21:34:29 +00:00
Bruce Momjian 585c967720 Change resjunk to a boolean. 1999-05-17 17:03:51 +00:00
Tom Lane 0b8b1fe3aa Tighten coding in new_join_pathkey, which seems to be a hotspot
for GEQO ...
1999-05-17 00:26:33 +00:00
Tom Lane 1332c1e144 Change GEQO optimizer to release memory after each gene
is evaluated.  This bounds memory usage to something reasonable even
when many tables are being joined.
1999-05-17 00:25:34 +00:00
Tom Lane fecb2b0024 Minor code cleanup in optimizer. 1999-05-16 19:45:37 +00:00
Tom Lane f2ed835baf Fix some typos in geqo optimizer --- it now generates
reasonable plans again.  Still eats memory like there's no tomorrow,
however :-(.
1999-05-16 19:45:00 +00:00
Tom Lane 507a0a2ab0 Rip out QueryTreeList structure, root and branch. Querytree
lists are now plain old garden-variety Lists, allocated with palloc,
rather than specialized expansible-array data allocated with malloc.
This substantially simplifies their handling and eliminates several
sources of memory leakage.
Several basic types of erroneous queries (syntax error, attempt to
insert a duplicate key into a unique index) now demonstrably leak
zero bytes per query.
1999-05-13 07:29:22 +00:00
Jan Wieck 79c2576f77 Replaced targetlist entry in GroupClause by reference number
in Resdom and GroupClause so changing of resno's doesn't confuse
the grouping any more.

Jan
1999-05-12 15:02:39 +00:00
Bruce Momjian 4853495e03 Change error messages to oids come out as %u and not %d. Change has no
real affect now.
1999-05-10 00:46:32 +00:00
Tom Lane ec1f5f78b9 Fix oversights in flatten_tlistentry and replace_clause_joinvar_refs
that led to CASE expressions not working very well in joined queries.
1999-05-06 23:07:33 +00:00
Tom Lane 5729c3503d fix_indxqual_references didn't cope with ArrayRef nodes,
meaning that this failed:
select proname,typname,prosrc from pg_proc,pg_type
where proname = 'float8' and pg_proc.proargtypes[0] = pg_type.oid;
1999-05-06 01:30:58 +00:00
Tom Lane 5da466c597 Make sure targetlist generated for subplan does not share
nodes with HAVING qualifier of upper plan.  Have not seen any failures,
just being a little bit paranoid...
1999-05-04 00:00:20 +00:00
Tom Lane da5f1dd722 Revise union_planner and associated routines to clean up breakage
from EXCEPT/HAVING patch.  Cases involving nontrivial GROUP BY expressions
now work again.  Also, the code is at least somewhat better documented...
1999-05-03 00:38:44 +00:00
Tom Lane 605d84941d Clean up cost_sort some more: most callers were double-counting
the cost of reading the source data.
1999-05-01 19:47:42 +00:00
Tom Lane 17dbeebb5f Fill in reasonable-looking cost estimates in inserted nodes.
This makes no difference to the optimizer, which has already decided what
it's gonna do, but it makes the output of EXPLAIN much more plausible.
1999-04-30 04:04:27 +00:00
Tom Lane 7a7ba33536 Clean up some bogosities in path cost estimation, like
sometimes estimating an index scan of a table to be cheaper than a
sequential scan of the same tuples...
1999-04-30 04:01:44 +00:00
Tom Lane 11a0027e28 Fix nasty little typo that prevented get_cheapest_path_for_joinkeys
from ever returning a path.  This put a bit of a crimp in the system's
ability to generate intelligent merge-join plans...
1999-04-30 03:59:06 +00:00
Tom Lane 970583ab4f Several routines in setrefs.c would crash on array refs
due to lack of check for recursing into a null subexpression.
1999-04-29 00:20:27 +00:00
Tom Lane eb00bdf237 Insert a test for missing targetlist entry in replace_agg_clause. 1999-04-26 00:37:46 +00:00
Tom Lane 4438b70b94 Repair some problems in planner's handling of HAVING clauses.
This fixes a few of the problems Hiroshi Inoue complained of, but
I have not touched the rewrite-related issues.
1999-04-19 01:43:12 +00:00
Tom Lane e91f43a122 Fix potential overflow problems when relation size exceeds
2gig.  Fix failure to reliably put the smaller relation on the inside of
a hashjoin.
1999-04-05 02:07:07 +00:00
Tom Lane ff38837fe9 Fix nasty bug in optimization of multiway joins: optimizer
would sometimes generate a plan that omitted a sort step before merge.
1999-04-03 00:18:28 +00:00
Bruce Momjian bd6f98af31 I suggest the following portability patch, which does not
change functionality, but makes the code more ANSI C'ish.
My AIX xlc compiler barfs on all of these. Can someone please
review and apply to current.

 <<port.patch>>
Thanks
Andreas
1999-03-19 18:56:43 +00:00
Bruce Momjian dc02fd709f cleanups 1999-03-18 19:59:55 +00:00
Bruce Momjian f7430af934 Fix OR index selectivity problem. 1999-03-08 14:01:57 +00:00
Bruce Momjian c831d08fac Fix for Alpha OR selectivity bug. 1999-03-08 13:35:50 +00:00
Tom Lane e0345e09bf Partial fix for copied-plan bugs reported by Hiroshi Inoue:
_copyResult didn't copy subPlan structure completely.  _copyAgg is still
busted, apparently because of changes from EXCEPT/INTERSECT patch
(get_agg_tlist_references is no longer sufficient to find all aggregates).
No time to look at that tonight, however.
1999-03-03 00:02:42 +00:00
Tom Lane b204d10c79 Executor no longer cares about mergejoinop, mergerightorder, mergeleftorder,
so remove them from MergeJoin node.  Hack together a partial
solution for commuted mergejoin operators --- yesterday
a mergejoin int4 = int8 would crash if the planner decided to
commute it, today it works.  The planner's representation of
mergejoins really needs a rewrite though.
Also, further testing of mergejoin ops in opr_sanity regress test.
1999-03-01 00:10:44 +00:00
Bruce Momjian ceb233ed11 more cleanup 1999-02-22 06:08:48 +00:00
Bruce Momjian 1ed5cbbfd8 Final optimizer cleanups. 1999-02-22 05:26:58 +00:00
Marc G. Fournier 8c3e8a8a0e From: Tatsuo Ishii <t-ishii@sra.co.jp>
Ok. I made patches replacing all of "#if FALSE" or "#if 0" to "#ifdef
NOT_USED" for current. I have tested these patches in that the
postgres binaries are identical.
1999-02-21 03:49:55 +00:00
Bruce Momjian 23c30246d7 pathkeys.c cleanup. 1999-02-21 01:55:03 +00:00
Bruce Momjian 75cccd0ad3 pathkeys fixes 1999-02-20 19:02:43 +00:00
Bruce Momjian 0ff2733355 Update pathkeys comparison function. 1999-02-20 18:01:02 +00:00
Bruce Momjian 148ec3b1d8 update pathkey description. 1999-02-20 16:32:35 +00:00
Bruce Momjian 9188aab758 add pathkeys description. 1999-02-20 16:28:20 +00:00
Bruce Momjian 67fd67f53a another rename of optimizer 1999-02-20 15:27:42 +00:00
Bruce Momjian 612b8434e4 optimizer cleanup 1999-02-19 05:18:06 +00:00
Bruce Momjian 8ab72a38df optimizer cleanup 1999-02-19 02:05:20 +00:00
Bruce Momjian cd38f08598 rename optimizer file name 1999-02-18 19:58:53 +00:00
Bruce Momjian b4e7510e09 Enable bushy and right-hand queries by default. 1999-02-18 06:01:11 +00:00
Bruce Momjian 65ccd1039a Enable bushy plans by default. 1999-02-18 05:26:34 +00:00
Bruce Momjian e78662d879 optimizer cleanup 1999-02-18 04:55:54 +00:00
Bruce Momjian d977ff7b52 more optimizer cleanups 1999-02-18 04:45:36 +00:00
Bruce Momjian 31cce21fb0 Fix bushy plans. Cleanup. 1999-02-18 00:49:48 +00:00
Bruce Momjian c82ca4c158 Re-enable bushy plans. Vadim want them. 1999-02-16 00:41:03 +00:00
Bruce Momjian cd550c7672 Update optimizer readme. 1999-02-15 22:19:01 +00:00
Bruce Momjian e6bf7b4d93 rename 1999-02-15 05:56:07 +00:00
Bruce Momjian 56bb23a8fe optimizer rename 1999-02-15 05:50:02 +00:00
Bruce Momjian 50034a852d optimizer rename 1999-02-15 05:28:10 +00:00
Bruce Momjian c5449d5354 otherrels is now unjoined_rels 1999-02-15 05:21:12 +00:00