Changeset: 4973d8ed32ab for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4973d8ed32ab
Modified Files:
monetdb5/extras/rdf/rdfalgebra.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_rdf.c
sql/backends/monet5/sql_rdf_jgraph.c
Branch: rdf
Log Message:
Fix the problem of projecting more columns than it needs
diffs (186 lines):
diff --git a/monetdb5/extras/rdf/rdfalgebra.c b/monetdb5/extras/rdf/rdfalgebra.c
--- a/monetdb5/extras/rdf/rdfalgebra.c
+++ b/monetdb5/extras/rdf/rdfalgebra.c
@@ -267,7 +267,7 @@ str RDFmultiway_merge_outerjoins(int np,
cand = (oid *) malloc(sizeof(oid) * np);
for (i = 0; i < np; i++){
- estimate += BATcount(obats[i]);
+ if (obats[i]) estimate += BATcount(obats[i]);
tmpCand[i] = (oid *) malloc(sizeof(oid) * maxNumExcept);
numCand[i] = 0;
cand[i] = oid_nil;
@@ -284,20 +284,23 @@ str RDFmultiway_merge_outerjoins(int np,
//assert(BATcount(sbats[i]) > 0);
//
//Keep the cursor to the first element of each input sbats
- sbatCursors[i] = (oid *) Tloc(sbats[i], BUNfirst(sbats[i]));
- obatCursors[i] = (oid *) Tloc(obats[i], BUNfirst(obats[i]));
+ if (sbats[i]) sbatCursors[i] = (oid *) Tloc(sbats[i],
BUNfirst(sbats[i]));
+ else sbatCursors[i] = NULL;
+
+ if (obats[i]) obatCursors[i] = (oid *) Tloc(obats[i],
BUNfirst(obats[i]));
+ else obatCursors[i] = NULL;
}
//Create a min heap with np heap nodes. Every heap node
//has first element of an array (pointing to the first element of each
sbat)
harr = (MinHeapNode*)malloc(sizeof(MinHeapNode) * np);
for (i = 0; i < np; i++){
- if (BATcount(sbats[i]) != 0){
+ if (sbats[i] && BATcount(sbats[i]) != 0){
harr[i].element = sbatCursors[i][0]; //Store the first
element
harr[i].i = i; //index of array
harr[i].j = 1; //Index of next element to be stored
from array
} else {
- harr[i].element = INT_MAX; //Store the INT_MAX in case
of empty BATs
+ harr[i].element = GDK_oid_max; //Store the INT_MAX in
case of empty BATs
harr[i].i = i; //index of array
harr[i].j = 1; //Index of next element to be stored
from array
}
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -130,7 +130,7 @@ sql_symbol2relation(mvc *c, symbol *sym)
if (1) c->emode = m_normal;
- if (0) c->emod = mod_explain;
+ if (1) c->emod = mod_explain;
}
}
else {
diff --git a/sql/backends/monet5/sql_rdf.c b/sql/backends/monet5/sql_rdf.c
--- a/sql/backends/monet5/sql_rdf.c
+++ b/sql/backends/monet5/sql_rdf.c
@@ -1518,8 +1518,8 @@ void get_full_outerjoin_p_slices(oid *ls
for (i = 0; i < np; i++){
getSlides_per_P(pso_propstat, &(lstprops[i]),full_obat,
full_sbat, &(obats[i]), &(sbats[i]));
printf("Slides of P = "BUNFMT"\n", lstprops[i]);
- BATprint(sbats[i]);
- BATprint(obats[i]);
+ if (sbats[i]) BATprint(sbats[i]);
+ if (obats[i]) BATprint(obats[i]);
}
RDFmultiway_merge_outerjoins(np, sbats, obats, r_sbat, (*r_obats));
@@ -2012,8 +2012,11 @@ void getOffsets(PsoPropStat *pso_pstat,
BUN pos;
pos = BUNfnd(pso_pstat->pBat, p);
- if (pos == BUN_NONE)
- fprintf(stderr, "[Error] The prop "BUNFMT " must be there!\n",
*p);
+ if (pos == BUN_NONE){
+ printf("The prop "BUNFMT " is not in PSO!\n", *p);
+ *start = BUN_NONE;
+ *end = BUN_NONE;
+ }
else{
oid *tmpstart = (oid *) Tloc(pso_pstat->offsetBat, pos);
*start = (*tmpstart);
@@ -2032,11 +2035,16 @@ void getSlides_per_P(PsoPropStat *pso_ps
BUN l, h;
getOffsets(pso_pstat, p, &l, &h);
+
+ if (l != BUN_NONE){
+ *ret_oBat = BATslice(obat, l, h+1);
- *ret_oBat = BATslice(obat, l, h+1);
-
- *ret_sBat = BATslice(sbat, l, h+1);
- (*ret_sBat)->tsorted = true;
+ *ret_sBat = BATslice(sbat, l, h+1);
+ (*ret_sBat)->tsorted = true;
+ } else {
+ *ret_oBat = NULL;
+ *ret_sBat = NULL;
+ }
}
diff --git a/sql/backends/monet5/sql_rdf_jgraph.c
b/sql/backends/monet5/sql_rdf_jgraph.c
--- a/sql/backends/monet5/sql_rdf_jgraph.c
+++ b/sql/backends/monet5/sql_rdf_jgraph.c
@@ -218,6 +218,7 @@ sql_table *create_dummy_table(mvc *c, st
assert(sch != NULL);
if ((tbl = mvc_bind_table(c, sch, tblname)) == NULL){
+ printf("The dummy table does not exist --> Create new one\n");
tbl = mvc_create_table(c, sch, tblname, tt_table, 0,
SQL_PERSIST, 0, 3);
}
@@ -500,6 +501,38 @@ void _add_jg_node(mvc *c, jgraph *jg, sq
addJGnode(&tmpvid, jg, rel, subjgId, soid, poid, prop, t);
}
+/* Example
+ * s10_t0.p, s10_t0.s, s10_t0.o, s10_t0.%TID% NOT NULL, s10_t1.p, s10_t1.s,
s10_t1.o, s10_t1.%TID% NOT NULL, s10_t2.p, s10_t2.s, s10_t2.o, s10_t2.%TID% NOT
NULL, s10_t3.p, s10_t3.s, s10_t3.o, s10_t3.%TID% NOT NULL, s10_t4.p, s10_t4.s,
s10_t4.o, s10_t4.%TID% NOT NULL, sys.rdf_idtostr(s10_t0.o) as L1.L1 ]
+ *
+ * We remove .p and .%TID%
+ * */
+
+
+static
+list* remove_p_from_proj_exps(mvc *c, list *exps){
+
+ node *en;
+ sql_allocator *sa = c->sa;
+ list *newexps = NULL;
+ newexps = new_exp_list(sa);
+ for (en = exps->h; en; en = en->next){
+ sql_exp *e = (sql_exp *) en->data;
+
+ if (e->type == e_column && strcmp(e->name, "p") == 0){ //e.g.,
sys.rdf_idtostr(s10_t0.s) as L.product, sys.rdf_idtostr(s10_t0.o) as L.label
+ continue;
+ } else if (e->type == e_column && strcmp(e->name, "o") != 0 &&
strcmp(e->name, "s") != 0){
+ continue;
+ } else {
+ sql_exp *newexp = exp_copy(sa, e);
+ //append this exp to list
+ append(newexps, newexp);
+ }
+
+ }
+
+ return newexps;
+}
+
/*
* Algorithm for adding sql rels to Join Graph
*
@@ -555,6 +588,16 @@ void addRelationsToJG(mvc *c, sql_rel *p
}
_add_jg_node(c, jg, (sql_rel *) rel, *subjgId,
JN_REQUIRED);
break;
+ case op_project:
+ printf("[%s]\n", op2string(rel->op));
+ //Update project expression in order to remove p from
expressions
+ rel->exps = remove_p_from_proj_exps(c, rel->exps);
+
+ if (rel->l)
+ addRelationsToJG(c, rel, rel->l, depth+1, jg,
1, subjgId, level, tmp_level + 1, node_root);
+ if (rel->r)
+ addRelationsToJG(c, rel, rel->r, depth+1, jg,
1, subjgId, level, tmp_level + 1, node_root);
+ break;
default:
printf("[%s]\n", op2string(rel->op));
if (rel->l)
@@ -1333,6 +1376,8 @@ void get_transform_select_exps(mvc *c, l
}
}
+
+
#if HANDLING_EXCEPTION
static
void get_transform_dummy_select_exps(mvc *c, list *exps, list
*trans_select_exps, str tblname){
@@ -3230,6 +3275,8 @@ void buildJoinGraph(mvc *c, sql_rel *r,
printf("e_start_level = %d | n_start_level = %d\n", e_start_level,
n_start_level);
if (numsp == 1) connect_rel_with_sprel(r, lstRels[0], e_start_level,
n_start_level, node_root, edge_root);
+ //Check the projection operator and then refine the expressions
+
if (numsp > 1){
//Connect to the first edge between sp0 and sp1
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list