8000 Parallel COPY FROM by ololobus · Pull Request #2 · ololobus/postgres · GitHub
[go: up one dir, main page]

Skip to content

Parallel COPY FROM #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 13 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
1,458 changes: 1,381 additions & 77 deletions src/backend/commands/copy.c

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/backend/postmaster/bgworker.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "libpq/pqsignal.h"
#include "access/parallel.h"
#include "commands/copy.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "port/atomics.h"
Expand Down Expand Up @@ -129,6 +130,9 @@ static const struct
},
{
"ApplyWorkerMain", ApplyWorkerMain
},
{
"CopyFromBgwMainLoop", CopyFromBgwMainLoop
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/backend/postmaster/pgstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -3612,6 +3612,9 @@ pgstat_get_wait_ipc(WaitEventIPC w)
case WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE:
event_name = "LogicalSyncStateChange";
break;
case WAIT_EVENT_COPY_FROM_BGWORKERS_FINISHED:
event_name = "CopyFromBGWorkersFinished";
break;
/* no default case, so that compiler will warn */
}

Expand Down
3 changes: 2 additions & 1 deletion src/backend/storage/lmgr/lwlock.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ RegisterLWLockTranches(void)

if (LWLockTrancheArray == NULL)
{
LWLockTranchesAllocated = 64;
LWLockTranchesAllocated = 128;
LWLockTrancheArray = (char **)
MemoryContextAllocZero(TopMemoryContext,
LWLockTranchesAllocated * sizeof(char *));
Expand All @@ -511,6 +511,7 @@ RegisterLWLockTranches(void)
LWLockRegisterTranche(LWTRANCHE_PARALLEL_QUERY_DSA,
"parallel_query_dsa");
LWLockRegisterTranche(LWTRANCHE_TBM, "tbm");
LWLockRegisterTranche(LWTRANCHE_COPY_FROM, "copy_from");

/* Register named tranches. */
for (i = 0; i < NamedLWLockTrancheRequests; i++)
Expand Down
1 change: 1 addition & 0 deletions src/backend/storage/lmgr/lwlocknames.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ OldSnapshotTimeMapLock 42
BackendRandomLock 43
LogicalRepWorkerLock 44
CLogTruncationLock 45
CopyFromBgwLock 46
2 changes: 1 addition & 1 deletion src/backend/tcop/utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ standard_ProcessUtility(PlannedStmt *pstmt,

DoCopy(pstate, (CopyStmt *) parsetree,
pstmt->stmt_location, pstmt->stmt_len,
&processed);
&processed, queryString, isTopLevel);
if (completionTag)
snprintf(completionTag, COMPLETION_TAG_BUFSIZE,
"COPY " UINT64_FORMAT, processed);
Expand Down
6 changes: 5 additions & 1 deletion src/include/commands/copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@

/* CopyStateData is private in commands/copy.c */
typedef struct CopyStateData *CopyState;
typedef struct CopyFromStateData *CopyFromState;
typedef int (*copy_data_source_cb) (void *outbuf, int minread, int maxread);

extern void DoCopy(ParseState *state, const CopyStmt *stmt,
int stmt_location, int stmt_len,
uint64 *processed);
uint64 *processed, const char *query_string,
bool is_top_level);

extern void ProcessCopyOptions(ParseState *pstate, CopyState cstate, bool is_from, List *options);
extern CopyState BeginCopyFrom(ParseState *pstate, Relation rel, const char *filename,
Expand All @@ -37,7 +39,9 @@ extern bool NextCopyFromRawFields(CopyState cstate,
char ***fields, int *nfields);
extern void CopyFromErrorCallback(void *arg);

extern void CopyFromBgwMainLoop(Datum main_arg);
extern uint64 CopyFrom(CopyState cstate);
extern uint64 ParallelCopyFrom(CopyState cstate, const char *query_string);

extern DestReceiver *CreateCopyDestReceiver(void);

Expand Down
3 changes: 2 additions & 1 deletion src/include/pgstat.h
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,8 @@ typedef enum
WAIT_EVENT_SAFE_SNAPSHOT,
WAIT_EVENT_SYNC_REP,
WAIT_EVENT_LOGICAL_SYNC_DATA,
WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE
WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE,
WAIT_EVENT_COPY_FROM_BGWORKERS_FINISHED
} WaitEventIPC;

/* ----------
Expand Down
1 change: 1 addition & 0 deletions src/include/storage/lwlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ typedef enum BuiltinTrancheIds
LWTRANCHE_PREDICATE_LOCK_MANAGER,
LWTRANCHE_PARALLEL_QUERY_DSA,
LWTRANCHE_TBM,
LWTRANCHE_COPY_FROM,
LWTRANCHE_FIRST_USER_DEFINED
} BuiltinTrancheIds;

Expand Down
0