|
42 | 42 | * Portions Copyright (c) 1994, Regents of the University of California
|
43 | 43 | *
|
44 | 44 | * IDENTIFICATION
|
45 |
| - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.64 2000/10/05 19:48:26 momjian Exp $ |
| 45 | + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.65 2000/12/12 23:33:33 tgl Exp $ |
46 | 46 | *
|
47 | 47 | *-------------------------------------------------------------------------
|
48 | 48 | */
|
@@ -672,8 +672,38 @@ Cost
|
672 | 672 | cost_qual_eval(List *quals)
|
673 | 673 | {
|
674 | 674 | Cost total = 0;
|
| 675 | + List *l; |
675 | 676 |
|
676 |
| - cost_qual_eval_walker((Node *) quals, &total); |
| 677 | + /* We don't charge any cost for the implicit ANDing at top level ... */ |
| 678 | + |
| 679 | + foreach(l, quals) |
| 680 | + { |
| 681 | + Node *qual = (Node *) lfirst(l); |
| 682 | + |
| 683 | + /* |
| 684 | + * RestrictInfo nodes contain an eval_cost field reserved for this |
| 685 | + * routine's use, so that it's not necessary to evaluate the qual |
| 686 | + * clause's cost more than once. If the clause's cost hasn't been |
| 687 | + * computed yet, the field will contain -1. |
| 688 | + */ |
| 689 | + if (qual && IsA(qual, RestrictInfo)) |
| 690 | + { |
| 691 | + RestrictInfo *restrictinfo = (RestrictInfo *) qual; |
| 692 | + |
| 693 | + if (restrictinfo->eval_cost < 0) |
| 694 | + { |
| 695 | + restrictinfo->eval_cost = 0; |
| 696 | + cost_qual_eval_walker((Node *) restrictinfo->clause, |
| 697 | + &restrictinfo->eval_cost); |
| 698 | + } |
| 699 | + total += restrictinfo->eval_cost; |
| 700 | + } |
| 701 | + else |
| 702 | + { |
| 703 | + /* If it's a bare expression, must always do it the hard way */ |
| 704 | + cost_qual_eval_walker(qual, &total); |
| 705 | + } |
| 706 | + } |
677 | 707 | return total;
|
678 | 708 | }
|
679 | 709 |
|
@@ -748,18 +778,6 @@ cost_qual_eval_walker(Node *node, Cost *total)
|
748 | 778 | }
|
749 | 779 | /* fall through to examine args of Expr node */
|
750 | 780 | }
|
751 |
| - |
752 |
| - /* |
753 |
| - * expression_tree_walker doesn't know what to do with RestrictInfo |
754 |
| - * nodes, but we just want to recurse through them. |
755 |
| - */ |
756 |
| - if (IsA(node, RestrictInfo)) |
757 |
| - { |
758 |
| - RestrictInfo *restrictinfo = (RestrictInfo *) node; |
759 |
| - |
760 |
| - return cost_qual_eval_walker((Node *) restrictinfo->clause, total); |
761 |
| - } |
762 |
| - /* Otherwise, recurse. */ |
763 | 781 | return expression_tree_walker(node, cost_qual_eval_walker,
|
764 | 782 | (void *) total);
|
765 | 783 | }
|
|
0 commit comments