Skip to content

Provide timings for FDW queries #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion contrib/postgres_fdw/postgres_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include "utils/rel.h"
#include "utils/sampling.h"

#include <sys/time.h>
#include <time.h>

PG_MODULE_MAGIC;

/* Default CPU cost to start up a foreign query. */
Expand Down Expand Up @@ -74,7 +77,7 @@ typedef struct PgFdwRelationInfo
bool use_remote_estimate;
Cost fdw_startup_cost;
Cost fdw_tuple_cost;

/* Cached catalog information. */
ForeignTable *table;
ForeignServer *server;
Expand Down Expand Up @@ -154,6 +157,9 @@ typedef struct PgFdwScanState
int fetch_ct_2; /* Min(# of fetches done, 2) */
bool eof_reached; /* true if last fetch reached EOF */

/* Timing */
struct timeval start_time;

/* working memory contexts */
MemoryContext batch_cxt; /* context holding current batch of tuples */
MemoryContext temp_cxt; /* context for per-tuple temporary data */
Expand Down Expand Up @@ -1019,7 +1025,10 @@ postgresIterateForeignScan(ForeignScanState *node)
* cursor on the remote side.
*/
if (!fsstate->cursor_exists)
{
gettimeofday(&(fsstate->start_time), NULL);
create_cursor(node);
}

/*
* Get some more tuples, if we've run out.
Expand Down Expand Up @@ -1116,7 +1125,15 @@ postgresEndForeignScan(ForeignScanState *node)

/* Close the cursor if open, to prevent accumulation of cursors */
if (fsstate->cursor_exists)
{
struct timeval end_time;
double secs;
gettimeofday(&end_time, NULL);
secs = 1000 * end_time.tv_sec + end_time.tv_usec/1000.0;
secs -= 1000 * (fsstate->start_time).tv_sec + (fsstate->start_time).tv_usec/1000.0;
elog(DEBUG1, "FDW Query Duration: %.3lf ms", secs);
close_cursor(fsstate->conn, fsstate->cursor_number);
}

/* Release remote connection */
ReleaseConnection(fsstate->conn);
Expand Down
86 changes: 46 additions & 40 deletions src/bin/initdb/initdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ static const char *backend_options = "--single -F -O -c search_path=pg_catalog -

static const char *subdirs[] = {
"global",
"pg_xlog",
"pg_xlog/archive_status",
"pg_clog",
"pg_commit_ts",
Expand All @@ -199,6 +198,7 @@ static const char *subdirs[] = {
"pg_snapshots",
"pg_subtrans",
"pg_twophase",
"pg_multixact",
"pg_multixact/members",
"pg_multixact/offsets",
"base",
Expand Down Expand Up @@ -236,7 +236,6 @@ static FILE *popen_check(const char *command, const char *mode);
static void exit_nicely(void);
static char *get_id(void);
static char *get_encoding_id(char *encoding_name);
static bool mkdatadir(const char *subdir);
static void set_input(char **dest, char *filename);
static void check_input(char *path);
static void write_version_file(char *extrapath);
Expand Down Expand Up @@ -276,7 +275,7 @@ void setup_locale_encoding(void);
void setup_signals(void);
void setup_text_search(void);
void create_data_directory(void);
void create_xlog_symlink(void);
void create_xlog_or_symlink(void);
void warn_on_mount_point(int error);
void initialize_data_directory(void);

Expand Down Expand Up @@ -924,29 +923,6 @@ find_matching_ts_config(const char *lc_type)
}


/*
* make the data directory (or one of its subdirectories if subdir is not NULL)
*/
static bool
mkdatadir(const char *subdir)
{
char *path;

if (subdir)
path = psprintf("%s/%s", pg_data, subdir);
else
path = pg_strdup(pg_data);

if (pg_mkdir_p(path, S_IRWXU) == 0)
return true;

fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
progname, path, strerror(errno));

return false;
}


/*
* set name of given input file variable under data directory
*/
Expand Down Expand Up @@ -3134,8 +3110,12 @@ create_data_directory(void)
pg_data);
fflush(stdout);

if (!mkdatadir(NULL))
if (pg_mkdir_p(pg_data, S_IRWXU) != 0)
{
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
progname, pg_data, strerror(errno));
exit_nicely();
}
else
check_ok();

Expand Down Expand Up @@ -3186,13 +3166,17 @@ create_data_directory(void)
}


/* Create transaction log directory, and symlink if required */
void
create_xlog_symlink(void)
create_xlog_or_symlink(void)
{
/* Create transaction log symlink, if required */
char *subdirloc;

/* form name of the place for the subdirectory or symlink */
subdirloc = psprintf("%s/pg_xlog", pg_data);

if (strcmp(xlog_dir, "") != 0)
{
char *linkloc;
int ret;

/* clean up xlog directory name, check it's absolute */
Expand Down Expand Up @@ -3265,22 +3249,30 @@ create_xlog_symlink(void)
exit_nicely();
}

/* form name of the place where the symlink must go */
linkloc = psprintf("%s/pg_xlog", pg_data);

#ifdef HAVE_SYMLINK
if (symlink(xlog_dir, linkloc) != 0)
if (symlink(xlog_dir, subdirloc) != 0)
{
fprintf(stderr, _("%s: could not create symbolic link \"%s\": %s\n"),
progname, linkloc, strerror(errno));
progname, subdirloc, strerror(errno));
exit_nicely();
}
#else
fprintf(stderr, _("%s: symlinks are not supported on this platform"));
exit_nicely();
#endif
free(linkloc);
}
else
{
/* Without -X option, just make the subdirectory normally */
if (mkdir(subdirloc, S_IRWXU) < 0)
{
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
progname, subdirloc, strerror(errno));
exit_nicely();
}
}

free(subdirloc);
}


Expand Down Expand Up @@ -3311,16 +3303,30 @@ initialize_data_directory(void)

create_data_directory();

create_xlog_symlink();
create_xlog_or_symlink();

/* Create required subdirectories */
/* Create required subdirectories (other than pg_xlog) */
printf(_("creating subdirectories ... "));
fflush(stdout);

for (i = 0; i < (sizeof(subdirs) / sizeof(char *)); i++)
for (i = 0; i < lengthof(subdirs); i++)
{
if (!mkdatadir(subdirs[i]))
char *path;

path = psprintf("%s/%s", pg_data, subdirs[i]);

/*
* The parent directory already exists, so we only need mkdir() not
* pg_mkdir_p() here, which avoids some failure modes; cf bug #13853.
*/
if (mkdir(path, S_IRWXU) < 0)
{
fprintf(stderr, _("%s: could not create directory \"%s\": %s\n"),
progname, path, strerror(errno));
exit_nicely();
}

free(path);
}

check_ok();
Expand Down
2 changes: 1 addition & 1 deletion src/include/port/atomics/arch-x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ typedef struct pg_atomic_uint32

/*
* It's too complicated to write inline asm for 64bit types on 32bit and the
* 468 can't do it.
* 486 can't do it.
*/
#ifdef __x86_64__
#define PG_HAVE_ATOMIC_U64_SUPPORT
Expand Down
1 change: 1 addition & 0 deletions src/pl/plpython/expected/README
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Guide to alternative expected files:

plpython_error_0.out Python 2.4 and older
plpython_error_5.out Python 3.5 and newer

plpython_unicode.out server encoding != SQL_ASCII
plpython_unicode_3.out server encoding == SQL_ASCII
Expand Down
Loading