DISCARD ALL will now discard cached sequence information, as well.
Fabrízio de Royes Mello, reviewed by Zoltán Böszörményi, with some
further tweaks by me.
<refsynopsisdiv>
<synopsis>
-DISCARD { ALL | PLANS | TEMPORARY | TEMP }
+DISCARD { ALL | PLANS | SEQUENCES | TEMPORARY | TEMP }
</synopsis>
</refsynopsisdiv>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><literal>SEQUENCES</literal></term>
+ <listitem>
+ <para>
+ Discards all cached sequence values.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><literal>ALL</literal></term>
<listitem>
SELECT pg_advisory_unlock_all();
DISCARD PLANS;
DISCARD TEMP;
+DISCARD SEQUENCES;
</programlisting></para>
</listitem>
</varlistentry>
#include "commands/async.h"
#include "commands/discard.h"
#include "commands/prepare.h"
+#include "commands/sequence.h"
#include "utils/guc.h"
#include "utils/portal.h"
static void DiscardAll(bool isTopLevel);
/*
- * DISCARD { ALL | TEMP | PLANS }
+ * DISCARD { ALL | SEQUENCES | TEMP | PLANS }
*/
void
DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
ResetPlanCache();
break;
+ case DISCARD_SEQUENCES:
+ ResetSequenceCaches();
+ break;
+
case DISCARD_TEMP:
ResetTempTableNamespace();
break;
LockReleaseAll(USER_LOCKMETHOD, true);
ResetPlanCache();
ResetTempTableNamespace();
+ ResetSequenceCaches();
}
pfree(localpage);
}
+
+/*
+ * Flush cached sequence information.
+ */
+void
+ResetSequenceCaches(void)
+{
+ SeqTableData *next;
+
+ while (seqtab != NULL)
+ {
+ next = seqtab->next;
+ free(seqtab);
+ seqtab = seqtab->next;
+ }
+}
/*****************************************************************************
*
- * DISCARD { ALL | TEMP | PLANS }
+ * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
*
*****************************************************************************/
n->target = DISCARD_PLANS;
$$ = (Node *) n;
}
+ | DISCARD SEQUENCES
+ {
+ DiscardStmt *n = makeNode(DiscardStmt);
+ n->target = DISCARD_SEQUENCES;
+ $$ = (Node *) n;
+ }
+
;
case DISCARD_TEMP:
tag = "DISCARD TEMP";
break;
+ case DISCARD_SEQUENCES:
+ tag = "DISCARD SEQUENCES";
+ break;
default:
tag = "???";
}
else if (pg_strcasecmp(prev_wd, "DISCARD") == 0)
{
static const char *const list_DISCARD[] =
- {"ALL", "PLANS", "TEMP", NULL};
+ {"ALL", "PLANS", "SEQUENCES", "TEMP", NULL};
COMPLETE_WITH_LIST(list_DISCARD);
}
extern Oid DefineSequence(CreateSeqStmt *stmt);
extern Oid AlterSequence(AlterSeqStmt *stmt);
extern void ResetSequence(Oid seq_relid);
+extern void ResetSequenceCaches(void);
extern void seq_redo(XLogRecPtr lsn, XLogRecord *rptr);
extern void seq_desc(StringInfo buf, uint8 xl_info, char *rec);
{
DISCARD_ALL,
DISCARD_PLANS,
+ DISCARD_SEQUENCES,
DISCARD_TEMP
} DiscardMode;
99
(1 row)
+DISCARD SEQUENCES;
+SELECT currval('sequence_test'::regclass);
+ERROR: currval of sequence "sequence_test" is not yet defined in this session
DROP SEQUENCE sequence_test;
-- renaming sequences
CREATE SEQUENCE foo_seq;
SELECT nextval('sequence_test'::text);
SELECT setval('sequence_test'::regclass, 99, false);
SELECT nextval('sequence_test'::text);
+DISCARD SEQUENCES;
+SELECT currval('sequence_test'::regclass);
DROP SEQUENCE sequence_test;