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

Commitfd1be3a

Browse files
committed
Merge commit 'a91935a781c62bdd05711a85837e6db36f43e296' into PGPRO9_6
2 parentscdc1f26 +a91935a commitfd1be3a

File tree

7 files changed

+216
-78
lines changed

7 files changed

+216
-78
lines changed

‎contrib/pg_pathman/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ Modify the **`shared_preload_libraries`** parameter in `postgresql.conf` as foll
6666
```
6767
shared_preload_libraries = 'pg_pathman'
6868
```
69+
>**Important:**`pg_pathman` may have conflicts with some other extensions which uses the same hook functions. For example,`pg_pathman` uses`ProcessUtility_hook` hook to handle COPY queries for partitioned tables. And it could sometimes interfere with`pg_stat_statements` extension which uses the same hook. In this case try to list libraries in certain order:`shared_preload_libraries = 'pg_pathman, pg_stat_statements'`
70+
6971
It is essential to restart the PostgreSQL instance. After that, execute the following query in psql:
7072
```plpgsql
7173
CREATE EXTENSION pg_pathman;

‎contrib/pg_pathman/expected/pathman_basic.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
\set VERBOSITY terse
2+
SET search_path = 'public';
23
CREATE SCHEMA pathman;
34
CREATE EXTENSION pg_pathman SCHEMA pathman;
45
CREATE SCHEMA test;

‎contrib/pg_pathman/sql/pathman_basic.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
\set VERBOSITY terse
22

3+
SET search_path='public';
34
CREATESCHEMApathman;
45
CREATE EXTENSION pg_pathman SCHEMA pathman;
56
CREATESCHEMAtest;

‎contrib/pg_pathman/src/copy_stmt_hooking.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@
3535
#include"libpq/libpq.h"
3636

3737

38+
/*
39+
* Determine whether we should enable COPY or not (PostgresPro has a fix).
40+
*/
41+
#if defined(WIN32)&& !defined(PGPRO_PATHMAN_AWARE_COPY)
42+
#defineDISABLE_PATHMAN_COPY
43+
#endif
44+
45+
/*
46+
* While building PostgreSQL on Windows the msvc compiler produces .def file
47+
* which contains all the symbols that were declared as external except the ones
48+
* that were declared but not defined. We redefine variables below to prevent
49+
* 'unresolved symbol' errors on Windows. But we have to disable COPY feature
50+
* on Windows.
51+
*/
52+
#ifdefDISABLE_PATHMAN_COPY
53+
boolXactReadOnly= false;
54+
ProtocolVersionFrontendProtocol= (ProtocolVersion)0;
55+
#endif
56+
57+
3858
staticuint64PathmanCopyFrom(CopyStatecstate,
3959
Relationparent_rel,
4060
List*range_table,
@@ -94,7 +114,14 @@ is_pathman_related_copy(Node *parsetree)
94114
elog(ERROR,"freeze is not supported for partitioned tables");
95115
}
96116

97-
elog(DEBUG1,"Overriding default behavior for COPY [%u]",partitioned_table);
117+
/* Emit ERROR if we can't see the necessary symbols */
118+
#ifdefDISABLE_PATHMAN_COPY
119+
elog(ERROR,"COPY is not supported for partitioned tables on Windows");
120+
#else
121+
elog(DEBUG1,"Overriding default behavior for COPY [%u]",
122+
partitioned_table);
123+
#endif
124+
98125
return true;
99126
}
100127

‎contrib/pg_pathman/src/hooks.c

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pathman_join_pathlist_hook(PlannerInfo *root,
4343
JoinPathExtraData*extra)
4444
{
4545
JoinCostWorkspaceworkspace;
46+
JoinTypesaved_jointype=jointype;
4647
RangeTblEntry*inner_rte=root->simple_rte_array[innerrel->relid];
4748
constPartRelationInfo*inner_prel;
4849
List*pathkeys=NIL,
@@ -118,6 +119,12 @@ pathman_join_pathlist_hook(PlannerInfo *root,
118119

119120
/* Select cheapest path for outerrel */
120121
outer=outerrel->cheapest_total_path;
122+
if (saved_jointype==JOIN_UNIQUE_OUTER)
123+
{
124+
outer= (Path*)create_unique_path(root,outerrel,
125+
outer,extra->sjinfo);
126+
Assert(outer);
127+
}
121128

122129
/* Make innerrel path depend on outerrel's column */
123130
inner_required=bms_union(PATH_REQ_OUTER((Path*)cur_inner_path),
@@ -133,6 +140,8 @@ pathman_join_pathlist_hook(PlannerInfo *root,
133140
continue;
134141

135142
inner=create_runtimeappend_path(root,cur_inner_path,ppi,paramsel);
143+
if (saved_jointype==JOIN_UNIQUE_INNER)
144+
return;/* No way to do this with a parameterized inner path */
136145

137146
initial_cost_nestloop(root,&workspace,jointype,
138147
outer,inner,/* built paths */
@@ -204,7 +213,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
204213
Oid*children;
205214
List*ranges,
206215
*wrappers,
207-
*rel_partattr_clauses=NIL;
216+
*rel_part_clauses=NIL;
208217
PathKey*pathkeyAsc=NULL,
209218
*pathkeyDesc=NULL;
210219
doubleparamsel=1.0;
@@ -310,8 +319,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
310319
IndexRangeirange=lfirst_irange(lc);
311320

312321
for (i=irange.ir_lower;i <=irange.ir_upper;i++)
313-
append_child_relation(root,rel,rti,rte,i,children[i],
314-
wrappers);
322+
append_child_relation(root,rel,rti,rte,i,children[i],wrappers);
315323
}
316324

317325
/* Clear old path list */
@@ -327,19 +335,26 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
327335
return;
328336

329337
/* Check that rel's RestrictInfo contains partitioned column */
330-
rel_partattr_clauses=get_partitioned_attr_clauses(rel->baserestrictinfo,
331-
prel,rel->relid);
338+
rel_part_clauses=get_partitioned_attr_clauses(rel->baserestrictinfo,
339+
prel,rel->relid);
332340

333341
/* Runtime[Merge]Append is pointless if there are no params in clauses */
334-
if (!clause_contains_params((Node*)rel_partattr_clauses))
342+
if (!clause_contains_params((Node*)rel_part_clauses))
335343
return;
336344

337345
foreach (lc,rel->pathlist)
338346
{
339347
AppendPath*cur_path= (AppendPath*)lfirst(lc);
340348
Relidsinner_required=PATH_REQ_OUTER((Path*)cur_path);
341-
ParamPathInfo*ppi=get_baserel_parampathinfo(root,rel,inner_required);
342349
Path*inner_path=NULL;
350+
ParamPathInfo*ppi;
351+
List*ppi_part_clauses=NIL;
352+
353+
/* Fetch ParamPathInfo & try to extract part-related clauses */
354+
ppi=get_baserel_parampathinfo(root,rel,inner_required);
355+
if (ppi&&ppi->ppi_clauses)
356+
ppi_part_clauses=get_partitioned_attr_clauses(ppi->ppi_clauses,
357+
prel,rel->relid);
343358

344359
/* Skip if rel contains some join-related stuff or path type mismatched */
345360
if (!(IsA(cur_path,AppendPath)||IsA(cur_path,MergeAppendPath))||
@@ -352,9 +367,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
352367
* Skip if neither rel->baserestrictinfo nor
353368
* ppi->ppi_clauses reference partition attribute
354369
*/
355-
if (!(rel_partattr_clauses||
356-
(ppi&&get_partitioned_attr_clauses(ppi->ppi_clauses,
357-
prel,rel->relid))))
370+
if (!(rel_part_clauses||ppi_part_clauses))
358371
continue;
359372

360373
if (IsA(cur_path,AppendPath)&&pg_pathman_enable_runtimeappend)
@@ -600,27 +613,28 @@ pathman_process_utility_hook(Node *parsetree,
600613
DestReceiver*dest,
601614
char*completionTag)
602615
{
603-
/* Call hooks set by other extensions */
604-
if (process_utility_hook_next)
605-
process_utility_hook_next(parsetree,queryString,
606-
context,params,
607-
dest,completionTag);
608-
609616
/* Override standard COPY statement if needed */
610617
if (IsPathmanReady()&&is_pathman_related_copy(parsetree))
611618
{
612619
uint64processed;
613620

621+
/* Handle our COPY case (and show a special cmd name) */
614622
PathmanDoCopy((CopyStmt*)parsetree,queryString,&processed);
615623
if (completionTag)
616624
snprintf(completionTag,COMPLETION_TAG_BUFSIZE,
617625
"PATHMAN COPY "UINT64_FORMAT,processed);
618626

619-
return;/* don't call standard_ProcessUtility() */
627+
return;/* don't call standard_ProcessUtility()or hooks*/
620628
}
621629

622-
/* Call internal implementation */
623-
standard_ProcessUtility(parsetree,queryString,
624-
context,params,
625-
dest,completionTag);
630+
/* Call hooks set by other extensions if needed */
631+
if (process_utility_hook_next)
632+
process_utility_hook_next(parsetree,queryString,
633+
context,params,
634+
dest,completionTag);
635+
/* Else call internal implementation */
636+
else
637+
standard_ProcessUtility(parsetree,queryString,
638+
context,params,
639+
dest,completionTag);
626640
}

‎contrib/pg_pathman/src/init.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ validate_range_constraint(const Expr *expr,
841841
constTypeCacheEntry*tce;
842842
constBoolExpr*boolexpr= (constBoolExpr*)expr;
843843
constOpExpr*opexpr;
844+
intstrategy;
844845

845846
if (!expr)
846847
return false;
@@ -853,8 +854,9 @@ validate_range_constraint(const Expr *expr,
853854

854855
/* check that left operand is >= operator */
855856
opexpr= (OpExpr*)linitial(boolexpr->args);
856-
if (BTGreaterEqualStrategyNumber==get_op_opfamily_strategy(opexpr->opno,
857-
tce->btree_opf))
857+
strategy=get_op_opfamily_strategy(opexpr->opno,tce->btree_opf);
858+
859+
if (strategy==BTGreaterEqualStrategyNumber)
858860
{
859861
if (!read_opexpr_const(opexpr,prel,min))
860862
return false;
@@ -864,8 +866,9 @@ validate_range_constraint(const Expr *expr,
864866

865867
/* check that right operand is < operator */
866868
opexpr= (OpExpr*)lsecond(boolexpr->args);
867-
if (BTLessStrategyNumber==get_op_opfamily_strategy(opexpr->opno,
868-
tce->btree_opf))
869+
strategy=get_op_opfamily_strategy(opexpr->opno,tce->btree_opf);
870+
871+
if (strategy==BTLessStrategyNumber)
869872
{
870873
if (!read_opexpr_const(opexpr,prel,max))
871874
return false;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp