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

Commit1285042

Browse files
committed
pathman: behaviour on DELETE command
1 parent45f85fa commit1285042

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

‎contrib/pg_pathman/pg_pathman.c

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ static void set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rt
8989
staticList*accumulate_append_subpath(List*subpaths,Path*path);
9090
staticvoidset_pathkeys(PlannerInfo*root,RelOptInfo*childrel,Path*path);
9191

92+
staticvoidhandle_delete_query(Query*parse);
93+
9294
/*
9395
* Compare two Datums with the given comarison function
9496
*
@@ -194,7 +196,20 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
194196
}
195197

196198
inheritance_disabled= false;
197-
disable_inheritance(parse);
199+
200+
// if (parse->commandType != CMD_SELECT)
201+
202+
switch(parse->commandType)
203+
{
204+
caseCMD_SELECT:
205+
disable_inheritance(parse);
206+
break;
207+
caseCMD_DELETE:
208+
handle_delete_query(parse);
209+
break;
210+
default:
211+
break;
212+
}
198213

199214
/* Invoke original hook */
200215
if (planner_hook_original)
@@ -217,9 +232,6 @@ disable_inheritance(Query *parse)
217232
PartRelationInfo*prel;
218233
boolfound;
219234

220-
if (parse->commandType!=CMD_SELECT)
221-
return;
222-
223235
foreach(lc,parse->rtable)
224236
{
225237
rte= (RangeTblEntry*)lfirst(lc);
@@ -253,6 +265,54 @@ disable_inheritance(Query *parse)
253265
}
254266
}
255267

268+
/*
269+
* Checks if query is affects only one partition. If true then substitute
270+
*/
271+
staticvoid
272+
handle_delete_query(Query*parse)
273+
{
274+
PartRelationInfo*prel;
275+
List*ranges,
276+
*wrappers=NIL;
277+
// ListCell *lc;
278+
RangeTblEntry*rte;
279+
WrapperNode*wrap;
280+
boolfound;
281+
282+
if (list_length(parse->rtable)!=1)
283+
return;
284+
285+
rte= (RangeTblEntry*)linitial(parse->rtable);
286+
prel=get_pathman_relation_info(rte->relid,&found);
287+
288+
// foreach(lc, parse->jointree->quals)
289+
// {
290+
// WrapperNode *wrap;
291+
// Expr *expr = (Expr *) lfirst(lc);
292+
293+
// wrap = walk_expr_tree(expr, prel);
294+
ranges=list_make1_int(make_irange(0,prel->children_count-1, false));
295+
wrap=walk_expr_tree( (Expr*)parse->jointree->quals,prel);
296+
wrappers=lappend(wrappers,wrap);
297+
ranges=irange_list_intersect(ranges,wrap->rangeset);
298+
// }
299+
300+
/* If only one partition is affected then substitute parent table with partition */
301+
if (irange_list_length(ranges))
302+
{
303+
IndexRangeirange= (IndexRange)linitial_oid(ranges);
304+
elog(WARNING,"lower: %d, upper: %d, lossy: %d",irange_lower(irange),irange_upper(irange),irange_is_lossy(irange));
305+
if (irange_lower(irange)==irange_upper(irange))
306+
{
307+
Oid*children= (Oid*)dsm_array_get_pointer(&prel->children);
308+
rte->relid=children[irange_lower(irange)];
309+
rte->inh= false;
310+
}
311+
}
312+
313+
return;
314+
}
315+
256316
/*
257317
* Shared memory startup hook
258318
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp