Content-Length: 909691 | pFad | http://github.com/tonybelloni/postgres/commit/#start-of-content

685DC226 Merge remote-tracking branch 'upstream/master' · tonybelloni/postgres@504aa32 · GitHub
Skip to content

Commit 504aa32

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 71808f5 + f83040c commit 504aa32

File tree

11 files changed

+119
-31
lines changed

11 files changed

+119
-31
lines changed

contrib/postgres_fdw/postgres_fdw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5115,7 +5115,7 @@ conversion_error_callback(void *arg)
51155115

51165116
/*
51175117
* Target list can have Vars and expressions. For Vars, we can get
5118-
* it's relation, however for expressions we can't. Thus for
5118+
* its relation, however for expressions we can't. Thus for
51195119
* expressions, just show generic context message.
51205120
*/
51215121
if (IsA(tle->expr, Var))

doc/src/sgml/ref/pgbench.sgml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,13 @@ pgbench <optional> <replaceable>options</replaceable> </optional> <replaceable>d
10691069
<entry><literal>pi()</literal></entry>
10701070
<entry><literal>3.14159265358979323846</literal></entry>
10711071
</row>
1072+
<row>
1073+
<entry><literal><function>pow(<replaceable>x</replaceable>, <replaceable>y</replaceable>)</function>, <function>power(<replaceable>x</replaceable>, <replaceable>y</replaceable>)</function></literal></entry>
1074+
<entry>double</entry>
1075+
<entry>exponentiation</entry>
1076+
<entry><literal>pow(2.0, 10)</literal>, <literal>power(2.0, 10)</literal></entry>
1077+
<entry><literal>1024.0</literal></entry>
1078+
</row>
10721079
<row>
10731080
<entry><literal><function>random(<replaceable>lb</replaceable>, <replaceable>ub</replaceable>)</function></literal></entry>
10741081
<entry>integer</entry>

src/backend/commands/cluster.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,9 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
738738
Relation NewHeap,
739739
OldHeap,
740740
OldIndex;
741+
Relation relRelation;
742+
HeapTuple reltup;
743+
Form_pg_class relform;
741744
TupleDesc oldTupDesc;
742745
TupleDesc newTupDesc;
743746
int natts;
@@ -756,6 +759,7 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
756759
double num_tuples = 0,
757760
tups_vacuumed = 0,
758761
tups_recently_dead = 0;
762+
BlockNumber num_pages;
759763
int elevel = verbose ? INFO : DEBUG2;
760764
PGRUsage ru0;
761765

@@ -1079,6 +1083,8 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
10791083
/* Reset rd_toastoid just to be tidy --- it shouldn't be looked at again */
10801084
NewHeap->rd_toastoid = InvalidOid;
10811085

1086+
num_pages = RelationGetNumberOfBlocks(NewHeap);
1087+
10821088
/* Log what we did */
10831089
ereport(elevel,
10841090
(errmsg("\"%s\": found %.0f removable, %.0f nonremovable row versions in %u pages",
@@ -1098,6 +1104,30 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex, bool verbose,
10981104
index_close(OldIndex, NoLock);
10991105
heap_close(OldHeap, NoLock);
11001106
heap_close(NewHeap, NoLock);
1107+
1108+
/* Update pg_class to reflect the correct values of pages and tuples. */
1109+
relRelation = heap_open(RelationRelationId, RowExclusiveLock);
1110+
1111+
reltup = SearchSysCacheCopy1(RELOID, ObjectIdGetDatum(OIDNewHeap));
1112+
if (!HeapTupleIsValid(reltup))
1113+
elog(ERROR, "cache lookup failed for relation %u", OIDNewHeap);
1114+
relform = (Form_pg_class) GETSTRUCT(reltup);
1115+
1116+
relform->relpages = num_pages;
1117+
relform->reltuples = num_tuples;
1118+
1119+
/* Don't update the stats for pg_class. See swap_relation_files. */
1120+
if (OIDOldHeap != RelationRelationId)
1121+
CatalogTupleUpdate(relRelation, &reltup->t_self, reltup);
1122+
else
1123+
CacheInvalidateRelcacheByTuple(reltup);
1124+
1125+
/* Clean up. */
1126+
heap_freetuple(reltup);
1127+
heap_close(relRelation, RowExclusiveLock);
1128+
1129+
/* Make the update visible */
1130+
CommandCounterIncrement();
11011131
}
11021132

11031133
/*

src/backend/executor/nodeHash.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,6 @@ MultiExecParallelHash(HashState *node)
288288
ExecParallelHashTableInsert(hashtable, slot, hashvalue);
289289
hashtable->partialTuples++;
290290
}
291-
BarrierDetach(&pstate->grow_buckets_barrier);
292-
BarrierDetach(&pstate->grow_batches_barrier);
293291

294292
/*
295293
* Make sure that any tuples we wrote to disk are visible to
@@ -304,6 +302,9 @@ MultiExecParallelHash(HashState *node)
304302
*/
305303
ExecParallelHashMergeCounters(hashtable);
306304

305+
BarrierDetach(&pstate->grow_buckets_barrier);
306+
BarrierDetach(&pstate->grow_batches_barrier);
307+
307308
/*
308309
* Wait for everyone to finish building and flushing files and
309310
* counters.

src/backend/storage/file/fd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ PathNameCreateTemporaryDir(const char *basedir, const char *directory)
14511451
basedir)));
14521452

14531453
/* Try again. */
1454-
if (mkdir(directory, S_IRWXU) < 0)
1454+
if (mkdir(directory, S_IRWXU) < 0 && errno != EEXIST)
14551455
ereport(ERROR,
14561456
(errcode_for_file_access(),
14571457
errmsg("cannot create temporary subdirectory \"%s\": %m",

src/backend/utils/cache/relcache.c

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -807,17 +807,16 @@ RelationBuildRuleLock(Relation relation)
807807
* RelationBuildPartitionKey
808808
* Build and attach to relcache partition key data of relation
809809
*
810-
* Partitioning key data is stored in CacheMemoryContext to ensure it survives
811-
* as long as the relcache. To avoid leaking memory in that context in case
812-
* of an error partway through this function, we build the structure in the
813-
* working context (which must be short-lived) and copy the completed
814-
* structure into the cache memory.
815-
*
816-
* Also, since the structure being created here is sufficiently complex, we
817-
* make a private child context of CacheMemoryContext for each relation that
818-
* has associated partition key information. That means no complicated logic
819-
* to free individual elements whenever the relcache entry is flushed - just
820-
* delete the context.
810+
* Partitioning key data is a complex structure; to avoid complicated logic to
811+
* free individual elements whenever the relcache entry is flushed, we give it
812+
* its own memory context, child of CacheMemoryContext, which can easily be
813+
* deleted on its own. To avoid leaking memory in that context in case of an
814+
* error partway through this function, the context is initially created as a
815+
* child of CurTransactionContext and only re-parented to CacheMemoryContext
816+
* at the end, when no further errors are possible. Also, we don't make this
817+
* context the current context except in very brief code sections, out of fear
818+
* that some of our callees allocate memory on their own which would be leaked
819+
* permanently.
821820
*/
822821
static void
823822
RelationBuildPartitionKey(Relation relation)
@@ -850,9 +849,9 @@ RelationBuildPartitionKey(Relation relation)
850849
RelationGetRelationName(relation),
851850
MEMCONTEXT_COPY_NAME,
852851
ALLOCSET_SMALL_SIZES);
853-
oldcxt = MemoryContextSwitchTo(partkeycxt);
854852

855-
key = (PartitionKey) palloc0(sizeof(PartitionKeyData));
853+
key = (PartitionKey) MemoryContextAllocZero(partkeycxt,
854+
sizeof(PartitionKeyData));
856855

857856
/* Fixed-length attributes */
858857
form = (Form_pg_partitioned_table) GETSTRUCT(tuple);
@@ -894,17 +893,20 @@ RelationBuildPartitionKey(Relation relation)
894893
/*
895894
* Run the expressions through const-simplification since the planner
896895
* will be comparing them to similarly-processed qual clause operands,
897-
* and may fail to detect valid matches without this step. We don't
898-
* need to bother with canonicalize_qual() though, because partition
899-
* expressions are not full-fledged qualification clauses.
896+
* and may fail to detect valid matches without this step; fix
897+
* opfuncids while at it. We don't need to bother with
898+
* canonicalize_qual() though, because partition expressions are not
899+
* full-fledged qualification clauses.
900900
*/
901-
expr = eval_const_expressions(NULL, (Node *) expr);
901+
expr = eval_const_expressions(NULL, expr);
902+
fix_opfuncids(expr);
902903

903-
/* May as well fix opfuncids too */
904-
fix_opfuncids((Node *) expr);
905-
key->partexprs = (List *) expr;
904+
oldcxt = MemoryContextSwitchTo(partkeycxt);
905+
key->partexprs = (List *) copyObject(expr);
906+
MemoryContextSwitchTo(oldcxt);
906907
}
907908

909+
oldcxt = MemoryContextSwitchTo(partkeycxt);
908910
key->partattrs = (AttrNumber *) palloc0(key->partnatts * sizeof(AttrNumber));
909911
key->partopfamily = (Oid *) palloc0(key->partnatts * sizeof(Oid));
910912
key->partopcintype = (Oid *) palloc0(key->partnatts * sizeof(Oid));
@@ -919,8 +921,9 @@ RelationBuildPartitionKey(Relation relation)
919921
key->parttypbyval = (bool *) palloc0(key->partnatts * sizeof(bool));
920922
key->parttypalign = (char *) palloc0(key->partnatts * sizeof(char));
921923
key->parttypcoll = (Oid *) palloc0(key->partnatts * sizeof(Oid));
924+
MemoryContextSwitchTo(oldcxt);
922925

923-
/* For the hash partitioning, an extended hash function will be used. */
926+
/* determine support function number to search for */
924927
procnum = (key->strategy == PARTITION_STRATEGY_HASH) ?
925928
HASHEXTENDED_PROC : BTORDER_PROC;
926929

@@ -952,7 +955,7 @@ RelationBuildPartitionKey(Relation relation)
952955
if (!OidIsValid(funcid))
953956
ereport(ERROR,
954957
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
955-
errmsg("operator class \"%s\" of access method %s is missing support function %d for data type \"%s\"",
958+
errmsg("operator class \"%s\" of access method %s is missing support function %d for type %s",
956959
NameStr(opclassform->opcname),
957960
(key->strategy == PARTITION_STRATEGY_HASH) ?
958961
"hash" : "btree",
@@ -989,11 +992,13 @@ RelationBuildPartitionKey(Relation relation)
989992

990993
ReleaseSysCache(tuple);
991994

992-
/* Success --- make the relcache point to the newly constructed key */
995+
/*
996+
* Success --- reparent our context and make the relcache point to the
997+
* newly constructed key
998+
*/
993999
MemoryContextSetParent(partkeycxt, CacheMemoryContext);
9941000
relation->rd_partkeycxt = partkeycxt;
9951001
relation->rd_partkey = key;
996-
MemoryContextSwitchTo(oldcxt);
9971002
}
9981003

9991004
/*

src/bin/pgbench/exprparse.y

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ static const struct
194194
{
195195
"random_zipfian", 3, PGBENCH_RANDOM_ZIPFIAN
196196
},
197+
{
198+
"pow", 2, PGBENCH_POW
199+
},
200+
{
201+
"power", 2, PGBENCH_POW
202+
},
197203
/* keep as last array element */
198204
{
199205
NULL, 0, 0

src/bin/pgbench/pgbench.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,6 +1850,24 @@ evalFunc(TState *thread, CState *st,
18501850
return true;
18511851
}
18521852

1853+
case PGBENCH_POW:
1854+
{
1855+
PgBenchValue *lval = &vargs[0];
1856+
PgBenchValue *rval = &vargs[1];
1857+
double ld,
1858+
rd;
1859+
1860+
Assert(nargs == 2);
1861+
1862+
if (!coerceToDouble(lval, &ld) ||
1863+
!coerceToDouble(rval, &rd))
1864+
return false;
1865+
1866+
setDoubleValue(retval, pow(ld, rd));
1867+
1868+
return true;
1869+
}
1870+
18531871
default:
18541872
/* cannot get here */
18551873
Assert(0);

src/bin/pgbench/pgbench.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ typedef enum PgBenchFunction
7676
PGBENCH_RANDOM,
7777
PGBENCH_RANDOM_GAUSSIAN,
7878
PGBENCH_RANDOM_EXPONENTIAL,
79-
PGBENCH_RANDOM_ZIPFIAN
79+
PGBENCH_RANDOM_ZIPFIAN,
80+
PGBENCH_POW
8081
} PgBenchFunction;
8182

8283
typedef struct PgBenchExpr PgBenchExpr;

src/bin/pgbench/t/001_pgbench_with_server.pl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,17 @@ sub pgbench
232232
qr{command=19.: double 19\b},
233233
qr{command=20.: double 20\b},
234234
qr{command=21.: int 9223372036854775807\b},
235-
qr{command=23.: int [1-9]\b}, ],
235+
qr{command=23.: int [1-9]\b},
236+
qr{command=24.: double -27\b},
237+
qr{command=25.: double 1024\b},
238+
qr{command=26.: double 1\b},
239+
qr{command=27.: double 1\b},
240+
qr{command=28.: double -0.125\b},
241+
qr{command=29.: double -0.125\b},
242+
qr{command=30.: double -0.00032\b},
243+
qr{command=31.: double 8.50705917302346e\+37\b},
244+
qr{command=32.: double 1e\+30\b},
245+
],
236246
'pgbench expressions',
237247
{ '001_pgbench_expressions' => q{-- integer functions
238248
\set i1 debug(random(1, 100))
@@ -264,6 +274,16 @@ sub pgbench
264274
\set i1 0
265275
-- yet another integer function
266276
\set id debug(random_zipfian(1, 9, 1.3))
277+
--- pow and power
278+
\set poweri debug(pow(-3,3))
279+
\set powerd debug(pow(2.0,10))
280+
\set poweriz debug(pow(0,0))
281+
\set powerdz debug(pow(0.0,0.0))
282+
\set powernegi debug(pow(-2,-3))
283+
\set powernegd debug(pow(-2.0,-3.0))
284+
\set powernegd2 debug(power(-5.0,-5.0))
285+
\set powerov debug(pow(9223372036854775807, 2))
286+
\set powerov2 debug(pow(10,30))
267287
} });
268288

269289
# backslash commands

src/include/access/hash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ typedef HashMetaPageData *HashMetaPage;
338338

339339
/*
340340
* When a new operator class is declared, we require that the user supply
341-
* us with an amproc procudure for hashing a key of the new type, returning
341+
* us with an amproc procedure for hashing a key of the new type, returning
342342
* a 32-bit hash value. We call this the "standard" hash procedure. We
343343
* also allow an optional "extended" hash procedure which accepts a salt and
344344
* returns a 64-bit hash value. This is highly recommended but, for reasons

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/tonybelloni/postgres/commit/#start-of-content

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy