• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: コミット

firtst release


コミットメタ情報

リビジョンbfcb1f0b5ef83160529e9b7329e1e7fc462a20b1 (tree)
日時2018-06-08 14:42:52
作者Kyotaro Horiguchi <horiguchi.kyotaro@lab....>
コミッターKyotaro Horiguchi

ログメッセージ

Took in (unrelated) improvement of pg_stat_statements.

Took in sevaral improvements of pg_stat_statments that have made so
far. All these changes are on unused part of the file so these don't
affect the behavior of pg_hint_plan.

bfa282a02b Avoid unlikely data-loss scenarios due to rename() without fsync.
053959397b pg_stat_statements forgot to let previous occupant of hook get control too.
b8cf89c041 Avoid unportable usage of sscanf(UINT64_FORMAT).

変更サマリ

差分

--- a/pg_stat_statements.c
+++ b/pg_stat_statements.c
@@ -4,7 +4,7 @@
44 * Track statement execution times across a whole database cluster.
55 *
66 * Execution costs are totalled for each distinct source query, and kept in
7- * a shared hashtable. (We track only as many distinct queries as will fit
7+ * a shared hashtable. (We track only as many distinct queries as will fit
88 * in the designated amount of shared memory.)
99 *
1010 * As of Postgres 9.2, this module normalizes query entries. Normalization
@@ -15,7 +15,7 @@
1515 *
1616 * Normalization is implemented by fingerprinting queries, selectively
1717 * serializing those fields of each query tree's nodes that are judged to be
18- * essential to the query. This is referred to as a query jumble. This is
18+ * essential to the query. This is referred to as a query jumble. This is
1919 * distinct from a regular serialization in that various extraneous
2020 * information is ignored as irrelevant or not essential to the query, such
2121 * as the collations of Vars and, most notably, the values of constants.
@@ -34,7 +34,7 @@
3434 * disappear!) and also take the entry's mutex spinlock.
3535 *
3636 *
37- * Copyright (c) 2008-2014, PostgreSQL Global Development Group
37+ * Copyright (c) 2008-2013, PostgreSQL Global Development Group
3838 *
3939 * IDENTIFICATION
4040 * contrib/pg_stat_statements/pg_stat_statements.c
@@ -600,11 +600,7 @@ pgss_shmem_shutdown(int code, Datum arg)
600600 /*
601601 * Rename file into place, so we atomically replace the old one.
602602 */
603- if (rename(PGSS_DUMP_FILE ".tmp", PGSS_DUMP_FILE) != 0)
604- ereport(LOG,
605- (errcode_for_file_access(),
606- errmsg("could not rename pg_stat_statement file \"%s\": %m",
607- PGSS_DUMP_FILE ".tmp")));
603+ (void) durable_rename(PGSS_DUMP_FILE ".tmp", PGSS_DUMP_FILE, LOG);
608604
609605 return;
610606
@@ -626,6 +622,9 @@ pgss_post_parse_analyze(ParseState *pstate, Query *query)
626622 {
627623 pgssJumbleState jstate;
628624
625+ if (prev_post_parse_analyze_hook)
626+ prev_post_parse_analyze_hook(pstate, query);
627+
629628 /* Assert we didn't do this already */
630629 Assert(query->queryId == 0);
631630
@@ -818,7 +817,7 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
818817 {
819818 instr_time start;
820819 instr_time duration;
821- uint64 rows = 0;
820+ uint64 rows;
822821 BufferUsage bufusage_start,
823822 bufusage;
824823 uint32 queryId;
@@ -851,7 +850,15 @@ pgss_ProcessUtility(Node *parsetree, const char *queryString,
851850
852851 /* parse command tag to retrieve the number of affected rows. */
853852 if (completionTag &&
854- sscanf(completionTag, "COPY " UINT64_FORMAT, &rows) != 1)
853+ strncmp(completionTag, "COPY ", 5) == 0)
854+ {
855+#ifdef HAVE_STRTOULL
856+ rows = strtoull(completionTag + 5, NULL, 10);
857+#else
858+ rows = strtoul(completionTag + 5, NULL, 10);
859+#endif
860+ }
861+ else
855862 rows = 0;
856863
857864 /* calc differences of buffer counters. */
@@ -1241,7 +1248,7 @@ pgss_memsize(void)
12411248 * would be difficult to demonstrate this even under artificial conditions.)
12421249 *
12431250 * Note: despite needing exclusive lock, it's not an error for the target
1244- * entry to already exist. This is because pgss_store releases and
1251+ * entry to already exist. This is because pgss_store releases and
12451252 * reacquires lock after failing to find a match; so someone else could
12461253 * have made the entry while we waited to get exclusive lock.
12471254 */
@@ -1501,7 +1508,7 @@ JumbleRangeTable(pgssJumbleState *jstate, List *rtable)
15011508 *
15021509 * Note: the reason we don't simply use expression_tree_walker() is that the
15031510 * point of that function is to support tree walkers that don't care about
1504- * most tree node types, but here we care about all types. We should complain
1511+ * most tree node types, but here we care about all types. We should complain
15051512 * about any unrecognized node type.
15061513 */
15071514 static void
@@ -2030,7 +2037,7 @@ generate_normalized_query(pgssJumbleState *jstate, const char *query,
20302037 * a problem.
20312038 *
20322039 * Duplicate constant pointers are possible, and will have their lengths
2033- * marked as '-1', so that they are later ignored. (Actually, we assume the
2040+ * marked as '-1', so that they are later ignored. (Actually, we assume the
20342041 * lengths were initialized as -1 to start with, and don't change them here.)
20352042 *
20362043 * N.B. There is an assumption that a '-' character at a Const location begins
@@ -2099,7 +2106,7 @@ fill_in_constant_lengths(pgssJumbleState *jstate, const char *query)
20992106 * adjustment of location to that of the leading '-'
21002107 * operator in the event of a negative constant. It is
21012108 * also useful for our purposes to start from the minus
2102- * symbol. In this way, queries like "select * from foo
2109+ * symbol. In this way, queries like "select * from foo
21032110 * where bar = 1" and "select * from foo where bar = -2"
21042111 * will have identical normalized query strings.
21052112 */
@@ -2143,4 +2150,3 @@ comp_location(const void *a, const void *b)
21432150 else
21442151 return 0;
21452152 }
2146-
旧リポジトリブラウザで表示