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

Commit74438aa

Browse files
committed
light refactoring, index size fetching fixed
1 parent0a3500c commit74438aa

File tree

1 file changed

+37
-25
lines changed

1 file changed

+37
-25
lines changed

‎init.c‎

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@ static CustomExecMethodscrossmatch_exec_methods;
8585
)
8686

8787

88+
staticinlineint64
89+
get_index_size(Oididx)
90+
{
91+
Datumsize=DirectFunctionCall2(pg_relation_size,
92+
ObjectIdGetDatum(idx),
93+
PointerGetDatum(cstring_to_text("main")));
94+
returnDatumGetInt64(size);
95+
}
96+
97+
staticinlineOid
98+
get_dist_func()
99+
{
100+
text*dist_func_name=
101+
cstring_to_text("public.dist(public.spoint, public.spoint)");
102+
103+
returnDatumGetObjectId(DirectFunctionCall1(to_regprocedure,
104+
PointerGetDatum(dist_func_name)));
105+
}
106+
88107
staticfloat8
89108
cstring_to_float8(char*str)
90109
{
@@ -166,10 +185,7 @@ pick_suitable_index(Oid relation, AttrNumber column)
166185

167186
if (pg_ind->indkey.values[i]==column)
168187
{
169-
cur_index_size=DatumGetInt64(
170-
DirectFunctionCall2(pg_relation_size,
171-
ObjectIdGetDatum(relation),
172-
PointerGetDatum(cstring_to_text("main"))));
188+
cur_index_size=get_index_size(pg_ind->indexrelid);
173189

174190
if (found_index==InvalidOid||cur_index_size<found_index_size)
175191
{
@@ -263,6 +279,9 @@ create_crossmatch_path(PlannerInfo *root,
263279
Oidouter_idx;
264280
Oidinner_idx;
265281

282+
if (outer_rel==inner_rel)
283+
return;
284+
266285
if ((outer_idx=pick_suitable_index(outer_rel,outer_spoint))==InvalidOid||
267286
(inner_idx=pick_suitable_index(inner_rel,inner_spoint))==InvalidOid)
268287
{
@@ -348,10 +367,17 @@ join_pathlist_hook(PlannerInfo *root,
348367
JoinPathExtraData*extra)
349368
{
350369
ListCell*restr;
351-
text*dist_func_name=cstring_to_text("dist(spoint,spoint)");
352370
Oiddist_func;
353371
Relidsrequired_relids=NULL;
354372

373+
if (set_join_pathlist_next)
374+
set_join_pathlist_next(root,joinrel,outerrel,
375+
innerrel,jointype,extra);
376+
377+
/* Get oid of the dist(spoint, spoint) function */
378+
if ((dist_func=get_dist_func())==InvalidOid)
379+
return;
380+
355381
if (outerrel->reloptkind==RELOPT_BASEREL&&
356382
innerrel->reloptkind==RELOPT_BASEREL)
357383
{
@@ -360,20 +386,6 @@ join_pathlist_hook(PlannerInfo *root,
360386
}
361387
elsereturn;/* one of relations can't have index */
362388

363-
dist_func=DatumGetObjectId(DirectFunctionCall1(to_regprocedure,
364-
PointerGetDatum(dist_func_name)));
365-
366-
if (dist_func==InvalidOid)
367-
return;
368-
369-
if (set_join_pathlist_next)
370-
set_join_pathlist_next(root,
371-
joinrel,
372-
outerrel,
373-
innerrel,
374-
jointype,
375-
extra);
376-
377389
foreach(restr,extra->restrictlist)
378390
{
379391
RestrictInfo*restrInfo= (RestrictInfo*)lfirst(restr);
@@ -433,7 +445,8 @@ create_crossmatch_plan(PlannerInfo *root,
433445
cscan->scan.plan.targetlist=tlist;
434446
cscan->scan.plan.qual=joinclauses;
435447
cscan->scan.scanrelid=0;
436-
cscan->custom_scan_tlist=tlist;/* output of this node */
448+
cscan->custom_scan_tlist=tlist;/* tlist of the 'virtual' join rel
449+
we'll have to build and scan */
437450

438451
cscan->flags=best_path->flags;
439452
cscan->methods=&crossmatch_plan_methods;
@@ -465,9 +478,7 @@ crossmatch_create_scan_state(CustomScan *node)
465478
scan_state->css.flags=node->flags;
466479
scan_state->css.methods=&crossmatch_exec_methods;
467480

468-
/* TODO: check if this assignment is redundant */
469-
scan_state->css.ss.ps.ps_TupFromTlist= false;
470-
481+
/* Save scan tlist for join relation */
471482
scan_state->scan_tlist=node->custom_scan_tlist;
472483

473484
scan_state->outer_idx=linitial_oid(linitial(node->custom_private));
@@ -519,6 +530,7 @@ crossmatch_exec(CustomScanState *node)
519530

520531
for(;;)
521532
{
533+
/* Fetch next tid pair */
522534
if (!node->ss.ps.ps_TupFromTlist)
523535
{
524536
Datum*values=scan_state->values;
@@ -541,9 +553,9 @@ crossmatch_exec(CustomScanState *node)
541553
if (scan_state->scan_tlist!=NIL)
542554
{
543555
TupleDesctupdesc=node->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
544-
intcol_index=0;
545556
boolhtup_outer_ready= false;
546557
boolhtup_inner_ready= false;
558+
intcol_index=0;
547559
ListCell*l;
548560

549561
htup_outer.t_self=p_tids[0];
@@ -645,7 +657,7 @@ crossmatch_end(CustomScanState *node)
645657
staticvoid
646658
crossmatch_rescan(CustomScanState*node)
647659
{
648-
660+
/* NOTE: nothing to do here? */
649661
}
650662

651663
staticvoid

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp