1818#include "access/htup_details.h"
1919#include "access/multixact.h"
2020#include "access/relation.h"
21+ #include "access/sequence.h"
2122#include "access/table.h"
2223#include "access/transam.h"
2324#include "access/xact.h"
@@ -208,7 +209,7 @@ DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
208209 seqoid = address .objectId ;
209210 Assert (seqoid != InvalidOid );
210211
211- rel = table_open (seqoid , AccessExclusiveLock );
212+ rel = sequence_open (seqoid , AccessExclusiveLock );
212213 tupDesc = RelationGetDescr (rel );
213214
214215 /* now initialize the sequence's data */
@@ -219,7 +220,7 @@ DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
219220 if (owned_by )
220221 process_owned_by (rel , owned_by , seq -> for_identity );
221222
222- table_close (rel , NoLock );
223+ sequence_close (rel , NoLock );
223224
224225 /* fill in pg_sequence */
225226 rel = table_open (SequenceRelationId , RowExclusiveLock );
@@ -324,7 +325,7 @@ ResetSequence(Oid seq_relid)
324325 /* Note that we do not change the currval() state */
325326 elm -> cached = elm -> last ;
326327
327- relation_close (seq_rel , NoLock );
328+ sequence_close (seq_rel , NoLock );
328329}
329330
330331/*
@@ -531,7 +532,7 @@ AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
531532 ObjectAddressSet (address , RelationRelationId , relid );
532533
533534 table_close (rel , RowExclusiveLock );
534- relation_close (seqrel , NoLock );
535+ sequence_close (seqrel , NoLock );
535536
536537 return address ;
537538}
@@ -555,7 +556,7 @@ SequenceChangePersistence(Oid relid, char newrelpersistence)
555556 fill_seq_with_data (seqrel , & seqdatatuple );
556557 UnlockReleaseBuffer (buf );
557558
558- relation_close (seqrel , NoLock );
559+ sequence_close (seqrel , NoLock );
559560}
560561
561562void
@@ -662,7 +663,7 @@ nextval_internal(Oid relid, bool check_permissions)
662663 Assert (elm -> last_valid );
663664 Assert (elm -> increment != 0 );
664665 elm -> last += elm -> increment ;
665- relation_close (seqrel , NoLock );
666+ sequence_close (seqrel , NoLock );
666667 last_used_seq = elm ;
667668 return elm -> last ;
668669 }
@@ -849,7 +850,7 @@ nextval_internal(Oid relid, bool check_permissions)
849850
850851 UnlockReleaseBuffer (buf );
851852
852- relation_close (seqrel , NoLock );
853+ sequence_close (seqrel , NoLock );
853854
854855 return result ;
855856}
@@ -880,7 +881,7 @@ currval_oid(PG_FUNCTION_ARGS)
880881
881882 result = elm -> last ;
882883
883- relation_close (seqrel , NoLock );
884+ sequence_close (seqrel , NoLock );
884885
885886 PG_RETURN_INT64 (result );
886887}
@@ -915,7 +916,7 @@ lastval(PG_FUNCTION_ARGS)
915916 RelationGetRelationName (seqrel ))));
916917
917918 result = last_used_seq -> last ;
918- relation_close (seqrel , NoLock );
919+ sequence_close (seqrel , NoLock );
919920
920921 PG_RETURN_INT64 (result );
921922}
@@ -1030,7 +1031,7 @@ do_setval(Oid relid, int64 next, bool iscalled)
10301031
10311032 UnlockReleaseBuffer (buf );
10321033
1033- relation_close (seqrel , NoLock );
1034+ sequence_close (seqrel , NoLock );
10341035}
10351036
10361037/*
@@ -1095,7 +1096,7 @@ lock_and_open_sequence(SeqTable seq)
10951096 }
10961097
10971098 /* We now know we have the lock, and can safely open the rel */
1098- return relation_open (seq -> relid , NoLock );
1099+ return sequence_open (seq -> relid , NoLock );
10991100}
11001101
11011102/*
@@ -1152,12 +1153,6 @@ init_sequence(Oid relid, SeqTable *p_elm, Relation *p_rel)
11521153 */
11531154 seqrel = lock_and_open_sequence (elm );
11541155
1155- if (seqrel -> rd_rel -> relkind != RELKIND_SEQUENCE )
1156- ereport (ERROR ,
1157- (errcode (ERRCODE_WRONG_OBJECT_TYPE ),
1158- errmsg ("\"%s\" is not a sequence" ,
1159- RelationGetRelationName (seqrel ))));
1160-
11611156 /*
11621157 * If the sequence has been transactionally replaced since we last saw it,
11631158 * discard any cached-but-unissued values. We do not touch the currval()
@@ -1803,7 +1798,7 @@ pg_sequence_last_value(PG_FUNCTION_ARGS)
18031798 result = seq -> last_value ;
18041799
18051800 UnlockReleaseBuffer (buf );
1806- relation_close (seqrel , NoLock );
1801+ sequence_close (seqrel , NoLock );
18071802
18081803 if (is_called )
18091804 PG_RETURN_INT64 (result );
0 commit comments