Skip to content

Commit 10021fa

Browse files
committed
reset per_table_parenthood_mapping completely in case of error
1 parent 989092c commit 10021fa

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
472472
ExecuteForPlanTree(result, add_partition_filters);
473473

474474
/* Decrement parenthood_statuses refcount */
475-
decr_refcount_parenthood_statuses();
475+
decr_refcount_parenthood_statuses(false);
476476

477477
/* HACK: restore queryId set by pg_stat_statements */
478478
result->queryId = query_id;

src/planner_tree_modification.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ assign_rel_parenthood_status(uint32 query_id,
538538
/* Saved status conflicts with 'new_status' */
539539
if (status_entry->parenthood_status != new_status)
540540
{
541-
/* Don't forget to clear all lists! */
542-
decr_refcount_parenthood_statuses();
541+
/* Don't forget to clear ALL tracked statuses! */
542+
decr_refcount_parenthood_statuses(true);
543543

544544
elog(ERROR, "It is prohibited to apply ONLY modifier to partitioned "
545545
"tables which have already been mentioned without ONLY");
@@ -592,10 +592,15 @@ incr_refcount_parenthood_statuses(void)
592592

593593
/* Reset all cached statuses if needed (query end) */
594594
void
595-
decr_refcount_parenthood_statuses(void)
595+
decr_refcount_parenthood_statuses(bool entirely)
596596
{
597597
Assert(per_table_parenthood_mapping_refcount > 0);
598-
per_table_parenthood_mapping_refcount--;
598+
599+
/* Should we destroy the table right now? */
600+
if (entirely)
601+
per_table_parenthood_mapping_refcount = 0;
602+
else
603+
per_table_parenthood_mapping_refcount--;
599604

600605
/* Free resources if no one is using them */
601606
if (per_table_parenthood_mapping_refcount == 0)

src/planner_tree_modification.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void assign_rel_parenthood_status(uint32 query_id, Oid relid,
4545
rel_parenthood_status new_status);
4646
rel_parenthood_status get_rel_parenthood_status(uint32 query_id, Oid relid);
4747
void incr_refcount_parenthood_statuses(void);
48-
void decr_refcount_parenthood_statuses(void);
48+
void decr_refcount_parenthood_statuses(bool entirely);
4949

5050

5151
#endif /* PLANNER_TREE_MODIFICATION_H */

0 commit comments

Comments
 (0)