Skip to content

Commit 7d2b7b6

Browse files
committed
Merge remote-tracking branch 'upstream/master' into dev/pglogical
2 parents 7ec4d36 + 54638f5 commit 7d2b7b6

File tree

132 files changed

+3629
-1020
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+3629
-1020
lines changed

contrib/file_fdw/file_fdw.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ static void fileEndForeignScan(ForeignScanState *node);
131131
static bool fileAnalyzeForeignTable(Relation relation,
132132
AcquireSampleRowsFunc *func,
133133
BlockNumber *totalpages);
134+
static bool fileIsForeignScanParallelSafe(PlannerInfo *root, RelOptInfo *rel,
135+
RangeTblEntry *rte);
134136

135137
/*
136138
* Helper functions
@@ -170,6 +172,7 @@ file_fdw_handler(PG_FUNCTION_ARGS)
170172
fdwroutine->ReScanForeignScan = fileReScanForeignScan;
171173
fdwroutine->EndForeignScan = fileEndForeignScan;
172174
fdwroutine->AnalyzeForeignTable = fileAnalyzeForeignTable;
175+
fdwroutine->IsForeignScanParallelSafe = fileIsForeignScanParallelSafe;
173176

174177
PG_RETURN_POINTER(fdwroutine);
175178
}
@@ -761,6 +764,18 @@ fileAnalyzeForeignTable(Relation relation,
761764
return true;
762765
}
763766

767+
/*
768+
* fileIsForeignScanParallelSafe
769+
* Reading a file in a parallel worker should work just the same as
770+
* reading it in the leader, so mark scans safe.
771+
*/
772+
static bool
773+
fileIsForeignScanParallelSafe(PlannerInfo *root, RelOptInfo *rel,
774+
RangeTblEntry *rte)
775+
{
776+
return true;
777+
}
778+
764779
/*
765780
* check_selective_binary_conversion
766781
*
@@ -806,7 +821,7 @@ check_selective_binary_conversion(RelOptInfo *baserel,
806821
}
807822

808823
/* Collect all the attributes needed for joins or final output. */
809-
pull_varattnos((Node *) baserel->reltargetlist, baserel->relid,
824+
pull_varattnos((Node *) baserel->reltarget.exprs, baserel->relid,
810825
&attrs_used);
811826

812827
/* Add all the attributes used by restriction clauses. */
@@ -938,7 +953,7 @@ estimate_size(PlannerInfo *root, RelOptInfo *baserel,
938953
*/
939954
int tuple_width;
940955

941-
tuple_width = MAXALIGN(baserel->width) +
956+
tuple_width = MAXALIGN(baserel->reltarget.width) +
942957
MAXALIGN(SizeofHeapTupleHeader);
943958
ntuples = clamp_row_est((double) stat_buf.st_size /
944959
(double) tuple_width);

contrib/pgstattuple/expected/pgstattuple.out

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,40 +41,44 @@ select pgstattuple(relname) from pg_class where relname = 'test';
4141
(0,0,0,0,0,0,0,0,0)
4242
(1 row)
4343

44-
select * from pgstatindex('test_pkey');
44+
select version, tree_level,
45+
index_size / current_setting('block_size')::int as index_size,
46+
root_block_no, internal_pages, leaf_pages, empty_pages, deleted_pages,
47+
avg_leaf_density, leaf_fragmentation
48+
from pgstatindex('test_pkey');
4549
version | tree_level | index_size | root_block_no | internal_pages | leaf_pages | empty_pages | deleted_pages | avg_leaf_density | leaf_fragmentation
4650
---------+------------+------------+---------------+----------------+------------+-------------+---------------+------------------+--------------------
47-
2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | NaN | NaN
51+
2 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | NaN | NaN
4852
(1 row)
4953

50-
select * from pgstatindex('test_pkey'::text);
54+
select version, tree_level,
55+
index_size / current_setting('block_size')::int as index_size,
56+
root_block_no, internal_pages, leaf_pages, empty_pages, deleted_pages,
57+
avg_leaf_density, leaf_fragmentation
58+
from pgstatindex('test_pkey'::text);
5159
version | tree_level | index_size | root_block_no | internal_pages | leaf_pages | empty_pages | deleted_pages | avg_leaf_density | leaf_fragmentation
5260
---------+------------+------------+---------------+----------------+------------+-------------+---------------+------------------+--------------------
53-
2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | NaN | NaN
61+
2 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | NaN | NaN
5462
(1 row)
5563

56-
select * from pgstatindex('test_pkey'::name);
64+
select version, tree_level,
65+
index_size / current_setting('block_size')::int as index_size,
66+
root_block_no, internal_pages, leaf_pages, empty_pages, deleted_pages,
67+
avg_leaf_density, leaf_fragmentation
68+
from pgstatindex('test_pkey'::name);
5769
version | tree_level | index_size | root_block_no | internal_pages | leaf_pages | empty_pages | deleted_pages | avg_leaf_density | leaf_fragmentation
5870
---------+------------+------------+---------------+----------------+------------+-------------+---------------+------------------+--------------------
59-
2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | NaN | NaN
71+
2 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | NaN | NaN
6072
(1 row)
6173

62-
select * from pgstatindex('test_pkey'::regclass);
74+
select version, tree_level,
75+
index_size / current_setting('block_size')::int as index_size,
76+
root_block_no, internal_pages, leaf_pages, empty_pages, deleted_pages,
77+
avg_leaf_density, leaf_fragmentation
78+
from pgstatindex('test_pkey'::regclass);
6379
version | tree_level | index_size | root_block_no | internal_pages | leaf_pages | empty_pages | deleted_pages | avg_leaf_density | leaf_fragmentation
6480
---------+------------+------------+---------------+----------------+------------+-------------+---------------+------------------+--------------------
65-
2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | NaN | NaN
66-
(1 row)
67-
68-
select pgstatindex(oid) from pg_class where relname = 'test_pkey';
69-
pgstatindex
70-
---------------------------
71-
(2,0,0,0,0,0,0,0,NaN,NaN)
72-
(1 row)
73-
74-
select pgstatindex(relname) from pg_class where relname = 'test_pkey';
75-
pgstatindex
76-
---------------------------
77-
(2,0,0,0,0,0,0,0,NaN,NaN)
81+
2 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | NaN | NaN
7882
(1 row)
7983

8084
select pg_relpages('test');

contrib/pgstattuple/pgstatindex.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ typedef struct BTIndexStat
7979
uint32 level;
8080
BlockNumber root_blkno;
8181

82-
uint64 root_pages;
8382
uint64 internal_pages;
8483
uint64 leaf_pages;
8584
uint64 empty_pages;
@@ -185,7 +184,6 @@ pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
185184
}
186185

187186
/* -- init counters -- */
188-
indexStat.root_pages = 0;
189187
indexStat.internal_pages = 0;
190188
indexStat.leaf_pages = 0;
191189
indexStat.empty_pages = 0;
@@ -218,7 +216,11 @@ pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
218216

219217
/* Determine page type, and update totals */
220218

221-
if (P_ISLEAF(opaque))
219+
if (P_ISDELETED(opaque))
220+
indexStat.deleted_pages++;
221+
else if (P_IGNORE(opaque))
222+
indexStat.empty_pages++; /* this is the "half dead" state */
223+
else if (P_ISLEAF(opaque))
222224
{
223225
int max_avail;
224226

@@ -235,12 +237,6 @@ pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
235237
if (opaque->btpo_next != P_NONE && opaque->btpo_next < blkno)
236238
indexStat.fragments++;
237239
}
238-
else if (P_ISDELETED(opaque))
239-
indexStat.deleted_pages++;
240-
else if (P_IGNORE(opaque))
241-
indexStat.empty_pages++;
242-
else if (P_ISROOT(opaque))
243-
indexStat.root_pages++;
244240
else
245241
indexStat.internal_pages++;
246242

@@ -269,7 +265,7 @@ pgstatindex_impl(Relation rel, FunctionCallInfo fcinfo)
269265
values[j++] = psprintf("%d", indexStat.version);
270266
values[j++] = psprintf("%d", indexStat.level);
271267
values[j++] = psprintf(INT64_FORMAT,
272-
(indexStat.root_pages +
268+
(1 + /* include the metapage in index_size */
273269
indexStat.leaf_pages +
274270
indexStat.internal_pages +
275271
indexStat.deleted_pages +

contrib/pgstattuple/sql/pgstattuple.sql

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,26 @@ select * from pgstattuple('test'::regclass);
1515
select pgstattuple(oid) from pg_class where relname = 'test';
1616
select pgstattuple(relname) from pg_class where relname = 'test';
1717

18-
select * from pgstatindex('test_pkey');
19-
select * from pgstatindex('test_pkey'::text);
20-
select * from pgstatindex('test_pkey'::name);
21-
select * from pgstatindex('test_pkey'::regclass);
22-
select pgstatindex(oid) from pg_class where relname = 'test_pkey';
23-
select pgstatindex(relname) from pg_class where relname = 'test_pkey';
18+
select version, tree_level,
19+
index_size / current_setting('block_size')::int as index_size,
20+
root_block_no, internal_pages, leaf_pages, empty_pages, deleted_pages,
21+
avg_leaf_density, leaf_fragmentation
22+
from pgstatindex('test_pkey');
23+
select version, tree_level,
24+
index_size / current_setting('block_size')::int as index_size,
25+
root_block_no, internal_pages, leaf_pages, empty_pages, deleted_pages,
26+
avg_leaf_density, leaf_fragmentation
27+
from pgstatindex('test_pkey'::text);
28+
select version, tree_level,
29+
index_size / current_setting('block_size')::int as index_size,
30+
root_block_no, internal_pages, leaf_pages, empty_pages, deleted_pages,
31+
avg_leaf_density, leaf_fragmentation
32+
from pgstatindex('test_pkey'::name);
33+
select version, tree_level,
34+
index_size / current_setting('block_size')::int as index_size,
35+
root_block_no, internal_pages, leaf_pages, empty_pages, deleted_pages,
36+
avg_leaf_density, leaf_fragmentation
37+
from pgstatindex('test_pkey'::regclass);
2438

2539
select pg_relpages('test');
2640
select pg_relpages('test_pkey');

contrib/postgres_fdw/deparse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,10 +728,10 @@ build_tlist_to_deparse(RelOptInfo *foreignrel)
728728
PgFdwRelationInfo *fpinfo = (PgFdwRelationInfo *) foreignrel->fdw_private;
729729

730730
/*
731-
* We require columns specified in foreignrel->reltargetlist and those
731+
* We require columns specified in foreignrel->reltarget.exprs and those
732732
* required for evaluating the local conditions.
733733
*/
734-
tlist = add_to_flat_tlist(tlist, foreignrel->reltargetlist);
734+
tlist = add_to_flat_tlist(tlist, foreignrel->reltarget.exprs);
735735
tlist = add_to_flat_tlist(tlist,
736736
pull_var_clause((Node *) fpinfo->local_conds,
737737
PVC_REJECT_AGGREGATES,

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ postgresGetForeignRelSize(PlannerInfo *root,
479479
* columns used in them. Doesn't seem worth detecting that case though.)
480480
*/
481481
fpinfo->attrs_used = NULL;
482-
pull_varattnos((Node *) baserel->reltargetlist, baserel->relid,
482+
pull_varattnos((Node *) baserel->reltarget.exprs, baserel->relid,
483483
&fpinfo->attrs_used);
484484
foreach(lc, fpinfo->local_conds)
485485
{
@@ -522,7 +522,7 @@ postgresGetForeignRelSize(PlannerInfo *root,
522522

523523
/* Report estimated baserel size to planner. */
524524
baserel->rows = fpinfo->rows;
525-
baserel->width = fpinfo->width;
525+
baserel->reltarget.width = fpinfo->width;
526526
}
527527
else
528528
{
@@ -539,7 +539,8 @@ postgresGetForeignRelSize(PlannerInfo *root,
539539
{
540540
baserel->pages = 10;
541541
baserel->tuples =
542-
(10 * BLCKSZ) / (baserel->width + MAXALIGN(SizeofHeapTupleHeader));
542+
(10 * BLCKSZ) / (baserel->reltarget.width +
543+
MAXALIGN(SizeofHeapTupleHeader));
543544
}
544545

545546
/* Estimate baserel size as best we can with local statistics. */
@@ -2176,7 +2177,7 @@ estimate_path_cost_size(PlannerInfo *root,
21762177
* between foreign relations.
21772178
*/
21782179
rows = foreignrel->rows;
2179-
width = foreignrel->width;
2180+
width = foreignrel->reltarget.width;
21802181

21812182
/* Back into an estimate of the number of retrieved rows. */
21822183
retrieved_rows = clamp_row_est(rows / fpinfo->local_conds_sel);
@@ -3487,30 +3488,30 @@ foreign_join_ok(PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype,
34873488
{
34883489
case JOIN_INNER:
34893490
fpinfo->remote_conds = list_concat(fpinfo->remote_conds,
3490-
fpinfo_i->remote_conds);
3491+
list_copy(fpinfo_i->remote_conds));
34913492
fpinfo->remote_conds = list_concat(fpinfo->remote_conds,
3492-
fpinfo_o->remote_conds);
3493+
list_copy(fpinfo_o->remote_conds));
34933494
break;
34943495

34953496
case JOIN_LEFT:
34963497
fpinfo->joinclauses = list_concat(fpinfo->joinclauses,
3497-
fpinfo_i->remote_conds);
3498+
list_copy(fpinfo_i->remote_conds));
34983499
fpinfo->remote_conds = list_concat(fpinfo->remote_conds,
3499-
fpinfo_o->remote_conds);
3500+
list_copy(fpinfo_o->remote_conds));
35003501
break;
35013502

35023503
case JOIN_RIGHT:
35033504
fpinfo->joinclauses = list_concat(fpinfo->joinclauses,
3504-
fpinfo_o->remote_conds);
3505+
list_copy(fpinfo_o->remote_conds));
35053506
fpinfo->remote_conds = list_concat(fpinfo->remote_conds,
3506-
fpinfo_i->remote_conds);
3507+
list_copy(fpinfo_i->remote_conds));
35073508
break;
35083509

35093510
case JOIN_FULL:
35103511
fpinfo->joinclauses = list_concat(fpinfo->joinclauses,
3511-
fpinfo_i->remote_conds);
3512+
list_copy(fpinfo_i->remote_conds));
35123513
fpinfo->joinclauses = list_concat(fpinfo->joinclauses,
3513-
fpinfo_o->remote_conds);
3514+
list_copy(fpinfo_o->remote_conds));
35143515
break;
35153516

35163517
default:
@@ -3646,7 +3647,7 @@ postgresGetForeignJoinPaths(PlannerInfo *root,
36463647
&width, &startup_cost, &total_cost);
36473648
/* Now update this information in the joinrel */
36483649
joinrel->rows = rows;
3649-
joinrel->width = width;
3650+
joinrel->reltarget.width = width;
36503651
fpinfo->rows = rows;
36513652
fpinfo->width = width;
36523653
fpinfo->startup_cost = startup_cost;

0 commit comments

Comments
 (0)