Skip to content

Commit

Permalink
feat: Enhance shortestpath algorithm and minor features
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyunsu Choi committed Nov 30, 2018
1 parent 4668563 commit 5759726
Show file tree
Hide file tree
Showing 41 changed files with 20,600 additions and 473 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -32,6 +32,8 @@ lib*.pc
tags
cscope.*
*.swp
*~
.DS_Store

# Local excludes in root directory
/GNUmakefile
Expand All @@ -44,6 +46,7 @@ cscope.*
/Release/
/tmp_install/
/doc/build/
/agensgraph.xcodeproj/

# Local excludes of install directories
/bin/
Expand Down
89 changes: 89 additions & 0 deletions src/backend/commands/explain.c
Expand Up @@ -102,6 +102,7 @@ static void show_tablesample(TableSampleClause *tsc, PlanState *planstate,
List *ancestors, ExplainState *es);
static void show_sort_info(SortState *sortstate, ExplainState *es);
static void show_hash_info(HashState *hashstate, ExplainState *es);
static void show_hash2side_info(Hash2SideState *hashstate, ExplainState *es);
static void show_tidbitmap_info(BitmapHeapScanState *planstate,
ExplainState *es);
static void show_instrumentation_count(const char *qlabel, int which,
Expand Down Expand Up @@ -1122,6 +1123,19 @@ ExplainNode(PlanState *planstate, List *ancestors,
break;
}
break;
case T_Shortestpath:
if (((Shortestpath *) plan)->limit == LONG_MAX)
{
pname = sname = "All Shortestpaths";
}
else
{
pname = sname = "Shortestpath";
}
break;
case T_Hash2Side:
pname = sname = "Hash2Side";
break;
case T_Dijkstra:
pname = sname = "Dijkstra";
break;
Expand Down Expand Up @@ -1233,6 +1247,17 @@ ExplainNode(PlanState *planstate, List *ancestors,
appendStringInfoString(es->str, " eager");
}
break;
case T_Shortestpath:
{
Shortestpath *shortestpath = (Shortestpath *) plan;

appendStringInfo(es->str, " VLE [%ld..", shortestpath->minhops);
if (shortestpath->maxhops != LONG_MAX)
appendStringInfo(es->str, "%ld]", shortestpath->maxhops);
else
appendStringInfo(es->str, "]");
}
break;
case T_NestLoop:
case T_NestLoopVLE:
case T_MergeJoin:
Expand Down Expand Up @@ -1662,6 +1687,19 @@ ExplainNode(PlanState *planstate, List *ancestors,
show_instrumentation_count("Rows Removed by Filter", 2,
planstate, es);
break;
case T_Shortestpath:
show_upper_qual(((Shortestpath *) plan)->hashclauses,
"Hash Cond", planstate, ancestors, es);
show_upper_qual(((Shortestpath *) plan)->join.joinqual,
"Join Filter", planstate, ancestors, es);
if (((Shortestpath *) plan)->join.joinqual)
show_instrumentation_count("Rows Removed by Join Filter", 1,
planstate, es);
show_upper_qual(plan->qual, "Filter", planstate, ancestors, es);
if (plan->qual)
show_instrumentation_count("Rows Removed by Filter", 2,
planstate, es);
break;
case T_Agg:
show_agg_keys(castNode(AggState, planstate), ancestors, es);
show_upper_qual(plan->qual, "Filter", planstate, ancestors, es);
Expand Down Expand Up @@ -1699,6 +1737,9 @@ ExplainNode(PlanState *planstate, List *ancestors,
case T_Hash:
show_hash_info(castNode(HashState, planstate), es);
break;
case T_Hash2Side:
show_hash2side_info((Hash2SideState *) planstate, es);
break;
default:
break;
}
Expand Down Expand Up @@ -2443,6 +2484,54 @@ show_hash_info(HashState *hashstate, ExplainState *es)
}
}

/*
* Show information on hash buckets/batches.
*/
static void
show_hash2side_info(Hash2SideState *hashstate, ExplainState *es)
{
HashJoinTable hashtable;

Assert(IsA(hashstate, Hash2SideState));
hashtable = hashstate->hashtable;

if (hashtable)
{
long spacePeakKb = (hashtable->spacePeak + 1023) / 1024;

if (es->format != EXPLAIN_FORMAT_TEXT)
{
ExplainPropertyLong("Hash Buckets", hashtable->nbuckets, es);
ExplainPropertyLong("Original Hash Buckets",
hashtable->nbuckets_original, es);
ExplainPropertyLong("Hash Batches", hashtable->nbatch, es);
ExplainPropertyLong("Original Hash Batches",
hashtable->nbatch_original, es);
ExplainPropertyLong("Peak Memory Usage", spacePeakKb, es);
}
else if (hashtable->nbatch_original != hashtable->nbatch ||
hashtable->nbuckets_original != hashtable->nbuckets)
{
appendStringInfoSpaces(es->str, es->indent * 2);
appendStringInfo(es->str,
"Buckets: %d (originally %d) Batches: %d (originally %d) Memory Usage: %ldkB\n",
hashtable->nbuckets,
hashtable->nbuckets_original,
hashtable->nbatch,
hashtable->nbatch_original,
spacePeakKb);
}
else
{
appendStringInfoSpaces(es->str, es->indent * 2);
appendStringInfo(es->str,
"Buckets: %d Batches: %d Memory Usage: %ldkB\n",
hashtable->nbuckets, hashtable->nbatch,
spacePeakKb);
}
}
}

/*
* If it's EXPLAIN ANALYZE, show exact/lossy pages for a BitmapHeapScan node
*/
Expand Down
3 changes: 2 additions & 1 deletion src/backend/executor/Makefile
Expand Up @@ -30,6 +30,7 @@ OBJS = execAmi.o execCurrent.o execExpr.o execExprInterp.o \
nodeGroup.o nodeSubplan.o nodeSubqueryscan.o nodeTidscan.o \
nodeForeignscan.o nodeWindowAgg.o tstoreReceiver.o tqueue.o spi.o \
nodeTableFuncscan.o \
nodeModifyGraph.o nodeNestloopVle.o nodeDijkstra.o
nodeModifyGraph.o nodeNestloopVle.o \
nodeHash2Side.o nodeShortestpath.o nodeDijkstra.o

include $(top_srcdir)/src/backend/common.mk
10 changes: 10 additions & 0 deletions src/backend/executor/execAmi.c
Expand Up @@ -31,6 +31,7 @@
#include "executor/nodeGroup.h"
#include "executor/nodeGroup.h"
#include "executor/nodeHash.h"
#include "executor/nodeHash2Side.h"
#include "executor/nodeHashjoin.h"
#include "executor/nodeIndexonlyscan.h"
#include "executor/nodeIndexscan.h"
Expand All @@ -49,6 +50,7 @@
#include "executor/nodeSamplescan.h"
#include "executor/nodeSeqscan.h"
#include "executor/nodeSetOp.h"
#include "executor/nodeShortestpath.h"
#include "executor/nodeSort.h"
#include "executor/nodeSubplan.h"
#include "executor/nodeSubqueryscan.h"
Expand Down Expand Up @@ -291,6 +293,14 @@ ExecReScan(PlanState *node)
ExecReScanLimit((LimitState *) node);
break;

case T_ShortestpathState:
ExecReScanShortestpath((ShortestpathState *) node);
break;

case T_Hash2SideState:
ExecReScanHash2Side((Hash2SideState *) node);
break;

case T_DijkstraState:
ExecReScanDijkstra((DijkstraState *) node);
break;
Expand Down
24 changes: 24 additions & 0 deletions src/backend/executor/execProcnode.c
Expand Up @@ -88,6 +88,7 @@
#include "executor/nodeGatherMerge.h"
#include "executor/nodeGroup.h"
#include "executor/nodeHash.h"
#include "executor/nodeHash2Side.h"
#include "executor/nodeHashjoin.h"
#include "executor/nodeIndexonlyscan.h"
#include "executor/nodeIndexscan.h"
Expand All @@ -108,6 +109,7 @@
#include "executor/nodeSamplescan.h"
#include "executor/nodeSeqscan.h"
#include "executor/nodeSetOp.h"
#include "executor/nodeShortestpath.h"
#include "executor/nodeSort.h"
#include "executor/nodeSubplan.h"
#include "executor/nodeSubqueryscan.h"
Expand Down Expand Up @@ -378,6 +380,16 @@ ExecInitNode(Plan *node, EState *estate, int eflags)
estate, eflags);
break;

case T_Shortestpath:
result = (PlanState *) ExecInitShortestpath((Shortestpath *) node,
estate, eflags);
break;

case T_Hash2Side:
result = (PlanState *) ExecInitHash2Side((Hash2Side *) node,
estate, eflags);
break;

case T_Dijkstra:
result = (PlanState *) ExecInitDijkstra((Dijkstra *) node,
estate, eflags);
Expand Down Expand Up @@ -517,6 +529,10 @@ MultiExecProcNode(PlanState *node)
result = MultiExecBitmapOr((BitmapOrState *) node);
break;

case T_Hash2SideState:
result = MultiExecHash2Side((Hash2SideState *) node);
break;

default:
elog(ERROR, "unrecognized node type: %d", (int) nodeTag(node));
result = NULL;
Expand Down Expand Up @@ -738,6 +754,14 @@ ExecEndNode(PlanState *node)
ExecEndLimit((LimitState *) node);
break;

case T_ShortestpathState:
ExecEndShortestpath((ShortestpathState *) node);
break;

case T_Hash2SideState:
ExecEndHash2Side((Hash2SideState *) node);
break;

case T_DijkstraState:
ExecEndDijkstra((DijkstraState *) node);
break;
Expand Down

0 comments on commit 5759726

Please sign in to comment.