Skip to content

Commit 6a60886

Browse files
committed
Fix handling of append_rel_array.
Also a bunch of other stuff noted by @funbringer.
1 parent 389c807 commit 6a60886

File tree

7 files changed

+66
-28
lines changed

7 files changed

+66
-28
lines changed

src/compat/pg_compat.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,8 @@ create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
4848
{
4949
int parallel_workers;
5050

51-
#if PG_VERSION_NUM >= 110000
52-
parallel_workers = compute_parallel_worker(rel, rel->pages, -1,
53-
max_parallel_workers_per_gather);
54-
#else
55-
parallel_workers = compute_parallel_worker(rel, rel->pages, -1);
56-
#endif
51+
/* no more than max_parallel_workers_per_gather since 11 */
52+
parallel_workers = compute_parallel_worker_compat(rel, rel->pages, -1);
5753

5854
/* If any limit was set to zero, the user doesn't want a parallel scan. */
5955
if (parallel_workers <= 0)

src/hooks.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,17 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
477477
memset((void *) &root->simple_rte_array[current_len], 0,
478478
irange_len * sizeof(RangeTblEntry *));
479479

480+
#if PG_VERSION_NUM >= 110000
481+
/* Make sure append_rel_array is wide enough */
482+
if (root->append_rel_array == NULL)
483+
root->append_rel_array = (AppendRelInfo **) palloc0(0);
484+
root->append_rel_array = (AppendRelInfo **)
485+
repalloc(root->append_rel_array,
486+
new_len * sizeof(AppendRelInfo *));
487+
memset((void *) &root->append_rel_array[current_len], 0,
488+
irange_len * sizeof(AppendRelInfo *));
489+
#endif
490+
480491
/* Don't forget to update array size! */
481492
root->simple_rel_array_size = new_len;
482493
}
@@ -485,7 +496,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
485496
parent_rel = heap_open(rte->relid, NoLock);
486497

487498
parent_rowmark = get_plan_rowmark(root->rowMarks, rti);
488-
499+
489500
/* Add parent if asked to */
490501
if (prel->enable_parent)
491502
append_child_relation(root, parent_rel, parent_rowmark,
@@ -514,21 +525,12 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
514525
rel->partial_pathlist = NIL;
515526
#endif
516527

517-
/* Convert list to array for faster lookups */
518-
#if PG_VERSION_NUM >= 110000
519-
setup_append_rel_array(root);
520-
#endif
521-
522528
/* Generate new paths using the rels we've just added */
523529
set_append_rel_pathlist(root, rel, rti, pathkeyAsc, pathkeyDesc);
524530
set_append_rel_size_compat(root, rel, rti);
525531

526-
/* consider gathering partial paths for the parent appendrel */
527-
#if PG_VERSION_NUM >= 110000
528-
generate_gather_paths(root, rel, false);
529-
#elif PG_VERSION_NUM >= 90600
530-
generate_gather_paths(root, rel);
531-
#endif
532+
/* consider gathering partial paths for the parent appendrel */
533+
generate_gather_paths_compat(root, rel);
532534

533535
/* Skip if both custom nodes are disabled */
534536
if (!(pg_pathman_enable_runtimeappend ||

src/include/compat/pg_compat.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,45 @@ extern AttrNumber *convert_tuples_by_name_map(TupleDesc indesc,
787787
heap_delete((relation), (tid), (cid), (crosscheck), (wait), (hufd))
788788
#endif
789789

790+
/*
791+
* compute_parallel_worker
792+
*/
793+
#if PG_VERSION_NUM >= 110000
794+
#define compute_parallel_worker_compat(rel, heap_pages, index_pages) \
795+
compute_parallel_worker((rel), (heap_pages), (index_pages), \
796+
max_parallel_workers_per_gather)
797+
#elif PG_VERSION_NUM >= 100000
798+
#define compute_parallel_worker_compat(rel, heap_pages, index_pages) \
799+
compute_parallel_worker((rel), (heap_pages), (index_pages))
800+
#endif
801+
802+
803+
/*
804+
* generate_gather_paths
805+
*/
806+
#if PG_VERSION_NUM >= 110000
807+
#define generate_gather_paths_compat(root, rel) \
808+
generate_gather_paths((root), (rel), false)
809+
#elif PG_VERSION_NUM >= 90600
810+
#define generate_gather_paths_compat(root, rel) \
811+
generate_gather_paths((rel), (heap_pages), false)
812+
#else
813+
#define generate_gather_paths_compat(root, rel)
814+
#endif
815+
816+
817+
/*
818+
* handling appendrelinfo array
819+
*/
820+
#if PG_VERSION_NUM >= 110000
821+
#define find_childrel_appendrelinfo_compat(root, rel) \
822+
((root)->append_rel_array[(rel)->relid])
823+
#else
824+
#define find_childrel_appendrelinfo_compat(root, rel) \
825+
find_childrel_appendrelinfo((root), (rel))
826+
#endif
827+
828+
790829
/*
791830
* -------------
792831
* Common code

src/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
#include "catalog/indexing.h"
2626
#include "catalog/pg_extension.h"
2727
#include "catalog/pg_inherits.h"
28-
#if PG_VERSION_NUM < 110000
29-
#include "catalog/pg_inherits_fn.h"
30-
#endif
3128
#include "catalog/pg_type.h"
3229
#include "miscadmin.h"
3330
#include "optimizer/clauses.h"
@@ -39,6 +36,9 @@
3936
#include "utils/snapmgr.h"
4037
#include "utils/syscache.h"
4138
#include "utils/typcache.h"
39+
#if PG_VERSION_NUM < 110000
40+
#include "catalog/pg_inherits_fn.h"
41+
#endif
4242

4343
#include <stdlib.h>
4444

src/nodes_common.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,9 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
569569
{
570570
Plan *child_plan = (Plan *) lfirst(lc2);
571571
RelOptInfo *child_rel = ((Path *) lfirst(lc1))->parent;
572-
#if PG_VERSION_NUM >= 110000
573-
AppendRelInfo *appinfo = root->append_rel_array[child_rel->relid];
574-
#else
575-
AppendRelInfo *appinfo = find_childrel_appendrelinfo(root, child_rel);
576-
#endif
572+
AppendRelInfo *appinfo;
573+
574+
appinfo = find_childrel_appendrelinfo_compat(root, child_rel);
577575

578576
/* Replace rel's tlist with a matching one (for ExecQual()) */
579577
if (!processed_rel_tlist)

src/pathman_workers.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ bgw_main_concurrent_part(Datum main_arg)
483483

484484
Oid types[2] = { OIDOID, INT4OID };
485485
Datum vals[2] = { part_slot->relid, part_slot->batch_size };
486-
char nulls[2] = { false, false };
487486

488487
bool rel_locked = false;
489488

@@ -557,7 +556,7 @@ bgw_main_concurrent_part(Datum main_arg)
557556
}
558557

559558
/* Call concurrent partitioning function */
560-
ret = SPI_execute_with_args(sql, 2, types, vals, nulls, false, 0);
559+
ret = SPI_execute_with_args(sql, 2, types, vals, NULL, false, 0);
561560
if (ret == SPI_OK_SELECT)
562561
{
563562
TupleDesc tupdesc = SPI_tuptable->tupdesc;

src/pg_pathman.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,10 @@ append_child_relation(PlannerInfo *root,
535535

536536
/* Now append 'appinfo' to 'root->append_rel_list' */
537537
root->append_rel_list = lappend(root->append_rel_list, appinfo);
538+
/* And to array in >= 11, it must be big enough */
539+
#if PG_VERSION_NUM >= 110000
540+
root->append_rel_array[child_rti] = appinfo;
541+
#endif
538542

539543
/* Translate column privileges for this child */
540544
if (parent_rte->relid != child_oid)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy