Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1753b1b

Browse files
committed
Add pg_sequence system catalog
Move sequence metadata (start, increment, etc.) into a proper systemcatalog instead of storing it in the sequence heap object. Thisseparates the metadata from the sequence data. Sequence metadata is nowoperated on transactionally by DDL commands, whereas previouslyrollbacks of sequence-related DDL commands would be ignored.Reviewed-by: Andreas Karlsson <andreas@proxel.se>
1 parentdb80acf commit1753b1b

File tree

19 files changed

+490
-269
lines changed

19 files changed

+490
-269
lines changed

‎doc/src/sgml/catalogs.sgml

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,11 @@
260260
<entry>security labels on database objects</entry>
261261
</row>
262262

263+
<row>
264+
<entry><link linkend="catalog-pg-sequence"><structname>pg_sequence</structname></link></entry>
265+
<entry>information about sequences</entry>
266+
</row>
267+
263268
<row>
264269
<entry><link linkend="catalog-pg-shdepend"><structname>pg_shdepend</structname></link></entry>
265270
<entry>dependencies on shared objects</entry>
@@ -1546,7 +1551,8 @@
15461551
The catalog <structname>pg_class</structname> catalogs tables and most
15471552
everything else that has columns or is otherwise similar to a
15481553
table. This includes indexes (but see also
1549-
<structname>pg_index</structname>), sequences, views, materialized
1554+
<structname>pg_index</structname>), sequences (but see also
1555+
<structname>pg_sequence</structname>), views, materialized
15501556
views, composite types, and TOAST tables; see <structfield>relkind</>.
15511557
Below, when we mean all of these
15521558
kinds of objects we speak of <quote>relations</quote>. Not all
@@ -5587,6 +5593,86 @@
55875593
</table>
55885594
</sect1>
55895595

5596+
<sect1 id="catalog-pg-sequence">
5597+
<title><structname>pg_sequence</structname></title>
5598+
5599+
<indexterm zone="catalog-pg-sequence">
5600+
<primary>pg_sequence</primary>
5601+
</indexterm>
5602+
5603+
<para>
5604+
The catalog <structname>pg_sequence</structname> contains information about
5605+
sequences. Some of the information about sequences, such as the name and
5606+
the schema, is in <structname>pg_class</structname>.
5607+
</para>
5608+
5609+
<table>
5610+
<title><structname>pg_sequence</> Columns</title>
5611+
5612+
<tgroup cols="4">
5613+
<thead>
5614+
<row>
5615+
<entry>Name</entry>
5616+
<entry>Type</entry>
5617+
<entry>References</entry>
5618+
<entry>Description</entry>
5619+
</row>
5620+
</thead>
5621+
5622+
<tbody>
5623+
<row>
5624+
<entry><structfield>seqrelid</structfield></entry>
5625+
<entry><type>oid</type></entry>
5626+
<entry><literal><link linkend="catalog-pg-class"><structname>pg_class</structname></link>.oid</literal></entry>
5627+
<entry>The OID of the <structname>pg_class</> entry for this sequence</entry>
5628+
</row>
5629+
5630+
<row>
5631+
<entry><structfield>seqstart</structfield></entry>
5632+
<entry><type>int8</type></entry>
5633+
<entry></entry>
5634+
<entry>Start value of the sequence</entry>
5635+
</row>
5636+
5637+
<row>
5638+
<entry><structfield>seqincrement</structfield></entry>
5639+
<entry><type>int8</type></entry>
5640+
<entry></entry>
5641+
<entry>Increment value of the sequence</entry>
5642+
</row>
5643+
5644+
<row>
5645+
<entry><structfield>seqmax</structfield></entry>
5646+
<entry><type>int8</type></entry>
5647+
<entry></entry>
5648+
<entry>Maximum value of the sequence</entry>
5649+
</row>
5650+
5651+
<row>
5652+
<entry><structfield>seqmin</structfield></entry>
5653+
<entry><type>int8</type></entry>
5654+
<entry></entry>
5655+
<entry>Minimum value of the sequence</entry>
5656+
</row>
5657+
5658+
<row>
5659+
<entry><structfield>seqcache</structfield></entry>
5660+
<entry><type>int8</type></entry>
5661+
<entry></entry>
5662+
<entry>Cache size of the sequence</entry>
5663+
</row>
5664+
5665+
<row>
5666+
<entry><structfield>seqcycle</structfield></entry>
5667+
<entry><type>bool</type></entry>
5668+
<entry></entry>
5669+
<entry>Whether the sequence cycles</entry>
5670+
</row>
5671+
</tbody>
5672+
</tgroup>
5673+
</table>
5674+
</sect1>
5675+
55905676
<sect1 id="catalog-pg-shdepend">
55915677
<title><structname>pg_shdepend</structname></title>
55925678

‎src/backend/catalog/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ POSTGRES_BKI_SRCS = $(addprefix $(top_srcdir)/src/include/catalog/,\
4242
pg_foreign_table.h pg_policy.h pg_replication_origin.h \
4343
pg_default_acl.h pg_init_privs.h pg_seclabel.h pg_shseclabel.h \
4444
pg_collation.h pg_partitioned_table.h pg_range.h pg_transform.h \
45+
pg_sequence.h \
4546
toasting.h indexing.h \
4647
)
4748

‎src/backend/catalog/dependency.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#include"commands/proclang.h"
6767
#include"commands/schemacmds.h"
6868
#include"commands/seclabel.h"
69+
#include"commands/sequence.h"
6970
#include"commands/trigger.h"
7071
#include"commands/typecmds.h"
7172
#include"nodes/nodeFuncs.h"
@@ -1114,6 +1115,11 @@ doDeletion(const ObjectAddress *object, int flags)
11141115
else
11151116
heap_drop_with_catalog(object->objectId);
11161117
}
1118+
1119+
/* for a sequence, in addition to dropping the heap, also
1120+
* delete pg_sequence tuple */
1121+
if (relKind==RELKIND_SEQUENCE)
1122+
DeleteSequenceTuple(object->objectId);
11171123
break;
11181124
}
11191125

‎src/backend/catalog/information_schema.sql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,15 +1535,16 @@ CREATE VIEW sequences AS
15351535
CAST(64AS cardinal_number)AS numeric_precision,
15361536
CAST(2AS cardinal_number)AS numeric_precision_radix,
15371537
CAST(0AS cardinal_number)AS numeric_scale,
1538-
CAST(p.start_valueAS character_data)AS start_value,
1539-
CAST(p.minimum_valueAS character_data)AS minimum_value,
1540-
CAST(p.maximum_valueAS character_data)AS maximum_value,
1541-
CAST(p.incrementAS character_data)AS increment,
1542-
CAST(CASE WHENp.cycle_option THEN'YES' ELSE'NO' ENDAS yes_or_no)AS cycle_option
1543-
FROM pg_namespace nc, pg_class c,LATERAL pg_sequence_parameters(c.oid) p
1538+
CAST(s.seqstartAS character_data)AS start_value,
1539+
CAST(s.seqminAS character_data)AS minimum_value,
1540+
CAST(s.seqmaxAS character_data)AS maximum_value,
1541+
CAST(s.seqincrementAS character_data)AS increment,
1542+
CAST(CASE WHENs.seqcycle THEN'YES' ELSE'NO' ENDAS yes_or_no)AS cycle_option
1543+
FROM pg_namespace nc, pg_class c,pg_sequence s
15441544
WHEREc.relnamespace=nc.oid
15451545
ANDc.relkind='S'
15461546
AND (NOT pg_is_other_temp_schema(nc.oid))
1547+
ANDc.oid=s.seqrelid
15471548
AND (pg_has_role(c.relowner,'USAGE')
15481549
OR has_sequence_privilege(c.oid,'SELECT, UPDATE, USAGE') );
15491550

‎src/backend/catalog/system_views.sql

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,15 @@ CREATE OR REPLACE VIEW pg_sequences AS
169169
N.nspnameAS schemaname,
170170
C.relnameAS sequencename,
171171
pg_get_userbyid(C.relowner)AS sequenceowner,
172-
p.start_valueAS start_value,
173-
p.minimum_valueAS min_value,
174-
p.maximum_valueAS max_value,
175-
p.incrementAS increment_by,
176-
p.cycle_optionAS cycle,
177-
p.cache_sizeAS cache_size,
172+
S.seqstartAS start_value,
173+
S.seqminAS min_value,
174+
S.seqmaxAS max_value,
175+
S.seqincrementAS increment_by,
176+
S.seqcycleAS cycle,
177+
S.seqcacheAS cache_size,
178178
pg_sequence_last_value(C.oid)AS last_value
179-
FROMpg_class CLEFTJOINpg_namespace NON (N.oid=C.relnamespace),
180-
LATERAL pg_sequence_parameters(C.oid) p
179+
FROMpg_sequence SJOINpg_class CON (C.oid=S.seqrelid)
180+
LEFT JOIN pg_namespace NON (N.oid=C.relnamespace)
181181
WHERE NOT pg_is_other_temp_schema(N.oid)
182182
AND relkind='S';
183183

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp