Add TRUNCATE command, with psql help and sgml additions.
authorBruce Momjian <bruce@momjian.us>
Thu, 23 Sep 1999 17:03:39 +0000 (17:03 +0000)
committerBruce Momjian <bruce@momjian.us>
Thu, 23 Sep 1999 17:03:39 +0000 (17:03 +0000)
15 files changed:
doc/src/sgml/ref/truncate.sgml [new file with mode: 0644]
src/backend/catalog/heap.c
src/backend/commands/creatinh.c
src/backend/parser/gram.y
src/backend/parser/keywords.c
src/backend/tcop/utility.c
src/backend/utils/mmgr/portalmem.c
src/bin/psql/psqlHelp.h
src/include/catalog/heap.h
src/include/commands/creatinh.h
src/include/nodes/nodes.h
src/include/nodes/parsenodes.h
src/include/storage/bufmgr.h
src/include/utils/portal.h
src/tools/pgindent/pgindent

diff --git a/doc/src/sgml/ref/truncate.sgml b/doc/src/sgml/ref/truncate.sgml
new file mode 100644 (file)
index 0000000..998f826
--- /dev/null
@@ -0,0 +1,133 @@
+<!--
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/truncate.sgml,v 1.1 1999/09/23 17:02:28 momjian Exp $
+Postgres documentation
+-->
+
+<refentry id="SQL-TRUNCATE">
+ <refmeta>
+  <refentrytitle id="SQL-TRUNCATE-TITLE">
+   TRUNCATE
+  </refentrytitle>
+  <refmiscinfo>SQL - Language Statements</refmiscinfo>
+ </refmeta>
+ <refnamediv>
+  <refname>
+   TRUNCATE
+  </refname>
+  <refpurpose>
+   Close a cursor
+  </refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+  <refsynopsisdivinfo>
+   <date>1999-07-20</date>
+  </refsynopsisdivinfo>
+  <synopsis>
+TRUNCATE TABLE <replaceable class="PARAMETER">table</replaceable>
+  </synopsis>
+  
+  <refsect2 id="R2-SQL-TRUNCATE-1">
+   <refsect2info>
+    <date>1998-09-08</date>
+   </refsect2info>
+   <title>
+    Inputs
+   </title>
+   <para>
+
+    <variablelist>
+     <varlistentry>
+      <term><replaceable class="PARAMETER">table</replaceable></term>
+      <listitem>
+       <para>
+       The table name to truncate.
+       </para>
+      </listitem>
+     </varlistentry>
+    </variablelist>
+   </para>
+  </refsect2>
+  
+  <refsect2 id="R2-SQL-TRUNCATE-2">
+   <refsect2info>
+    <date>1998-09-08</date>
+   </refsect2info>
+   <title>
+    Outputs
+   </title>
+   <para>
+
+    <variablelist>
+     <varlistentry>
+      <term><computeroutput>
+TRUNCATE
+       </computeroutput></term>
+      <listitem>
+       <para>
+       Message returned if the table is successfully truncated.
+       </para>
+      </listitem>
+     </varlistentry>
+    </variablelist>
+   </para>
+  </refsect2>
+ </refsynopsisdiv>
+
+ <refsect1 id="R1-SQL-TRUNCATE-1">
+  <refsect1info>
+   <date>1998-09-08</date>
+  </refsect1info>
+  <title>
+   Description
+  </title>
+  <para>
+   <command>TRUNCATE</command> quickly removes all rows from a table.
+  </para>
+  
+ <refsect1 id="R1-SQL-TRUNCATE-2">
+  <title>
+   Usage
+  </title>
+  <para>
+   Truncate the table bigtable.
+  </para>
+  <programlisting>
+TRUNCATE TABLE bigtable;
+  </programlisting>
+ </refsect1>
+ <refsect1 id="R1-SQL-TRUNCATE-3">
+  <title>
+   Compatibility
+  </title>
+  
+  <refsect2 id="R2-SQL-TRUNCATE-4">
+   <refsect2info>
+    <date>1998-09-08</date>
+   </refsect2info>
+   <title>
+    SQL92
+   </title>
+   <para>
+    There is no <command>TRUNCATE</command> in <acronym>SQL92</acronym>.
+   </para>
+  </refsect2>
+ </refsect1>
+</refentry>
+
+<!-- Keep this comment at the end of the file
+Local variables:
+mode: sgml
+sgml-omittag:t
+sgml-shorttag:t
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:1
+sgml-indent-data:t
+sgml-parent-document:nil
+sgml-default-dtd-file:"../reference.ced"
+sgml-exposed-tags:nil
+sgml-local-catalogs:"/usr/lib/sgml/catalog"
+sgml-local-ecat-files:nil
+End:
+-->
index 644f03eba870a0406202ee4d6cd86c1274562f97..e225a5834dc55a0a5da9f694a80ea64f0102808a 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.96 1999/09/18 19:06:33 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.97 1999/09/23 17:02:34 momjian Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -30,6 +30,7 @@
 #include "miscadmin.h"
 
 #include "access/heapam.h"
+#include "access/genam.h"
 #include "access/xact.h"
 #include "catalog/catalog.h"
 #include "catalog/catname.h"
@@ -40,6 +41,7 @@
 #include "catalog/pg_index.h"
 #include "catalog/pg_inherits.h"
 #include "catalog/pg_ipl.h"
+#include "catalog/pg_proc.h"
 #include "catalog/pg_relcheck.h"
 #include "commands/trigger.h"
 #include "optimizer/tlist.h"
@@ -49,6 +51,7 @@
 #include "storage/smgr.h"
 #include "tcop/tcopprot.h"
 #include "utils/builtins.h"
+#include "utils/portal.h"
 #include "utils/relcache.h"
 #include "utils/syscache.h"
 #include "utils/temprel.h"
@@ -1056,6 +1059,233 @@ DeleteRelationTuple(Relation rel)
        heap_close(pg_class_desc, RowExclusiveLock);
 }
 
+/* --------------------------------
+ * RelationTruncateIndexes - This routine is used to truncate all
+ * indices associated with the heap relation to zero tuples.
+ * The routine will truncate and then reconstruct the indices on
+ * the relation specified by the heapRelation parameter.
+ * --------------------------------
+*/
+
+static void 
+RelationTruncateIndexes(Relation heapRelation) {
+
+  Relation indexRelation, currentIndex;
+  ScanKeyData entry;
+  HeapScanDesc scan;  
+  HeapTuple indexTuple, procTuple, classTuple;
+  Form_pg_index index;
+  Oid heapId, indexId, procId, accessMethodId;
+  Node *oldPred = NULL;
+  PredInfo *predInfo;
+  List *cnfPred = NULL;
+  AttrNumber *attributeNumberA;
+  FuncIndexInfo fInfo, *funcInfo = NULL;
+  int i, numberOfAttributes;
+  char *predString;
+
+  /*** Save the id of the heap relation ***/
+
+  heapId = RelationGetRelid(heapRelation);
+  
+  /*** Open the System relation, pg_index ***/
+
+  indexRelation = heap_openr(IndexRelationName);
+  
+  /*** Scan pg_index For indexes related to heap relation ***/
+
+  ScanKeyEntryInitialize(&entry, 0x0, Anum_pg_index_indrelid, F_OIDEQ,
+                        ObjectIdGetDatum(heapId));
+
+  scan = heap_beginscan(indexRelation, false, SnapshotNow, 1, &entry);
+  while (HeapTupleIsValid(indexTuple = heap_getnext(scan, 0))) {
+      
+    /*** For each index, fetch index attributes ***/
+
+    index = (Form_pg_index) GETSTRUCT(indexTuple);
+    indexId = index->indexrelid;
+    procId = index->indproc;
+    
+    for (i = 0; i < INDEX_MAX_KEYS; i++) {
+      if (index->indkey[i] == InvalidAttrNumber) break;
+    }
+    numberOfAttributes = i;
+    
+    /*** If a valid where predicate, compute predicate Node ***/
+
+    if (VARSIZE(&index->indpred) != 0) {       
+      predString = fmgr(F_TEXTOUT, &index->indpred);
+      oldPred = stringToNode(predString);
+      pfree(predString);
+    }
+    
+    predInfo = (PredInfo *) palloc(sizeof(PredInfo));
+    predInfo->pred = (Node *) cnfPred;
+    /* predInfo->pred = (Node *) oldPred; */
+    predInfo->oldPred = oldPred;
+
+    /*** Assign Index keys to attributes array ***/
+
+    attributeNumberA = (AttrNumber *) palloc(numberOfAttributes * 
+                                            sizeof(attributeNumberA[0]));    
+    for (i = 0; i < numberOfAttributes; i++) {
+      attributeNumberA[i] = index->indkey[i];
+    }
+    
+    /*** If this is a procedural index, initialize our FuncIndexInfo ***/
+
+    if (procId != InvalidOid) {
+      funcInfo = &fInfo;
+      FIsetnArgs(funcInfo, numberOfAttributes);      
+      procTuple = SearchSysCacheTuple(PROOID, ObjectIdGetDatum(procId),
+                                     0, 0, 0);
+      if (!HeapTupleIsValid(procTuple)) {
+       elog(ERROR, "RelationTruncateIndexes: index procedure not found");
+      }
+      namecpy(&(funcInfo->funcName),
+             &(((Form_pg_proc) GETSTRUCT(procTuple))->proname));
+      FIsetProcOid(funcInfo, procTuple->t_data->t_oid);
+    }
+
+    /*** Fetch the classTuple associated with this index ***/
+    
+    classTuple = SearchSysCacheTupleCopy(RELOID, ObjectIdGetDatum(indexId),
+                                        0, 0, 0);
+    if (!HeapTupleIsValid(classTuple)) {
+      elog(ERROR, "RelationTruncateIndexes: index access method not found");
+    }
+    accessMethodId = ((Form_pg_class) GETSTRUCT(classTuple))->relam;
+
+    /*** Open our index relation ***/
+    
+    currentIndex = index_open(indexId);
+    if (currentIndex == NULL) {
+      elog(ERROR, "RelationTruncateIndexes: can't open index relation");
+    }
+
+    /*** Truncate the index before building ***/
+
+    smgrtruncate(DEFAULT_SMGR, currentIndex, 0);
+    currentIndex->rd_nblocks = 0;
+    
+    /*** Initialize the index and rebuild ***/
+
+    InitIndexStrategy(numberOfAttributes, currentIndex, accessMethodId);
+    index_build(heapRelation, currentIndex, numberOfAttributes,
+               attributeNumberA, 0, NULL, funcInfo, predInfo);
+
+    /*** Re-open our heap relation and re-lock, since index_build ***/
+    /*** will close and unlock the relation ***/
+
+    heapRelation = heap_open(heapId);
+    LockRelation(heapRelation, AccessExclusiveLock);
+
+    /*** RelationUnsetLockForWrite(currentIndex); ***/
+    
+  }
+
+  /*** Complete the scan and close the Catalogueindex Relation ***/
+  
+  heap_endscan(scan);
+  heap_close(indexRelation);
+
+}
+
+/* ----------------------------
+ *   heap_truncate
+ *   
+ *   This routine is used to truncate the data from the 
+ *   storange manager of any data within the relation handed
+ *   to this routine.  The routine assumes that the relation 
+ *   handed to this routine is an open relation.  
+ *
+ * ----------------------------
+ */
+
+void 
+heap_truncate(char *relname) {
+  
+  Relation rel;
+  Oid rid;     
+  Portal portal;
+  char *pname;
+  MemoryContext old;
+  PortalVariableMemory pmem;
+  NameData truncRel;
+
+  /*
+   * Create a portal for safe memory across transctions. We need to
+   * palloc the name space for it because our hash function expects the
+   * name to be on a longword boundary.  CreatePortal copies the name to
+   * safe storage for us.
+   */
+  
+  pname = (char *) palloc(strlen(TRUNCPNAME) + 1);
+  strcpy(pname, TRUNCPNAME);
+  portal = CreatePortal(pname);
+  pfree(pname);
+
+  /* relname gets de-allocated on transaction commit */
+  
+  strcpy(truncRel.data, relname);
+  
+  pmem = PortalGetVariableMemory(portal);
+  old = MemoryContextSwitchTo((MemoryContext) pmem);
+  MemoryContextSwitchTo(old);
+  
+  /* Commit the current transaction */
+  
+  CommitTransactionCommand();
+  StartTransactionCommand();
+     
+  /* Open relation for processing */
+
+  rel = heap_openr(truncRel.data);
+  if (rel == NULL)
+    elog(ERROR, "Relation %s Does Not Exist!", truncRel.data);
+  rid = rel->rd_id;
+
+  LockRelation(rel, AccessExclusiveLock); 
+
+  /* Release any buffers associated with this relation */
+
+  ReleaseRelationBuffers(rel);  
+  BlowawayRelationBuffers(rel, 0);
+
+  /* Now truncate the actual data and set blocks to zero */
+  
+  smgrtruncate(DEFAULT_SMGR, rel, 0);
+  rel->rd_nblocks = 0;
+
+  /* If this relation has indexes, truncate the indexes, which */
+  /* will unlock the relation as a result.  Otherwise, unlock */
+  /* the relation ourselves. */
+  
+  if (rel->rd_rel->relhasindex) {
+    RelationTruncateIndexes(rel);
+  } else {
+    UnlockRelation(rel, AccessExclusiveLock);
+  }
+
+  /* Close our relation */
+  
+  heap_close(rel);
+  RelationForgetRelation(rid);
+  
+  /* Destoy cross-transaction memory */
+
+  PortalDestroy(&portal);
+
+  /* Start new transaction */
+
+  CommitTransactionCommand();
+  StartTransactionCommand();
+  
+  return;
+
+}
+
+
 /* --------------------------------
  *             DeleteAttributeTuples
  *
index c1069dd41e6948f78d576be7a07c9b22f428c8ed..c146afa1db4b600953f83e53a82639ea93d81c4e 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.46 1999/09/18 19:06:40 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.47 1999/09/23 17:02:40 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -157,6 +157,26 @@ RemoveRelation(char *name)
        heap_destroy_with_catalog(name);
 }
 
+/*
+ * TruncateRelation --
+ *                Removes all the rows from a relation
+ *
+ * Exceptions:
+ *                BadArg if name is invalid
+ *
+ *
+ * Note:
+ *                Rows are removed, indices are truncated and reconstructed.
+ */
+
+void
+TruncateRelation(char *name)
+{
+
+  AssertArg(name);
+  heap_truncate(name);
+
+}
 
 /*
  * MergeAttributes
index 20c33bc20c75161790ca90ab6f47fec9c9a03652..32c46e05d1c06ce161c0be4d99f86438dbe174db 100644 (file)
@@ -10,7 +10,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.98 1999/09/14 06:06:31 thomas Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.99 1999/09/23 17:02:46 momjian Exp $
  *
  * HISTORY
  *       AUTHOR                        DATE                    MAJOR EVENT
@@ -122,6 +122,7 @@ Oid param_type(int t); /* used in parse_expr.c */
 %type <node>   stmt,
                AddAttrStmt, ClosePortalStmt,
                CopyStmt, CreateStmt, CreateAsStmt, CreateSeqStmt, DefineStmt, DestroyStmt,
+               TruncateStmt,
                ExtendStmt, FetchStmt,  GrantStmt, CreateTrigStmt, DropTrigStmt,
                CreatePLangStmt, DropPLangStmt,
                IndexStmt, ListenStmt, UnlistenStmt, LockStmt, OptimizableStmt,
@@ -318,7 +319,7 @@ Oid param_type(int t); /* used in parse_expr.c */
                OFFSET, OIDS, OPERATOR, PASSWORD, PROCEDURAL,
                RENAME, RESET, RETURNS, ROW, RULE,
                SEQUENCE, SERIAL, SETOF, SHARE, SHOW, START, STATEMENT, STDIN, STDOUT,
-               TRUSTED, 
+               TRUNCATE, TRUSTED, 
                UNLISTEN, UNTIL, VACUUM, VALID, VERBOSE, VERSION
 
 /* Special keywords, not in the query language - see the "lex" file */
@@ -383,7 +384,8 @@ stmt :        AddAttrStmt
                | CreateUserStmt
                | ClusterStmt
                | DefineStmt
-               | DestroyStmt
+               | DestroyStmt           
+               | TruncateStmt
                | DropPLangStmt
                | DropTrigStmt
                | DropUserStmt
@@ -1607,6 +1609,20 @@ DestroyStmt:  DROP TABLE relation_name_list
                                }
                ;
 
+/*****************************************************************************
+ *
+ *             QUERY:
+ *                             truncate table relname
+ *
+ *****************************************************************************/
+
+TruncateStmt:  TRUNCATE TABLE relation_name
+                               {
+                                       TruncateStmt *n = makeNode(TruncateStmt);
+                                       n->relName = $3;
+                                       $$ = (Node *)n;
+                               }
+                       ;
 
 /*****************************************************************************
  *
@@ -2371,7 +2387,6 @@ ClusterStmt:  CLUSTER index_name ON relation_name
                                }
                ;
 
-
 /*****************************************************************************
  *
  *             QUERY:
index bd5b43ad1fd0b17d3a085ca6c892635f8ff3e2df..17a521337e40ce91cc0915a2d105b08ad6490920 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.60 1999/07/17 20:17:22 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.61 1999/09/23 17:02:46 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -225,6 +225,7 @@ static ScanKeyword ScanKeywords[] = {
        {"trigger", TRIGGER},
        {"trim", TRIM},
        {"true", TRUE_P},
+       {"truncate", TRUNCATE},
        {"trusted", TRUSTED},
        {"type", TYPE_P},
        {"union", UNION},
index 29b4fb527c66eed7a1ba59d3af290eafc090dc02..26735a5d80672dc6ff39608399b6dfaa56b64922 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.65 1999/09/18 19:07:44 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.66 1999/09/23 17:02:52 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -206,6 +206,38 @@ ProcessUtility(Node *parsetree,
                        }
                        break;
 
+               case T_TruncateStmt:     
+                       {
+
+                         Relation      rel;
+
+                         PS_SET_STATUS(commandTag = "TRUNCATE");
+                         CHECK_IF_ABORTED();           
+
+                         relname = ((TruncateStmt *) parsetree)->relName;                        
+                         if (!allowSystemTableMods && IsSystemRelationName(relname)) {
+                           elog(ERROR, "TRUNCATE cannot be used on system tables. '%s' is a system table", 
+                                relname);
+                         }                       
+                         
+                         rel = heap_openr(relname);
+                         if (RelationIsValid(rel)) {
+                           if (rel->rd_rel->relkind == RELKIND_SEQUENCE) {
+                             elog(ERROR, "TRUNCATE cannot be used on sequences. '%s' is a sequence", 
+                                  relname);
+                           }                       
+                           heap_close(rel);
+                         }
+#ifndef NO_SECURITY
+                         if (!pg_ownercheck(userName, relname, RELNAME)) {
+                           elog(ERROR, "you do not own class \"%s\"", relname);
+                         }
+#endif
+                         TruncateRelation(((TruncateStmt *) parsetree)->relName);
+                         
+                       }
+                       break;
+
                case T_CopyStmt:
                        {
                                CopyStmt   *stmt = (CopyStmt *) parsetree;
index d625d25d5bdd13548c52189b69881d7875022d6d..4120c24dd677d1b244e77580e062e59870f0f8d2 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.29 1999/09/09 16:25:29 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/utils/mmgr/portalmem.c,v 1.30 1999/09/23 17:02:58 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -410,6 +410,8 @@ PortalNameIsSpecial(char *pname)
 {
        if (strcmp(pname, VACPNAME) == 0)
                return true;
+       if (strcmp(pname, TRUNCPNAME) == 0) 
+               return true;
        return false;
 }
 
index 63540a7998714c1a16411eb66cd9697439c44190..be2fb3fb0cc37f2fb1899eb7ba8e4551f29e708d 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: psqlHelp.h,v 1.72 1999/07/11 22:47:21 ishii Exp $
+ * $Id: psqlHelp.h,v 1.73 1999/09/23 17:03:04 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -23,11 +23,11 @@ static struct _helpStruct QL_HELP[] = {
        "\
 \tabort [transaction|work];"},
        {"alter table",
-               "add/rename attributes, rename tables",
+               "add/rename columns, rename tables",
        "\
-\tALTER TABLE class_name [*] ADD COLUMN attr type\n\
-\tALTER TABLE class_name [*] RENAME [COLUMN] attr1 TO attr2\n\
-\tALTER TABLE class_name1 RENAME TO class_name2"},
+\tALTER TABLE tablename [*] ADD COLUMN colname type\n\
+\tALTER TABLE tablename [*] RENAME [COLUMN] colname1 TO colname2\n\
+\tALTER TABLE tablename1 RENAME TO tablename2"},
        {"alter user",
                "alter system information for a user",
        "\
@@ -56,7 +56,7 @@ static struct _helpStruct QL_HELP[] = {
        {"copy",
                "copy data to and from a table",
        "\
-\tCOPY [BINARY] class_name [WITH OIDS]\n\
+\tCOPY [BINARY] tablename [WITH OIDS]\n\
 \tTO|FROM filename|STDIN|STDOUT [USING DELIMITERS 'delim'];"},
        {"create",
                "Please be more specific:",
@@ -93,8 +93,8 @@ static struct _helpStruct QL_HELP[] = {
        {"create index",
                "construct an index",
        "\
-\tCREATE [UNIQUE] INDEX indexname ON class_name [USING access_method]\n\
-( attr1 [type_class1], ...attrN | funcname(attr1, ...) [type_class] );"},
+\tCREATE [UNIQUE] INDEX indexname ON tablename [USING access_method]\n\
+( colname1 [type_class1], ...colnameN | funcname(colname1, ...) [type_class] );"},
        {"create operator",
                "create a user-defined operator",
        "\
@@ -124,16 +124,16 @@ static struct _helpStruct QL_HELP[] = {
        {"create table",
                "create a new table",
        "\
-\tCREATE [TEMP] TABLE class_name\n\
-\t(attr1 type1 [DEFAULT expression] [NOT NULL], ...attrN\n\
+\tCREATE [TEMP] TABLE tablename\n\
+\t(colname1 type1 [DEFAULT expression] [NOT NULL], ...colnameN\n\
 \t[[CONSTRAINT name] CHECK condition1, ...conditionN] )\n\
-\t[INHERITS (class_name1, ...class_nameN)\n\
+\t[INHERITS (tablename1, ...tablenameN)\n\
 ;"},
        {"create trigger",
                "create a new trigger",
        "\
 \tCREATE TRIGGER trigger_name AFTER|BEFORE event1 [OR event2 [OR event3] ]\n\
-\tON class_name FOR EACH ROW|STATEMENT\n\
+\tON tablename FOR EACH ROW|STATEMENT\n\
 \tEXECUTE PROCEDURE func_name ([arguments])\n\
 \n\
 \teventX is one of INSERT, DELETE, UPDATE"},
@@ -159,8 +159,8 @@ static struct _helpStruct QL_HELP[] = {
                "create a view",
        "\
 \tCREATE VIEW view_name AS\n\
-\tSELECT [DISTINCT [ON attrN]]\n\
-\texpr1 [AS attr1], ...exprN\n\
+\tSELECT [DISTINCT [ON colnameN]]\n\
+\texpr1 [AS colname1], ...exprN\n\
 \t[FROM from_list]\n\
 \t[WHERE qual]\n\
 \t[GROUP BY group_list];"},
@@ -168,18 +168,18 @@ static struct _helpStruct QL_HELP[] = {
                "set up a cursor",
        "\
 \tDECLARE cursorname [BINARY] CURSOR FOR\n\
-\tSELECT [DISTINCT [ON attrN]]\n\
-\texpr1 [AS attr1], ...exprN\n\
+\tSELECT [DISTINCT [ON colnameN]]\n\
+\texpr1 [AS colname1], ...exprN\n\
 \t[FROM from_list]\n\
 \t[WHERE qual]\n\
 \t[GROUP BY group_list]\n\
 \t[HAVING having_clause]\n\
-\t[ORDER BY attr1 [USING op1], ...attrN]\n\
+\t[ORDER BY colname1 [USING op1], ...colnameN]\n\
 \t[ { UNION [ALL] | INTERSECT | EXCEPT } SELECT ...];"},
        {"delete",
                "delete tuples",
        "\
-\tDELETE FROM class_name [WHERE qual];"},
+\tDELETE FROM tablename [WHERE qual];"},
        {"drop",
                "Please be more specific:",
        "\
@@ -225,11 +225,11 @@ static struct _helpStruct QL_HELP[] = {
        {"drop table",
                "remove a table",
        "\
-\tDROP TABLE class_name1, ...class_nameN;"},
+\tDROP TABLE tablename1, ...tablenameN;"},
        {"drop trigger",
                "remove a trigger",
        "\
-\tDROP TRIGGER trigger_name ON class_name;"},
+\tDROP TRIGGER trigger_name ON tablename;"},
        {"drop type",
                "remove a user-defined base type",
        "\
@@ -263,9 +263,9 @@ static struct _helpStruct QL_HELP[] = {
        {"insert",
                "insert tuples",
        "\
-\tINSERT INTO class_name [(attr1, ...attrN)]\n\
+\tINSERT INTO tablename [(colname1, ...colnameN)]\n\
 \tVALUES (expr1,..exprN) |\n\
-\tSELECT [DISTINCT [ON attrN]]\n\
+\tSELECT [DISTINCT [ON colnameN]]\n\
 \texpr1, ...exprN\n\
 \t[FROM from_clause]\n\
 \t[WHERE qual]\n\
@@ -283,7 +283,7 @@ static struct _helpStruct QL_HELP[] = {
        {"lock",
                "exclusive lock a table inside a transaction",
        "\
-\tLOCK [TABLE] class_name \n\
+\tLOCK [TABLE] tablename \n\
 \t[IN [ROW|ACCESS] [SHARE|EXCLUSIVE] | [SHARE ROW EXCLUSIVE] MODE];"},
        {"move",
                "move an cursor position",
@@ -311,15 +311,15 @@ TIMEZONE|XACTISOLEVEL|CLIENT_ENCODING|SERVER_ENCODING"},
        {"select",
                "retrieve tuples",
        "\
-\tSELECT [DISTINCT [ON attrN]] expr1 [AS attr1], ...exprN\n\
-\t[INTO [TEMP] [TABLE] class_name]\n\
+\tSELECT [DISTINCT [ON colnameN]] expr1 [AS colname1], ...exprN\n\
+\t[INTO [TEMP] [TABLE] tablename]\n\
 \t[FROM from_list]\n\
 \t[WHERE qual]\n\
 \t[GROUP BY group_list]\n\
 \t[HAVING having_clause]\n\
 \t[ { UNION [ALL] | INTERSECT | EXCEPT } SELECT ...]\n\
-\t[ORDER BY attr1 [ASC|DESC] [USING op1], ...attrN ]\n\
-\t[FOR UPDATE [OF class_name...]]\n\
+\t[ORDER BY colname1 [ASC|DESC] [USING op1], ...colnameN ]\n\
+\t[FOR UPDATE [OF tablename...]]\n\
 \t[LIMIT count [OFFSET|, count]];"},
        {"set",
                "set run-time environment",
@@ -346,10 +346,14 @@ TIMEZONE|XACTISOLEVEL|CLIENT_ENCODING|SERVER_ENCODING"},
                "stop listening for notification on a condition name",
        "\
 \tUNLISTEN name|\"non-name string\"|\"*\""},
+       {"truncate",
+               "quickly removes all rows from a table",
+       "\
+\tTRUNCATE TABLE tablename"},
        {"update",
                "update tuples",
        "\
-\tUPDATE class_name SET attr1 = expr1, ...attrN = exprN\n\
+\tUPDATE tablename SET colname1 = expr1, ...colnameN = exprN\n\
 \t[FROM from_clause]\n\
 \t[WHERE qual];"},
        {"vacuum",
@@ -357,7 +361,7 @@ TIMEZONE|XACTISOLEVEL|CLIENT_ENCODING|SERVER_ENCODING"},
        "\
 \tVACUUM [VERBOSE] [ANALYZE] [table]\n\
 \tor\n\
-\tVACUUM [VERBOSE]  ANALYZE  [table [(attr1, ...attrN)]];"},
+\tVACUUM [VERBOSE]  ANALYZE  [table [(colname1, ...colnameN)]];"},
        {NULL, NULL, NULL}                      /* important to keep a NULL terminator
                                                                 * here! */
 };
index b8e89d8c395dba9d0107a87ccc79c90873664c37..c8c130da96b1620858f2a43938540d4c834f3ef5 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: heap.h,v 1.20 1999/07/15 23:03:41 momjian Exp $
+ * $Id: heap.h,v 1.21 1999/09/23 17:03:10 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -23,6 +23,7 @@ extern Oid heap_create_with_catalog(char *relname,
                                                 TupleDesc tupdesc, char relkind, bool istemp);
 
 extern void heap_destroy_with_catalog(char *relname);
+extern void heap_truncate(char *relname);
 extern void heap_destroy(Relation rel);
 
 extern void InitNoNameRelList(void);
index 60b5ae0d04491dcc7df79f271d4dedfc5cd6b016..ffb111937a0e5e6cfd76d4d487065cec5ca45f42 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: creatinh.h,v 1.9 1999/02/13 23:21:18 momjian Exp $
+ * $Id: creatinh.h,v 1.10 1999/09/23 17:03:16 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,5 +17,6 @@
 
 extern void DefineRelation(CreateStmt *stmt, char relkind);
 extern void RemoveRelation(char *name);
+extern void TruncateRelation(char *name);
 
 #endif  /* CREATINH_H */
index 37f47c53062e711998bca658381d33610a50432f..da8a06af42393cc0e31cb708ff23204bd22d9023 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: nodes.h,v 1.51 1999/08/16 02:17:39 tgl Exp $
+ * $Id: nodes.h,v 1.52 1999/09/23 17:03:21 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -151,6 +151,7 @@ typedef enum NodeTag
        T_VersionStmt,
        T_DefineStmt,
        T_DestroyStmt,
+       T_TruncateStmt,
        T_ExtendStmt,
        T_FetchStmt,
        T_IndexStmt,
index 5a1d07ec3913bb0ec4c79778b0588617157a1bd5..66c5a9132aab45f21a3c399adfc1fb8e0527fec2 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: parsenodes.h,v 1.78 1999/08/21 03:49:09 tgl Exp $
+ * $Id: parsenodes.h,v 1.79 1999/09/23 17:03:22 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -282,6 +282,16 @@ typedef struct DestroyStmt
        bool            sequence;
 } DestroyStmt;
 
+/* ----------------------
+ *              Truncate Table Statement
+ * ----------------------
+ */
+typedef struct TruncateStmt
+{
+        NodeTag         type;
+        char      *relName;            /* relation to be truncated */
+} TruncateStmt;
+      
 /* ----------------------
  *             Extend Index Statement
  * ----------------------
index 195401e23fc13a8503450be6300409b72a03be5d..b55230e13672c1a348a4886125a7f232f550c14a 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: bufmgr.h,v 1.29 1999/07/17 20:18:33 momjian Exp $
+ * $Id: bufmgr.h,v 1.30 1999/09/23 17:03:27 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -161,6 +161,7 @@ extern void BufferRefCountReset(int *refcountsave);
 extern void BufferRefCountRestore(int *refcountsave);
 extern int     SetBufferWriteMode(int mode);
 extern void SetBufferCommitInfoNeedsSave(Buffer buffer);
+extern int BlowawayRelationBuffers(Relation rel, BlockNumber block);
 
 extern void UnlockBuffers(void);
 extern void LockBuffer(Buffer buffer, int mode);
index c299f9a6d53d434d655da753c2124959da48457e..62d08804607af53214633c5c3e4cb7639ad2488e 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: portal.h,v 1.18 1999/09/09 16:25:23 tgl Exp $
+ * $Id: portal.h,v 1.19 1999/09/23 17:03:33 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -60,6 +60,7 @@ struct PortalD
  * Special portals (well, their names anyway)
  */
 #define VACPNAME               "<vacuum>"
+#define TRUNCPNAME              "<truncate>"
 
 extern bool PortalNameIsSpecial(char *pname);
 extern void AtEOXact_portals(void);
index 06802edbee1b579b58dabceb887d069005fb283c..ddffb937b6c80bfce3f14f21ede1d664ec2e1b1b 100755 (executable)
@@ -163,6 +163,7 @@ do
 -TDepth \
 -TDestReceiver \
 -TDestroyStmt \
+-TTruncateStmt \
 -TDestroydbStmt \
 -TDisplay \
 -TDl_info \