postgresql/src/backend/optimizer
Bruce Momjian c579ce0fb0 I started adding the Having Clause and it works quite fine for
sequential scans! (I think it will also work with hash, index, etc
but I did not check it out! I made some High level changes which
should work for all access methods, but maybe I'm wrong. Please
let me know.)

Now it is possible to make queries like:

select s.sname, max(p.pid), min(p.pid) from part p, supplier s
where s.sid=p.sid group by s.sname having max(pid)=6 and min(pid)=1
or avg(pid)=4;

Having does not work yet for queries that contain a subselect
statement in the Having clause, I'll try to fix this in the next
days.

If there are some bugs, please let me know, I'll start to read the
mailinglists now!

Now here is the patch against the original 6.3 version (no snapshot!!):

Stefan
1998-03-30 16:36:43 +00:00
..
geqo pgindent run before 6.3 release, with Thomas' requested changes. 1998-02-26 04:46:47 +00:00
path pgindent run before 6.3 release, with Thomas' requested changes. 1998-02-26 04:46:47 +00:00
plan I started adding the Having Clause and it works quite fine for 1998-03-30 16:36:43 +00:00
prep pgindent run before 6.3 release, with Thomas' requested changes. 1998-02-26 04:46:47 +00:00
util pgindent run before 6.3 release, with Thomas' requested changes. 1998-02-26 04:46:47 +00:00
Makefile From: Robert Bruccoleri <bruc@bms.com> 1997-06-11 01:13:10 +00:00
README Cost cleanup. 1997-12-18 12:21:02 +00:00

Thse directories take the Query structure returned by the parser, and
generate a plan used by the executor.  The /plan directory generates the
plan, the /path generates all possible ways to join the tables, and
/prep handles special cases like inheritance.  /utils is utility stuff.

planner()
 handle inheritance by processing separately
-init_query_planner()
  preprocess target list
  preprocess qualifications(WHERE)
--query_planner()
   pull out constants from target list
   get a target list that only contains column names, no expressions
   if none, then return
---subplanner()
    make list of relations in target
    make list of relations in where clause
    find which relations can do merge sort and hash joins
----find_paths()
     find scan and all index paths for each relation not yet joined
     one relation, return
     find selectivity of columns used in joins
-----find_join_paths()
      Summary:  With OPTIMIZER_DEBUG defined, you see:

      Tables 1, 2, 3, and 4 are joined as:
         {1 2},{1 3},{1 4},{2 3},{2 4}
         {1 2 3},{1 2 4},{2 3 4}
         {1 2 3 4}

      Actual output tests show combinations:
         {4 2},{3 2},{1 4},{1 3},{1 2}
         {4 2 3},{1 4 2},{1 3 2}
         {4 2 3 1}

      Cheapest join order shows:
         {4 2},{3 2},{1 4},{1 3},{1 2}
         {3 2 4},{1 4 2},{1 3 2}
         {1 4 2 3}

      It first finds the best way to join each table to every other
      table.  It then takes those joined table combinations, and joins
      them to the other joined table combinations, until all tables are
      joined.

      jump to geqo if needed
      again:
       find_join_rels():
        for each joinrel:
         find_clause_joins()
          for each join on joinrel:
           if a join from the join clause adds only one relation, do the join
         or find_clauseless_joins()
       find_all_join_paths()
        generate paths(nested,sortmerge) for joins found in find_join_rels()
       prune_joinrels()
        remove from the join list the relation we just added to each join
       prune_rel_paths()
        set cheapest and perhaps remove unordered path, recompute table sizes
       if we have not done all the tables, go to "again"
   do group(GROUP)
   do aggregate
   put back constants
   re-flatten target list
 make unique(DISTINCT)
 make sort(ORDER BY)