PostgreSQL Source Code: src/backend/catalog/index.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

23

25

73#include "utils/fmgroids.h"

83

84

88

89

90

91

92

93typedef struct

94{

100

101

105 const List *indexColNames,

106 Oid accessMethodId,

107 const Oid *collationIds,

108 const Oid *opclassIds);

110 int numatts, Oid indexoid);

113 Oid parentIndexId,

115 const Oid *collationOids,

116 const Oid *opclassOids,

117 const int16 *coloptions,

118 bool primary,

119 bool isexclusion,

120 bool immediate,

121 bool isvalid,

122 bool isready);

124 bool hasindex,

125 double reltuples);

135

136

137

138

139

140

141

142

143

144

145

146

147static bool

149{

150 bool result = false;

151 List *indexoidlist;

153

154

155

156

157

158

160

161 foreach(indexoidscan, indexoidlist)

162 {

165

168 elog(ERROR, "cache lookup failed for index %u", indexoid);

171 if (result)

172 break;

173 }

174

176

177 return result;

178}

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201void

204 bool is_alter_table,

206{

207 int i;

208

209

210

211

212

213

214

215 if ((is_alter_table || heapRel->rd_rel->relispartition) &&

217 {

219 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),

220 errmsg("multiple primary keys for table \"%s\" are not allowed",

222 }

223

224

225

226

227

228

229

231 {

233 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),

234 errmsg("primary keys cannot use NULLS NOT DISTINCT indexes")));

235 }

236

237

238

239

240

241

243 {

247

250 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

251 errmsg("primary keys cannot be expressions")));

252

253

255 continue;

256

261 elog(ERROR, "cache lookup failed for attribute %d of relation %u",

264

265 if (!attform->attnotnull)

267 (errcode(ERRCODE_INVALID_TABLE_DEFINITION),

268 errmsg("primary key column \"%s\" is not marked NOT NULL",

269 NameStr(attform->attname))));

270

272 }

273}

274

275

276

277

278

279

283 const List *indexColNames,

284 Oid accessMethodId,

285 const Oid *collationIds,

286 const Oid *opclassIds)

287{

295 int natts;

296 int i;

297

298

300

301

304

305

306

307

309

310

311

312

313 for (i = 0; i < numatts; i++)

314 {

320 Oid keyType;

321

323 to->attnum = i + 1;

324 to->attislocal = true;

325 to->attcollation = (i < numkeyatts) ? collationIds[i] : InvalidOid;

326

327

328

329

330 if (colnames_item == NULL)

331 elog(ERROR, "too few entries in colnames list");

332 namestrcpy(&to->attname, (const char *) lfirst(colnames_item));

333 colnames_item = lnext(indexColNames, colnames_item);

334

335

336

337

338

339

340 if (atnum != 0)

341 {

342

344

345 Assert(atnum > 0);

346

347 if (atnum > natts)

348 elog(ERROR, "invalid column number %d", atnum);

351

352 to->atttypid = from->atttypid;

353 to->attlen = from->attlen;

354 to->attndims = from->attndims;

355 to->atttypmod = from->atttypmod;

356 to->attbyval = from->attbyval;

357 to->attalign = from->attalign;

358 to->attstorage = from->attstorage;

359 to->attcompression = from->attcompression;

360 }

361 else

362 {

363

364 Node *indexkey;

365

366 if (indexpr_item == NULL)

367 elog(ERROR, "too few entries in indexprs list");

368 indexkey = (Node *) lfirst(indexpr_item);

370

371

372

373

374 keyType = exprType(indexkey);

377 elog(ERROR, "cache lookup failed for type %u", keyType);

379

380

381

382

383 to->atttypid = keyType;

384 to->attlen = typeTup->typlen;

385 to->atttypmod = exprTypmod(indexkey);

386 to->attbyval = typeTup->typbyval;

387 to->attalign = typeTup->typalign;

388 to->attstorage = typeTup->typstorage;

389

390

391

392

393

394

395

396

398

400

401

402

403

404

405

406

407

408

409

411 to->atttypid, to->attcollation,

413 }

414

415

416

417

418

419

421

422

423

424

425

426

428

429 if (i < indexInfo->ii_NumIndexKeyAttrs)

430 {

433 elog(ERROR, "cache lookup failed for opclass %u", opclassIds[i]);

435 if (OidIsValid(opclassTup->opckeytype))

436 keyType = opclassTup->opckeytype;

437

438

439

440

441

442

443

444

445

446

447 if (keyType == ANYELEMENTOID && opclassTup->opcintype == ANYARRAYOID)

448 {

451 elog(ERROR, "could not get element type of array type %u",

452 to->atttypid);

453 }

454

456 }

457

458

459

460

461

462 if (OidIsValid(keyType) && keyType != to->atttypid)

463 {

466 elog(ERROR, "cache lookup failed for type %u", keyType);

468

469 to->atttypid = keyType;

470 to->atttypmod = -1;

471 to->attlen = typeTup->typlen;

472 to->attbyval = typeTup->typbyval;

473 to->attalign = typeTup->typalign;

474 to->attstorage = typeTup->typstorage;

475

477

479 }

480

482 }

483

484 pfree(amroutine);

485

486 return indexTupDesc;

487}

488

489

490

491

492

493static void

495 int numatts,

496 Oid indexoid)

497{

499 int i;

500

502

503 for (i = 0; i < numatts; i += 1)

504 TupleDescAttr(tupleDescriptor, i)->attrelid = indexoid;

505}

506

507

508

509

510

511static void

513{

518

519 if (attopts)

520 {

522

523 for (int i = 0; i < indexRelation->rd_att->natts; i++)

524 {

525 if (attopts[i])

527 else

529

530 if (stattargets)

532 else

534 }

535 }

536

537

538

539

541

543

544

545

546

548

550

552

554}

555

556

557

558

559

560

561

562static void

564 Oid heapoid,

565 Oid parentIndexId,

567 const Oid *collationOids,

568 const Oid *opclassOids,

569 const int16 *coloptions,

570 bool primary,

571 bool isexclusion,

572 bool immediate,

573 bool isvalid,

574 bool isready)

575{

580 Datum exprsDatum;

583 bool nulls[Natts_pg_index] = {0};

586 int i;

587

588

589

590

591

598

599

600

601

603 {

604 char *exprsString;

605

608 pfree(exprsString);

609 }

610 else

611 exprsDatum = (Datum) 0;

612

613

614

615

616

618 {

619 char *predString;

620

623 pfree(predString);

624 }

625 else

626 predDatum = (Datum) 0;

627

628

629

630

631

633

634

635

636

644 values[Anum_pg_index_indisexclusion - 1] = BoolGetDatum(isexclusion);

656 values[Anum_pg_index_indexprs - 1] = exprsDatum;

657 if (exprsDatum == (Datum) 0)

658 nulls[Anum_pg_index_indexprs - 1] = true;

659 values[Anum_pg_index_indpred - 1] = predDatum;

660 if (predDatum == (Datum) 0)

661 nulls[Anum_pg_index_indpred - 1] = true;

662

664

665

666

667

669

670

671

672

675}

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

727 const char *indexRelationName,

728 Oid indexRelationId,

729 Oid parentIndexRelid,

730 Oid parentConstraintId,

733 const List *indexColNames,

734 Oid accessMethodId,

735 Oid tableSpaceId,

736 const Oid *collationIds,

737 const Oid *opclassIds,

738 const Datum *opclassOptions,

739 const int16 *coloptions,

741 Datum reloptions,

744 bool allow_system_table_mods,

745 bool is_internal,

746 Oid *constraintId)

747{

752 bool shared_relation;

753 bool mapped_relation;

754 bool is_exclusion;

755 Oid namespaceId;

756 int i;

757 char relpersistence;

762 char relkind;

766

767

768 Assert((constr_flags == 0) ||

770

772

773 relkind = partitioned ? RELKIND_PARTITIONED_INDEX : RELKIND_INDEX;

775

777

778

779

780

781

782

783

785 shared_relation = heapRelation->rd_rel->relisshared;

787 relpersistence = heapRelation->rd_rel->relpersistence;

788

789

790

791

793 elog(ERROR, "must index at least one column");

794

795 if (!allow_system_table_mods &&

799 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

800 errmsg("user-defined indexes on system catalog tables are not supported")));

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

822 {

823 Oid collation = collationIds[i];

824 Oid opclass = opclassIds[i];

825

826 if (collation)

827 {

828 if ((opclass == TEXT_BTREE_PATTERN_OPS_OID ||

829 opclass == VARCHAR_BTREE_PATTERN_OPS_OID ||

830 opclass == BPCHAR_BTREE_PATTERN_OPS_OID) &&

832 {

834

837 elog(ERROR, "cache lookup failed for operator class %u", opclass);

839 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

840 errmsg("nondeterministic collations are not supported for operator class \"%s\"",

843 }

844 }

845 }

846

847

848

849

850

851 if (concurrent &&

854 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

855 errmsg("concurrent index creation on system catalog tables is not supported")));

856

857

858

859

860

861 if (concurrent && is_exclusion)

863 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

864 errmsg("concurrent index creation for exclusion constraints is not supported")));

865

866

867

868

869

872 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),

873 errmsg("shared indexes cannot be created after initdb")));

874

875

876

877

878 if (shared_relation && tableSpaceId != GLOBALTABLESPACE_OID)

879 elog(ERROR, "shared relations must be placed in pg_global tablespace");

880

881

882

883

884

885

886

888 {

890 {

892 (errcode(ERRCODE_DUPLICATE_TABLE),

893 errmsg("relation \"%s\" already exists, skipping",

894 indexRelationName)));

897 }

898

900 (errcode(ERRCODE_DUPLICATE_TABLE),

901 errmsg("relation \"%s\" already exists",

902 indexRelationName)));

903 }

904

907 indexRelationName))

908 {

909

910

911

912

915 errmsg("constraint \"%s\" for relation \"%s\" already exists",

917 }

918

919

920

921

923 indexInfo,

924 indexColNames,

925 accessMethodId,

926 collationIds,

927 opclassIds);

928

929

930

931

932

933

934

936 {

937

939 {

942 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

943 errmsg("pg_class index OID value not set when in binary upgrade mode")));

944

947

948

949 if ((relkind == RELKIND_INDEX) &&

952 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),

953 errmsg("index relfilenumber value not set when in binary upgrade mode")));

956

957

958

959

960

961

962 Assert(create_storage);

963 }

964 else

965 {

966 indexRelationId =

968 }

969 }

970

971

972

973

974

975

976 indexRelation = heap_create(indexRelationName,

977 namespaceId,

978 tableSpaceId,

979 indexRelationId,

980 relFileNumber,

981 accessMethodId,

982 indexTupDesc,

983 relkind,

984 relpersistence,

985 shared_relation,

986 mapped_relation,

987 allow_system_table_mods,

988 &relfrozenxid,

989 &relminmxid,

990 create_storage);

991

995

996

997

998

999

1000

1002

1003

1004

1005

1006

1007

1008

1009 indexRelation->rd_rel->relowner = heapRelation->rd_rel->relowner;

1010 indexRelation->rd_rel->relam = accessMethodId;

1011 indexRelation->rd_rel->relispartition = OidIsValid(parentIndexRelid);

1012

1013

1014

1015

1019 reloptions);

1020

1021

1023

1024

1025

1026

1027

1030 indexRelationId);

1031

1032

1033

1034

1036

1037

1038

1039

1040

1041

1042

1043

1044

1046 indexInfo,

1047 collationIds, opclassIds, coloptions,

1048 isprimary, is_exclusion,

1050 !concurrent && invalid,

1051 !concurrent);

1052

1053

1054

1055

1056

1058

1059

1061 {

1065 }

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1082 {

1084 referenced;

1086

1087 ObjectAddressSet(myself, RelationRelationId, indexRelationId);

1088

1090 {

1091 char constraintType;

1093

1094 if (isprimary)

1095 constraintType = CONSTRAINT_PRIMARY;

1097 constraintType = CONSTRAINT_UNIQUE;

1098 else if (is_exclusion)

1099 constraintType = CONSTRAINT_EXCLUSION;

1100 else

1101 {

1102 elog(ERROR, "constraint must be PRIMARY, UNIQUE or EXCLUDE");

1103 constraintType = 0;

1104 }

1105

1107 indexRelationId,

1108 parentConstraintId,

1109 indexInfo,

1110 indexRelationName,

1111 constraintType,

1112 constr_flags,

1113 allow_system_table_mods,

1114 is_internal);

1115 if (constraintId)

1116 *constraintId = localaddr.objectId;

1117 }

1118 else

1119 {

1120 bool have_simple_col = false;

1121

1123

1124

1126 {

1128 {

1130 heapRelationId,

1133 have_simple_col = true;

1134 }

1135 }

1136

1137

1138

1139

1140

1141

1142

1143 if (!have_simple_col)

1144 {

1146 heapRelationId);

1148 }

1149

1152 }

1153

1154

1155

1156

1157

1158

1159

1161 {

1162 ObjectAddressSet(referenced, RelationRelationId, parentIndexRelid);

1164

1165 ObjectAddressSet(referenced, RelationRelationId, heapRelationId);

1167 }

1168

1169

1171

1172

1173

1174

1176 {

1177 if (OidIsValid(collationIds[i]) && collationIds[i] != DEFAULT_COLLATION_OID)

1178 {

1179 ObjectAddressSet(referenced, CollationRelationId, collationIds[i]);

1181 }

1182 }

1183

1184

1186 {

1187 ObjectAddressSet(referenced, OperatorClassRelationId, opclassIds[i]);

1189 }

1190

1193

1194

1196 {

1199 heapRelationId,

1202 }

1203

1204

1206 {

1209 heapRelationId,

1212 }

1213 }

1214 else

1215 {

1216

1218 }

1219

1220

1222 indexRelationId, 0, is_internal);

1223

1224

1225

1226

1227

1229

1230

1231

1232

1233

1234

1235

1238 else

1240

1242

1243

1244 if (opclassOptions)

1247 opclassOptions[i],

1248 true);

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1260 {

1261 index_register(heapRelationId, indexRelationId, indexInfo);

1262 }

1264 {

1265

1266

1267

1268

1269

1271 true,

1272 -1.0);

1273

1275 }

1276 else

1277 {

1278 index_build(heapRelation, indexRelation, indexInfo, false, true);

1279 }

1280

1281

1282

1283

1284

1286

1287 return indexRelationId;

1288}

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1301 Oid tablespaceOid, const char *newName)

1302{

1305 *newInfo;

1308 classTuple;

1309 Datum indclassDatum,

1310 colOptionDatum,

1311 reloptionsDatum;

1312 Datum *opclassOptions;

1316 bool isnull;

1317 List *indexColNames = NIL;

1320

1322

1323

1325

1326

1327

1328

1329

1332 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

1333 errmsg("concurrent index creation for exclusion constraints is not supported")));

1334

1335

1338 elog(ERROR, "cache lookup failed for index %u", oldIndexId);

1340 Anum_pg_index_indclass);

1342

1344 Anum_pg_index_indoption);

1346

1347

1350 elog(ERROR, "cache lookup failed for relation %u", oldIndexId);

1352 Anum_pg_class_reloptions, &isnull);

1353

1354

1355

1356

1357

1358

1360 {

1361 Datum exprDatum;

1362 char *exprString;

1363

1365 Anum_pg_index_indexprs);

1368 pfree(exprString);

1369 }

1371 {

1372 Datum predDatum;

1373 char *predString;

1374

1376 Anum_pg_index_indpred);

1379

1380

1382 pfree(predString);

1383 }

1384

1385

1386

1387

1388

1389

1393 indexExprs,

1394 indexPreds,

1397 false,

1398 true,

1401

1402

1403

1404

1405

1406

1408 {

1411

1412 indexColNames = lappend(indexColNames, NameStr(att->attname));

1414 }

1415

1416

1420

1421

1424 {

1427

1430 elog(ERROR, "cache lookup failed for attribute %d of relation %u",

1431 i + 1, oldIndexId);

1432 dat = SysCacheGetAttr(ATTNUM, tp, Anum_pg_attribute_attstattarget, &isnull);

1434 stattargets[i].value = dat;

1435 stattargets[i].isnull = isnull;

1436 }

1437

1438

1439

1440

1441

1442

1443

1444

1446 newName,

1449 InvalidOid,

1451 newInfo,

1452 indexColNames,

1453 indexRelation->rd_rel->relam,

1454 tablespaceOid,

1457 opclassOptions,

1458 indcoloptions->values,

1459 stattargets,

1460 reloptionsDatum,

1462 0,

1463 true,

1464 false,

1465 NULL);

1466

1467

1471

1472 return newIndexId;

1473}

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484void

1486 Oid indexRelationId)

1487{

1489 Oid save_userid;

1490 int save_sec_context;

1491 int save_nestlevel;

1494

1495

1497

1498

1500

1501

1502

1503

1504

1505

1511

1513

1514

1515

1516

1517

1518

1523

1524

1525 index_build(heapRel, indexRelation, indexInfo, false, true);

1526

1527

1529

1530

1532

1533

1536

1537

1538

1539

1540

1541

1543}

1544

1545

1546

1547

1548

1549

1550

1551void

1553{

1555 pg_index,

1556 pg_constraint,

1557 pg_trigger;

1559 newClassRel;

1561 newClassTuple;

1563 newClassForm;

1565 newIndexTuple;

1567 newIndexForm;

1568 bool isPartition;

1569 Oid indexConstraintOid;

1570 List *constraintOids = NIL;

1572

1573

1574

1575

1578

1579

1581

1585 elog(ERROR, "could not find tuple for relation %u", oldIndexId);

1589 elog(ERROR, "could not find tuple for relation %u", newIndexId);

1590

1593

1594

1595 namestrcpy(&newClassForm->relname, NameStr(oldClassForm->relname));

1596 namestrcpy(&oldClassForm->relname, oldName);

1597

1598

1599 isPartition = newClassForm->relispartition;

1600 newClassForm->relispartition = oldClassForm->relispartition;

1601 oldClassForm->relispartition = isPartition;

1602

1605

1608

1609

1611

1615 elog(ERROR, "could not find tuple for relation %u", oldIndexId);

1619 elog(ERROR, "could not find tuple for relation %u", newIndexId);

1620

1623

1624

1625

1626

1627

1628 newIndexForm->indisprimary = oldIndexForm->indisprimary;

1629 oldIndexForm->indisprimary = false;

1630 newIndexForm->indisexclusion = oldIndexForm->indisexclusion;

1631 oldIndexForm->indisexclusion = false;

1632 newIndexForm->indimmediate = oldIndexForm->indimmediate;

1633 oldIndexForm->indimmediate = true;

1634

1635

1636 newIndexForm->indisreplident = oldIndexForm->indisreplident;

1637

1638

1639 newIndexForm->indisclustered = oldIndexForm->indisclustered;

1640

1641

1642

1643

1644

1645 newIndexForm->indisvalid = true;

1646 oldIndexForm->indisvalid = false;

1647 oldIndexForm->indisclustered = false;

1648 oldIndexForm->indisreplident = false;

1649

1652

1655

1656

1657

1658

1659

1661

1663

1665 constraintOids = lappend_oid(constraintOids, indexConstraintOid);

1666

1669

1670 foreach(lc, constraintOids)

1671 {

1673 triggerTuple;

1678

1679

1683 elog(ERROR, "could not find tuple for constraint %u", constraintOid);

1684

1686

1687 if (conForm->conindid == oldIndexId)

1688 {

1689 conForm->conindid = newIndexId;

1690

1692 }

1693

1695

1696

1698 Anum_pg_trigger_tgconstraint,

1701

1702 scan = systable_beginscan(pg_trigger, TriggerConstraintIndexId, true,

1703 NULL, 1, key);

1704

1706 {

1708

1709 if (tgForm->tgconstrindid != oldIndexId)

1710 continue;

1711

1712

1715

1716 tgForm->tgconstrindid = newIndexId;

1717

1719

1721 }

1722

1724 }

1725

1726

1727

1728

1729 {

1734 Datum values[Natts_pg_description] = {0};

1735 bool nulls[Natts_pg_description] = {0};

1736 bool replaces[Natts_pg_description] = {0};

1737

1739 replaces[Anum_pg_description_objoid - 1] = true;

1740

1742 Anum_pg_description_objoid,

1746 Anum_pg_description_classoid,

1750 Anum_pg_description_objsubid,

1753

1755

1757 NULL, 3, skey);

1758

1760 {

1762 values, nulls, replaces);

1764

1765 break;

1766 }

1767

1770 }

1771

1772

1773

1774

1776 {

1779

1782

1784 }

1785

1786

1787

1788

1789

1790

1793

1796

1797

1799

1800

1802

1803

1808

1809

1812}

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822void

1824{

1827

1828

1829

1830

1831

1832

1833

1837

1838

1839

1840

1841

1842

1844

1845

1846

1847

1848

1849

1851

1852

1853

1854

1857}

1858

1859

1860

1861

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871

1872

1873

1874

1875

1876

1877

1878

1879

1880

1881

1882

1883

1886 Oid indexRelationId,

1887 Oid parentConstraintId,

1889 const char *constraintName,

1890 char constraintType,

1891 bits16 constr_flags,

1892 bool allow_system_table_mods,

1893 bool is_internal)

1894{

1897 idxaddr;

1898 Oid conOid;

1899 bool deferrable;

1900 bool initdeferred;

1901 bool mark_as_primary;

1902 bool islocal;

1903 bool noinherit;

1904 bool is_without_overlaps;

1906

1911

1912

1914

1915

1916 if (!allow_system_table_mods &&

1920 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

1921 errmsg("user-defined indexes on system catalog tables are not supported")));

1922

1923

1925 constraintType != CONSTRAINT_EXCLUSION)

1926 elog(ERROR, "constraints cannot have index expressions");

1927

1928

1929

1930

1931

1932

1933

1934

1935

1936

1940

1942 {

1943 islocal = false;

1944 inhcount = 1;

1945 noinherit = false;

1946 }

1947 else

1948 {

1949 islocal = true;

1950 inhcount = 0;

1951 noinherit = true;

1952 }

1953

1954

1955

1956

1958 namespaceId,

1959 constraintType,

1960 deferrable,

1961 initdeferred,

1962 true,

1963 true,

1964 parentConstraintId,

1970 indexRelationId,

1972 NULL,

1973 NULL,

1974 NULL,

1975 NULL,

1976 0,

1977 ' ',

1978 ' ',

1979 NULL,

1980 0,

1981 ' ',

1983 NULL,

1984 NULL,

1985 islocal,

1986 inhcount,

1987 noinherit,

1988 is_without_overlaps,

1989 is_internal);

1990

1991

1992

1993

1994

1995

1996

1998 ObjectAddressSet(idxaddr, RelationRelationId, indexRelationId);

2000

2001

2002

2003

2004

2006 {

2008

2009 ObjectAddressSet(referenced, ConstraintRelationId, parentConstraintId);

2014 }

2015

2016

2017

2018

2019

2020

2021 if (deferrable)

2022 {

2024

2025 trigger->replace = false;

2027 trigger->trigname = (constraintType == CONSTRAINT_PRIMARY) ?

2028 "PK_ConstraintTrigger" :

2029 "Unique_ConstraintTrigger";

2033 trigger->row = true;

2034 trigger->timing = TRIGGER_TYPE_AFTER;

2035 trigger->events = TRIGGER_TYPE_INSERT | TRIGGER_TYPE_UPDATE;

2042

2046 }

2047

2048

2049

2050

2051

2052

2053

2054

2055

2057 (mark_as_primary || deferrable))

2058 {

2062 bool dirty = false;

2063 bool marked_as_primary = false;

2064

2066

2070 elog(ERROR, "cache lookup failed for index %u", indexRelationId);

2072

2073 if (mark_as_primary && !indexForm->indisprimary)

2074 {

2075 indexForm->indisprimary = true;

2076 dirty = true;

2077 marked_as_primary = true;

2078 }

2079

2080 if (deferrable && indexForm->indimmediate)

2081 {

2082 indexForm->indimmediate = false;

2083 dirty = true;

2084 }

2085

2086 if (dirty)

2087 {

2089

2090

2091

2092

2093

2094

2095

2096 if (marked_as_primary)

2098

2101 }

2102

2105 }

2106

2107 return myself;

2108}

2109

2110

2111

2112

2113

2114

2115

2116

2117

2118

2119

2120

2121void

2122index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)

2123{

2124 Oid heapId;

2129 bool hasexprs;

2131 indexrelid;

2134

2135

2136

2137

2138

2139

2140

2142 (!concurrent && !concurrent_lock_mode));

2143

2144

2145

2146

2147

2148

2149

2150

2151

2152

2153

2154

2155

2156

2157

2158

2159

2160

2161

2164 userHeapRelation = table_open(heapId, lockmode);

2165 userIndexRelation = index_open(indexId, lockmode);

2166

2167

2168

2169

2170

2172

2173

2174

2175

2176

2177

2178

2179

2180

2181

2182

2183

2184

2185

2186

2187

2188

2189

2190

2191

2192

2193

2194

2195

2196

2197

2198

2199

2200

2201

2202

2203

2204 if (concurrent)

2205 {

2206

2207

2208

2209

2210

2211

2212

2213

2214

2215

2216

2217

2218

2221 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

2222 errmsg("DROP INDEX CONCURRENTLY must be first action in transaction")));

2223

2224

2225

2226

2228

2229

2230

2231

2232

2233

2235

2236

2240

2243

2244

2245

2246

2247

2248

2249

2250

2251

2252

2253

2254

2257

2261

2262

2263

2264

2265

2266

2267

2268

2269

2270

2271

2272

2273

2274

2275

2276

2277

2278

2279

2281

2282

2283

2284

2285

2287

2288

2290

2292

2293

2294

2295

2296

2299

2300

2301

2302

2303

2305

2306

2307

2308

2309

2310

2311

2312

2315 }

2316 else

2317 {

2318

2320 }

2321

2322

2323

2324

2325 if (RELKIND_HAS_STORAGE(userIndexRelation->rd_rel->relkind))

2327

2328

2330

2331

2332

2333

2334

2335

2337

2339

2340

2341

2342

2343

2345

2346

2347

2348

2350

2353 elog(ERROR, "cache lookup failed for index %u", indexId);

2354

2355 hasexprs = heap\_attisnull(tuple, Anum_pg_index_indexprs,

2357

2359

2362

2364

2365

2366

2367

2368

2369 if (hasexprs)

2371

2372

2373

2374

2376

2377

2378

2379

2381

2382

2383

2384

2386

2387

2388

2389

2390

2391

2392

2393

2394

2396

2397

2398

2399

2401

2402

2403

2404

2405 if (concurrent)

2406 {

2409 }

2410}

2411

2412

2413

2414

2415

2416

2417

2418

2419

2420

2421

2422

2423

2424

2425

2426

2429{

2432 int i;

2433 int numAtts;

2434

2435

2436 numAtts = indexStruct->indnatts;

2438 elog(ERROR, "invalid indnatts %d for index %u",

2440

2441

2442

2443

2444

2446 indexStruct->indnkeyatts,

2447 index->rd_rel->relam,

2450 indexStruct->indisunique,

2451 indexStruct->indnullsnotdistinct,

2452 indexStruct->indisready,

2453 false,

2454 index->rd_indam->amsummarizing,

2455 indexStruct->indisexclusion && indexStruct->indisunique);

2456

2457

2458 for (i = 0; i < numAtts; i++)

2460

2461

2462 if (indexStruct->indisexclusion)

2463 {

2468 }

2469

2470 return ii;

2471}

2472

2473

2474

2475

2476

2477

2478

2479

2480

2481

2482

2483

2484

2485

2486

2489{

2492 int i;

2493 int numAtts;

2494

2495

2496 numAtts = indexStruct->indnatts;

2498 elog(ERROR, "invalid indnatts %d for index %u",

2500

2501

2502

2503

2504

2506 indexStruct->indnkeyatts,

2507 index->rd_rel->relam,

2510 indexStruct->indisunique,

2511 indexStruct->indnullsnotdistinct,

2512 indexStruct->indisready,

2513 false,

2514 index->rd_indam->amsummarizing,

2515 indexStruct->indisexclusion && indexStruct->indisunique);

2516

2517

2518 for (i = 0; i < numAtts; i++)

2520

2521

2522

2523 return ii;

2524}

2525

2526

2527

2528

2529

2530

2531

2532

2533

2534

2535

2536bool

2538 const Oid *collations1, const Oid *collations2,

2539 const Oid *opfamilies1, const Oid *opfamilies2,

2541{

2542 int i;

2543

2545 return false;

2546

2548 return false;

2549

2550

2552 return false;

2553

2554

2556 return false;

2557

2558

2560 return false;

2561

2562

2563

2564

2565

2566

2567

2569 {

2571 elog(ERROR, "incorrect attribute map");

2572

2573

2576 {

2577

2580 return false;

2581

2582

2585 return false;

2586 }

2587

2588

2590 continue;

2591

2592 if (collations1[i] != collations2[i])

2593 return false;

2594 if (opfamilies1[i] != opfamilies2[i])

2595 return false;

2596 }

2597

2598

2599

2600

2601

2603 return false;

2605 {

2606 bool found_whole_row;

2607 Node *mapped;

2608

2610 1, 0, attmap,

2612 if (found_whole_row)

2613 {

2614

2615

2616

2617

2618 return false;

2619 }

2620

2622 return false;

2623 }

2624

2625

2627 return false;

2629 {

2630 bool found_whole_row;

2631 Node *mapped;

2632

2634 1, 0, attmap,

2636 if (found_whole_row)

2637 {

2638

2639

2640

2641

2642 return false;

2643 }

2645 return false;

2646 }

2647

2648

2650 return false;

2651

2652 return true;

2653}

2654

2655

2656

2657

2658

2659

2660

2661

2662

2663

2664

2665

2666

2667

2668void

2670{

2671 int indnkeyatts;

2672 int i;

2673

2675

2676

2677

2678

2680

2684

2685

2686

2687

2688

2689

2690 for (i = 0; i < indnkeyatts; i++)

2691 {

2694 index->rd_rel->relam,

2695 index->rd_opfamily[i],

2696 false);

2699 index->rd_opcintype[i],

2700 index->rd_opcintype[i],

2703 elog(ERROR, "missing operator %d(%u,%u) in opfamily %u",

2705 index->rd_opcintype[i], index->rd_opfamily[i]);

2707 }

2708}

2709

2710

2711

2712

2713

2714

2715

2716

2717

2718

2719

2720

2721

2722

2723

2724

2725

2726

2727

2728

2729void

2734 bool *isnull)

2735{

2737 int i;

2738

2741 {

2742

2745

2747 }

2749

2751 {

2754 bool isNull;

2755

2756 if (keycol < 0)

2758 else if (keycol != 0)

2759 {

2760

2761

2762

2763

2764 iDatum = slot_getattr(slot, keycol, &isNull);

2765 }

2766 else

2767 {

2768

2769

2770

2771 if (indexpr_item == NULL)

2772 elog(ERROR, "wrong number of index expressions");

2775 &isNull);

2777 }

2779 isnull[i] = isNull;

2780 }

2781

2782 if (indexpr_item != NULL)

2783 elog(ERROR, "wrong number of index expressions");

2784}

2785

2786

2787

2788

2789

2790

2791

2792

2793

2794

2795

2796

2797

2798

2799

2800

2801

2802

2803

2804

2805

2806

2807

2808static void

2810 bool hasindex,

2811 double reltuples)

2812{

2813 bool update_stats;

2814 BlockNumber relpages = 0;

2823 bool dirty;

2824

2825

2826

2827

2828

2829

2830

2831

2832

2833

2834

2835 if (reltuples == 0 && rel->rd_rel->reltuples < 0)

2836 reltuples = -1;

2837

2838

2839

2840

2841

2843

2844

2845

2846

2847

2848

2849

2850 if (rel->rd_rel->relkind == RELKIND_RELATION ||

2851 rel->rd_rel->relkind == RELKIND_TOASTVALUE ||

2852 rel->rd_rel->relkind == RELKIND_MATVIEW)

2853 {

2855 {

2857

2859 update_stats = false;

2860 }

2861 else

2862 update_stats = false;

2863 }

2864

2865

2866

2867

2868

2869

2870

2871

2872 if (update_stats)

2873 {

2875

2876 if (rel->rd_rel->relkind != RELKIND_INDEX)

2878 }

2879

2880

2881

2882

2883

2884

2885

2886

2887

2888

2889

2890

2891

2892

2893

2894

2895

2896

2897

2898

2899

2900

2901

2902

2903

2904

2905

2906

2907

2909

2911 Anum_pg_class_oid,

2916

2918 elog(ERROR, "could not find tuple for relation %u", relid);

2920

2921

2922 Assert(rd_rel->relkind != RELKIND_PARTITIONED_INDEX);

2923

2924

2925

2926 dirty = false;

2927 if (rd_rel->relhasindex != hasindex)

2928 {

2929 rd_rel->relhasindex = hasindex;

2930 dirty = true;

2931 }

2932

2933 if (update_stats)

2934 {

2935 if (rd_rel->relpages != (int32) relpages)

2936 {

2937 rd_rel->relpages = (int32) relpages;

2938 dirty = true;

2939 }

2940 if (rd_rel->reltuples != (float4) reltuples)

2941 {

2942 rd_rel->reltuples = (float4) reltuples;

2943 dirty = true;

2944 }

2945 if (rd_rel->relallvisible != (int32) relallvisible)

2946 {

2947 rd_rel->relallvisible = (int32) relallvisible;

2948 dirty = true;

2949 }

2950 if (rd_rel->relallfrozen != (int32) relallfrozen)

2951 {

2952 rd_rel->relallfrozen = (int32) relallfrozen;

2953 dirty = true;

2954 }

2955 }

2956

2957

2958

2959

2960 if (dirty)

2961 {

2963

2964 }

2965 else

2966 {

2968

2969

2970

2971

2972

2973

2974

2975

2977 }

2978

2980

2982}

2983

2984

2985

2986

2987

2988

2989

2990

2991

2992

2993

2994

2995

2996

2997

2998

2999

3000

3001void

3005 bool isreindex,

3006 bool parallel)

3007{

3009 Oid save_userid;

3010 int save_sec_context;

3011 int save_nestlevel;

3012

3013

3014

3015

3020

3021

3022

3023

3024

3025

3026

3032

3035 (errmsg_internal("building index \"%s\" on table \"%s\" serially",

3038 else

3040 (errmsg_internal("building index \"%s\" on table \"%s\" with request for %d parallel workers",

3044

3045

3046

3047

3048

3049

3055

3056

3057 {

3058 const int progress_index[] = {

3065 };

3066 const int64 progress_vals[] = {

3069 0, 0, 0, 0

3070 };

3071

3073 }

3074

3075

3076

3077

3078 stats = indexRelation->rd_indam->ambuild(heapRelation, indexRelation,

3079 indexInfo);

3081

3082

3083

3084

3085

3086

3087

3088

3089 if (indexRelation->rd_rel->relpersistence == RELPERSISTENCE_UNLOGGED &&

3091 {

3095 }

3096

3097

3098

3099

3100

3101

3102

3103

3104

3105

3106

3107

3108

3109

3110

3111

3112

3113

3114

3115

3116

3117

3118

3119

3120

3121

3122

3123

3124

3126 !isreindex &&

3128 {

3133

3135

3139 elog(ERROR, "cache lookup failed for index %u", indexId);

3141

3142

3143 Assert(!indexForm->indcheckxmin);

3144

3145 indexForm->indcheckxmin = true;

3147

3150 }

3151

3152

3153

3154

3156 true,

3158

3160 false,

3162

3163

3165

3166

3167

3168

3169

3170

3171

3174

3175

3177

3178

3180}

3181

3182

3183

3184

3185

3186

3187

3188

3189

3190

3191

3192

3193

3194static void

3198{

3207

3208

3209

3210

3211

3212

3215

3216

3217

3218

3219

3223

3224

3226

3227

3229

3230

3231

3232

3235 snapshot,

3236 0,

3237 NULL,

3238 true,

3239 true);

3240

3242 {

3244

3245

3246

3247

3248 if (predicate != NULL)

3249 {

3250 if (ExecQual(predicate, econtext))

3251 continue;

3252 }

3253

3254

3255

3256

3258 slot,

3259 estate,

3261 isnull);

3262

3263

3264

3265

3267 indexRelation, indexInfo,

3269 estate, true);

3270

3272 }

3273

3276

3278

3280

3281

3284}

3285

3286

3287

3288

3289

3290

3291

3292

3293

3294

3295

3296

3297

3298

3299

3300

3301

3302

3303

3304

3305

3306

3307

3308

3309

3310

3311

3312

3313

3314

3315

3316

3317

3318

3319

3320

3321

3322

3323

3324

3325

3326

3327

3328

3329

3330

3331

3332

3333

3334

3335

3336

3337

3338

3339

3340

3341

3342

3343

3344

3345

3346

3347

3348

3349void

3351{

3353 indexRelation;

3357 Oid save_userid;

3358 int save_sec_context;

3359 int save_nestlevel;

3360

3361 {

3362 const int progress_index[] = {

3368 };

3369 const int64 progress_vals[] = {

3371 0, 0, 0, 0

3372 };

3373

3375 }

3376

3377

3379

3380

3381

3382

3383

3384

3390

3392

3393

3394

3395

3396

3397

3399

3400

3402

3403

3404

3405

3406 ivinfo.index = indexRelation;

3407 ivinfo.heaprel = heapRelation;

3414

3415

3416

3417

3418

3419

3420

3426

3427

3430

3431

3432 {

3433 const int progress_index[] = {

3437 };

3438 const int64 progress_vals[] = {

3440 0, 0

3441 };

3442

3444 }

3446

3447

3448

3449

3453 indexRelation,

3454 indexInfo,

3455 snapshot,

3457

3458

3460

3461

3463

3465 "validate_index found %.0f heap tuples, %.0f index tuples; inserted %.0f missing tuples",

3467

3468

3470

3471

3473

3474

3477}

3478

3479

3480

3481

3482static bool

3484{

3487

3489 state->itups += 1;

3490 return false;

3491}

3492

3493

3494

3495

3496

3497

3498

3499

3500

3501

3502void

3504{

3508

3509

3511

3515 elog(ERROR, "cache lookup failed for index %u", indexId);

3517

3518

3520 {

3522

3523 Assert(indexForm->indislive);

3524 Assert(!indexForm->indisready);

3525 Assert(!indexForm->indisvalid);

3526 indexForm->indisready = true;

3527 break;

3529

3530 Assert(indexForm->indislive);

3531 Assert(indexForm->indisready);

3532 Assert(!indexForm->indisvalid);

3533 indexForm->indisvalid = true;

3534 break;

3536

3537

3538

3539

3540

3541

3542

3543

3544

3545

3546

3547

3548

3549

3550 indexForm->indisvalid = false;

3551 indexForm->indisclustered = false;

3552 indexForm->indisreplident = false;

3553 break;

3555

3556

3557

3558

3559

3560

3561

3562

3563 Assert(!indexForm->indisvalid);

3564 Assert(!indexForm->indisclustered);

3565 Assert(!indexForm->indisreplident);

3566 indexForm->indisready = false;

3567 indexForm->indislive = false;

3568 break;

3569 }

3570

3571

3573

3575}

3576

3577

3578

3579

3580

3581

3584{

3587 Oid result;

3588

3591 {

3592 if (missing_ok)

3594 elog(ERROR, "cache lookup failed for index %u", indexId);

3595 }

3598

3599 result = index->indrelid;

3601 return result;

3602}

3603

3604

3605

3606

3607void

3609 bool skip_constraint_checks, char persistence,

3611{

3613 heapRelation;

3614 Oid heapId;

3615 Oid save_userid;

3616 int save_sec_context;

3617 int save_nestlevel;

3619 volatile bool skipped_constraint = false;

3622 bool set_tablespace = false;

3623

3625

3626

3627

3628

3629

3632

3634 return;

3635

3638 else

3640

3641

3642 if (!heapRelation)

3643 return;

3644

3645

3646

3647

3648

3649

3655

3657 {

3658 const int progress_cols[] = {

3661 };

3662 const int64 progress_vals[] = {

3664 indexId

3665 };

3666

3668 heapId);

3670 }

3671

3672

3673

3674

3675

3678 else

3680

3681

3682 if (!iRel)

3683 {

3684

3686

3687

3689

3690

3692 return;

3693 }

3694

3697 iRel->rd_rel->relam);

3698

3699

3700

3701

3702

3704 {

3706

3711 }

3712

3713

3714

3715

3716

3717 if (iRel->rd_rel->relkind == RELKIND_PARTITIONED_INDEX)

3718 elog(ERROR, "cannot reindex partitioned index \"%s.%s\"",

3721

3722

3723

3724

3725

3728 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

3729 errmsg("cannot reindex temporary tables of other sessions")));

3730

3731

3732

3733

3734

3735

3739 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

3740 errmsg("cannot reindex invalid index on TOAST table")));

3741

3742

3743

3744

3745

3746

3747

3748

3749

3750

3751

3755 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

3756 errmsg("cannot move system relation \"%s\"",

3758

3759

3762 set_tablespace = true;

3763

3764

3765

3766

3767

3769

3770

3771 if (set_tablespace)

3772 {

3773

3775

3776

3777

3778

3781

3782

3784 }

3785

3786

3787

3788

3789

3791

3792

3794

3795

3796 if (skip_constraint_checks)

3797 {

3799 skipped_constraint = true;

3804 }

3805

3806

3808

3809

3811

3812

3813

3814 index_build(heapRelation, iRel, indexInfo, true, true);

3815

3816

3818

3819

3820

3821

3822

3823

3824

3825

3826

3827

3828

3829

3830

3831

3832

3833

3834

3835

3836

3837

3838

3839

3840

3841

3842

3843

3844

3845

3846

3847 if (!skipped_constraint)

3848 {

3852 bool index_bad;

3853

3855

3859 elog(ERROR, "cache lookup failed for index %u", indexId);

3861

3862 index_bad = (!indexForm->indisvalid ||

3863 !indexForm->indisready ||

3864 !indexForm->indislive);

3865 if (index_bad ||

3867 {

3869 indexForm->indcheckxmin = false;

3870 else if (index_bad)

3871 indexForm->indcheckxmin = true;

3872 indexForm->indisvalid = true;

3873 indexForm->indisready = true;

3874 indexForm->indislive = true;

3876

3877

3878

3879

3880

3881

3882

3883

3885 }

3886

3888 }

3889

3890

3893 (errmsg("index \"%s\" was reindexed",

3897

3898

3900

3901

3903

3904

3907

3910}

3911

3912

3913

3914

3915

3916

3917

3918

3919

3920

3921

3922

3923

3924

3925

3926

3927

3928

3929

3930

3931

3932

3933

3934

3935

3936

3937

3938

3939

3940

3941

3942

3943

3944

3945

3946

3947bool

3950{

3952 Oid toast_relid;

3953 List *indexIds;

3954 char persistence;

3955 bool result = false;

3957 int i;

3958

3959

3960

3961

3962

3963

3966 else

3968

3969

3970 if (!rel)

3971 return false;

3972

3973

3974

3975

3976

3977 if (rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)

3978 elog(ERROR, "cannot reindex partitioned table \"%s.%s\"",

3981

3982 toast_relid = rel->rd_rel->reltoastrelid;

3983

3984

3985

3986

3987

3989

3991 {

3992

3994

3995

3996

3997

3998

4000 }

4001

4002

4003

4004

4005

4006

4007

4008

4009

4010

4011

4012

4013

4014

4015

4017 {

4018

4019

4020

4021

4022

4023

4025

4029 }

4030

4031

4032

4033

4034

4036 persistence = RELPERSISTENCE_UNLOGGED;

4038 persistence = RELPERSISTENCE_PERMANENT;

4039 else

4040 persistence = rel->rd_rel->relpersistence;

4041

4042

4043 i = 1;

4044 foreach(indexId, indexIds)

4045 {

4048

4049

4050

4051

4052

4053

4056 {

4058 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),

4059 errmsg("cannot reindex invalid index \"%s.%s\" on TOAST table, skipping",

4062

4063

4064

4065

4066

4067

4070 continue;

4071 }

4072

4074 persistence, params);

4075

4077

4078

4080

4081

4083 i);

4084 i++;

4085 }

4086

4087

4088

4089

4091

4092 result |= (indexIds != NIL);

4093

4094 return result;

4095}

4096

4097

4098

4099

4100

4101

4102

4103

4104

4105

4106

4107

4108

4113

4114

4115

4116

4117

4118bool

4120{

4122}

4123

4124

4125

4126

4127

4128static bool

4130{

4132}

4133

4134

4135

4136

4137

4138

4139bool

4141{

4144}

4145

4146

4147

4148

4149

4150static void

4152{

4154

4156 elog(ERROR, "cannot reindex while reindexing");

4159

4161

4163}

4164

4165

4166

4167

4168

4169static void

4171{

4174

4175}

4176

4177

4178

4179

4180

4181

4182

4183static void

4185{

4186

4188 elog(ERROR, "cannot reindex while reindexing");

4190 elog(ERROR, "cannot modify reindex state during a parallel operation");

4193}

4194

4195

4196

4197

4198

4199static void

4201{

4203 elog(ERROR, "cannot modify reindex state during a parallel operation");

4205 indexOid);

4206}

4207

4208

4209

4210

4211

4212void

4214{

4215

4216

4217

4218

4219

4220

4222 {

4225

4226

4227

4228

4229

4230

4232

4234 }

4235}

4236

4237

4238

4239

4240

4243{

4246}

4247

4248

4249

4250

4251

4252void

4254{

4256 int c = 0;

4258

4264}

4265

4266

4267

4268

4269

4270void

4272{

4274 int c = 0;

4276

4279

4287

4288

4290}

StrategyNumber IndexAmTranslateCompareType(CompareType cmptype, Oid amoid, Oid opfamily, bool missing_ok)

IndexAmRoutine * GetIndexAmRoutineByAmId(Oid amoid, bool noerror)

#define AttrNumberGetAttrOffset(attNum)

#define InvalidAttrNumber

bool AutoVacuumingActive(void)

void pgstat_progress_start_command(ProgressCommandType cmdtype, Oid relid)

void pgstat_progress_update_param(int index, int64 val)

void pgstat_progress_update_multi_param(int nparam, const int *index, const int64 *val)

void pgstat_progress_end_command(void)

@ PROGRESS_COMMAND_CREATE_INDEX

static Datum values[MAXATTR]

void index_register(Oid heap, Oid ind, const IndexInfo *indexInfo)

#define RelationGetNumberOfBlocks(reln)

#define CStringGetTextDatum(s)

#define TextDatumGetCString(d)

TransactionId MultiXactId

#define PointerIsValid(pointer)

#define FLEXIBLE_ARRAY_MEMBER

#define MemSet(start, val, len)

#define OidIsValid(objectId)

bool IsToastNamespace(Oid namespaceId)

bool IsSystemRelation(Relation relation)

RelFileNumber GetNewRelFileNumber(Oid reltablespace, Relation pg_class, char relpersistence)

bool IsCatalogRelation(Relation relation)

void record_object_address_dependencies(const ObjectAddress *depender, ObjectAddresses *referenced, DependencyType behavior)

void recordDependencyOnSingleRelExpr(const ObjectAddress *depender, Node *expr, Oid relId, DependencyType behavior, DependencyType self_behavior, bool reverse_self)

void add_exact_object_address(const ObjectAddress *object, ObjectAddresses *addrs)

ObjectAddresses * new_object_addresses(void)

void free_object_addresses(ObjectAddresses *addrs)

@ DEPENDENCY_PARTITION_PRI

@ DEPENDENCY_PARTITION_SEC

int errmsg_internal(const char *fmt,...)

int errdetail_internal(const char *fmt,...)

int errcode(int sqlerrcode)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

bool equal(const void *a, const void *b)

void EventTriggerCollectSimpleCommand(ObjectAddress address, ObjectAddress secondaryObject, Node *parsetree)

ExprState * ExecPrepareQual(List *qual, EState *estate)

List * ExecPrepareExprList(List *nodes, EState *estate)

void check_exclusion_constraint(Relation heap, Relation index, IndexInfo *indexInfo, ItemPointer tupleid, const Datum *values, const bool *isnull, EState *estate, bool newIndex)

void ExecDropSingleTupleTableSlot(TupleTableSlot *slot)

void FreeExecutorState(EState *estate)

EState * CreateExecutorState(void)

#define GetPerTupleExprContext(estate)

static bool ExecQual(ExprState *state, ExprContext *econtext)

static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)

#define palloc0_array(type, count)

Datum Int64GetDatum(int64 X)

void systable_endscan(SysScanDesc sysscan)

void systable_inplace_update_cancel(void *state)

void systable_inplace_update_begin(Relation relation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, const ScanKeyData *key, HeapTuple *oldtupcopy, void **state)

void systable_inplace_update_finish(void *state, HeapTuple tuple)

HeapTuple systable_getnext(SysScanDesc sysscan)

SysScanDesc systable_beginscan(Relation heapRelation, Oid indexId, bool indexOK, Snapshot snapshot, int nkeys, ScanKey key)

int NewGUCNestLevel(void)

void RestrictSearchPath(void)

void AtEOXact_GUC(bool isCommit, int nestLevel)

Assert(PointerIsAligned(start, uint64))

void DeleteRelationTuple(Oid relid)

void DeleteAttributeTuples(Oid relid)

void RemoveStatistics(Oid relid, AttrNumber attnum)

void CheckAttributeType(const char *attname, Oid atttypid, Oid attcollation, List *containing_rowtypes, int flags)

void CopyStatistics(Oid fromrelid, Oid torelid)

void InsertPgClassTuple(Relation pg_class_desc, Relation new_rel_desc, Oid new_rel_oid, Datum relacl, Datum reloptions)

void InsertPgAttributeTuples(Relation pg_attribute_rel, TupleDesc tupdesc, Oid new_rel_oid, const FormExtraData_pg_attribute tupdesc_extra[], CatalogIndexState indstate)

Relation heap_create(const char *relname, Oid relnamespace, Oid reltablespace, Oid relid, RelFileNumber relfilenumber, Oid accessmtd, TupleDesc tupDesc, char relkind, char relpersistence, bool shared_relation, bool mapped_relation, bool allow_system_table_mods, TransactionId *relfrozenxid, MultiXactId *relminmxid, bool create_storage)

HeapTuple heap_modify_tuple(HeapTuple tuple, TupleDesc tupleDesc, const Datum *replValues, const bool *replIsnull, const bool *doReplace)

HeapTuple heap_copytuple(HeapTuple tuple)

HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)

bool heap_attisnull(HeapTuple tup, int attnum, TupleDesc tupleDesc)

void heap_freetuple(HeapTuple htup)

#define HeapTupleIsValid(tuple)

static void * GETSTRUCT(const HeapTupleData *tuple)

bool ReindexIsProcessingIndex(Oid indexOid)

static bool validate_index_callback(ItemPointer itemptr, void *opaque)

void validate_index(Oid heapId, Oid indexId, Snapshot snapshot)

void index_drop(Oid indexId, bool concurrent, bool concurrent_lock_mode)

void ResetReindexState(int nestLevel)

Oid IndexGetRelation(Oid indexId, bool missing_ok)

static int reindexingNestLevel

void index_concurrently_set_dead(Oid heapId, Oid indexId)

Oid index_create(Relation heapRelation, const char *indexRelationName, Oid indexRelationId, Oid parentIndexRelid, Oid parentConstraintId, RelFileNumber relFileNumber, IndexInfo *indexInfo, const List *indexColNames, Oid accessMethodId, Oid tableSpaceId, const Oid *collationIds, const Oid *opclassIds, const Datum *opclassOptions, const int16 *coloptions, const NullableDatum *stattargets, Datum reloptions, bits16 flags, bits16 constr_flags, bool allow_system_table_mods, bool is_internal, Oid *constraintId)

static Oid currentlyReindexedHeap

static void ResetReindexProcessing(void)

void index_concurrently_swap(Oid newIndexId, Oid oldIndexId, const char *oldName)

static void RemoveReindexPending(Oid indexOid)

static List * pendingReindexedIndexes

void index_set_state_flags(Oid indexId, IndexStateFlagsAction action)

bool CompareIndexInfo(const IndexInfo *info1, const IndexInfo *info2, const Oid *collations1, const Oid *collations2, const Oid *opfamilies1, const Oid *opfamilies2, const AttrMap *attmap)

RelFileNumber binary_upgrade_next_index_pg_class_relfilenumber

IndexInfo * BuildDummyIndexInfo(Relation index)

bool reindex_relation(const ReindexStmt *stmt, Oid relid, int flags, const ReindexParams *params)

void SerializeReindexState(Size maxsize, char *start_address)

static void index_update_stats(Relation rel, bool hasindex, double reltuples)

IndexInfo * BuildIndexInfo(Relation index)

static bool relationHasPrimaryKey(Relation rel)

static void SetReindexProcessing(Oid heapOid, Oid indexOid)

static void IndexCheckExclusion(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo)

static void InitializeAttributeOids(Relation indexRelation, int numatts, Oid indexoid)

Oid index_concurrently_create_copy(Relation heapRelation, Oid oldIndexId, Oid tablespaceOid, const char *newName)

Oid binary_upgrade_next_index_pg_class_oid

static void AppendAttributeTuples(Relation indexRelation, const Datum *attopts, const NullableDatum *stattargets)

void BuildSpeculativeIndexInfo(Relation index, IndexInfo *ii)

void index_check_primary_key(Relation heapRel, const IndexInfo *indexInfo, bool is_alter_table, const IndexStmt *stmt)

bool ReindexIsProcessingHeap(Oid heapOid)

static bool ReindexIsCurrentlyProcessingIndex(Oid indexOid)

void RestoreReindexState(const void *reindexstate)

static TupleDesc ConstructTupleDescriptor(Relation heapRelation, const IndexInfo *indexInfo, const List *indexColNames, Oid accessMethodId, const Oid *collationIds, const Oid *opclassIds)

void index_build(Relation heapRelation, Relation indexRelation, IndexInfo *indexInfo, bool isreindex, bool parallel)

ObjectAddress index_constraint_create(Relation heapRelation, Oid indexRelationId, Oid parentConstraintId, const IndexInfo *indexInfo, const char *constraintName, char constraintType, bits16 constr_flags, bool allow_system_table_mods, bool is_internal)

void FormIndexDatum(IndexInfo *indexInfo, TupleTableSlot *slot, EState *estate, Datum *values, bool *isnull)

static void SetReindexPending(List *indexes)

void index_concurrently_build(Oid heapRelationId, Oid indexRelationId)

static void UpdateIndexRelation(Oid indexoid, Oid heapoid, Oid parentIndexId, const IndexInfo *indexInfo, const Oid *collationOids, const Oid *opclassOids, const int16 *coloptions, bool primary, bool isexclusion, bool immediate, bool isvalid, bool isready)

static Oid currentlyReindexedIndex

Size EstimateReindexStateSpace(void)

void reindex_index(const ReindexStmt *stmt, Oid indexId, bool skip_constraint_checks, char persistence, const ReindexParams *params)

#define INDEX_CREATE_IS_PRIMARY

#define INDEX_CREATE_IF_NOT_EXISTS

#define REINDEX_REL_PROCESS_TOAST

#define INDEX_CREATE_PARTITIONED

#define REINDEXOPT_MISSING_OK

#define INDEX_CREATE_INVALID

#define INDEX_CONSTR_CREATE_WITHOUT_OVERLAPS

static int64 itemptr_encode(ItemPointer itemptr)

#define INDEX_CREATE_ADD_CONSTRAINT

#define INDEX_CREATE_SKIP_BUILD

#define INDEX_CONSTR_CREATE_UPDATE_INDEX

#define REINDEX_REL_FORCE_INDEXES_UNLOGGED

#define INDEX_CONSTR_CREATE_REMOVE_OLD_DEPS

#define INDEX_CONSTR_CREATE_DEFERRABLE

#define REINDEXOPT_REPORT_PROGRESS

#define INDEX_CONSTR_CREATE_MARK_AS_PRIMARY

#define REINDEX_REL_SUPPRESS_INDEX_USE

#define REINDEX_REL_FORCE_INDEXES_PERMANENT

#define INDEX_CONSTR_CREATE_INIT_DEFERRED

#define INDEX_CREATE_CONCURRENT

#define REINDEXOPT_VERBOSE

#define REINDEX_REL_CHECK_CONSTRAINTS

bytea * index_opclass_options(Relation indrel, AttrNumber attnum, Datum attoptions, bool validate)

IndexBulkDeleteResult * index_bulk_delete(IndexVacuumInfo *info, IndexBulkDeleteResult *istat, IndexBulkDeleteCallback callback, void *callback_state)

void index_insert_cleanup(Relation indexRelation, IndexInfo *indexInfo)

void index_close(Relation relation, LOCKMODE lockmode)

Relation try_index_open(Oid relationId, LOCKMODE lockmode)

Relation index_open(Oid relationId, LOCKMODE lockmode)

void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)

void CatalogCloseIndexes(CatalogIndexState indstate)

void CatalogTupleInsert(Relation heapRel, HeapTuple tup)

CatalogIndexState CatalogOpenIndexes(Relation heapRel)

void CatalogTupleDelete(Relation heapRel, ItemPointer tid)

int2vector * buildint2vector(const int16 *int2s, int n)

void CacheInvalidateRelcache(Relation relation)

void CacheInvalidateRelcacheByTuple(HeapTuple classTuple)

invalidindex index d is invalid

if(TABLE==NULL||TABLE_index==NULL)

List * lappend(List *list, void *datum)

List * list_delete_oid(List *list, Oid datum)

List * list_copy(const List *oldlist)

List * lappend_oid(List *list, Oid datum)

void list_free(List *list)

bool list_member_oid(const List *list, Oid datum)

void LockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)

void LockRelationOid(Oid relid, LOCKMODE lockmode)

void LockRelation(Relation relation, LOCKMODE lockmode)

void WaitForLockers(LOCKTAG heaplocktag, LOCKMODE lockmode, bool progress)

void UnlockRelationIdForSession(LockRelId *relid, LOCKMODE lockmode)

#define SET_LOCKTAG_RELATION(locktag, dboid, reloid)

#define AccessExclusiveLock

#define ShareUpdateExclusiveLock

char * get_rel_name(Oid relid)

bool get_rel_relispartition(Oid relid)

char get_rel_persistence(Oid relid)

bool get_index_isvalid(Oid index_oid)

Datum get_attoptions(Oid relid, int16 attnum)

Oid get_rel_namespace(Oid relid)

RegProcedure get_opcode(Oid opno)

Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)

bool get_collation_isdeterministic(Oid colloid)

Oid get_base_element_type(Oid typid)

char * get_namespace_name(Oid nspid)

Oid get_relname_relid(const char *relname, Oid relnamespace)

Expr * make_ands_explicit(List *andclauses)

IndexInfo * makeIndexInfo(int numattrs, int numkeyattrs, Oid amoid, List *expressions, List *predicates, bool unique, bool nulls_not_distinct, bool isready, bool concurrent, bool summarizing, bool withoutoverlaps)

List * make_ands_implicit(Expr *clause)

void MemoryContextReset(MemoryContext context)

void pfree(void *pointer)

void * palloc0(Size size)

MemoryContext TopMemoryContext

#define IsBootstrapProcessingMode()

#define SECURITY_RESTRICTED_OPERATION

#define CHECK_FOR_INTERRUPTS()

#define IsNormalProcessingMode()

void GetUserIdAndSecContext(Oid *userid, int *sec_context)

void SetUserIdAndSecContext(Oid userid, int sec_context)

#define InvalidMultiXactId

void namestrcpy(Name name, const char *str)

Oid exprType(const Node *expr)

int32 exprTypmod(const Node *expr)

#define InvokeObjectPostAlterHookArg(classId, objectId, subId, auxiliaryId, is_internal)

#define InvokeObjectPostCreateHookArg(classId, objectId, subId, is_internal)

const ObjectAddress InvalidObjectAddress

#define ObjectAddressSet(addr, class_id, object_id)

#define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id)

oidvector * buildoidvector(const Oid *oids, int n)

char * nodeToString(const void *obj)

static MemoryContext MemoryContextSwitchTo(MemoryContext context)

List * SystemFuncName(char *name)

List * get_partition_ancestors(Oid relid)

#define ATTRIBUTE_FIXED_PART_SIZE

FormData_pg_attribute * Form_pg_attribute

FormData_pg_class * Form_pg_class

Oid CreateConstraintEntry(const char *constraintName, Oid constraintNamespace, char constraintType, bool isDeferrable, bool isDeferred, bool isEnforced, bool isValidated, Oid parentConstrId, Oid relId, const int16 *constraintKey, int constraintNKeys, int constraintNTotalKeys, Oid domainId, Oid indexRelId, Oid foreignRelId, const int16 *foreignKey, const Oid *pfEqOp, const Oid *ppEqOp, const Oid *ffEqOp, int foreignNKeys, char foreignUpdateType, char foreignDeleteType, const int16 *fkDeleteSetCols, int numFkDeleteSetCols, char foreignMatchType, const Oid *exclOp, Node *conExpr, const char *conBin, bool conIsLocal, int16 conInhCount, bool conNoInherit, bool conPeriod, bool is_internal)

bool ConstraintNameIsUsed(ConstraintCategory conCat, Oid objId, const char *conname)

FormData_pg_constraint * Form_pg_constraint

void recordDependencyOn(const ObjectAddress *depender, const ObjectAddress *referenced, DependencyType behavior)

long deleteDependencyRecordsForClass(Oid classId, Oid objectId, Oid refclassId, char deptype)

long changeDependenciesOf(Oid classId, Oid oldObjectId, Oid newObjectId)

List * get_index_ref_constraints(Oid indexId)

long changeDependenciesOn(Oid refClassId, Oid oldRefObjectId, Oid newRefObjectId)

Oid get_index_constraint(Oid indexId)

FormData_pg_index * Form_pg_index

bool DeleteInheritsTuple(Oid inhrelid, Oid inhparent, bool expect_detach_pending, const char *childname)

void StoreSingleInheritance(Oid relationId, Oid parentOid, int32 seqNumber)

static int list_length(const List *l)

static ListCell * list_head(const List *l)

static ListCell * lnext(const List *l, const ListCell *c)

FormData_pg_opclass * Form_pg_opclass

const char * pg_rusage_show(const PGRUsage *ru0)

void pg_rusage_init(PGRUsage *ru0)

FormData_pg_trigger * Form_pg_trigger

FormData_pg_type * Form_pg_type

void pgstat_copy_relation_stats(Relation dst, Relation src)

void pgstat_drop_relation(Relation rel)

int plan_create_index_workers(Oid tableOid, Oid indexOid)

static Datum PointerGetDatum(const void *X)

static Datum Int16GetDatum(int16 X)

static Datum BoolGetDatum(bool X)

static Datum ObjectIdGetDatum(Oid X)

static Pointer DatumGetPointer(Datum X)

static Datum Int32GetDatum(int32 X)

void TransferPredicateLocksToHeapRelation(Relation relation)

#define PROGRESS_CREATEIDX_PHASE_BUILD

#define PROGRESS_CREATEIDX_PHASE_VALIDATE_TABLESCAN

#define PROGRESS_CREATEIDX_ACCESS_METHOD_OID

#define PROGRESS_CREATEIDX_TUPLES_TOTAL

#define PROGRESS_CREATEIDX_PHASE_VALIDATE_SORT

#define PROGRESS_SCAN_BLOCKS_DONE

#define PROGRESS_CREATEIDX_TUPLES_DONE

#define PROGRESS_CREATEIDX_SUBPHASE

#define PROGRESS_CREATEIDX_SUBPHASE_INITIALIZE

#define PROGRESS_CREATEIDX_PHASE

#define PROGRESS_CREATEIDX_COMMAND_REINDEX

#define PROGRESS_CLUSTER_INDEX_REBUILD_COUNT

#define PROGRESS_CREATEIDX_PHASE_VALIDATE_IDXSCAN

#define PROGRESS_SCAN_BLOCKS_TOTAL

#define PROGRESS_CREATEIDX_INDEX_OID

#define PROGRESS_CREATEIDX_COMMAND

void * stringToNode(const char *str)

#define RelationGetForm(relation)

#define RelationGetRelid(relation)

static SMgrRelation RelationGetSmgr(Relation rel)

#define RelationGetDescr(relation)

#define RelationIsMapped(relation)

#define RelationGetRelationName(relation)

#define RELATION_IS_OTHER_TEMP(relation)

#define RelationIsValid(relation)

#define RelationGetNamespace(relation)

#define IndexRelationGetNumberOfKeyAttributes(relation)

List * RelationGetIndexList(Relation relation)

List * RelationGetDummyIndexExpressions(Relation relation)

void RelationInitIndexAccessInfo(Relation relation)

List * RelationGetIndexPredicate(Relation relation)

void RelationSetNewRelfilenumber(Relation relation, char persistence)

void RelationForgetRelation(Oid rid)

List * RelationGetIndexExpressions(Relation relation)

void RelationAssumeNewRelfilelocator(Relation relation)

void RelationGetExclusionInfo(Relation indexRelation, Oid **operators, Oid **procs, uint16 **strategies)

#define InvalidRelFileNumber

#define RelFileNumberIsValid(relnumber)

Node * map_variable_attnos(Node *node, int target_varno, int sublevels_up, const AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)

void ScanKeyInit(ScanKey entry, AttrNumber attributeNumber, StrategyNumber strategy, RegProcedure procedure, Datum argument)

Size mul_size(Size s1, Size s2)

void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)

bool smgrexists(SMgrRelation reln, ForkNumber forknum)

Snapshot GetTransactionSnapshot(void)

Snapshot GetLatestSnapshot(void)

void UnregisterSnapshot(Snapshot snapshot)

void PushActiveSnapshot(Snapshot snapshot)

bool ActiveSnapshotSet(void)

Snapshot RegisterSnapshot(Snapshot snapshot)

void PopActiveSnapshot(void)

void relation_close(Relation relation, LOCKMODE lockmode)

Relation relation_open(Oid relationId, LOCKMODE lockmode)

void log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum)

void RelationDropStorage(Relation rel)

#define BTEqualStrategyNumber

#define ERRCODE_DUPLICATE_OBJECT

MemoryContext ecxt_per_tuple_memory

TupleTableSlot * ecxt_scantuple

ambuildempty_function ambuildempty

uint16 * ii_ExclusionStrats

ExprState * ii_PredicateState

List * ii_ExpressionsState

AttrNumber ii_IndexAttrNumbers[INDEX_MAX_KEYS]

BufferAccessStrategy strategy

struct IndexAmRoutine * rd_indam

MemoryContext rd_indexcxt

RelFileLocator rd_locator

Oid currentlyReindexedHeap

Oid currentlyReindexedIndex

int numPendingReindexedIndexes

Oid pendingReindexedIndexes[FLEXIBLE_ARRAY_MEMBER]

int16 values[FLEXIBLE_ARRAY_MEMBER]

Oid values[FLEXIBLE_ARRAY_MEMBER]

void ReleaseSysCache(HeapTuple tuple)

HeapTuple SearchSysCache1(int cacheId, Datum key1)

Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)

HeapTuple SearchSysCache2(int cacheId, Datum key1, Datum key2)

Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)

#define SearchSysCacheCopy1(cacheId, key1)

Relation try_table_open(Oid relationId, LOCKMODE lockmode)

void table_close(Relation relation, LOCKMODE lockmode)

Relation table_open(Oid relationId, LOCKMODE lockmode)

TupleTableSlot * table_slot_create(Relation relation, List **reglist)

static void table_endscan(TableScanDesc scan)

static void table_index_validate_scan(Relation table_rel, Relation index_rel, struct IndexInfo *index_info, Snapshot snapshot, struct ValidateIndexState *state)

static TableScanDesc table_beginscan_strat(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key, bool allow_strat, bool allow_sync)

static bool table_scan_getnextslot(TableScanDesc sscan, ScanDirection direction, TupleTableSlot *slot)

void CheckTableNotInUse(Relation rel, const char *stmt)

bool CheckRelationTableSpaceMove(Relation rel, Oid newTableSpaceId)

void SetRelationHasSubclass(Oid relationId, bool relhassubclass)

void SetRelationTableSpace(Relation rel, Oid newTableSpaceId, RelFileNumber newRelFilenumber)

#define InvalidCompressionMethod

#define InvalidTransactionId

ObjectAddress CreateTrigger(CreateTrigStmt *stmt, const char *queryString, Oid relOid, Oid refRelOid, Oid constraintOid, Oid indexOid, Oid funcoid, Oid parentTriggerOid, Node *whenClause, bool isInternal, bool in_partition)

TupleDesc CreateTemplateTupleDesc(int natts)

void populate_compact_attribute(TupleDesc tupdesc, int attnum)

static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)

void tuplesort_performsort(Tuplesortstate *state)

void tuplesort_end(Tuplesortstate *state)

void tuplesort_putdatum(Tuplesortstate *state, Datum val, bool isNull)

Tuplesortstate * tuplesort_begin_datum(Oid datumType, Oid sortOperator, Oid sortCollation, bool nullsFirstFlag, int workMem, SortCoordinate coordinate, int sortopt)

static Datum slot_getsysattr(TupleTableSlot *slot, int attnum, bool *isnull)

static Datum slot_getattr(TupleTableSlot *slot, int attnum, bool *isnull)

void visibilitymap_count(Relation rel, BlockNumber *all_visible, BlockNumber *all_frozen)

int GetCurrentTransactionNestLevel(void)

void CommandCounterIncrement(void)

TransactionId GetTopTransactionIdIfAny(void)

void StartTransactionCommand(void)

bool IsInParallelMode(void)

void CommitTransactionCommand(void)