Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

seems to me a workable version

  • Loading branch information...
commit d09c69a3bb73bec0bc38b0fe0e00fca7e6cf2f47 1 parent fe1a419
@kaigai authored
View
2  blkload.c
@@ -449,7 +449,7 @@ pgstrom_data_load(PG_FUNCTION_ARGS)
/*
* Lookup the Oid of rowid sequencial generator
*/
- range = pgstrom_lookup_sequence(drel);
+ range = pgstrom_lookup_sequence(RelationGetRelid(drel));
nspid = get_namespace_oid(range->schemaname, false);
seqid = get_relname_relid(range->relname, nspid);
if (!OidIsValid(seqid))
View
3  exec.c
@@ -680,7 +680,7 @@ pgstrom_init_exec_state(ForeignScanState *fss)
ListCell *cell;
PgStromExecState *sestate;
- foreach (cell, fscan->fdwplan->fdw_private)
+ foreach (cell, fscan->fdw_private)
{
DefElem *defel = (DefElem *) lfirst(cell);
@@ -920,6 +920,7 @@ pgstrom_end_foreign_scan(ForeignScanState *fss)
/* TODO: Wait for completion of in-exec chunks */
+ pgstrom_shmseg_list_delete(&sestate->chkb_head->chkbh_chain);
pgstrom_shmseg_free(sestate->chkb_head);
bms_free(sestate->gpu_cols);
bms_free(sestate->cpu_cols);
View
4 main.c
@@ -23,7 +23,9 @@ void _PG_init(void);
FdwRoutine PgStromFdwHandlerData = {
.type = T_FdwRoutine,
- .PlanForeignScan = pgstrom_plan_foreign_scan,
+ .GetForeignRelSize = pgstrom_get_foreign_rel_size,
+ .GetForeignPaths = pgstrom_get_foreign_paths,
+ .GetForeignPlan = pgstrom_get_foreign_plan,
.ExplainForeignScan = pgstrom_explain_foreign_scan,
.BeginForeignScan = pgstrom_begin_foreign_scan,
.IterateForeignScan = pgstrom_iterate_foreign_scan,
View
21 pg_strom.h
@@ -151,11 +151,20 @@ extern void pgstrom_openmp_enqueue_chunk(ChunkBuffer *chunk);
/*
* plan.c
*/
-extern FdwPlan *pgstrom_plan_foreign_scan(Oid ftableOid,
- PlannerInfo *root,
- RelOptInfo *baserel);
-extern void pgstrom_explain_foreign_scan(ForeignScanState *fss,
- ExplainState *es);
+extern void pgstrom_get_foreign_rel_size(PlannerInfo *root,
+ RelOptInfo *baserel,
+ Oid foreigntableid);
+extern void pgstrom_get_foreign_paths(PlannerInfo *root,
+ RelOptInfo *baserel,
+ Oid foreigntableid);
+extern ForeignScan *pgstrom_get_foreign_plan(PlannerInfo *root,
+ RelOptInfo *baserel,
+ Oid foreigntableid,
+ ForeignPath *best_path,
+ List *tlist,
+ List *scan_clauses);
+extern void pgstrom_explain_foreign_scan(ForeignScanState *fss,
+ ExplainState *es);
/*
* exec.c
@@ -174,7 +183,7 @@ extern Relation pgstrom_open_cs_table(Relation base, AttrNumber attno,
LOCKMODE lockmode);
extern Relation pgstrom_open_cs_index(Relation base, AttrNumber attno,
LOCKMODE lockmode);
-extern RangeVar *pgstrom_lookup_sequence(Relation base);
+extern RangeVar *pgstrom_lookup_sequence(Oid base_relid);
extern void pgstrom_utilcmds_init(void);
/*
View
110 plan.c
@@ -13,10 +13,16 @@
#include "postgres.h"
#include "access/sysattr.h"
#include "catalog/pg_type.h"
+#include "commands/sequence.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
+#include "utils/syscache.h"
+#include "optimizer/cost.h"
+#include "optimizer/planmain.h"
+#include "optimizer/pathnode.h"
+#include "optimizer/restrictinfo.h"
#include "optimizer/var.h"
#include "pg_strom.h"
#include "cuda_cmds.h"
@@ -332,12 +338,34 @@ make_cpu_commands(List *cpu_quals, Bitmapset **cpu_cols)
return NULL;
}
-FdwPlan *
-pgstrom_plan_foreign_scan(Oid ftableOid,
- PlannerInfo *root,
- RelOptInfo *baserel)
+
+void
+pgstrom_get_foreign_rel_size(PlannerInfo *root,
+ RelOptInfo *baserel,
+ Oid ftableOid)
+{
+ AttrNumber attno;
+ int width = 0;
+
+ for (attno = baserel->min_attr; attno <= baserel->max_attr; attno++)
+ {
+ int index = attno - baserel->min_attr;
+
+ if (attno > 0 && !bms_is_empty(baserel->attr_needed[index]))
+ {
+ width += get_attavgwidth(ftableOid, attno);
+ }
+ }
+ /* need more practical estimation */
+ baserel->rows = 10000.0;
+ baserel->width = width;
+}
+
+void
+pgstrom_get_foreign_paths(PlannerInfo *root,
+ RelOptInfo *baserel,
+ Oid foreigntableid)
{
- FdwPlan *fdwplan;
List *host_quals = NIL;
List *gpu_quals = NIL;
List *cpu_quals = NIL;
@@ -347,7 +375,12 @@ pgstrom_plan_foreign_scan(Oid ftableOid,
AttrNumber attno;
bytea *cmds_bytea;
Const *cmds_const;
+ int gpu_cmds_len = 0;
+ int cpu_cmds_len = 0;
DefElem *defel;
+ Cost startup_cost;
+ Cost total_cost;
+ ForeignPath *fdwpath;
/*
* check whether GPU/CPU executable qualifier, or not
@@ -384,6 +417,8 @@ pgstrom_plan_foreign_scan(Oid ftableOid,
defel = makeDefElem("gpu_cmds", (Node *) cmds_const);
private = lappend(private, defel);
+ gpu_cmds_len = VARSIZE_ANY_EXHDR(cmds_bytea) / sizeof(int);
+
while ((attno = bms_first_member(gpu_cols)) >= 0)
{
defel = makeDefElem("gpu_cols", (Node *) makeInteger(attno));
@@ -403,6 +438,8 @@ pgstrom_plan_foreign_scan(Oid ftableOid,
defel = makeDefElem("cpu_cmds", (Node *) cmds_const);
private = lappend(private, defel);
+ cpu_cmds_len = VARSIZE_ANY_EXHDR(cmds_bytea) / sizeof(int);
+
while ((attno = bms_first_member(cpu_cols)) >= 0)
{
defel = makeDefElem("cpu_cols", (Node *) makeInteger(attno));
@@ -432,14 +469,67 @@ pgstrom_plan_foreign_scan(Oid ftableOid,
bms_free(required_cols);
/*
- * Construct FdwPlan object
+ * Cost estimations
+ *
+ * TODO: this logic should be revised later
*/
- fdwplan = makeNode(FdwPlan);
- fdwplan->fdw_private = private;
+ cost_qual_eval(&baserel->baserestrictcost,
+ baserel->baserestrictinfo, root);
- return fdwplan;
+ startup_cost = baserel->baserestrictcost.startup;
+ total_cost = baserel->baserestrictcost.per_tuple * baserel->rows
+ + 0.01 * gpu_cmds_len * baserel->rows / PGSTROM_CHUNK_SIZE
+ + 0.01 * cpu_cmds_len * baserel->rows / PGSTROM_CHUNK_SIZE;
+
+ /*
+ * Construct Plan object
+ */
+ fdwpath = create_foreignscan_path(root, baserel,
+ baserel->rows,
+ startup_cost,
+ total_cost,
+ NIL,
+ NULL,
+ NIL,
+ private);
+ add_path(baserel, (Path *) fdwpath);
+}
+
+ForeignScan *
+pgstrom_get_foreign_plan(PlannerInfo *root,
+ RelOptInfo *baserel,
+ Oid foreigntableid,
+ ForeignPath *best_path,
+ List *tlist,
+ List *scan_clauses)
+{
+ Index scan_relid = baserel->relid;
+
+ /* it should be a base rel... */
+ Assert(scan_relid > 0);
+ Assert(best_path->path.parent->rtekind == RTE_RELATION);
+
+ /*
+ * Reduce RestrictInfo list to bare expressions;
+ * ignore pseudoconstants
+ */
+ scan_clauses = extract_actual_clauses(scan_clauses, false);
+
+ /* Create the ForeignScan node */
+ return make_foreignscan(tlist,
+ scan_clauses,
+ scan_relid,
+ NIL,
+ best_path->fdw_private);
}
+/*
+ * pgstrom_explain_foreign_scan
+ *
+ *
+ *
+ *
+ */
void
pgstrom_explain_foreign_scan(ForeignScanState *fss,
ExplainState *es)
@@ -456,7 +546,7 @@ pgstrom_explain_foreign_scan(ForeignScanState *fss,
AttrNumber attno;
Form_pg_attribute attr;
- foreach (cell, fscan->fdwplan->fdw_private)
+ foreach (cell, fscan->fdw_private)
{
DefElem *defel = (DefElem *) lfirst(cell);
View
1  shmseg.c
@@ -279,6 +279,7 @@ pgstrom_shmseg_free(void *ptr)
block = temp;
}
+ block->magic = SHMSEG_BLOCK_MAGIC_FREE;
pgstrom_shmseg_list_add(&shmseg_head->free_list, &block->list);
pthread_mutex_unlock(&shmseg_head->lock);
View
14 utilcmds.c
@@ -147,18 +147,24 @@ pgstrom_open_cs_index(Relation base, AttrNumber attno, LOCKMODE lockmode)
}
RangeVar *
-pgstrom_lookup_sequence(Relation base_rel)
+pgstrom_lookup_sequence(Oid base_relid)
{
+ Oid nsp_oid;
char *nsp_name;
+ char *rel_name;
char seq_name[NAMEDATALEN * 2 + 20];
RangeVar *range;
- nsp_name = get_namespace_name(RelationGetForm(base_rel)->relnamespace);
+ nsp_oid = get_rel_namespace(base_relid);
+ nsp_name = get_namespace_name(nsp_oid);
+ rel_name = get_rel_name(base_relid);
+
snprintf(seq_name, sizeof(seq_name), "%s.%s.seq",
- nsp_name, RelationGetRelationName(base_rel));
+ nsp_name, rel_name);
range = makeRangeVar(PGSTROM_SCHEMA_NAME, pstrdup(seq_name), -1);
pfree(nsp_name);
+ pfree(rel_name);
return range;
}
@@ -394,7 +400,7 @@ pgstrom_post_create_foreign_table(CreateForeignTableStmt *stmt)
if (!OidIsValid(namespaceId))
{
namespaceId = NamespaceCreate(PGSTROM_SCHEMA_NAME,
- BOOTSTRAP_SUPERUSERID);
+ BOOTSTRAP_SUPERUSERID, false);
CommandCounterIncrement();
}
Please sign in to comment.
Something went wrong with that request. Please try again.