Changeset: 2589429c024b for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2589429c024b
Modified Files:
monetdb5/extras/rdf/rdfschema.c
monetdb5/extras/rdf/rdfschema.h
sql/backends/monet5/sql_rdf.c
sql/backends/monet5/sql_rdf.h
sql/backends/monet5/sql_rdf_jgraph.c
Branch: rdf
Log Message:
Add OPT for handling exception with possible matching table candidates
diffs (300 lines):
diff --git a/monetdb5/extras/rdf/rdfschema.c b/monetdb5/extras/rdf/rdfschema.c
--- a/monetdb5/extras/rdf/rdfschema.c
+++ b/monetdb5/extras/rdf/rdfschema.c
@@ -9994,6 +9994,15 @@ void getTblIdxFromS(oid Soid, int *tbidx
//return freqCSid;
}
+int getTblId_from_S_simple(oid Soid){
+
+ int tbidx = (int) ((Soid >> (sizeof(BUN)*8 - NBITS_FOR_CSID)) & ((1
<< (NBITS_FOR_CSID-1)) - 1)) ;
+
+ tbidx = tbidx - 1;
+
+ return tbidx;
+}
+
/* This function should be the same as getTblIdxFromS */
static
void getTblIdxFromO(oid Ooid, int *tbidx){
diff --git a/monetdb5/extras/rdf/rdfschema.h b/monetdb5/extras/rdf/rdfschema.h
--- a/monetdb5/extras/rdf/rdfschema.h
+++ b/monetdb5/extras/rdf/rdfschema.h
@@ -571,4 +571,8 @@ void addaProp(PropStat* propStat, oid pr
rdf_export
void getTblIdxFromS(oid Soid, int *tbidx, oid *baseSoid);
+rdf_export
+int getTblId_from_S_simple(oid Soid);
+
+
#endif /* _RDFSCHEMA_H_ */
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
@@ -1513,23 +1513,115 @@ bat2return(MalStkPtr stk, InstrPtr pci,
}
}
+static
+void setBasicProps(BAT *b){
+ b->hdense = 1;
+ b->hseqbase = 0;
+ b->hsorted = 1;
+}
+
+#if RDF_HANDLING_EXCEPTION_POSSIBLE_TBL_OPT
+/*
+ * Input:
+ * sbat: BAT of subjects
+ * obat: BAT of objects
+ * tblCand: Set of possible matching table Ids
+ * nt: number of possible matching table
+ * Output:
+ *
+ * */
+static void refine_BAT_with_possible_tblId(BAT *sbat, BAT *obat, BAT
**retsbat, BAT **retobat, int *tblCand, int nt){
+ oid *sbatpt = (oid *) Tloc(sbat, BUNfirst(sbat));
+ oid *obatpt = (oid *) Tloc(obat, BUNfirst(obat));
+ int cnt = BATcount(sbat);
+ int i = 0;
+ int curId = -1; //Cur possible tblId
+ int curpos = -1; //Cur possition in the tblCand
+ BAT *r_sbat = NULL;
+ BAT *r_obat = NULL;
+
+ r_sbat = BATnew(TYPE_void, TYPE_oid, cnt, TRANSIENT);
+ setBasicProps(r_sbat);
+ r_sbat->tsorted = 1;
+
+ r_obat = BATnew(TYPE_void, TYPE_oid, cnt, TRANSIENT);
+
+ for (i = 0; i < cnt; i++){
+ //Check one by one from sbat and obat and then write to the
output BAT
+ oid tmps = sbatpt[i];
+ oid tmpo = obatpt[i];
+ int tmptbid = -1;
+ tmptbid = getTblId_from_S_simple(tmps);
+
+ while (tmptbid > curId){
+ curpos++;
+ if (curpos >= nt) break;
+ curId = tblCand[curpos];
+ }
+
+ if (curpos >= nt) break;
+
+ if (tmptbid == curId){
+ //This row is possible candidate. Write tmps, tmpo to
the ret BATs
+ if (BUNfastins(r_sbat, ATOMnilptr(TYPE_void), &tmps)==
GDK_FAIL){
+ fprintf(stderr, "Cannot insert into r_sbat in
refine_BAT_with_possible_tblId \n");
+ }
+ if (BUNfastins(r_obat, ATOMnilptr(TYPE_void), &tmpo)==
GDK_FAIL){
+ fprintf(stderr, "Cannot insert into r_obat in
refine_BAT_with_possible_tblId \n");
+ }
+ } else {
+ continue;
+ }
+ }
+
+ *retsbat = r_sbat;
+ *retobat = r_obat;
+}
+#endif
static
-void get_full_outerjoin_p_slices(oid *lstprops, int np, oid *los, oid *his,
BAT *full_obat, BAT *full_sbat, BAT **r_sbat, BAT ***r_obats){
+void get_full_outerjoin_p_slices(oid *lstprops, int nrp, int np, oid *los, oid
*his, BAT *full_obat, BAT *full_sbat, BAT **r_sbat, BAT ***r_obats){
BAT **obats, **sbats;
int i;
clock_t start, end;
+ #if RDF_HANDLING_EXCEPTION_POSSIBLE_TBL_OPT
+ int num_match_tbl = 0;
+ int *regtblIds = NULL;
+ #endif
+ (void) nrp;
obats = (BAT**)malloc(sizeof(BAT*) * np);
sbats = (BAT**)malloc(sizeof(BAT*) * np);
(*r_obats) = (BAT**)malloc(sizeof(BAT*) * np);
+ #if RDF_HANDLING_EXCEPTION_POSSIBLE_TBL_OPT
+ get_possible_matching_tbl_from_RPs(®tblIds, &num_match_tbl,
lstprops, nrp, BUN_NONE);
+
+ printf("Exception handling: Possible matching regular table [ ");
+ for (i = 0; i < num_match_tbl; i++){
+ printf(" %d ", regtblIds[i]);
+ }
+ printf(" ]\n");
+ #endif
+
for (i = 0; i < np; i++){
+ BAT *tmpobat = NULL;
+ BAT *tmpsbat = NULL;
start = clock();
printf("Slides of P = "BUNFMT " with o constraints from
"BUNFMT" to " BUNFMT"\n", lstprops[i], los[i], his[i]);
- getSlides_per_P(pso_propstat, &(lstprops[i]), los[i], his[i],
full_obat, full_sbat, &(obats[i]), &(sbats[i]));
+ getSlides_per_P(pso_propstat, &(lstprops[i]), los[i], his[i],
full_obat, full_sbat, &tmpobat, &tmpsbat);
end = clock();
+
+ printf(" [Took %f seconds)\n",((float)(end -
start))/CLOCKS_PER_SEC);
+
+ #if RDF_HANDLING_EXCEPTION_POSSIBLE_TBL_OPT
+ refine_BAT_with_possible_tblId(tmpsbat, tmpobat, &(sbats[i]),
&(obats[i]), regtblIds, num_match_tbl);
+ #else
+ sbats[i] = tmpsbat;
+ obats[i] = tmpobat;
+ #endif
+
if (sbats[i]){
printf(" contains "BUNFMT " rows in sbat\n",
BATcount(sbats[i]));
//BATprint(sbats[i]);
@@ -1543,9 +1635,8 @@ void get_full_outerjoin_p_slices(oid *ls
BATprint(obats[i]);
}
}
- printf(" [Took %f seconds)\n",((float)(end -
start))/CLOCKS_PER_SEC);
}
-
+
start = clock();
RDFmultiway_merge_outerjoins(np, sbats, obats, r_sbat, (*r_obats));
end = clock();
@@ -1631,12 +1722,7 @@ void fetch_result(BAT **r_obats, oid **o
}
-static
-void setBasicProps(BAT *b){
- b->hdense = 1;
- b->hseqbase = 0;
- b->hsorted = 1;
-}
+
/*
* Combine exceptioins and regular tables
* */
@@ -1719,8 +1805,10 @@ void combine_exception_and_regular_table
regular_obat_cursors[j] = NULL;
regular_obat_mv_cursors[j] = NULL;
#if
RDF_HANDLING_EXCEPTION_MISSINGPROP_OPT
- if (j < nRP) lst_missing_props[num_mp]
= j;
- num_mp++;
+ if (j < nRP){
+ lst_missing_props[num_mp] = j;
+ num_mp++;
+ }
#endif
continue;
}
@@ -1896,7 +1984,7 @@ SQLrdfScan(Client cntxt, MalBlkPtr mb, M
pso_fullSbat = mvc_bind(m, schema, "pso", "s",0);
pso_fullObat = mvc_bind(m, schema, "pso", "o",0);
- get_full_outerjoin_p_slices(lstProps, *nP, los, his,
pso_fullObat, pso_fullSbat, &r_sbat, &r_obats);
+ get_full_outerjoin_p_slices(lstProps, *nRP, *nP, los, his,
pso_fullObat, pso_fullSbat, &r_sbat, &r_obats);
eT1 = clock();
printf("Step 1 in Handling exception took %f seconds.\n",
((float)(eT1 - sT1))/CLOCKS_PER_SEC);
diff --git a/sql/backends/monet5/sql_rdf.h b/sql/backends/monet5/sql_rdf.h
--- a/sql/backends/monet5/sql_rdf.h
+++ b/sql/backends/monet5/sql_rdf.h
@@ -58,6 +58,8 @@ sql5_export str SQLrdfScan(Client cntxt,
sql5_export void getSlides_per_P(PsoPropStat *pso_pstat, oid *p, oid low, oid
hi, BAT *obat, BAT *sbat, BAT **ret_oBat, BAT **ret_sBat);
+sql5_export void get_possible_matching_tbl_from_RPs(int **rettbId, int
*num_match_tbl, oid *lstRP, int num, oid subj);
+
extern SimpleCSset *global_csset;
extern PropStat *global_p_propstat;
extern PropStat *global_c_propstat;
@@ -74,4 +76,6 @@ extern PsoPropStat *pso_propstat;
#define RDF_HANDLING_EXCEPTION_SELECTPUSHDOWN_OPT 1
+#define RDF_HANDLING_EXCEPTION_POSSIBLE_TBL_OPT 1 /* Use the set of
possible table for the set of required props to limit the number of matching
subj Id */
+
#endif /*_SQL_RDF_H */
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
@@ -1800,7 +1800,10 @@ void tranforms_mvprop_exps(mvc *c, sql_r
}
/*
- *
+ * Output:
+ * num_match_tbl: Number of table having columns of these input props
+ * rettbId: List of matching tables
+ *
* */
static
void get_matching_tbl_from_spprops(int **rettbId, spProps *spprops, int
*num_match_tbl){
@@ -1887,6 +1890,66 @@ void get_matching_tbl_from_spprops(int *
}
+/*
+ * lstRP: list of required props
+ * num: Num of RP
+ * subj: Subject oid
+ * num_possible_tbl: Number of tables that, by combining with exceptions, can
contain these set of RP props
+ * ret_pos_tbId: List of possible tables
+ */
+void get_possible_matching_tbl_from_RPs(int **rettbId, int *num_match_tbl, oid
*lstRP, int num, oid subj){
+
+ int i;
+ int **tmptblId; //lists of tables corresonding to each prop
+ int *count; //number of tables per prop
+ int *tblId; //list of matching tblId
+ int numtbl = 0;
+
+ if (subj != BUN_NONE){
+ int tblIdx;
+ oid baseSoid;
+ getTblIdxFromS(subj, &tblIdx, &baseSoid);
+ numtbl = 1;
+ tblId = (int *) malloc(sizeof(int));
+ tblId[0] = tblIdx;
+ printf("Possible table Id found based on known subj is: %d\n",
tblIdx);
+ }
+ else{
+
+ tmptblId = (int **) malloc(sizeof(int *) * num);
+ count = (int *) malloc(sizeof(int) * num);
+
+ printf("Possible table Id for set of props [");
+ for (i = 0; i < num; i++){
+ Postinglist *pl = get_p_postingList(global_p_propstat,
lstRP[i]);
+ if (pl != NULL){
+ tmptblId[i] = pl->lstIdx;
+ count[i] = pl->numAdded;
+ printf(" " BUNFMT, lstRP[i]);
+ } else {
+ printf(" NO TABLE");
+ break;
+ }
+
+ }
+
+ if (i == num) //All props have matching tabe
+ intersect_intsets(tmptblId, count, num, &tblId,
&numtbl);
+
+ printf(" ] --> ");
+
+ free(count);
+
+ }
+
+ *rettbId = (int *) malloc(sizeof(int) * numtbl);
+ for (i = 0; i < numtbl; i++){
+ (*rettbId)[i] = tblId[i];
+ }
+
+ *num_match_tbl = numtbl;
+
+}
static
mvPropRel* init_mvPropRelSet(int n){
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list