Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3b528e7

Browse files
committed
Add compat version of BeginCopyFrom and DoCopy routines
1 parent8be8a19 commit3b528e7

File tree

6 files changed

+93
-53
lines changed

6 files changed

+93
-53
lines changed

‎expected/pathman_utility_stmt.out

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,13 @@ SELECT create_hash_partitions('rename.test', 'a', 3);
294294

295295
ALTER TABLE rename.test_0 RENAME TO test_one;
296296
/* We expect to find check constraint renamed as well */
297-
\d+ rename.test_one
298-
Table "rename.test_one"
299-
Column | Type | Modifiers | Storage | Stats target | Description
300-
--------+---------+---------------------------------------------------------+---------+--------------+-------------
301-
a | integer | not null default nextval('rename.test_a_seq'::regclass) | plain | |
302-
b | integer | | plain | |
303-
Check constraints:
304-
"pathman_test_one_check" CHECK (get_hash_part_idx(hashint4(a), 3) = 0)
305-
Inherits: rename.test
297+
SELECT r.conname, pg_get_constraintdef(r.oid, true)
298+
FROM pg_constraint r
299+
WHERE r.conrelid = 'rename.test_one'::regclass AND r.contype = 'c';
300+
conname | pg_get_constraintdef
301+
------------------------+-----------------------------------------------
302+
pathman_test_one_check | CHECK (get_hash_part_idx(hashint4(a), 3) = 0)
303+
(1 row)
306304

307305
/* Generates check constraint for relation */
308306
CREATE OR REPLACE FUNCTION add_constraint(rel regclass)
@@ -329,15 +327,14 @@ SELECT add_constraint('rename.test_inh_1');
329327
(1 row)
330328

331329
ALTER TABLE rename.test_inh_1 RENAME TO test_inh_one;
332-
\d+ rename.test_inh_one
333-
Table "rename.test_inh_one"
334-
Column | Type | Modifiers | Storage | Stats target | Description
335-
--------+---------+---------------------------------------------------------+---------+--------------+-------------
336-
a | integer | not null default nextval('rename.test_a_seq'::regclass) | plain | |
337-
b | integer | | plain | |
338-
Check constraints:
339-
"pathman_test_inh_1_check" CHECK (a < 100)
340-
Inherits: rename.test_inh
330+
/* Show check constraints of rename.test_inh_one */
331+
SELECT r.conname, pg_get_constraintdef(r.oid, true)
332+
FROM pg_constraint r
333+
WHERE r.conrelid = 'rename.test_inh_one'::regclass AND r.contype = 'c';
334+
conname | pg_get_constraintdef
335+
--------------------------+----------------------
336+
pathman_test_inh_1_check | CHECK (a < 100)
337+
(1 row)
341338

342339
/* Check that plain tables are not affected too */
343340
CREATE TABLE rename.plain_test(a serial, b int);
@@ -348,24 +345,24 @@ SELECT add_constraint('rename.plain_test_renamed');
348345

349346
(1 row)
350347

351-
\d+rename.plain_test_renamed
352-
Table "rename.plain_test_renamed"
353-
Column | Type | Modifiers | Storage | Stats target | Description
354-
--------+---------+---------------------------------------------------------------+---------+--------------+-------------
355-
a| integer | not null default nextval('rename.plain_test_a_seq'::regclass) | plain| |
356-
b | integer | | plain | |
357-
Check constraints:
358-
"pathman_plain_test_renamed_check" CHECK (a < 100)
348+
/* Show check constraints ofrename.plain_test_renamed */
349+
SELECT r.conname, pg_get_constraintdef(r.oid, true)
350+
FROM pg_constraint r
351+
WHERE r.conrelid = 'rename.plain_test_renamed'::regclass AND r.contype = 'c';
352+
conname| pg_get_constraintdef
353+
----------------------------------+----------------------
354+
pathman_plain_test_renamed_check | CHECK (a < 100)
355+
(1 row)
359356

360357
ALTER TABLE rename.plain_test_renamed RENAME TO plain_test;
361-
\d+rename.plain_test
362-
Table "rename.plain_test"
363-
Column | Type | Modifiers | Storage | Stats target | Description
364-
--------+---------+---------------------------------------------------------------+---------+--------------+-------------
365-
a| integer | not null default nextval('rename.plain_test_a_seq'::regclass) | plain| |
366-
b | integer | | plain | |
367-
Check constraints:
368-
"pathman_plain_test_renamed_check" CHECK (a < 100)
358+
/* ... and check constraints ofrename.plain_test */
359+
SELECT r.conname, pg_get_constraintdef(r.oid, true)
360+
FROM pg_constraint r
361+
WHERE r.conrelid = 'rename.plain_test'::regclass AND r.contype = 'c';
362+
conname| pg_get_constraintdef
363+
----------------------------------+----------------------
364+
pathman_plain_test_renamed_check | CHECK (a < 100)
365+
(1 row)
369366

370367
DROP SCHEMA rename CASCADE;
371368
NOTICE: drop cascades to 7 other objects

‎sql/pathman_utility_stmt.sql

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ CREATE TABLE rename.test(a serial, b int);
168168
SELECT create_hash_partitions('rename.test','a',3);
169169
ALTERTABLErename.test_0 RENAME TO test_one;
170170
/* We expect to find check constraint renamed as well*/
171-
\d+rename.test_one
171+
SELECTr.conname, pg_get_constraintdef(r.oid, true)
172+
FROM pg_constraint r
173+
WHEREr.conrelid='rename.test_one'::regclassANDr.contype='c';
172174

173175
/* Generates check constraint for relation*/
174176
CREATE OR REPLACEFUNCTIONadd_constraint(rel regclass)
@@ -191,15 +193,25 @@ CREATE TABLE rename.test_inh_1 (LIKE rename.test INCLUDING ALL);
191193
ALTERTABLErename.test_inh_1 INHERITrename.test_inh;
192194
SELECT add_constraint('rename.test_inh_1');
193195
ALTERTABLErename.test_inh_1 RENAME TO test_inh_one;
194-
\d+rename.test_inh_one
196+
/* Show check constraints of rename.test_inh_one*/
197+
SELECTr.conname, pg_get_constraintdef(r.oid, true)
198+
FROM pg_constraint r
199+
WHEREr.conrelid='rename.test_inh_one'::regclassANDr.contype='c';
195200

196201
/* Check that plain tables are not affected too*/
197202
CREATETABLErename.plain_test(aserial, bint);
198203
ALTERTABLErename.plain_test RENAME TO plain_test_renamed;
199204
SELECT add_constraint('rename.plain_test_renamed');
200-
\d+rename.plain_test_renamed
205+
/* Show check constraints of rename.plain_test_renamed*/
206+
SELECTr.conname, pg_get_constraintdef(r.oid, true)
207+
FROM pg_constraint r
208+
WHEREr.conrelid='rename.plain_test_renamed'::regclassANDr.contype='c';
209+
201210
ALTERTABLErename.plain_test_renamed RENAME TO plain_test;
202-
\d+rename.plain_test
211+
/* ... and check constraints of rename.plain_test*/
212+
SELECTr.conname, pg_get_constraintdef(r.oid, true)
213+
FROM pg_constraint r
214+
WHEREr.conrelid='rename.plain_test'::regclassANDr.contype='c';
203215

204216
DROPSCHEMA rename CASCADE;
205217

‎src/hooks.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,8 @@ pathman_process_utility_hook(PlannedStmt *pstmt,
771771
DestReceiver*dest,char*completionTag)
772772
{
773773
Node*parsetree=pstmt->utilityStmt;
774+
intstmt_location=pstmt->stmt_location,
775+
stmt_len=pstmt->stmt_len;
774776
#else
775777
pathman_process_utility_hook(Node*parsetree,
776778
constchar*queryString,
@@ -779,6 +781,8 @@ pathman_process_utility_hook(Node *parsetree,
779781
DestReceiver*dest,
780782
char*completionTag)
781783
{
784+
intstmt_location=-1,
785+
stmt_len=0;
782786
#endif
783787

784788
if (IsPathmanReady())
@@ -793,7 +797,8 @@ pathman_process_utility_hook(Node *parsetree,
793797
uint64processed;
794798

795799
/* Handle our COPY case (and show a special cmd name) */
796-
PathmanDoCopy((CopyStmt*)parsetree,queryString,&processed);
800+
PathmanDoCopy((CopyStmt*)parsetree,queryString,stmt_location,
801+
stmt_len,&processed);
797802
if (completionTag)
798803
snprintf(completionTag,COMPLETION_TAG_BUFSIZE,
799804
"PATHMAN COPY "UINT64_FORMAT,processed);

‎src/include/compat/pg_compat.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@
6060
#endif
6161

6262

63+
/*
64+
* BeginCopyFrom()
65+
*/
66+
#ifPG_VERSION_NUM >=100000
67+
#defineBeginCopyFromCompat(pstate,rel,filename,is_program,data_source_cb, \
68+
attnamelist,options) \
69+
BeginCopyFrom((pstate), (rel), (filename), (is_program), \
70+
(data_source_cb), (attnamelist), (options))
71+
#elifPG_VERSION_NUM >=90500
72+
#defineBeginCopyFromCompat(pstate,rel,filename,is_program,data_source_cb, \
73+
attnamelist,options) \
74+
BeginCopyFrom((rel), (filename), (is_program), (attnamelist), (options))
75+
#endif
76+
77+
6378
/*
6479
* Define ALLOCSET_DEFAULT_SIZES for our precious MemoryContexts
6580
*/
@@ -184,6 +199,18 @@ extern void create_plain_partial_paths(PlannerInfo *root,
184199
#endif
185200

186201

202+
/*
203+
* DoCopy()
204+
*/
205+
#ifPG_VERSION_NUM >=100000
206+
#defineDoCopyCompat(pstate,copy_stmt,stmt_location,stmt_len,processed) \
207+
DoCopy((pstate), (copy_stmt), (stmt_location), (stmt_len), (processed))
208+
#elifPG_VERSION_NUM >=90500
209+
#defineDoCopyCompat(pstate,copy_stmt,stmt_location,stmt_len,processed) \
210+
DoCopy((copy_stmt), (pstate)->p_sourcetext, (processed))
211+
#endif
212+
213+
187214
/*
188215
* ExecBuildProjectionInfo
189216
*/

‎src/include/utility_stmt_hooking.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ bool is_pathman_related_alter_column_type(Node *parsetree,
3030
PartType*part_type_out);
3131

3232
/* Statement handlers */
33-
voidPathmanDoCopy(constCopyStmt*stmt,constchar*queryString,uint64*processed);
33+
voidPathmanDoCopy(constCopyStmt*stmt,constchar*queryString,
34+
intstmt_location,intstmt_len,uint64*processed);
3435
voidPathmanRenameConstraint(Oidpartition_relid,
3536
constRenameStmt*partition_rename_stmt);
3637

‎src/utility_stmt_hooking.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,16 @@ CopyGetAttnums(TupleDesc tupDesc, Relation rel, List *attnamelist)
325325
* NOTE: based on DoCopy() (see copy.c).
326326
*/
327327
void
328-
PathmanDoCopy(constCopyStmt*stmt,constchar*queryString,uint64*processed)
328+
PathmanDoCopy(constCopyStmt*stmt,constchar*queryString,intstmt_location,
329+
intstmt_len,uint64*processed)
329330
{
330331
CopyStatecstate;
331332
boolis_from=stmt->is_from;
332333
boolpipe= (stmt->filename==NULL);
333334
Relationrel;
334335
Node*query=NULL;
335336
List*range_table=NIL;
337+
ParseState*pstate;
336338

337339
/* Disallow COPY TO/FROM file or program except to superusers. */
338340
if (!pipe&& !superuser())
@@ -481,6 +483,9 @@ PathmanDoCopy(const CopyStmt *stmt, const char *queryString, uint64 *processed)
481483
/* This should never happen (see is_pathman_related_copy()) */
482484
elseelog(ERROR,"error in function "CppAsString(PathmanDoCopy));
483485

486+
pstate=make_parsestate(NULL);
487+
pstate->p_sourcetext=queryString;
488+
484489
/* COPY ... FROM ... */
485490
if (is_from)
486491
{
@@ -495,13 +500,9 @@ PathmanDoCopy(const CopyStmt *stmt, const char *queryString, uint64 *processed)
495500
PreventCommandIfReadOnly("PATHMAN COPY FROM");
496501
PreventCommandIfParallelMode("PATHMAN COPY FROM");
497502

498-
#ifPG_VERSION_NUM >=100000
499-
cstate=BeginCopyFrom(NULL,rel,stmt->filename,stmt->is_program,
500-
NULL,stmt->attlist,stmt->options);
501-
#else
502-
cstate=BeginCopyFrom(rel,stmt->filename,stmt->is_program,
503-
stmt->attlist,stmt->options);
504-
#endif
503+
cstate=BeginCopyFromCompat(pstate,rel,stmt->filename,
504+
stmt->is_program,NULL,stmt->attlist,
505+
stmt->options);
505506
*processed=PathmanCopyFrom(cstate,rel,range_table,is_old_protocol);
506507
EndCopyFrom(cstate);
507508
}
@@ -519,11 +520,8 @@ PathmanDoCopy(const CopyStmt *stmt, const char *queryString, uint64 *processed)
519520
modified_copy_stmt.query=query;
520521

521522
/* Call standard DoCopy using a new CopyStmt */
522-
#ifPG_VERSION_NUM >=100000
523-
DoCopy(NULL,&modified_copy_stmt,0,0,processed);
524-
#else
525-
DoCopy(&modified_copy_stmt,queryString,processed);
526-
#endif
523+
DoCopyCompat(pstate,&modified_copy_stmt,stmt_location,stmt_len,
524+
processed);
527525
}
528526

529527
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp