The attached patch fixes some spelling mistakes, makes the

comments on one of the optimizer functions a lot more
clear, adds a summary of the recent KSQO discussion to the
comments in the code, adds regression tests for the bug with
sequence state Tom fixed recently and another reg. test, and
removes some PostQuel legacy stuff: ExecAppend -> ExecInsert,
ExecRetrieve -> ExecSelect, etc.

Error messages remain unchanged until a vote.

Neil Conway
This commit is contained in:
Bruce Momjian 2002-06-26 21:58:56 +00:00
parent 893fe4919d
commit 73ad6ca96c
9 changed files with 83 additions and 56 deletions

View File

@ -27,7 +27,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.167 2002/06/25 17:58:10 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.168 2002/06/26 21:58:56 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -62,14 +62,14 @@ static TupleTableSlot *ExecutePlan(EState *estate, Plan *plan,
long numberTuples, long numberTuples,
ScanDirection direction, ScanDirection direction,
DestReceiver *destfunc); DestReceiver *destfunc);
static void ExecRetrieve(TupleTableSlot *slot, static void ExecSelect(TupleTableSlot *slot,
DestReceiver *destfunc, DestReceiver *destfunc,
EState *estate); EState *estate);
static void ExecAppend(TupleTableSlot *slot, ItemPointer tupleid, static void ExecInsert(TupleTableSlot *slot, ItemPointer tupleid,
EState *estate); EState *estate);
static void ExecDelete(TupleTableSlot *slot, ItemPointer tupleid, static void ExecDelete(TupleTableSlot *slot, ItemPointer tupleid,
EState *estate); EState *estate);
static void ExecReplace(TupleTableSlot *slot, ItemPointer tupleid, static void ExecUpdate(TupleTableSlot *slot, ItemPointer tupleid,
EState *estate); EState *estate);
static TupleTableSlot *EvalPlanQualNext(EState *estate); static TupleTableSlot *EvalPlanQualNext(EState *estate);
static void EndEvalPlanQual(EState *estate); static void EndEvalPlanQual(EState *estate);
@ -583,7 +583,7 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
/* /*
* Get the tuple descriptor describing the type of tuples to return. * Get the tuple descriptor describing the type of tuples to return.
* (this is especially important if we are creating a relation with * (this is especially important if we are creating a relation with
* "retrieve into") * "SELECT INTO")
*/ */
tupType = ExecGetTupType(plan); /* tuple descriptor */ tupType = ExecGetTupType(plan); /* tuple descriptor */
@ -892,7 +892,7 @@ EndPlan(Plan *plan, EState *estate)
* Retrieves all tuples if numberTuples is 0 * Retrieves all tuples if numberTuples is 0
* *
* result is either a slot containing the last tuple in the case * result is either a slot containing the last tuple in the case
* of a RETRIEVE or NULL otherwise. * of a SELECT or NULL otherwise.
* *
* Note: the ctid attribute is a 'junk' attribute that is removed before the * Note: the ctid attribute is a 'junk' attribute that is removed before the
* user can see it * user can see it
@ -1068,29 +1068,26 @@ lnext: ;
slot = ExecStoreTuple(newTuple, /* tuple to store */ slot = ExecStoreTuple(newTuple, /* tuple to store */
junkfilter->jf_resultSlot, /* dest slot */ junkfilter->jf_resultSlot, /* dest slot */
InvalidBuffer, /* this tuple has no InvalidBuffer, /* this tuple has no buffer */
* buffer */
true); /* tuple should be pfreed */ true); /* tuple should be pfreed */
} /* if (junkfilter... */ }
/* /*
* now that we have a tuple, do the appropriate thing with it.. * now that we have a tuple, do the appropriate thing with it..
* either return it to the user, add it to a relation someplace, * either return it to the user, add it to a relation someplace,
* delete it from a relation, or modify some of its attributes. * delete it from a relation, or modify some of its attributes.
*/ */
switch (operation) switch (operation)
{ {
case CMD_SELECT: case CMD_SELECT:
ExecRetrieve(slot, /* slot containing tuple */ ExecSelect(slot, /* slot containing tuple */
destfunc, /* destination's tuple-receiver destfunc, /* destination's tuple-receiver obj */
* obj */ estate);
estate); /* */
result = slot; result = slot;
break; break;
case CMD_INSERT: case CMD_INSERT:
ExecAppend(slot, tupleid, estate); ExecInsert(slot, tupleid, estate);
result = NULL; result = NULL;
break; break;
@ -1100,7 +1097,7 @@ lnext: ;
break; break;
case CMD_UPDATE: case CMD_UPDATE:
ExecReplace(slot, tupleid, estate); ExecUpdate(slot, tupleid, estate);
result = NULL; result = NULL;
break; break;
@ -1121,23 +1118,23 @@ lnext: ;
/* /*
* here, result is either a slot containing a tuple in the case of a * here, result is either a slot containing a tuple in the case of a
* RETRIEVE or NULL otherwise. * SELECT or NULL otherwise.
*/ */
return result; return result;
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* ExecRetrieve * ExecSelect
* *
* RETRIEVEs are easy.. we just pass the tuple to the appropriate * SELECTs are easy.. we just pass the tuple to the appropriate
* print function. The only complexity is when we do a * print function. The only complexity is when we do a
* "retrieve into", in which case we insert the tuple into * "SELECT INTO", in which case we insert the tuple into
* the appropriate relation (note: this is a newly created relation * the appropriate relation (note: this is a newly created relation
* so we don't need to worry about indices or locks.) * so we don't need to worry about indices or locks.)
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
static void static void
ExecRetrieve(TupleTableSlot *slot, ExecSelect(TupleTableSlot *slot,
DestReceiver *destfunc, DestReceiver *destfunc,
EState *estate) EState *estate)
{ {
@ -1169,16 +1166,15 @@ ExecRetrieve(TupleTableSlot *slot,
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* ExecAppend * ExecInsert
* *
* APPENDs are trickier.. we have to insert the tuple into * INSERTs are trickier.. we have to insert the tuple into
* the base relation and insert appropriate tuples into the * the base relation and insert appropriate tuples into the
* index relations. * index relations.
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
static void static void
ExecAppend(TupleTableSlot *slot, ExecInsert(TupleTableSlot *slot,
ItemPointer tupleid, ItemPointer tupleid,
EState *estate) EState *estate)
{ {
@ -1227,7 +1223,7 @@ ExecAppend(TupleTableSlot *slot,
* Check the constraints of the tuple * Check the constraints of the tuple
*/ */
if (resultRelationDesc->rd_att->constr) if (resultRelationDesc->rd_att->constr)
ExecConstraints("ExecAppend", resultRelInfo, slot, estate); ExecConstraints("ExecInsert", resultRelInfo, slot, estate);
/* /*
* insert the tuple * insert the tuple
@ -1259,7 +1255,7 @@ ExecAppend(TupleTableSlot *slot,
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* ExecDelete * ExecDelete
* *
* DELETE is like append, we delete the tuple and its * DELETE is like UPDATE, we delete the tuple and its
* index tuples. * index tuples.
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
@ -1346,18 +1342,18 @@ ldelete:;
} }
/* ---------------------------------------------------------------- /* ----------------------------------------------------------------
* ExecReplace * ExecUpdate
* *
* note: we can't run replace queries with transactions * note: we can't run UPDATE queries with transactions
* off because replaces are actually appends and our * off because UPDATEs are actually INSERTs and our
* scan will mistakenly loop forever, replacing the tuple * scan will mistakenly loop forever, updating the tuple
* it just appended.. This should be fixed but until it * it just inserted.. This should be fixed but until it
* is, we don't want to get stuck in an infinite loop * is, we don't want to get stuck in an infinite loop
* which corrupts your database.. * which corrupts your database..
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
static void static void
ExecReplace(TupleTableSlot *slot, ExecUpdate(TupleTableSlot *slot,
ItemPointer tupleid, ItemPointer tupleid,
EState *estate) EState *estate)
{ {
@ -1472,7 +1468,7 @@ lreplace:;
/* /*
* Note: instead of having to update the old index tuples associated * Note: instead of having to update the old index tuples associated
* with the heap tuple, all we do is form and insert new index tuples. * with the heap tuple, all we do is form and insert new index tuples.
* This is because replaces are actually deletes and inserts and index * This is because UPDATEs are actually DELETEs and INSERTs and index
* tuple deletion is done automagically by the vacuum daemon. All we * tuple deletion is done automagically by the vacuum daemon. All we
* do is insert new index tuples. -cim 9/27/89 * do is insert new index tuples. -cim 9/27/89
*/ */
@ -1481,7 +1477,7 @@ lreplace:;
* process indices * process indices
* *
* heap_update updates a tuple in the base relation by invalidating it * heap_update updates a tuple in the base relation by invalidating it
* and then appending a new tuple to the relation. As a side effect, * and then inserting a new tuple to the relation. As a side effect,
* the tupleid of the new tuple is placed in the new tuple's t_ctid * the tupleid of the new tuple is placed in the new tuple's t_ctid
* field. So we now insert index tuples using the new tupleid stored * field. So we now insert index tuples using the new tupleid stored
* there. * there.
@ -1554,7 +1550,7 @@ ExecRelCheck(ResultRelInfo *resultRelInfo,
} }
void void
ExecConstraints(char *caller, ResultRelInfo *resultRelInfo, ExecConstraints(const char *caller, ResultRelInfo *resultRelInfo,
TupleTableSlot *slot, EState *estate) TupleTableSlot *slot, EState *estate)
{ {
Relation rel = resultRelInfo->ri_RelationDesc; Relation rel = resultRelInfo->ri_RelationDesc;

View File

@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.85 2002/06/25 17:58:10 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.86 2002/06/26 21:58:56 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -18,7 +18,7 @@
* *
* ExecOpenIndices \ * ExecOpenIndices \
* ExecCloseIndices | referenced by InitPlan, EndPlan, * ExecCloseIndices | referenced by InitPlan, EndPlan,
* ExecInsertIndexTuples / ExecAppend, ExecReplace * ExecInsertIndexTuples / ExecInsert, ExecUpdate
* *
* RegisterExprContextCallback Register function shutdown callback * RegisterExprContextCallback Register function shutdown callback
* UnregisterExprContextCallback Deregister function shutdown callback * UnregisterExprContextCallback Deregister function shutdown callback

View File

@ -42,7 +42,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.87 2002/06/25 17:58:10 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/optimizer/path/costsize.c,v 1.88 2002/06/26 21:58:56 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -154,11 +154,11 @@ cost_seqscan(Path *path, Query *root,
* *
* Given a guesstimated cache size, we estimate the actual I/O cost per page * Given a guesstimated cache size, we estimate the actual I/O cost per page
* with the entirely ad-hoc equations: * with the entirely ad-hoc equations:
* for rel_size <= effective_cache_size: * if relpages >= effective_cache_size:
* 1 + (random_page_cost/2-1) * (rel_size/effective_cache_size) ** 2 * random_page_cost * (1 - (effective_cache_size/relpages)/2)
* for rel_size >= effective_cache_size: * if relpages < effective_cache_size:
* random_page_cost * (1 - (effective_cache_size/rel_size)/2) * 1 + (random_page_cost/2-1) * (relpages/effective_cache_size) ** 2
* These give the right asymptotic behavior (=> 1.0 as rel_size becomes * These give the right asymptotic behavior (=> 1.0 as relpages becomes
* small, => random_page_cost as it becomes large) and meet in the middle * small, => random_page_cost as it becomes large) and meet in the middle
* with the estimate that the cache is about 50% effective for a relation * with the estimate that the cache is about 50% effective for a relation
* of the same size as effective_cache_size. (XXX this is probably all * of the same size as effective_cache_size. (XXX this is probably all

View File

@ -1,7 +1,7 @@
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* prepkeyset.c * prepkeyset.c
* Special preperation for keyset queries. * Special preparation for keyset queries (KSQO).
* *
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
@ -14,12 +14,6 @@
#include "postgres.h" #include "postgres.h"
#include "optimizer/planmain.h" #include "optimizer/planmain.h"
/*
* Node_Copy
* a macro to simplify calling of copyObject on the specified field
*/
#define Node_Copy(from, newnode, field) newnode->field = copyObject(from->field)
bool _use_keyset_query_optimizer = FALSE; bool _use_keyset_query_optimizer = FALSE;
#ifdef ENABLE_KEY_SET_QUERY #ifdef ENABLE_KEY_SET_QUERY
@ -55,13 +49,20 @@ static int TotalExpr;
* a HAVING, or a GROUP BY. It must be a single table and have KSQO * a HAVING, or a GROUP BY. It must be a single table and have KSQO
* set to 'on'. * set to 'on'.
* *
* The primary use of this transformation is to avoid the exponrntial * The primary use of this transformation is to avoid the exponential
* memory consumption of cnfify() and to make use of index access * memory consumption of cnfify() and to make use of index access
* methods. * methods.
* *
* daveh@insightdist.com 1998-08-31 * daveh@insightdist.com 1998-08-31
* *
* May want to also prune out duplicate terms. * May want to also prune out duplicate terms.
*
* XXX: this code is currently not compiled because it has not been
* updated to work with the re-implementation of UNION/INTERSECT/EXCEPT
* in PostgreSQL 7.1. However, it is of questionable value in any
* case, because it changes the semantics of the original query:
* UNION will add an implicit SELECT DISTINCT, which might change
* the results that are returned.
**********************************************************************/ **********************************************************************/
void void
transformKeySetQuery(Query *origNode) transformKeySetQuery(Query *origNode)

View File

@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: executor.h,v 1.68 2002/06/25 17:58:10 momjian Exp $ * $Id: executor.h,v 1.69 2002/06/26 21:58:56 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
@ -52,7 +52,7 @@ extern TupleDesc ExecutorStart(QueryDesc *queryDesc, EState *estate);
extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc, EState *estate, extern TupleTableSlot *ExecutorRun(QueryDesc *queryDesc, EState *estate,
ScanDirection direction, long count); ScanDirection direction, long count);
extern void ExecutorEnd(QueryDesc *queryDesc, EState *estate); extern void ExecutorEnd(QueryDesc *queryDesc, EState *estate);
extern void ExecConstraints(char *caller, ResultRelInfo *resultRelInfo, extern void ExecConstraints(const char *caller, ResultRelInfo *resultRelInfo,
TupleTableSlot *slot, EState *estate); TupleTableSlot *slot, EState *estate);
extern TupleTableSlot *EvalPlanQual(EState *estate, Index rti, extern TupleTableSlot *EvalPlanQual(EState *estate, Index rti,
ItemPointer tid); ItemPointer tid);

View File

@ -151,3 +151,13 @@ SELECT * FROM serialTest;
force | 100 force | 100
(3 rows) (3 rows)
CREATE SEQUENCE sequence_test;
BEGIN;
SELECT nextval('sequence_test');
nextval
---------
1
(1 row)
DROP SEQUENCE sequence_test;
END;

View File

@ -21,6 +21,15 @@ SELECT b, c FROM test_having
3 | bbbb 3 | bbbb
(2 rows) (2 rows)
-- HAVING is equivalent to WHERE in this case
SELECT b, c FROM test_having
GROUP BY b, c HAVING b = 3;
b | c
---+----------
3 | BBBB
3 | bbbb
(2 rows)
SELECT lower(c), count(c) FROM test_having SELECT lower(c), count(c) FROM test_having
GROUP BY lower(c) HAVING count(*) > 2 OR min(a) = max(a); GROUP BY lower(c) HAVING count(*) > 2 OR min(a) = max(a);
lower | count lower | count

View File

@ -217,3 +217,10 @@ INSERT INTO serialTest VALUES ('force', 100);
INSERT INTO serialTest VALUES ('wrong', NULL); INSERT INTO serialTest VALUES ('wrong', NULL);
SELECT * FROM serialTest; SELECT * FROM serialTest;
CREATE SEQUENCE sequence_test;
BEGIN;
SELECT nextval('sequence_test');
DROP SEQUENCE sequence_test;
END;

View File

@ -18,6 +18,10 @@ INSERT INTO test_having VALUES (9, 4, 'CCCC', 'j');
SELECT b, c FROM test_having SELECT b, c FROM test_having
GROUP BY b, c HAVING count(*) = 1; GROUP BY b, c HAVING count(*) = 1;
-- HAVING is equivalent to WHERE in this case
SELECT b, c FROM test_having
GROUP BY b, c HAVING b = 3;
SELECT lower(c), count(c) FROM test_having SELECT lower(c), count(c) FROM test_having
GROUP BY lower(c) HAVING count(*) > 2 OR min(a) = max(a); GROUP BY lower(c) HAVING count(*) > 2 OR min(a) = max(a);