Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Provide feedback

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

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit26a6d6c

Browse files
committed
resolve conflicts
2 parents135064f +f5dc278 commit26a6d6c

File tree

7 files changed

+147
-62
lines changed

7 files changed

+147
-62
lines changed

‎expected/pathman_calamity.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ SELECT context, entries FROM pathman_cache_stats ORDER BY context;/* OK */
867867
maintenance | 0
868868
partition bounds cache | 0
869869
partition dispatch cache | 1
870-
partition parents cache |10
870+
partition parents cache | 0
871871
(4 rows)
872872

873873
SELECT drop_partitions('calamity.test_pathman_cache_stats');
@@ -910,9 +910,9 @@ SELECT context, entries FROM pathman_cache_stats ORDER BY context;/* OK */
910910
context | entries
911911
--------------------------+---------
912912
maintenance | 0
913-
partition bounds cache |10
913+
partition bounds cache | 0
914914
partition dispatch cache | 1
915-
partition parents cache |10
915+
partition parents cache | 0
916916
(4 rows)
917917

918918
SELECT drop_partitions('calamity.test_pathman_cache_stats');

‎src/compat/pg_compat.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ oid_cmp(const void *p1, const void *p2)
281281

282282
if (v1<v2)
283283
return-1;
284+
284285
if (v1>v2)
285286
return1;
287+
286288
return0;
287289
}
288290
#endif

‎src/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ pathman_relcache_hook(Datum arg, Oid relid)
725725

726726
/* Which means that 'relid' might be parent */
727727
if (relid!=InvalidOid)
728-
delay_invalidation_parent_rel(relid);
728+
delay_invalidation_vague_rel(relid);
729729
#ifdefNOT_USED
730730
elog(DEBUG2,"Invalidation message for relation %u [%u]",
731731
relid,MyProcPid);

‎src/include/init.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ bool read_pathman_params(Oid relid,
225225
Datum*values,
226226
bool*isnull);
227227

228+
Oid*read_parent_oids(int*nelems);
229+
228230

229231
boolvalidate_range_constraint(constExpr*expr,
230232
constPartRelationInfo*prel,

‎src/init.c

Lines changed: 90 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ static bool init_pathman_relation_oids(void);
7070
staticvoidfini_pathman_relation_oids(void);
7171
staticvoidinit_local_cache(void);
7272
staticvoidfini_local_cache(void);
73-
staticvoidread_pathman_config(void);
73+
74+
/* Special handlers for read_pathman_config() */
75+
staticvoidadd_partrel_to_array(Datum*values,bool*isnull,void*context);
76+
staticvoidstartup_invalidate_parent(Datum*values,bool*isnull,void*context);
77+
78+
staticvoidread_pathman_config(void (*per_row_cb)(Datum*values,
79+
bool*isnull,
80+
void*context),
81+
void*context);
7482

7583
staticboolvalidate_range_opexpr(constExpr*expr,
7684
constPartRelationInfo*prel,
@@ -200,8 +208,11 @@ load_config(void)
200208
/* Validate pg_pathman's Pl/PgSQL facade (might be outdated) */
201209
validate_sql_facade_version(get_sql_facade_version());
202210

203-
init_local_cache();/* create various hash tables (caches) */
204-
read_pathman_config();/* read PATHMAN_CONFIG table & fill cache */
211+
/* Create various hash tables (caches) */
212+
init_local_cache();
213+
214+
/* Read PATHMAN_CONFIG table & fill cache */
215+
read_pathman_config(startup_invalidate_parent,NULL);
205216

206217
/* Register pathman_relcache_hook(), currently we can't unregister it */
207218
if (relcache_callback_needed)
@@ -777,11 +788,83 @@ read_pathman_params(Oid relid, Datum *values, bool *isnull)
777788
}
778789

779790

791+
typedefstruct
792+
{
793+
Oid*array;
794+
intnelems;
795+
intcapacity;
796+
}read_parent_oids_cxt;
797+
798+
/*
799+
* Get a sorted array of partitioned tables' Oids.
800+
*/
801+
Oid*
802+
read_parent_oids(int*nelems)
803+
{
804+
read_parent_oids_cxtcontext= {NULL,0,0 };
805+
806+
read_pathman_config(add_partrel_to_array,&context);
807+
808+
/* Perform sorting */
809+
qsort(context.array,context.nelems,sizeof(Oid),oid_cmp);
810+
811+
/* Return values */
812+
*nelems=context.nelems;
813+
returncontext.array;
814+
}
815+
816+
817+
/* read_pathman_config(): add parent to array of Oids */
818+
staticvoid
819+
add_partrel_to_array(Datum*values,bool*isnull,void*context)
820+
{
821+
Oidrelid=DatumGetObjectId(values[Anum_pathman_config_partrel-1]);
822+
read_parent_oids_cxt*result= (read_parent_oids_cxt*)context;
823+
824+
if (result->array==NULL)
825+
{
826+
result->capacity=PART_RELS_SIZE;
827+
result->array=palloc(result->capacity*sizeof(Oid));
828+
}
829+
830+
if (result->nelems >=result->capacity)
831+
{
832+
result->capacity=result->capacity*2+1;
833+
result->array=repalloc(result->array,result->capacity*sizeof(Oid));
834+
}
835+
836+
/* Append current relid */
837+
result->array[result->nelems++]=relid;
838+
}
839+
840+
/* read_pathman_config(): create dummy cache entry for parent */
841+
staticvoid
842+
startup_invalidate_parent(Datum*values,bool*isnull,void*context)
843+
{
844+
Oidrelid=DatumGetObjectId(values[Anum_pathman_config_partrel-1]);
845+
846+
/* Check that relation 'relid' exists */
847+
if (!SearchSysCacheExists1(RELOID,ObjectIdGetDatum(relid)))
848+
{
849+
DisablePathman();/* disable pg_pathman since config is broken */
850+
ereport(ERROR,
851+
(errmsg("table \"%s\" contains nonexistent relation %u",
852+
PATHMAN_CONFIG,relid),
853+
errhint(INIT_ERROR_HINT)));
854+
}
855+
856+
/* get_pathman_relation_info() will refresh this entry */
857+
invalidate_pathman_relation_info(relid,NULL);
858+
}
859+
780860
/*
781861
* Go through the PATHMAN_CONFIG table and create PartRelationInfo entries.
782862
*/
783863
staticvoid
784-
read_pathman_config(void)
864+
read_pathman_config(void (*per_row_cb)(Datum*values,
865+
bool*isnull,
866+
void*context),
867+
void*context)
785868
{
786869
Relationrel;
787870
HeapScanDescscan;
@@ -807,7 +890,6 @@ read_pathman_config(void)
807890
{
808891
Datumvalues[Natts_pathman_config];
809892
boolisnull[Natts_pathman_config];
810-
Oidrelid;/* partitioned table */
811893

812894
/* Extract Datums from tuple 'htup' */
813895
heap_deform_tuple(htup,RelationGetDescr(rel),values,isnull);
@@ -817,21 +899,8 @@ read_pathman_config(void)
817899
Assert(!isnull[Anum_pathman_config_parttype-1]);
818900
Assert(!isnull[Anum_pathman_config_expr-1]);
819901

820-
/* Extract values from Datums */
821-
relid=DatumGetObjectId(values[Anum_pathman_config_partrel-1]);
822-
823-
/* Check that relation 'relid' exists */
824-
if (!SearchSysCacheExists1(RELOID,ObjectIdGetDatum(relid)))
825-
{
826-
DisablePathman();/* disable pg_pathman since config is broken */
827-
ereport(ERROR,
828-
(errmsg("table \"%s\" contains nonexistent relation %u",
829-
PATHMAN_CONFIG,relid),
830-
errhint(INIT_ERROR_HINT)));
831-
}
832-
833-
/* get_pathman_relation_info() will refresh this entry */
834-
invalidate_pathman_relation_info(relid,NULL);
902+
/* Execute per row callback */
903+
per_row_cb(values,isnull,context);
835904
}
836905

837906
/* Clean resources */
@@ -1123,6 +1192,7 @@ validate_hash_constraint(const Expr *expr,
11231192
return false;
11241193
}
11251194

1195+
11261196
/* Parse cstring and build uint32 representing the version */
11271197
staticuint32
11281198
build_sql_facade_version(char*version_cstr)

‎src/relation_info.c

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ static booldelayed_shutdown = false; /* pathman was dropped */
8888
list = NIL; \
8989
} while (0)
9090

91+
/* Handy wrappers for Oids */
92+
#definebsearch_oid(key,array,array_size) \
93+
bsearch((const void *) &(key), (array), (array_size), sizeof(Oid), oid_cmp)
9194

92-
staticbooltry_perform_parent_refresh(Oidparent);
95+
96+
staticbooltry_invalidate_parent(Oidrelid,Oid*parents,intparents_count);
9397
staticOidtry_syscache_parent_search(Oidpartition,PartParentSearch*status);
9498
staticOidget_parent_of_partition_internal(Oidpartition,
9599
PartParentSearch*status,
@@ -862,6 +866,9 @@ finish_delayed_invalidation(void)
862866
/* Check that current state is transactional */
863867
if (IsTransactionState())
864868
{
869+
Oid*parents=NULL;
870+
intparents_count;
871+
boolparents_fetched= false;
865872
ListCell*lc;
866873

867874
/* Handle the probable 'DROP EXTENSION' case */
@@ -901,11 +908,19 @@ finish_delayed_invalidation(void)
901908
if (IsToastNamespace(get_rel_namespace(parent)))
902909
continue;
903910

904-
if (!pathman_config_contains_relation(parent,NULL,NULL,NULL,NULL))
905-
remove_pathman_relation_info(parent);
906-
else
911+
/* Fetch all partitioned tables */
912+
if (!parents_fetched)
913+
{
914+
parents=read_parent_oids(&parents_count);
915+
parents_fetched= true;
916+
}
917+
918+
/* Check if parent still exists */
919+
if (bsearch_oid(parent,parents,parents_count))
907920
/* get_pathman_relation_info() will refresh this entry */
908921
invalidate_pathman_relation_info(parent,NULL);
922+
else
923+
remove_pathman_relation_info(parent);
909924
}
910925

911926
/* Process all other vague cases */
@@ -917,8 +932,15 @@ finish_delayed_invalidation(void)
917932
if (IsToastNamespace(get_rel_namespace(vague_rel)))
918933
continue;
919934

935+
/* Fetch all partitioned tables */
936+
if (!parents_fetched)
937+
{
938+
parents=read_parent_oids(&parents_count);
939+
parents_fetched= true;
940+
}
941+
920942
/* It might be a partitioned table or a partition */
921-
if (!try_perform_parent_refresh(vague_rel))
943+
if (!try_invalidate_parent(vague_rel,parents,parents_count))
922944
{
923945
PartParentSearchsearch;
924946
Oidparent;
@@ -928,21 +950,17 @@ finish_delayed_invalidation(void)
928950

929951
switch (search)
930952
{
931-
/* It's still parent */
953+
/*
954+
* Two main cases:
955+
*- It's *still* parent (in PATHMAN_CONFIG)
956+
*- It *might have been* parent before (not in PATHMAN_CONFIG)
957+
*/
932958
casePPS_ENTRY_PART_PARENT:
933-
{
934-
/* Skip if we've already refreshed this parent */
935-
if (!list_member_oid(fresh_rels,parent))
936-
try_perform_parent_refresh(parent);
937-
}
938-
break;
939-
940-
/* It *might have been* parent before (not in PATHMAN_CONFIG) */
941959
casePPS_ENTRY_PARENT:
942960
{
943961
/* Skip if we've already refreshed this parent */
944962
if (!list_member_oid(fresh_rels,parent))
945-
try_perform_parent_refresh(parent);
963+
try_invalidate_parent(parent,parents,parents_count);
946964
}
947965
break;
948966

@@ -959,6 +977,9 @@ finish_delayed_invalidation(void)
959977

960978
free_invalidation_list(delayed_invalidation_parent_rels);
961979
free_invalidation_list(delayed_invalidation_vague_rels);
980+
981+
if (parents)
982+
pfree(parents);
962983
}
963984
}
964985

@@ -1118,34 +1139,25 @@ try_syscache_parent_search(Oid partition, PartParentSearch *status)
11181139
}
11191140
}
11201141

1121-
/*
1122-
* Try to refresh cache entry for relation 'parent'.
1123-
*
1124-
* Return true on success.
1125-
*/
1142+
/* Try to invalidate cache entry for relation 'parent' */
11261143
staticbool
1127-
try_perform_parent_refresh(Oidparent)
1144+
try_invalidate_parent(Oidrelid,Oid*parents,intparents_count)
11281145
{
1129-
ItemPointerDataiptr;
1130-
Datumvalues[Natts_pathman_config];
1131-
boolisnull[Natts_pathman_config];
1132-
1133-
if (pathman_config_contains_relation(parent,values,isnull,NULL,&iptr))
1146+
/* Check if this is a partitioned table */
1147+
if (bsearch_oid(relid,parents,parents_count))
11341148
{
1135-
boolshould_update_expr=isnull[Anum_pathman_config_cooked_expr-1];
1136-
1137-
if (should_update_expr)
1138-
pathman_config_refresh_parsed_expression(parent,values,isnull,&iptr);
1149+
/* get_pathman_relation_info() will refresh this entry */
1150+
invalidate_pathman_relation_info(relid,NULL);
11391151

1140-
/* If anything went wrong, return false (actually, it might emit ERROR) */
1141-
refresh_pathman_relation_info(parent,
1142-
values,
1143-
true);/* allow lazy */
1152+
/* Success */
1153+
return true;
11441154
}
1145-
/* Not a partitioned relation */
1146-
elsereturn false;
11471155

1148-
return true;
1156+
/* Clear remaining cache entry */
1157+
remove_pathman_relation_info(relid);
1158+
1159+
/* Not a partitioned relation */
1160+
return false;
11491161
}
11501162

11511163

‎src/utils.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ list_reverse(List *l)
183183
}
184184

185185

186-
187186
/*
188187
* Get relation owner.
189188
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp