|
11 | 11 | * Portions Copyright (c) 1994, Regents of the University of California |
12 | 12 | * |
13 | 13 | * IDENTIFICATION |
14 | | - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.47 2003/02/15 20:12:40 tgl Exp $ |
| 14 | + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.48 2003/05/02 19:48:53 tgl Exp $ |
15 | 15 | * |
16 | 16 | *------------------------------------------------------------------------- |
17 | 17 | */ |
|
27 | 27 | #include"parser/parsetree.h" |
28 | 28 | #include"parser/parse_func.h" |
29 | 29 | #include"utils/lsyscache.h" |
| 30 | +#include"utils/memutils.h" |
30 | 31 |
|
31 | 32 |
|
32 | 33 | staticPathKeyItem*makePathKeyItem(Node*key,Oidsortop); |
@@ -942,26 +943,35 @@ make_pathkeys_for_sortclauses(List *sortclauses, |
942 | 943 | * same, but not if the mergeclause appears above an OUTER JOIN.) |
943 | 944 | * This is a worthwhile savings because these routines will be invoked |
944 | 945 | * many times when dealing with a many-relation query. |
| 946 | + * |
| 947 | + * We have to be careful that the cached values are palloc'd in the same |
| 948 | + * context the RestrictInfo node itself is in. This is not currently a |
| 949 | + * problem for normal planning, but it is an issue for GEQO planning. |
945 | 950 | */ |
946 | 951 | void |
947 | 952 | cache_mergeclause_pathkeys(Query*root,RestrictInfo*restrictinfo) |
948 | 953 | { |
949 | 954 | Node*key; |
950 | 955 | PathKeyItem*item; |
| 956 | +MemoryContextoldcontext; |
951 | 957 |
|
952 | 958 | Assert(restrictinfo->mergejoinoperator!=InvalidOid); |
953 | 959 |
|
954 | 960 | if (restrictinfo->left_pathkey==NIL) |
955 | 961 | { |
| 962 | +oldcontext=MemoryContextSwitchTo(GetMemoryChunkContext(restrictinfo)); |
956 | 963 | key=get_leftop(restrictinfo->clause); |
957 | 964 | item=makePathKeyItem(key,restrictinfo->left_sortop); |
958 | 965 | restrictinfo->left_pathkey=make_canonical_pathkey(root,item); |
| 966 | +MemoryContextSwitchTo(oldcontext); |
959 | 967 | } |
960 | 968 | if (restrictinfo->right_pathkey==NIL) |
961 | 969 | { |
| 970 | +oldcontext=MemoryContextSwitchTo(GetMemoryChunkContext(restrictinfo)); |
962 | 971 | key=get_rightop(restrictinfo->clause); |
963 | 972 | item=makePathKeyItem(key,restrictinfo->right_sortop); |
964 | 973 | restrictinfo->right_pathkey=make_canonical_pathkey(root,item); |
| 974 | +MemoryContextSwitchTo(oldcontext); |
965 | 975 | } |
966 | 976 | } |
967 | 977 |
|
|