Skip to content

Commit d056e02

Browse files
author
Maksim Milyutin
committed
Add prototype of CatalogInsertIndex routine and stub of CatalogUpdateIndex into pg_pathman
1 parent 9fff484 commit d056e02

File tree

5 files changed

+112
-177
lines changed

5 files changed

+112
-177
lines changed

src/compat/pg_compat.c

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,98 @@
3434
*/
3535

3636

37+
/*
38+
* CatalogIndexInsert is the copy of static prototype having the same name from
39+
* src/backend/catalog/indexing.c
40+
*
41+
* CatalogUpdateIndexes
42+
*/
43+
#if PG_VERSION_NUM >= 100000
44+
#include "catalog/index.h"
45+
void
46+
CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
47+
{
48+
int i;
49+
int numIndexes;
50+
RelationPtr relationDescs;
51+
Relation heapRelation;
52+
TupleTableSlot *slot;
53+
IndexInfo **indexInfoArray;
54+
Datum values[INDEX_MAX_KEYS];
55+
bool isnull[INDEX_MAX_KEYS];
56+
57+
/* HOT update does not require index inserts */
58+
if (HeapTupleIsHeapOnly(heapTuple))
59+
return;
60+
61+
/*
62+
* Get information from the state structure. Fall out if nothing to do.
63+
*/
64+
numIndexes = indstate->ri_NumIndices;
65+
if (numIndexes == 0)
66+
return;
67+
relationDescs = indstate->ri_IndexRelationDescs;
68+
indexInfoArray = indstate->ri_IndexRelationInfo;
69+
heapRelation = indstate->ri_RelationDesc;
70+
71+
/* Need a slot to hold the tuple being examined */
72+
slot = MakeSingleTupleTableSlot(RelationGetDescr(heapRelation));
73+
ExecStoreTuple(heapTuple, slot, InvalidBuffer, false);
74+
75+
/*
76+
* for each index, form and insert the index tuple
77+
*/
78+
for (i = 0; i < numIndexes; i++)
79+
{
80+
IndexInfo *indexInfo;
81+
82+
indexInfo = indexInfoArray[i];
83+
84+
/* If the index is marked as read-only, ignore it */
85+
if (!indexInfo->ii_ReadyForInserts)
86+
continue;
87+
88+
/*
89+
* Expressional and partial indexes on system catalogs are not
90+
* supported, nor exclusion constraints, nor deferred uniqueness
91+
*/
92+
Assert(indexInfo->ii_Expressions == NIL);
93+
Assert(indexInfo->ii_Predicate == NIL);
94+
Assert(indexInfo->ii_ExclusionOps == NULL);
95+
Assert(relationDescs[i]->rd_index->indimmediate);
96+
97+
/*
98+
* FormIndexDatum fills in its values and isnull parameters with the
99+
* appropriate values for the column(s) of the index.
100+
*/
101+
FormIndexDatum(indexInfo,
102+
slot,
103+
NULL, /* no expression eval to do */
104+
values,
105+
isnull);
106+
107+
/*
108+
* The index AM does the rest.
109+
*/
110+
index_insert(relationDescs[i], /* index relation */
111+
values, /* array of index Datums */
112+
isnull, /* is-null flags */
113+
&(heapTuple->t_self), /* tid of heap tuple */
114+
heapRelation,
115+
relationDescs[i]->rd_index->indisunique ?
116+
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
117+
indexInfo);
118+
}
119+
120+
ExecDropSingleTupleTableSlot(slot);
121+
}
122+
void
123+
CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple)
124+
{
125+
}
126+
#endif
127+
128+
37129
/*
38130
* create_plain_partial_paths
39131
* Build partial access paths for parallel scan of a plain relation

src/include/compat/pg_compat.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
#ifndef PG_COMPAT_H
1212
#define PG_COMPAT_H
1313

14+
/* Check PostgreSQL version (9.5.4 contains an important fix for BGW) */
15+
#include "pg_config.h"
16+
#if PG_VERSION_NUM < 90503
17+
#error "Cannot build pg_pathman with PostgreSQL version lower than 9.5.3"
18+
#elif PG_VERSION_NUM < 90504
19+
#warning "It is STRONGLY recommended to use pg_pathman with PostgreSQL 9.5.4 since it contains important fixes"
20+
#endif
21+
1422
#include "compat/debug_compat_features.h"
1523

1624
#include "postgres.h"
@@ -60,6 +68,17 @@
6068
#endif
6169

6270

71+
/*
72+
* CatalogIndexInsert
73+
* CatalogUpdateIndexes
74+
*/
75+
#if PG_VERSION_NUM >= 100000
76+
#include "catalog/indexing.h"
77+
void CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple);
78+
void CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple);
79+
#endif
80+
81+
6382
/*
6483
* check_index_predicates()
6584
*/

src/include/pathman.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323
#include "parser/parsetree.h"
2424

2525

26-
/* Check PostgreSQL version (9.5.4 contains an important fix for BGW) */
27-
#if PG_VERSION_NUM < 90503
28-
#error "Cannot build pg_pathman with PostgreSQL version lower than 9.5.3"
29-
#elif PG_VERSION_NUM < 90504
30-
#warning "It is STRONGLY recommended to use pg_pathman with PostgreSQL 9.5.4 since it contains important fixes"
31-
#endif
32-
3326
/* Get CString representation of Datum (simple wrapper) */
3427
#ifdef USE_ASSERT_CHECKING
3528
#include "utils.h"

src/partition_creation.c

Lines changed: 1 addition & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "partition_filter.h"
1414
#include "pathman.h"
1515
#include "pathman_workers.h"
16+
#include "compat/pg_compat.h"
1617
#include "xact_handling.h"
1718

1819
#include "access/htup_details.h"
@@ -891,96 +892,6 @@ create_table_using_stmt(CreateStmt *create_stmt, Oid relowner)
891892
return table_addr;
892893
}
893894

894-
#if PG_VERSION_NUM >= 100000
895-
#include "catalog/index.h"
896-
static void
897-
CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
898-
{
899-
int i;
900-
int numIndexes;
901-
RelationPtr relationDescs;
902-
Relation heapRelation;
903-
TupleTableSlot *slot;
904-
IndexInfo **indexInfoArray;
905-
Datum values[INDEX_MAX_KEYS];
906-
bool isnull[INDEX_MAX_KEYS];
907-
908-
/* HOT update does not require index inserts */
909-
if (HeapTupleIsHeapOnly(heapTuple))
910-
return;
911-
912-
/*
913-
* Get information from the state structure. Fall out if nothing to do.
914-
*/
915-
numIndexes = indstate->ri_NumIndices;
916-
if (numIndexes == 0)
917-
return;
918-
relationDescs = indstate->ri_IndexRelationDescs;
919-
indexInfoArray = indstate->ri_IndexRelationInfo;
920-
heapRelation = indstate->ri_RelationDesc;
921-
922-
/* Need a slot to hold the tuple being examined */
923-
slot = MakeSingleTupleTableSlot(RelationGetDescr(heapRelation));
924-
ExecStoreTuple(heapTuple, slot, InvalidBuffer, false);
925-
926-
/*
927-
* for each index, form and insert the index tuple
928-
*/
929-
for (i = 0; i < numIndexes; i++)
930-
{
931-
IndexInfo *indexInfo;
932-
933-
indexInfo = indexInfoArray[i];
934-
935-
/* If the index is marked as read-only, ignore it */
936-
if (!indexInfo->ii_ReadyForInserts)
937-
continue;
938-
939-
/*
940-
* Expressional and partial indexes on system catalogs are not
941-
* supported, nor exclusion constraints, nor deferred uniqueness
942-
*/
943-
Assert(indexInfo->ii_Expressions == NIL);
944-
Assert(indexInfo->ii_Predicate == NIL);
945-
Assert(indexInfo->ii_ExclusionOps == NULL);
946-
Assert(relationDescs[i]->rd_index->indimmediate);
947-
948-
/*
949-
* FormIndexDatum fills in its values and isnull parameters with the
950-
* appropriate values for the column(s) of the index.
951-
*/
952-
FormIndexDatum(indexInfo,
953-
slot,
954-
NULL, /* no expression eval to do */
955-
values,
956-
isnull);
957-
958-
/*
959-
* The index AM does the rest.
960-
*/
961-
index_insert(relationDescs[i], /* index relation */
962-
values, /* array of index Datums */
963-
isnull, /* is-null flags */
964-
&(heapTuple->t_self), /* tid of heap tuple */
965-
heapRelation,
966-
relationDescs[i]->rd_index->indisunique ?
967-
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
968-
indexInfo);
969-
}
970-
971-
ExecDropSingleTupleTableSlot(slot);
972-
}
973-
static void
974-
CatalogUpdateIndexes(Relation heapRel, HeapTuple heapTuple)
975-
{
976-
CatalogIndexState indstate;
977-
978-
indstate = CatalogOpenIndexes(heapRel);
979-
CatalogIndexInsert(indstate, heapTuple);
980-
CatalogCloseIndexes(indstate);
981-
}
982-
#endif
983-
984895
/* Copy ACL privileges of parent table and set "attislocal" = true */
985896
static void
986897
postprocess_child_table_and_atts(Oid parent_relid, Oid partition_relid)

src/pl_funcs.c

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -794,86 +794,6 @@ build_check_constraint_name_attname(PG_FUNCTION_ARGS)
794794
* ------------------------
795795
*/
796796

797-
#if PG_VERSION_NUM >= 100000
798-
#include "catalog/index.h"
799-
static void
800-
CatalogIndexInsert(CatalogIndexState indstate, HeapTuple heapTuple)
801-
{
802-
int i;
803-
int numIndexes;
804-
RelationPtr relationDescs;
805-
Relation heapRelation;
806-
TupleTableSlot *slot;
807-
IndexInfo **indexInfoArray;
808-
Datum values[INDEX_MAX_KEYS];
809-
bool isnull[INDEX_MAX_KEYS];
810-
811-
/* HOT update does not require index inserts */
812-
if (HeapTupleIsHeapOnly(heapTuple))
813-
return;
814-
815-
/*
816-
* Get information from the state structure. Fall out if nothing to do.
817-
*/
818-
numIndexes = indstate->ri_NumIndices;
819-
if (numIndexes == 0)
820-
return;
821-
relationDescs = indstate->ri_IndexRelationDescs;
822-
indexInfoArray = indstate->ri_IndexRelationInfo;
823-
heapRelation = indstate->ri_RelationDesc;
824-
825-
/* Need a slot to hold the tuple being examined */
826-
slot = MakeSingleTupleTableSlot(RelationGetDescr(heapRelation));
827-
ExecStoreTuple(heapTuple, slot, InvalidBuffer, false);
828-
829-
/*
830-
* for each index, form and insert the index tuple
831-
*/
832-
for (i = 0; i < numIndexes; i++)
833-
{
834-
IndexInfo *indexInfo;
835-
836-
indexInfo = indexInfoArray[i];
837-
838-
/* If the index is marked as read-only, ignore it */
839-
if (!indexInfo->ii_ReadyForInserts)
840-
continue;
841-
842-
/*
843-
* Expressional and partial indexes on system catalogs are not
844-
* supported, nor exclusion constraints, nor deferred uniqueness
845-
*/
846-
Assert(indexInfo->ii_Expressions == NIL);
847-
Assert(indexInfo->ii_Predicate == NIL);
848-
Assert(indexInfo->ii_ExclusionOps == NULL);
849-
Assert(relationDescs[i]->rd_index->indimmediate);
850-
851-
/*
852-
* FormIndexDatum fills in its values and isnull parameters with the
853-
* appropriate values for the column(s) of the index.
854-
*/
855-
FormIndexDatum(indexInfo,
856-
slot,
857-
NULL, /* no expression eval to do */
858-
values,
859-
isnull);
860-
861-
/*
862-
* The index AM does the rest.
863-
*/
864-
index_insert(relationDescs[i], /* index relation */
865-
values, /* array of index Datums */
866-
isnull, /* is-null flags */
867-
&(heapTuple->t_self), /* tid of heap tuple */
868-
heapRelation,
869-
relationDescs[i]->rd_index->indisunique ?
870-
UNIQUE_CHECK_YES : UNIQUE_CHECK_NO,
871-
indexInfo);
872-
}
873-
874-
ExecDropSingleTupleTableSlot(slot);
875-
}
876-
#endif
877797

878798
/*
879799
* Try to add previously partitioned table to PATHMAN_CONFIG.

0 commit comments

Comments
 (0)