diff --exclude=gram.c -ur postgresql-7.1.orig/src/backend/access/gist/gist.c postgresql-7.1/src/backend/access/gist/gist.c --- postgresql-7.1.orig/src/backend/access/gist/gist.c Sat Mar 24 11:54:34 2001 +++ postgresql-7.1/src/backend/access/gist/gist.c Wed Jul 4 22:05:47 2001 @@ -193,7 +193,7 @@ */ if (oldPred != NULL) { - slot->val = htup; + ExecStoreTuple( htup, slot, InvalidBuffer, false ); if (ExecQual((List *) oldPred, econtext, false)) { nitups++; @@ -207,7 +207,7 @@ */ if (pred != NULL) { - slot->val = htup; + ExecStoreTuple( htup, slot, InvalidBuffer, false ); if (!ExecQual((List *) pred, econtext, false)) continue; } diff --exclude=gram.c -ur postgresql-7.1.orig/src/backend/access/hash/hash.c postgresql-7.1/src/backend/access/hash/hash.c --- postgresql-7.1.orig/src/backend/access/hash/hash.c Sat Mar 24 11:54:34 2001 +++ postgresql-7.1/src/backend/access/hash/hash.c Wed Jul 4 22:06:10 2001 @@ -128,7 +128,7 @@ */ if (oldPred != NULL) { - slot->val = htup; + ExecStoreTuple( htup, slot, InvalidBuffer, false ); if (ExecQual((List *) oldPred, econtext, false)) { nitups++; @@ -142,7 +142,7 @@ */ if (pred != NULL) { - slot->val = htup; + ExecStoreTuple( htup, slot, InvalidBuffer, false ); if (!ExecQual((List *) pred, econtext, false)) continue; } diff --exclude=gram.c -ur postgresql-7.1.orig/src/backend/access/nbtree/nbtree.c postgresql-7.1/src/backend/access/nbtree/nbtree.c --- postgresql-7.1.orig/src/backend/access/nbtree/nbtree.c Sat Mar 24 11:54:35 2001 +++ postgresql-7.1/src/backend/access/nbtree/nbtree.c Wed Jul 4 21:59:55 2001 @@ -206,7 +206,8 @@ */ if (oldPred != NULL) { - slot->val = htup; + /* Invalid buffer should be ok, index shouldn't go away, i hope */ + ExecStoreTuple( htup, slot, InvalidBuffer, false ); if (ExecQual((List *) oldPred, econtext, false)) { nitups++; @@ -220,7 +221,8 @@ */ if (pred != NULL) { - slot->val = htup; + /* Invalid buffer should be ok, index shouldn't go away, i hope */ + ExecStoreTuple( htup, slot, InvalidBuffer, false ); if (!ExecQual((List *) pred, econtext, false)) continue; } diff --exclude=gram.c -ur postgresql-7.1.orig/src/backend/access/rtree/rtree.c postgresql-7.1/src/backend/access/rtree/rtree.c --- postgresql-7.1.orig/src/backend/access/rtree/rtree.c Sat Mar 24 11:54:35 2001 +++ postgresql-7.1/src/backend/access/rtree/rtree.c Wed Jul 4 22:07:13 2001 @@ -182,7 +182,7 @@ */ if (oldPred != NULL) { - slot->val = htup; + ExecStoreTuple( htup, slot, InvalidBuffer, false ); if (ExecQual((List *) oldPred, econtext, false)) { nitups++; @@ -196,7 +196,7 @@ */ if (pred != NULL) { - slot->val = htup; + ExecStoreTuple( htup, slot, InvalidBuffer, false ); if (!ExecQual((List *) pred, econtext, false)) continue; } diff --exclude=gram.c -ur postgresql-7.1.orig/src/backend/optimizer/path/indxpath.c postgresql-7.1/src/backend/optimizer/path/indxpath.c --- postgresql-7.1.orig/src/backend/optimizer/path/indxpath.c Sat Mar 24 11:54:40 2001 +++ postgresql-7.1/src/backend/optimizer/path/indxpath.c Wed Jul 4 19:59:53 2001 @@ -196,8 +196,10 @@ * 4. Generate an indexscan path if there are relevant restriction * clauses OR the index ordering is potentially useful for later * merging or final output ordering. + * + * If there is a predicate, consider it anyway since the clause may be useful */ - if (restrictclauses != NIL || useful_pathkeys != NIL) + if (restrictclauses != NIL || useful_pathkeys != NIL || index->indpred != NIL) add_path(rel, (Path *) create_index_path(root, rel, index, restrictclauses, @@ -1153,6 +1155,8 @@ ScanKeyData entry[3]; Form_pg_amop aform; + ExprContext *econtext; + pred_var = (Var *) get_leftop(predicate); pred_const = (Const *) get_rightop(predicate); clause_var = (Var *) get_leftop((Expr *) clause); @@ -1302,7 +1306,8 @@ copyObject(clause_const), copyObject(pred_const)); - test_result = ExecEvalExpr((Node *) test_expr, NULL, &isNull, NULL); + econtext = MakeExprContext(NULL, TransactionCommandContext); + test_result = ExecEvalExpr((Node *) test_expr, econtext, &isNull, NULL); if (isNull) { diff --exclude=gram.c -ur postgresql-7.1.orig/src/backend/optimizer/util/pathnode.c postgresql-7.1/src/backend/optimizer/util/pathnode.c --- postgresql-7.1.orig/src/backend/optimizer/util/pathnode.c Sat Mar 24 11:54:42 2001 +++ postgresql-7.1/src/backend/optimizer/util/pathnode.c Wed Jul 4 20:27:42 2001 @@ -362,6 +362,11 @@ pathnode->alljoinquals = false; pathnode->rows = rel->rows; + /* Not sure if this is necessary, but it should help if the + * statistics are too far off */ + if( index->indpred && index->tuples < pathnode->rows ) + pathnode->rows = index->tuples; + cost_index(&pathnode->path, root, rel, index, indexquals, false); return pathnode; diff --exclude=gram.c -ur postgresql-7.1.orig/src/backend/parser/analyze.c postgresql-7.1/src/backend/parser/analyze.c --- postgresql-7.1.orig/src/backend/parser/analyze.c Sat Mar 24 11:54:42 2001 +++ postgresql-7.1/src/backend/parser/analyze.c Wed Jul 4 23:03:16 2001 @@ -1525,6 +1525,12 @@ { Query *qry; + /* Add the table to the range table so that the WHERE clause can use the fields */ + /* no inheritence, yes we can use fields from relation */ + RangeTblEntry *rte = addRangeTableEntry( pstate, stmt->relname, NULL, false, true ); + /* no to join list, yes to namespace */ + addRTEtoQuery( pstate, rte, false, true ); + qry = makeNode(Query); qry->commandType = CMD_UTILITY; diff --exclude=gram.c -ur postgresql-7.1.orig/src/backend/parser/gram.y postgresql-7.1/src/backend/parser/gram.y --- postgresql-7.1.orig/src/backend/parser/gram.y Sat Feb 24 05:12:06 2001 +++ postgresql-7.1/src/backend/parser/gram.y Fri Jun 29 23:54:52 2001 @@ -2313,7 +2313,7 @@ *****************************************************************************/ IndexStmt: CREATE index_opt_unique INDEX index_name ON relation_name - access_method_clause '(' index_params ')' opt_with + access_method_clause '(' index_params ')' opt_with where_clause { IndexStmt *n = makeNode(IndexStmt); n->unique = $2; @@ -2322,7 +2322,7 @@ n->accessMethod = $7; n->indexParams = $9; n->withClause = $11; - n->whereClause = NULL; + n->whereClause = $12; $$ = (Node *)n; } ;