PostgreSQL Source Code: src/backend/commands/sequence.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
51
52
53
54
55
56
57
58#define SEQ_LOG_VALS 32
59
60
61
62
63#define SEQ_MAGIC 0x1717
64
66{
69
70
71
72
73
74
75
77{
81 bool last_valid;
84
86
88
90
91static HTAB *seqhashtab = NULL;
92
93
94
95
96
98
107 bool isInit,
110 bool *need_seq_rewrite,
111 List **owned_by);
114
115
116
117
118
119
122{
125 bool need_seq_rewrite;
126 List *owned_by;
128 Oid seqoid;
135 Datum pgs_values[Natts_pg_sequence];
136 bool pgs_nulls[Natts_pg_sequence];
137 int i;
138
139
140
141
142
143
145 {
148 {
149
150
151
152
155
156
158 (errcode(ERRCODE_DUPLICATE_TABLE),
159 errmsg("relation \"%s\" already exists, skipping",
162 }
163 }
164
165
167 &seqform, &seqdataform,
168 &need_seq_rewrite, &owned_by);
169
170
171
172
175 {
177
178 switch (i)
179 {
183 break;
187 break;
191 break;
192 }
193
195 null[i - 1] = false;
196
198 }
199
205 stmt->tablespacename = NULL;
207
211
214
215
218
219
220 if (owned_by)
222
224
225
228
229 memset(pgs_nulls, 0, sizeof(pgs_nulls));
230
231 pgs_values[Anum_pg_sequence_seqrelid - 1] = ObjectIdGetDatum(seqoid);
232 pgs_values[Anum_pg_sequence_seqtypid - 1] = ObjectIdGetDatum(seqform.seqtypid);
233 pgs_values[Anum_pg_sequence_seqstart - 1] = Int64GetDatumFast(seqform.seqstart);
234 pgs_values[Anum_pg_sequence_seqincrement - 1] = Int64GetDatumFast(seqform.seqincrement);
235 pgs_values[Anum_pg_sequence_seqmax - 1] = Int64GetDatumFast(seqform.seqmax);
236 pgs_values[Anum_pg_sequence_seqmin - 1] = Int64GetDatumFast(seqform.seqmin);
237 pgs_values[Anum_pg_sequence_seqcache - 1] = Int64GetDatumFast(seqform.seqcache);
238 pgs_values[Anum_pg_sequence_seqcycle - 1] = BoolGetDatum(seqform.seqcycle);
239
242
245
246 return address;
247}
248
249
250
251
252
253
254
255
256
257
258
259
260
261void
263{
273
274
275
276
277
278
281
284 elog(ERROR, "cache lookup failed for sequence %u", seq_relid);
286 startv = pgsform->seqstart;
288
289
290
291
293
294
296
297
298
299
300
305
306
307
308
310
311
312
313
314
315
318
319
320
321
323
324
325
327
329}
330
331
332
333
334
335
336
337static void
339{
341
342 if (rel->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED)
343 {
345
352 }
353}
354
355
356
357
358static void
360{
365
366
367
371
373
377
378
379
380
381
382
383
384
385
386
393
394
397
399
401
405 elog(ERROR, "failed to add sequence tuple to page");
406
407
409 {
412
415
417
420
422
424 }
425
427
429}
430
431
432
433
434
435
438{
439 Oid relid;
446 bool need_seq_rewrite;
447 List *owned_by;
452
453
458 NULL);
460 {
462 (errmsg("relation \"%s\" does not exist, skipping",
463 stmt->sequence->relname)));
465 }
466
468
473 elog(ERROR, "cache lookup failed for sequence %u",
474 relid);
475
477
478
480
481
484
486
487
489 seqform, newdataform,
490 &need_seq_rewrite, &owned_by);
491
492
493 if (need_seq_rewrite)
494 {
495
498
499
500
501
502
504
505
506
507
508
509
512
513
514
515
517 }
518
519
520
522
523
524 if (owned_by)
526
527
529
531
533
536
537 return address;
538}
539
540void
542{
547
548
549
550
551
552
553
556
557
560
565
567}
568
569void
571{
574
576
579 elog(ERROR, "cache lookup failed for sequence %u", relid);
580
582
585}
586
587
588
589
590
591
594{
597 Oid relid;
598
600
601
602
603
604
605
606
607
608
610
612}
613
616{
618
620}
621
624{
634 maxv,
635 minv,
636 cache,
637 log,
638 fetch,
639 last;
642 rescnt = 0;
643 bool cycle;
644 bool logit = false;
645
646
648
649 if (check_permissions &&
653 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
654 errmsg("permission denied for sequence %s",
656
657
660
661
662
663
664
665
667
668 if (elm->last != elm->cached)
669 {
675 return elm->last;
676 }
677
680 elog(ERROR, "cache lookup failed for sequence %u", relid);
682 incby = pgsform->seqincrement;
683 maxv = pgsform->seqmax;
684 minv = pgsform->seqmin;
685 cache = pgsform->seqcache;
686 cycle = pgsform->seqcycle;
688
689
692
694 fetch = cache;
696
698 {
699 rescnt++;
700 fetch--;
701 }
702
703
704
705
706
707
708
709
710
711
712
713 if (log < fetch || !seq->is_called)
714 {
715
717 logit = true;
718 }
719 else
720 {
722
724 {
725
727 logit = true;
728 }
729 }
730
731 while (fetch)
732 {
733
734
735
736
737 if (incby > 0)
738 {
739
740 if ((maxv >= 0 && next > maxv - incby) ||
741 (maxv < 0 && next + incby > maxv))
742 {
743 if (rescnt > 0)
744 break;
745 if (!cycle)
747 (errcode(ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED),
748 errmsg("nextval: reached maximum value of sequence \"%s\" (%" PRId64 ")",
750 maxv)));
752 }
753 else
754 next += incby;
755 }
756 else
757 {
758
759 if ((minv < 0 && next < minv - incby) ||
760 (minv >= 0 && next + incby < minv))
761 {
762 if (rescnt > 0)
763 break;
764 if (!cycle)
766 (errcode(ERRCODE_SEQUENCE_GENERATOR_LIMIT_EXCEEDED),
767 errmsg("nextval: reached minimum value of sequence \"%s\" (%" PRId64 ")",
769 minv)));
771 }
772 else
773 next += incby;
774 }
775 fetch--;
776 if (rescnt < cache)
777 {
778 log--;
779 rescnt++;
781 if (rescnt == 1)
782 result = next;
783 }
784 }
785
786 log -= fetch;
788
789
791 elm->last = result;
792 elm->cached = last;
794
796
797
798
799
800
801
802
803
806
807
809
810
811
812
813
814
815
816
817
818
820
821
823 {
826
827
828
829
830
831
832
835
836
840
842
845
847
849 }
850
851
852 seq->last_value = last;
854 seq->log_cnt = log;
855
857
859
861
862 return result;
863}
864
867{
872
873
875
879 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
880 errmsg("permission denied for sequence %s",
882
885 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
886 errmsg("currval of sequence \"%s\" is not yet defined in this session",
888
889 result = elm->last;
890
892
894}
895
898{
901
904 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
905 errmsg("lastval is not yet defined in this session")));
906
907
910 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
911 errmsg("lastval is not yet defined in this session")));
912
914
915
917
921 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
922 errmsg("permission denied for sequence %s",
924
927
929}
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944static void
946{
955 minv;
956
957
959
962 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
963 errmsg("permission denied for sequence %s",
965
968 elog(ERROR, "cache lookup failed for sequence %u", relid);
970 maxv = pgsform->seqmax;
971 minv = pgsform->seqmin;
973
974
977
978
979
980
981
982
984
985
987
988 if ((next < minv) || (next > maxv))
990 (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
991 errmsg("setval: value %" PRId64 " is out of bounds for sequence \"%s\" (%" PRId64 "..%" PRId64 ")",
993 minv, maxv)));
994
995
996 if (iscalled)
997 {
1000 }
1001
1002
1004
1005
1008
1009
1011
1015
1017
1018
1020 {
1024
1027
1031
1033
1035 }
1036
1038
1040
1042}
1043
1044
1045
1046
1047
1050{
1053
1055
1057}
1058
1059
1060
1061
1062
1065{
1069
1071
1073}
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1086{
1088
1089
1090 if (seq->lxid != thislxid)
1091 {
1093
1096
1098
1100
1101
1102 seq->lxid = thislxid;
1103 }
1104
1105
1107}
1108
1109
1110
1111
1112static void
1114{
1116
1117 ctl.keysize = sizeof(Oid);
1119
1122}
1123
1124
1125
1126
1127
1128static void
1130{
1133 bool found;
1134
1135
1138
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149 if (!found)
1150 {
1151
1156 }
1157
1158
1159
1160
1162
1163
1164
1165
1166
1167
1169 {
1172 }
1173
1174
1175 *p_elm = elm;
1176 *p_rel = seqrel;
1177}
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1191{
1196
1199
1202
1204 elog(ERROR, "bad magic number in sequence \"%s\": %08X",
1206
1209
1210
1213
1214
1215
1216
1217
1218
1219
1220
1221
1224 {
1229 }
1230
1232
1233 return seq;
1234}
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256static void
1258 bool isInit,
1261 bool *need_seq_rewrite,
1262 List **owned_by)
1263{
1264 DefElem *as_type = NULL;
1265 DefElem *start_value = NULL;
1266 DefElem *restart_value = NULL;
1267 DefElem *increment_by = NULL;
1268 DefElem *max_value = NULL;
1269 DefElem *min_value = NULL;
1270 DefElem *cache_value = NULL;
1271 DefElem *is_cycled = NULL;
1273 bool reset_max_value = false;
1274 bool reset_min_value = false;
1275
1276 *need_seq_rewrite = false;
1277 *owned_by = NIL;
1278
1280 {
1282
1283 if (strcmp(defel->defname, "as") == 0)
1284 {
1285 if (as_type)
1287 as_type = defel;
1288 *need_seq_rewrite = true;
1289 }
1290 else if (strcmp(defel->defname, "increment") == 0)
1291 {
1292 if (increment_by)
1294 increment_by = defel;
1295 *need_seq_rewrite = true;
1296 }
1297 else if (strcmp(defel->defname, "start") == 0)
1298 {
1299 if (start_value)
1301 start_value = defel;
1302 *need_seq_rewrite = true;
1303 }
1304 else if (strcmp(defel->defname, "restart") == 0)
1305 {
1306 if (restart_value)
1308 restart_value = defel;
1309 *need_seq_rewrite = true;
1310 }
1311 else if (strcmp(defel->defname, "maxvalue") == 0)
1312 {
1313 if (max_value)
1315 max_value = defel;
1316 *need_seq_rewrite = true;
1317 }
1318 else if (strcmp(defel->defname, "minvalue") == 0)
1319 {
1320 if (min_value)
1322 min_value = defel;
1323 *need_seq_rewrite = true;
1324 }
1325 else if (strcmp(defel->defname, "cache") == 0)
1326 {
1327 if (cache_value)
1329 cache_value = defel;
1330 *need_seq_rewrite = true;
1331 }
1332 else if (strcmp(defel->defname, "cycle") == 0)
1333 {
1334 if (is_cycled)
1336 is_cycled = defel;
1337 *need_seq_rewrite = true;
1338 }
1339 else if (strcmp(defel->defname, "owned_by") == 0)
1340 {
1341 if (*owned_by)
1344 }
1345 else if (strcmp(defel->defname, "sequence_name") == 0)
1346 {
1347
1348
1349
1350
1351
1352
1353
1354
1356 (errcode(ERRCODE_SYNTAX_ERROR),
1357 errmsg("invalid sequence option SEQUENCE NAME"),
1359 }
1360 else
1361 elog(ERROR, "option \"%s\" not recognized",
1363 }
1364
1365
1366
1367
1368
1369 if (isInit)
1370 seqdataform->log_cnt = 0;
1371
1372
1373 if (as_type != NULL)
1374 {
1376
1377 if (newtypid != INT2OID &&
1378 newtypid != INT4OID &&
1379 newtypid != INT8OID)
1381 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1382 for_identity
1383 ? errmsg("identity column type must be smallint, integer, or bigint")
1384 : errmsg("sequence type must be smallint, integer, or bigint")));
1385
1386 if (!isInit)
1387 {
1388
1389
1390
1391
1392
1393
1394 if ((seqform->seqtypid == INT2OID && seqform->seqmax == PG_INT16_MAX) ||
1395 (seqform->seqtypid == INT4OID && seqform->seqmax == PG_INT32_MAX) ||
1396 (seqform->seqtypid == INT8OID && seqform->seqmax == PG_INT64_MAX))
1397 reset_max_value = true;
1398 if ((seqform->seqtypid == INT2OID && seqform->seqmin == PG_INT16_MIN) ||
1399 (seqform->seqtypid == INT4OID && seqform->seqmin == PG_INT32_MIN) ||
1400 (seqform->seqtypid == INT8OID && seqform->seqmin == PG_INT64_MIN))
1401 reset_min_value = true;
1402 }
1403
1404 seqform->seqtypid = newtypid;
1405 }
1406 else if (isInit)
1407 {
1408 seqform->seqtypid = INT8OID;
1409 }
1410
1411
1412 if (increment_by != NULL)
1413 {
1414 seqform->seqincrement = defGetInt64(increment_by);
1415 if (seqform->seqincrement == 0)
1417 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1418 errmsg("INCREMENT must not be zero")));
1419 seqdataform->log_cnt = 0;
1420 }
1421 else if (isInit)
1422 {
1423 seqform->seqincrement = 1;
1424 }
1425
1426
1427 if (is_cycled != NULL)
1428 {
1429 seqform->seqcycle = boolVal(is_cycled->arg);
1431 seqdataform->log_cnt = 0;
1432 }
1433 else if (isInit)
1434 {
1435 seqform->seqcycle = false;
1436 }
1437
1438
1439 if (max_value != NULL && max_value->arg)
1440 {
1441 seqform->seqmax = defGetInt64(max_value);
1442 seqdataform->log_cnt = 0;
1443 }
1444 else if (isInit || max_value != NULL || reset_max_value)
1445 {
1446 if (seqform->seqincrement > 0 || reset_max_value)
1447 {
1448
1449 if (seqform->seqtypid == INT2OID)
1451 else if (seqform->seqtypid == INT4OID)
1453 else
1455 }
1456 else
1457 seqform->seqmax = -1;
1458 seqdataform->log_cnt = 0;
1459 }
1460
1461
1462 if ((seqform->seqtypid == INT2OID && (seqform->seqmax < PG_INT16_MIN || seqform->seqmax > PG_INT16_MAX))
1463 || (seqform->seqtypid == INT4OID && (seqform->seqmax < PG_INT32_MIN || seqform->seqmax > PG_INT32_MAX)))
1465 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1466 errmsg("MAXVALUE (%" PRId64 ") is out of range for sequence data type %s",
1467 seqform->seqmax,
1469
1470
1471 if (min_value != NULL && min_value->arg)
1472 {
1473 seqform->seqmin = defGetInt64(min_value);
1474 seqdataform->log_cnt = 0;
1475 }
1476 else if (isInit || min_value != NULL || reset_min_value)
1477 {
1478 if (seqform->seqincrement < 0 || reset_min_value)
1479 {
1480
1481 if (seqform->seqtypid == INT2OID)
1483 else if (seqform->seqtypid == INT4OID)
1485 else
1487 }
1488 else
1489 seqform->seqmin = 1;
1490 seqdataform->log_cnt = 0;
1491 }
1492
1493
1494 if ((seqform->seqtypid == INT2OID && (seqform->seqmin < PG_INT16_MIN || seqform->seqmin > PG_INT16_MAX))
1495 || (seqform->seqtypid == INT4OID && (seqform->seqmin < PG_INT32_MIN || seqform->seqmin > PG_INT32_MAX)))
1497 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1498 errmsg("MINVALUE (%" PRId64 ") is out of range for sequence data type %s",
1499 seqform->seqmin,
1501
1502
1503 if (seqform->seqmin >= seqform->seqmax)
1505 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1506 errmsg("MINVALUE (%" PRId64 ") must be less than MAXVALUE (%" PRId64 ")",
1507 seqform->seqmin,
1508 seqform->seqmax)));
1509
1510
1511 if (start_value != NULL)
1512 {
1513 seqform->seqstart = defGetInt64(start_value);
1514 }
1515 else if (isInit)
1516 {
1517 if (seqform->seqincrement > 0)
1518 seqform->seqstart = seqform->seqmin;
1519 else
1520 seqform->seqstart = seqform->seqmax;
1521 }
1522
1523
1524 if (seqform->seqstart < seqform->seqmin)
1526 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1527 errmsg("START value (%" PRId64 ") cannot be less than MINVALUE (%" PRId64 ")",
1528 seqform->seqstart,
1529 seqform->seqmin)));
1530 if (seqform->seqstart > seqform->seqmax)
1532 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1533 errmsg("START value (%" PRId64 ") cannot be greater than MAXVALUE (%" PRId64 ")",
1534 seqform->seqstart,
1535 seqform->seqmax)));
1536
1537
1538 if (restart_value != NULL)
1539 {
1540 if (restart_value->arg != NULL)
1542 else
1543 seqdataform->last_value = seqform->seqstart;
1545 seqdataform->log_cnt = 0;
1546 }
1547 else if (isInit)
1548 {
1549 seqdataform->last_value = seqform->seqstart;
1551 }
1552
1553
1554 if (seqdataform->last_value < seqform->seqmin)
1556 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1557 errmsg("RESTART value (%" PRId64 ") cannot be less than MINVALUE (%" PRId64 ")",
1559 seqform->seqmin)));
1560 if (seqdataform->last_value > seqform->seqmax)
1562 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1563 errmsg("RESTART value (%" PRId64 ") cannot be greater than MAXVALUE (%" PRId64 ")",
1565 seqform->seqmax)));
1566
1567
1568 if (cache_value != NULL)
1569 {
1570 seqform->seqcache = defGetInt64(cache_value);
1571 if (seqform->seqcache <= 0)
1573 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1574 errmsg("CACHE (%" PRId64 ") must be greater than zero",
1575 seqform->seqcache)));
1576 seqdataform->log_cnt = 0;
1577 }
1578 else if (isInit)
1579 {
1580 seqform->seqcache = 1;
1581 }
1582}
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592static void
1594{
1596 int nnames;
1599
1601
1604 if (nnames == 1)
1605 {
1606
1607 if (strcmp(strVal(linitial(owned_by)), "none") != 0)
1609 (errcode(ERRCODE_SYNTAX_ERROR),
1610 errmsg("invalid OWNED BY option"),
1611 errhint("Specify OWNED BY table.column or OWNED BY NONE.")));
1612 tablerel = NULL;
1614 }
1615 else
1616 {
1618 char *attrname;
1620
1621
1624
1625
1628
1629
1630 if (!(tablerel->rd_rel->relkind == RELKIND_RELATION ||
1631 tablerel->rd_rel->relkind == RELKIND_FOREIGN_TABLE ||
1632 tablerel->rd_rel->relkind == RELKIND_VIEW ||
1633 tablerel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE))
1635 (errcode(ERRCODE_WRONG_OBJECT_TYPE),
1636 errmsg("sequence cannot be owned by relation \"%s\"",
1639
1640
1641 if (seqrel->rd_rel->relowner != tablerel->rd_rel->relowner)
1643 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1644 errmsg("sequence must have same owner as table it is linked to")));
1647 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
1648 errmsg("sequence must be in same schema as table it is linked to")));
1649
1650
1654 (errcode(ERRCODE_UNDEFINED_COLUMN),
1655 errmsg("column \"%s\" of relation \"%s\" does not exist",
1657 }
1658
1659
1660
1661
1663 {
1664 Oid tableId;
1666
1669 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
1670 errmsg("cannot change ownership of identity sequence"),
1671 errdetail("Sequence \"%s\" is linked to table \"%s\".",
1674 }
1675
1676
1677
1678
1679
1681 RelationRelationId, deptype);
1682
1683 if (tablerel)
1684 {
1686 depobject;
1687
1688 refobject.classId = RelationRelationId;
1691 depobject.classId = RelationRelationId;
1695 }
1696
1697
1698 if (tablerel)
1700}
1701
1702
1703
1704
1705
1708{
1712
1715 elog(ERROR, "cache lookup failed for sequence %u", relid);
1717
1718
1731
1733
1735}
1736
1737
1738
1739
1742{
1746 bool isnull[7];
1749
1752 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1753 errmsg("permission denied for sequence %s",
1755
1757 elog(ERROR, "return type must be a row type");
1758
1759 memset(isnull, 0, sizeof(isnull));
1760
1763 elog(ERROR, "cache lookup failed for sequence %u", relid);
1765
1773
1775
1777}
1778
1779
1780
1781
1782
1783
1784
1785
1788{
1789#define PG_GET_SEQUENCE_DATA_COLS 2
1798
1801 INT8OID, -1, 0);
1803 BOOLOID, -1, 0);
1805
1807
1808
1809
1810
1811
1815 {
1819
1821
1824
1826 }
1827 else
1828 memset(isnull, true, sizeof(isnull));
1829
1831
1835#undef PG_GET_SEQUENCE_DATA_COLS
1836}
1837
1838
1839
1840
1841
1842
1843
1846{
1850 bool is_called = false;
1851 int64 result = 0;
1852
1853
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1868 {
1872
1874
1877
1879 }
1881
1882 if (is_called)
1884 else
1886}
1887
1888
1889void
1891{
1896 Page localpage;
1897 char *item;
1898 Size itemsz;
1901
1903 elog(PANIC, "seq_redo: unknown op code %u", info);
1904
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1918
1922
1923 item = (char *) xlrec + sizeof(xl_seq_rec);
1925
1928 elog(PANIC, "seq_redo: failed to add item to page");
1929
1931
1935
1936 pfree(localpage);
1937}
1938
1939
1940
1941
1942void
1944{
1946 {
1949 }
1950
1952}
1953
1954
1955
1956
1957void
1959{
1961
1963}
Relation sequence_open(Oid relationId, LOCKMODE lockmode)
void sequence_close(Relation relation, LOCKMODE lockmode)
AclResult pg_class_aclcheck(Oid table_oid, Oid roleid, AclMode mode)
#define InvalidAttrNumber
static Datum values[MAXATTR]
void mask_page_lsn_and_checksum(Page page)
void mask_unused_space(Page page)
BlockNumber BufferGetBlockNumber(Buffer buffer)
Buffer ExtendBufferedRel(BufferManagerRelation bmr, ForkNumber forkNum, BufferAccessStrategy strategy, uint32 flags)
void UnlockReleaseBuffer(Buffer buffer)
void MarkBufferDirty(Buffer buffer)
void LockBuffer(Buffer buffer, int mode)
void MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
void FlushRelationBuffers(Relation rel)
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
static Page BufferGetPage(Buffer buffer)
static Size BufferGetPageSize(Buffer buffer)
#define BUFFER_LOCK_EXCLUSIVE
void PageInit(Page page, Size pageSize, Size specialSize)
#define PageGetSpecialPointer(page)
static Item PageGetItem(const PageData *page, const ItemIdData *itemId)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static void PageSetLSN(Page page, XLogRecPtr lsn)
static XLogRecPtr PageGetLSN(const PageData *page)
#define PageAddItem(page, item, size, offsetNumber, overwrite, is_heap)
#define BoolIsValid(boolean)
uint32 LocalTransactionId
#define OidIsValid(objectId)
ObjectAddress DefineSequence(ParseState *pstate, CreateSeqStmt *seq)
static void fill_seq_fork_with_data(Relation rel, HeapTuple tuple, ForkNumber forkNum)
void ResetSequence(Oid seq_relid)
static void fill_seq_with_data(Relation rel, HeapTuple tuple)
struct sequence_magic sequence_magic
Datum setval_oid(PG_FUNCTION_ARGS)
List * sequence_options(Oid relid)
static SeqTableData * last_used_seq
ObjectAddress AlterSequence(ParseState *pstate, AlterSeqStmt *stmt)
Datum pg_sequence_parameters(PG_FUNCTION_ARGS)
Datum nextval_oid(PG_FUNCTION_ARGS)
static void init_sequence(Oid relid, SeqTable *p_elm, Relation *p_rel)
Datum setval3_oid(PG_FUNCTION_ARGS)
static Form_pg_sequence_data read_seq_tuple(Relation rel, Buffer *buf, HeapTuple seqdatatuple)
Datum pg_get_sequence_data(PG_FUNCTION_ARGS)
Datum lastval(PG_FUNCTION_ARGS)
void seq_mask(char *page, BlockNumber blkno)
Datum nextval(PG_FUNCTION_ARGS)
int64 nextval_internal(Oid relid, bool check_permissions)
void SequenceChangePersistence(Oid relid, char newrelpersistence)
#define PG_GET_SEQUENCE_DATA_COLS
static void process_owned_by(Relation seqrel, List *owned_by, bool for_identity)
Datum pg_sequence_last_value(PG_FUNCTION_ARGS)
Datum currval_oid(PG_FUNCTION_ARGS)
static void do_setval(Oid relid, int64 next, bool iscalled)
static void init_params(ParseState *pstate, List *options, bool for_identity, bool isInit, Form_pg_sequence seqform, Form_pg_sequence_data seqdataform, bool *need_seq_rewrite, List **owned_by)
void seq_redo(XLogReaderState *record)
struct SeqTableData SeqTableData
void ResetSequenceCaches(void)
static void create_seq_hashtable(void)
static Relation lock_and_open_sequence(SeqTable seq)
void DeleteSequenceTuple(Oid relid)
FormData_pg_sequence_data * Form_pg_sequence_data
struct xl_seq_rec xl_seq_rec
TypeName * defGetTypeName(DefElem *def)
List * defGetQualifiedName(DefElem *def)
int64 defGetInt64(DefElem *def)
void errorConflictingDefElem(DefElem *defel, ParseState *pstate)
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
void hash_destroy(HTAB *hashp)
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Datum Int64GetDatum(int64 X)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_INT64(x)
#define PG_GETARG_INT64(n)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_DATUM(x)
char * format_type_be(Oid type_oid)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
Assert(PointerIsAligned(start, uint64))
HeapTuple heap_copytuple(HeapTuple tuple)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_freetuple(HeapTuple htup)
HeapTupleHeaderData * HeapTupleHeader
#define HeapTupleIsValid(tuple)
static void HeapTupleHeaderSetXminFrozen(HeapTupleHeaderData *tup)
static void HeapTupleHeaderSetCmin(HeapTupleHeaderData *tup, CommandId cid)
static TransactionId HeapTupleHeaderGetRawXmax(const HeapTupleHeaderData *tup)
#define HEAP_XMAX_IS_MULTI
#define HEAP_XMAX_INVALID
static void * GETSTRUCT(const HeapTupleData *tuple)
static void HeapTupleHeaderSetXmin(HeapTupleHeaderData *tup, TransactionId xid)
static void HeapTupleHeaderSetXmax(HeapTupleHeaderData *tup, TransactionId xid)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
void CatalogTupleInsert(Relation heapRel, HeapTuple tup)
void CatalogTupleDelete(Relation heapRel, ItemPointer tid)
#define ItemIdGetLength(itemId)
#define ItemIdIsNormal(itemId)
static void ItemPointerSet(ItemPointerData *pointer, BlockNumber blockNumber, OffsetNumber offNum)
List * lappend(List *list, void *datum)
List * list_copy_head(const List *oldlist, int len)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
#define InvalidLocalTransactionId
#define AccessExclusiveLock
#define ShareRowExclusiveLock
char * get_rel_name(Oid relid)
AttrNumber get_attnum(Oid relid, const char *attname)
DefElem * makeDefElem(char *name, Node *arg, int location)
ColumnDef * makeColumnDef(const char *colname, Oid typeOid, int32 typmod, Oid collOid)
void pfree(void *pointer)
#define START_CRIT_SECTION()
#define END_CRIT_SECTION()
#define InvalidMultiXactId
Oid RangeVarGetAndCheckCreationNamespace(RangeVar *relation, LOCKMODE lockmode, Oid *existing_relation_id)
RangeVar * makeRangeVarFromNameList(const List *names)
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
#define RangeVarGetRelid(relation, lockmode, missing_ok)
#define InvokeObjectPostAlterHook(classId, objectId, subId)
const ObjectAddress InvalidObjectAddress
#define ObjectAddressSet(addr, class_id, object_id)
#define InvalidOffsetNumber
#define FirstOffsetNumber
int parser_errposition(ParseState *pstate, int location)
Oid typenameTypeId(ParseState *pstate, const TypeName *typeName)
int errdetail_relkind_not_supported(char relkind)
void checkMembershipInCurrentExtension(const ObjectAddress *object)
void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)
long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)
bool sequenceIsOwned(Oid seqId, char deptype, Oid *tableId, int32 *colId)
static int list_length(const List *l)
FormData_pg_sequence * Form_pg_sequence
#define Int64GetDatumFast(X)
static Datum BoolGetDatum(bool X)
static Datum ObjectIdGetDatum(Oid X)
#define INVALID_PROC_NUMBER
char * psprintf(const char *fmt,...)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define RelationNeedsWAL(relation)
#define RELATION_IS_OTHER_TEMP(relation)
#define RelationGetNamespace(relation)
#define RelationIsPermanent(relation)
void RelationSetNewRelfilenumber(Relation relation, char persistence)
#define InvalidRelFileNumber
ResourceOwner TopTransactionResourceOwner
ResourceOwner CurrentResourceOwner
SMgrRelation smgropen(RelFileLocator rlocator, ProcNumber backend)
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
void smgrclose(SMgrRelation reln)
void relation_close(Relation relation, LOCKMODE lockmode)
Relation relation_openrv(const RangeVar *relation, LOCKMODE lockmode)
void log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum)
RelFileLocator rd_locator
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
#define SearchSysCacheCopy1(cacheId, key1)
#define SearchSysCacheExists1(cacheId, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
ObjectAddress DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId, ObjectAddress *typaddress, const char *queryString)
void RangeVarCallbackOwnsRelation(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
#define FrozenTransactionId
#define InvalidTransactionId
TupleDesc CreateTemplateTupleDesc(int natts)
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
void PreventCommandIfReadOnly(const char *cmdname)
void PreventCommandIfParallelMode(const char *cmdname)
Float * makeFloat(char *numericStr)
Boolean * makeBoolean(bool val)
List * textToQualifiedNameList(text *textval)
TransactionId GetTopTransactionId(void)
bool RecoveryInProgress(void)
XLogRecPtr GetRedoRecPtr(void)
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
void XLogRegisterData(const void *data, uint32 len)
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
void XLogBeginInsert(void)
#define XLogRecGetDataLen(decoder)
#define XLogRecGetInfo(decoder)
#define XLogRecGetData(decoder)
Buffer XLogInitBufferForRedo(XLogReaderState *record, uint8 block_id)