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

Commit2fcdddd

Browse files
akorotkovzilder
authored andcommitted
Make restrictions from wrappers.
1 parentd5f50e3 commit2fcdddd

File tree

3 files changed

+92
-13
lines changed

3 files changed

+92
-13
lines changed

‎contrib/pathman/pathman.c

Lines changed: 72 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ static void my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry
4747
staticPlannedStmt*my_planner_hook(Query*parse,intcursorOptions,ParamListInfoboundParams);
4848

4949
staticvoidappend_child_relation(PlannerInfo*root,RelOptInfo*rel,Indexrti,
50-
RangeTblEntry*rte,intindex,intchildOID,List*wrappers);
50+
RangeTblEntry*rte,intindex,OidchildOID,List*wrappers);
51+
staticNode*wrapper_make_expression(WrapperNode*wrap,intindex,bool*alwaysTrue);
5152
staticvoidset_pathkeys(PlannerInfo*root,RelOptInfo*childrel,Path*path);
5253
staticvoiddisable_inheritance(Query*parse);
5354

@@ -206,7 +207,6 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
206207
List*ranges,
207208
*wrappers;
208209
ListCell*lc;
209-
intchildOID=-1;
210210
inti;
211211
Oid*dsm_arr;
212212

@@ -265,13 +265,12 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
265265
foreach(lc,ranges)
266266
{
267267
IndexRangeirange=lfirst_irange(lc);
268-
inti;
269268
OidchildOid;
270269

271270
for (i=irange_lower(irange);i <=irange_upper(irange);i++)
272271
{
273272
childOid=dsm_arr[i];
274-
append_child_relation(root,rel,rti,rte,i,childOID,wrappers);
273+
append_child_relation(root,rel,rti,rte,i,childOid,wrappers);
275274
}
276275
}
277276

@@ -289,7 +288,7 @@ my_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
289288

290289
staticvoid
291290
append_child_relation(PlannerInfo*root,RelOptInfo*rel,Indexrti,
292-
RangeTblEntry*rte,intindex,intchildOID,List*wrappers)
291+
RangeTblEntry*rte,intindex,OidchildOid,List*wrappers)
293292
{
294293
RangeTblEntry*childrte;
295294
RelOptInfo*childrel;
@@ -305,7 +304,7 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
305304

306305
/* Create RangeTblEntry for child relation */
307306
childrte=copyObject(rte);
308-
childrte->relid=childOID;
307+
childrte->relid=childOid;
309308
childrte->inh= false;
310309
childrte->requiredPerms=0;
311310
root->parse->rtable=lappend(root->parse->rtable,childrte);
@@ -329,15 +328,17 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
329328

330329
/* copy restrictions */
331330
childrel->baserestrictinfo=NIL;
332-
foreach(lc,rel->baserestrictinfo)
331+
foreach(lc,wrappers)
333332
{
334-
Node*new_rinfo;
333+
boolalwaysTrue;
334+
WrapperNode*wrap= (WrapperNode*)lfirst(lc);
335+
Node*new_rinfo=wrapper_make_expression(wrap,index,&alwaysTrue);
335336

336-
node= (Node*)lfirst(lc);
337-
new_rinfo=copyObject(node);
337+
if (alwaysTrue)
338+
continue;
339+
Assert(new_rinfo);
338340

339341
/* replace old relids with new ones */
340-
// change_varnos_in_restrinct_info(new_rinfo, rel->relid, childrel->relid);
341342
change_varnos(new_rinfo,rel->relid,childrel->relid);
342343

343344
childrel->baserestrictinfo=lappend(childrel->baserestrictinfo,
@@ -353,7 +354,65 @@ append_child_relation(PlannerInfo *root, RelOptInfo *rel, Index rti,
353354
root->total_table_pages+= (double)childrel->pages;
354355

355356
ereport(LOG,
356-
(errmsg("Relation %u appended",childOID)));
357+
(errmsg("Relation %u appended",childOid)));
358+
}
359+
360+
staticNode*
361+
wrapper_make_expression(WrapperNode*wrap,intindex,bool*alwaysTrue)
362+
{
363+
boollossy,found;
364+
365+
*alwaysTrue= false;
366+
found=irange_list_find(wrap->rangeset,index,&lossy);
367+
if (!found)
368+
returnNULL;
369+
if (!lossy)
370+
{
371+
*alwaysTrue= true;
372+
returnNULL;
373+
}
374+
375+
if (IsA(wrap->orig,BoolExpr))
376+
{
377+
constBoolExpr*expr= (constBoolExpr*)wrap->orig;
378+
BoolExpr*result;
379+
380+
if (expr->boolop==OR_EXPR||expr->boolop==AND_EXPR)
381+
{
382+
ListCell*lc;
383+
List*args;
384+
385+
foreach (lc,wrap->args)
386+
{
387+
Node*arg;
388+
389+
arg=wrapper_make_expression((WrapperNode*)lfirst(lc),index,alwaysTrue);
390+
Assert(!(*alwaysTrue));
391+
Assert(arg||*alwaysTrue);
392+
if (arg)
393+
args=lappend(args,arg);
394+
}
395+
396+
Assert(list_length(args)>1);
397+
if (list_length(args)==1)
398+
return (Node*)linitial(args);
399+
400+
result= (BoolExpr*)palloc(sizeof(BoolExpr));
401+
result->xpr.type=T_BoolExpr;
402+
result->args=args;
403+
result->boolop=expr->boolop;
404+
result->location=expr->location;
405+
return (Node*)result;
406+
}
407+
else
408+
{
409+
returncopyObject(wrap->orig);
410+
}
411+
}
412+
else
413+
{
414+
returncopyObject(wrap->orig);
415+
}
357416
}
358417

359418

@@ -686,6 +745,7 @@ handle_boolexpr(const BoolExpr *expr, const PartRelationInfo *prel)
686745
result->rangeset=irange_list_intersect(result->rangeset,arg->rangeset);
687746
break;
688747
default:
748+
result->rangeset=list_make1_irange(make_irange(0,prel->children_count-1, false));
689749
break;
690750
}
691751
}

‎contrib/pathman/pathman.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ IndexRange irange_intersect(IndexRange a, IndexRange b);
164164
List*irange_list_union(List*a,List*b);
165165
List*irange_list_intersect(List*a,List*b);
166166
intirange_list_length(List*rangeset);
167+
boolirange_list_find(List*rangeset,intindex,bool*lossy);
167168

168169

169170
LWLock*load_config_lock;
@@ -175,7 +176,7 @@ LWLock *dsm_init_lock;
175176
// void free_dsm_array(DsmArray *array);
176177
// void *get_dsm_array(const ArrayPtr* ptr);
177178

178-
voidalloc_dsm_table();
179+
voidalloc_dsm_table(void);
179180
voidcreate_dsm_segment(size_tblock_size);
180181
voidinit_dsm_table(Table*tbl,dsm_handleh,size_tblock_size);
181182
voidalloc_dsm_array(DsmArray*arr,size_tentry_size,size_tlength);

‎contrib/pathman/rangeset.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,21 @@ irange_list_length(List *rangeset)
169169
}
170170
returnresult;
171171
}
172+
173+
bool
174+
irange_list_find(List*rangeset,intindex,bool*lossy)
175+
{
176+
ListCell*lc;
177+
178+
foreach (lc,rangeset)
179+
{
180+
IndexRangeirange=lfirst_irange(lc);
181+
if (index >=irange_lower(irange)&&index <=irange_upper(irange))
182+
{
183+
if (lossy)
184+
*lossy=irange_is_lossy(irange);
185+
return true;
186+
}
187+
}
188+
return false;
189+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp