Skip to content

Commit 4c3a428

Browse files
committed
merge with master
2 parents c56e9be + 101fd93 commit 4c3a428

File tree

419 files changed

+20847
-7610
lines changed

Some content is hidden

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

419 files changed

+20847
-7610
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ contrib/tsearch2/sql/tsearch2.sql whitespace=space-before-tab,blank-at-eof,-bla
1717
contrib/pgcrypto/sql/pgp-armor.sql whitespace=-blank-at-eol
1818
doc/bug.template whitespace=space-before-tab,-blank-at-eof,blank-at-eol
1919
src/backend/catalog/sql_features.txt whitespace=space-before-tab,blank-at-eof,-blank-at-eol
20-
src/backend/tsearch/hunspell_sample.affix whitespace=-blank-at-eof
2120

2221
# Test output files that contain extra whitespace
2322
*.out -whitespace

config/tcl.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
AC_DEFUN([PGAC_PATH_TCLSH],
7-
[AC_PATH_PROGS(TCLSH, [tclsh tcl tclsh8.6 tclsh86 tclsh8.5 tclsh85 tclsh8.4 tclsh84 tclsh8.3 tclsh83])
7+
[AC_PATH_PROGS(TCLSH, [tclsh tcl tclsh8.6 tclsh86 tclsh8.5 tclsh85 tclsh8.4 tclsh84])
88
if test x"$TCLSH" = x""; then
99
AC_MSG_ERROR([Tcl shell not found])
1010
fi

configure

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3100,6 +3100,17 @@ _ACEOF
31003100

31013101

31023102

3103+
# It's worth validating port; you can get very confusing errors otherwise
3104+
if test x"$default_port" = x""; then
3105+
as_fn_error $? "invalid --with-pgport specification: empty string" "$LINENO" 5
3106+
elif test ! x`echo "$default_port" | sed -e 's/[0-9]*//'` = x""; then
3107+
as_fn_error $? "invalid --with-pgport specification: must be a number" "$LINENO" 5
3108+
elif test ! x`echo "$default_port" | sed -e 's/^0.//'` = x"$default_port"; then
3109+
as_fn_error $? "invalid --with-pgport specification: must not have leading 0" "$LINENO" 5
3110+
elif test "$default_port" -lt "1" -o "$default_port" -gt "65535"; then
3111+
as_fn_error $? "invalid --with-pgport specification: must be between 1 and 65535" "$LINENO" 5
3112+
fi
3113+
31033114
#
31043115
# '-rpath'-like feature can be disabled
31053116
#
@@ -14955,7 +14966,7 @@ fi
1495514966

1495614967
# Check for Tcl configuration script tclConfig.sh
1495714968
if test "$with_tcl" = yes; then
14958-
for ac_prog in tclsh tcl tclsh8.6 tclsh86 tclsh8.5 tclsh85 tclsh8.4 tclsh84 tclsh8.3 tclsh83
14969+
for ac_prog in tclsh tcl tclsh8.6 tclsh86 tclsh8.5 tclsh85 tclsh8.4 tclsh84
1495914970
do
1496014971
# Extract the first word of "$ac_prog", so it can be a program name with args.
1496114972
set dummy $ac_prog; ac_word=$2

configure.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ AC_DEFINE_UNQUOTED(DEF_PGPORT_STR, "${default_port}",
165165
[Define to the default TCP port number as a string constant.])
166166
AC_SUBST(default_port)
167167

168+
# It's worth validating port; you can get very confusing errors otherwise
169+
if test x"$default_port" = x""; then
170+
AC_MSG_ERROR([invalid --with-pgport specification: empty string])
171+
elif test ! x`echo "$default_port" | sed -e 's/[[0-9]]*//'` = x""; then
172+
AC_MSG_ERROR([invalid --with-pgport specification: must be a number])
173+
elif test ! x`echo "$default_port" | sed -e 's/^0.//'` = x"$default_port"; then
174+
AC_MSG_ERROR([invalid --with-pgport specification: must not have leading 0])
175+
elif test "$default_port" -lt "1" -o "$default_port" -gt "65535"; then
176+
AC_MSG_ERROR([invalid --with-pgport specification: must be between 1 and 65535])
177+
fi
178+
168179
#
169180
# '-rpath'-like feature can be disabled
170181
#

contrib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ SUBDIRS = \
3737
pgcrypto \
3838
pgrowlocks \
3939
pgstattuple \
40+
pg_visibility \
4041
postgres_fdw \
4142
seg \
4243
spi \

contrib/auto_explain/auto_explain.c

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static bool auto_explain_log_triggers = false;
2929
static bool auto_explain_log_timing = true;
3030
static int auto_explain_log_format = EXPLAIN_FORMAT_TEXT;
3131
static bool auto_explain_log_nested_statements = false;
32+
static double auto_explain_sample_rate = 1;
3233

3334
static const struct config_enum_entry format_options[] = {
3435
{"text", EXPLAIN_FORMAT_TEXT, false},
@@ -47,6 +48,9 @@ static ExecutorRun_hook_type prev_ExecutorRun = NULL;
4748
static ExecutorFinish_hook_type prev_ExecutorFinish = NULL;
4849
static ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
4950

51+
/* Is the current query sampled, per backend */
52+
static bool current_query_sampled = true;
53+
5054
#define auto_explain_enabled() \
5155
(auto_explain_log_min_duration >= 0 && \
5256
(nesting_level == 0 || auto_explain_log_nested_statements))
@@ -57,7 +61,7 @@ void _PG_fini(void);
5761
static void explain_ExecutorStart(QueryDesc *queryDesc, int eflags);
5862
static void explain_ExecutorRun(QueryDesc *queryDesc,
5963
ScanDirection direction,
60-
long count);
64+
uint64 count);
6165
static void explain_ExecutorFinish(QueryDesc *queryDesc);
6266
static void explain_ExecutorEnd(QueryDesc *queryDesc);
6367

@@ -159,6 +163,19 @@ _PG_init(void)
159163
NULL,
160164
NULL);
161165

166+
DefineCustomRealVariable("auto_explain.sample_rate",
167+
"Fraction of queries to process.",
168+
NULL,
169+
&auto_explain_sample_rate,
170+
1.0,
171+
0.0,
172+
1.0,
173+
PGC_SUSET,
174+
0,
175+
NULL,
176+
NULL,
177+
NULL);
178+
162179
EmitWarningsOnPlaceholders("auto_explain");
163180

164181
/* Install hooks. */
@@ -191,7 +208,15 @@ _PG_fini(void)
191208
static void
192209
explain_ExecutorStart(QueryDesc *queryDesc, int eflags)
193210
{
194-
if (auto_explain_enabled())
211+
/*
212+
* For rate sampling, randomly choose top-level statement. Either
213+
* all nested statements will be explained or none will.
214+
*/
215+
if (auto_explain_log_min_duration >= 0 && nesting_level == 0)
216+
current_query_sampled = (random() < auto_explain_sample_rate *
217+
MAX_RANDOM_VALUE);
218+
219+
if (auto_explain_enabled() && current_query_sampled)
195220
{
196221
/* Enable per-node instrumentation iff log_analyze is required. */
197222
if (auto_explain_log_analyze && (eflags & EXEC_FLAG_EXPLAIN_ONLY) == 0)
@@ -210,7 +235,7 @@ explain_ExecutorStart(QueryDesc *queryDesc, int eflags)
210235
else
211236
standard_ExecutorStart(queryDesc, eflags);
212237

213-
if (auto_explain_enabled())
238+
if (auto_explain_enabled() && current_query_sampled)
214239
{
215240
/*
216241
* Set up to track total elapsed time in ExecutorRun. Make sure the
@@ -232,7 +257,7 @@ explain_ExecutorStart(QueryDesc *queryDesc, int eflags)
232257
* ExecutorRun hook: all we need do is track nesting depth
233258
*/
234259
static void
235-
explain_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, long count)
260+
explain_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count)
236261
{
237262
nesting_level++;
238263
PG_TRY();
@@ -280,7 +305,7 @@ explain_ExecutorFinish(QueryDesc *queryDesc)
280305
static void
281306
explain_ExecutorEnd(QueryDesc *queryDesc)
282307
{
283-
if (queryDesc->totaltime && auto_explain_enabled())
308+
if (queryDesc->totaltime && auto_explain_enabled() && current_query_sampled)
284309
{
285310
double msec;
286311

contrib/file_fdw/file_fdw.c

Lines changed: 18 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
}
@@ -521,6 +524,7 @@ fileGetForeignPaths(PlannerInfo *root,
521524
*/
522525
add_path(baserel, (Path *)
523526
create_foreignscan_path(root, baserel,
527+
NULL, /* default pathtarget */
524528
baserel->rows,
525529
startup_cost,
526530
total_cost,
@@ -761,6 +765,18 @@ fileAnalyzeForeignTable(Relation relation,
761765
return true;
762766
}
763767

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

808824
/* Collect all the attributes needed for joins or final output. */
809-
pull_varattnos((Node *) baserel->reltargetlist, baserel->relid,
825+
pull_varattnos((Node *) baserel->reltarget->exprs, baserel->relid,
810826
&attrs_used);
811827

812828
/* Add all the attributes used by restriction clauses. */
@@ -938,7 +954,7 @@ estimate_size(PlannerInfo *root, RelOptInfo *baserel,
938954
*/
939955
int tuple_width;
940956

941-
tuple_width = MAXALIGN(baserel->width) +
957+
tuple_width = MAXALIGN(baserel->reltarget->width) +
942958
MAXALIGN(SizeofHeapTupleHeader);
943959
ntuples = clamp_row_est((double) stat_buf.st_size /
944960
(double) tuple_width);

contrib/ltree/_ltree_gist.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
8585
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
8686
errmsg("array must not contain nulls")));
8787

88-
key = (ltree_gist *) palloc(len);
88+
key = (ltree_gist *) palloc0(len);
8989
SET_VARSIZE(key, len);
9090
key->flag = 0;
9191

@@ -116,7 +116,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
116116
PG_RETURN_POINTER(retval);
117117
}
118118
len = LTG_HDRSIZE;
119-
key = (ltree_gist *) palloc(len);
119+
key = (ltree_gist *) palloc0(len);
120120
SET_VARSIZE(key, len);
121121
key->flag = LTG_ALLTRUE;
122122

@@ -196,7 +196,7 @@ _ltree_union(PG_FUNCTION_ARGS)
196196
}
197197

198198
len = LTG_HDRSIZE + ((flag & LTG_ALLTRUE) ? 0 : ASIGLEN);
199-
result = (ltree_gist *) palloc(len);
199+
result = (ltree_gist *) palloc0(len);
200200
SET_VARSIZE(result, len);
201201
result->flag = flag;
202202
if (!LTG_ISALLTRUE(result))
@@ -333,26 +333,26 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
333333
/* form initial .. */
334334
if (LTG_ISALLTRUE(GETENTRY(entryvec, seed_1)))
335335
{
336-
datum_l = (ltree_gist *) palloc(LTG_HDRSIZE);
336+
datum_l = (ltree_gist *) palloc0(LTG_HDRSIZE);
337337
SET_VARSIZE(datum_l, LTG_HDRSIZE);
338338
datum_l->flag = LTG_ALLTRUE;
339339
}
340340
else
341341
{
342-
datum_l = (ltree_gist *) palloc(LTG_HDRSIZE + ASIGLEN);
342+
datum_l = (ltree_gist *) palloc0(LTG_HDRSIZE + ASIGLEN);
343343
SET_VARSIZE(datum_l, LTG_HDRSIZE + ASIGLEN);
344344
datum_l->flag = 0;
345345
memcpy((void *) LTG_SIGN(datum_l), (void *) LTG_SIGN(GETENTRY(entryvec, seed_1)), sizeof(ABITVEC));
346346
}
347347
if (LTG_ISALLTRUE(GETENTRY(entryvec, seed_2)))
348348
{
349-
datum_r = (ltree_gist *) palloc(LTG_HDRSIZE);
349+
datum_r = (ltree_gist *) palloc0(LTG_HDRSIZE);
350350
SET_VARSIZE(datum_r, LTG_HDRSIZE);
351351
datum_r->flag = LTG_ALLTRUE;
352352
}
353353
else
354354
{
355-
datum_r = (ltree_gist *) palloc(LTG_HDRSIZE + ASIGLEN);
355+
datum_r = (ltree_gist *) palloc0(LTG_HDRSIZE + ASIGLEN);
356356
SET_VARSIZE(datum_r, LTG_HDRSIZE + ASIGLEN);
357357
datum_r->flag = 0;
358358
memcpy((void *) LTG_SIGN(datum_r), (void *) LTG_SIGN(GETENTRY(entryvec, seed_2)), sizeof(ABITVEC));

contrib/ltree/_ltree_op.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ _ltree_extract_isparent(PG_FUNCTION_ARGS)
211211
PG_RETURN_NULL();
212212
}
213213

214-
item = (ltree *) palloc(VARSIZE(found));
214+
item = (ltree *) palloc0(VARSIZE(found));
215215
memcpy(item, found, VARSIZE(found));
216216

217217
PG_FREE_IF_COPY(la, 0);
@@ -234,7 +234,7 @@ _ltree_extract_risparent(PG_FUNCTION_ARGS)
234234
PG_RETURN_NULL();
235235
}
236236

237-
item = (ltree *) palloc(VARSIZE(found));
237+
item = (ltree *) palloc0(VARSIZE(found));
238238
memcpy(item, found, VARSIZE(found));
239239

240240
PG_FREE_IF_COPY(la, 0);
@@ -257,7 +257,7 @@ _ltq_extract_regex(PG_FUNCTION_ARGS)
257257
PG_RETURN_NULL();
258258
}
259259

260-
item = (ltree *) palloc(VARSIZE(found));
260+
item = (ltree *) palloc0(VARSIZE(found));
261261
memcpy(item, found, VARSIZE(found));
262262

263263
PG_FREE_IF_COPY(la, 0);
@@ -280,7 +280,7 @@ _ltxtq_extract_exec(PG_FUNCTION_ARGS)
280280
PG_RETURN_NULL();
281281
}
282282

283-
item = (ltree *) palloc(VARSIZE(found));
283+
item = (ltree *) palloc0(VARSIZE(found));
284284
memcpy(item, found, VARSIZE(found));
285285

286286
PG_FREE_IF_COPY(la, 0);

contrib/ltree/ltree_gist.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ ltree_compress(PG_FUNCTION_ARGS)
5656
ltree *val = (ltree *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
5757
int32 len = LTG_HDRSIZE + VARSIZE(val);
5858

59-
key = (ltree_gist *) palloc(len);
59+
key = (ltree_gist *) palloc0(len);
6060
SET_VARSIZE(key, len);
6161
key->flag = LTG_ONENODE;
6262
memcpy((void *) LTG_NODE(key), (void *) val, VARSIZE(val));
@@ -213,7 +213,7 @@ ltree_union(PG_FUNCTION_ARGS)
213213
isleqr = (left == right || ISEQ(left, right)) ? true : false;
214214
*size = LTG_HDRSIZE + ((isalltrue) ? 0 : SIGLEN) + VARSIZE(left) + ((isleqr) ? 0 : VARSIZE(right));
215215

216-
result = (ltree_gist *) palloc(*size);
216+
result = (ltree_gist *) palloc0(*size);
217217
SET_VARSIZE(result, *size);
218218
result->flag = 0;
219219

@@ -386,7 +386,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
386386
lu_l = LTG_GETLNODE(GETENTRY(entryvec, array[FirstOffsetNumber].index));
387387
isleqr = (lu_l == lu_r || ISEQ(lu_l, lu_r)) ? true : false;
388388
size = LTG_HDRSIZE + ((lisat) ? 0 : SIGLEN) + VARSIZE(lu_l) + ((isleqr) ? 0 : VARSIZE(lu_r));
389-
lu = (ltree_gist *) palloc(size);
389+
lu = (ltree_gist *) palloc0(size);
390390
SET_VARSIZE(lu, size);
391391
lu->flag = 0;
392392
if (lisat)
@@ -403,7 +403,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
403403
ru_l = LTG_GETLNODE(GETENTRY(entryvec, array[1 + ((maxoff - FirstOffsetNumber + 1) / 2)].index));
404404
isleqr = (ru_l == ru_r || ISEQ(ru_l, ru_r)) ? true : false;
405405
size = LTG_HDRSIZE + ((risat) ? 0 : SIGLEN) + VARSIZE(ru_l) + ((isleqr) ? 0 : VARSIZE(ru_r));
406-
ru = (ltree_gist *) palloc(size);
406+
ru = (ltree_gist *) palloc0(size);
407407
SET_VARSIZE(ru, size);
408408
ru->flag = 0;
409409
if (risat)
@@ -445,7 +445,7 @@ gist_isparent(ltree_gist *key, ltree *query)
445445
static ltree *
446446
copy_ltree(ltree *src)
447447
{
448-
ltree *dst = (ltree *) palloc(VARSIZE(src));
448+
ltree *dst = (ltree *) palloc0(VARSIZE(src));
449449

450450
memcpy(dst, src, VARSIZE(src));
451451
return dst;

contrib/ltree/ltree_op.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ inner_subltree(ltree *t, int32 startpos, int32 endpos)
211211
ptr = LEVEL_NEXT(ptr);
212212
}
213213

214-
res = (ltree *) palloc(LTREE_HDRSIZE + (end - start));
214+
res = (ltree *) palloc0(LTREE_HDRSIZE + (end - start));
215215
SET_VARSIZE(res, LTREE_HDRSIZE + (end - start));
216216
res->numlevel = endpos - startpos;
217217

@@ -268,7 +268,7 @@ ltree_concat(ltree *a, ltree *b)
268268
{
269269
ltree *r;
270270

271-
r = (ltree *) palloc(VARSIZE(a) + VARSIZE(b) - LTREE_HDRSIZE);
271+
r = (ltree *) palloc0(VARSIZE(a) + VARSIZE(b) - LTREE_HDRSIZE);
272272
SET_VARSIZE(r, VARSIZE(a) + VARSIZE(b) - LTREE_HDRSIZE);
273273
r->numlevel = a->numlevel + b->numlevel;
274274

@@ -450,7 +450,7 @@ lca_inner(ltree **a, int len)
450450
l1 = LEVEL_NEXT(l1);
451451
}
452452

453-
res = (ltree *) palloc(reslen);
453+
res = (ltree *) palloc0(reslen);
454454
SET_VARSIZE(res, reslen);
455455
res->numlevel = num;
456456

contrib/ltree/ltxtquery_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ queryin(char *buf)
350350
errmsg("ltxtquery is too large")));
351351
commonlen = COMPUTESIZE(state.num, state.sumlen);
352352

353-
query = (ltxtquery *) palloc(commonlen);
353+
query = (ltxtquery *) palloc0(commonlen);
354354
SET_VARSIZE(query, commonlen);
355355
query->size = state.num;
356356
ptr = GETQUERY(query);

0 commit comments

Comments
 (0)