Changeset: b55d331c12c8 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b55d331c12c8
Modified Files:
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_rdf.c
        sql/backends/monet5/sql_rdf.h
        sql/backends/monet5/sql_rdf_jgraph.c
        sql/backends/monet5/sql_scenario.c
        sql/server/Makefile.ag
        sql/server/rel_optimizer.c
Branch: rdf
Log Message:

Add PK for mvtable.

Add the option in order to choose not simplifying the predicates of cross 
products.


diffs (244 lines):

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
@@ -148,10 +148,12 @@ sql_symbol2relation(mvc *c, symbol *sym)
                        eT = clock(); 
                        printf("----- Transformation time: %f seconds.\n", 
((float)(eT - sT))/CLOCKS_PER_SEC);
                }
+
+               #if PRINT_FOR_DEBUG
                else {
-               
                        _rel_print(c,r);
                }
+               #endif
 
                if (1){
                sT = clock(); 
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
@@ -617,7 +617,12 @@ void addPKandFKs(CStableStat* cstablesta
                                getMvTblSQLname(mvTbl, i, j, 
cstablestat->lstcstable[i].tblname, cstablestat->lstcstable[i].lstProp[j], 
mapi, mbat);
                                fprintf(foutMV, "ALTER TABLE %s.\"%s\" ADD 
UNIQUE (\"%s\");\n",schema,fromTbl,fromTblCol);              
                                fprintf(foutMV, "ALTER TABLE %s.\"%s\" ADD 
FOREIGN KEY (\"mvKey\") REFERENCES %s.\"%s\" (\"%s\");\n",schema, mvTbl, 
schema, fromTbl,fromTblCol);
-                       
+
+                               fprintf(foutMV, "ALTER TABLE %s.\"%s\" ADD 
FOREIGN KEY (\"mvsubj\") REFERENCES %s.\"%s\" (\"subject\");\n",schema, mvTbl, 
schema, fromTbl);
+                                       
+                               //Add primary key for MV table
+                               getColSQLname(mvCol, j, 0, 
cstablestat->lstcstable[i].lstProp[j], mapi, mbat);
+                               fprintf(foutPK, "ALTER TABLE %s.\"%s\" ADD 
PRIMARY KEY (mvsubj, \"%s\");\n",schema,mvTbl,mvCol);
                        }
                }
        }
@@ -1484,7 +1489,7 @@ SQLrdftimetoid(oid *ret, str *datetime){
        lng tmp = BUN_NONE; 
        ValRecord vrec;
 
-       printf("SQLrdftimetoid: %s\n", *datetime);
+       //printf("SQLrdftimetoid: %s\n", *datetime);
 
        convertDateTimeToLong(*datetime, &tmp); 
 
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
@@ -83,6 +83,6 @@ extern int need_handling_exception;
 
 #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 */
 
-#define PRINT_FOR_DEBUG 1
+#define PRINT_FOR_DEBUG 0
 
 #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
@@ -723,14 +723,8 @@ void handling_Union(mvc *c, sql_rel *rel
                case op_union:
                        assert (rel->l && rel->r); 
                        *hasUnion = 1; 
-                       printf("Left Union: ===Before====\n"); 
-                       _rel_print(c, rel->l);          
                        buildJoinGraph(c, rel->l, depth + 1);
-                       printf("Left Union: ===After=====\n"); 
-                       _rel_print(c, rel->l); 
                        buildJoinGraph(c, rel->r, depth + 1); 
-                       printf("Right Union: =======\n"); 
-                       _rel_print(c, rel->r); 
                        break; 
                default:
                        if (rel->l) 
@@ -750,7 +744,6 @@ void handling_Union(mvc *c, sql_rel *rel
 static
 const char *get_relname_from_basetable(sql_rel *rel){
 
-       sql_exp *tmpexp;
        const char *rname = NULL; 
        list *tmpexps; 
 
@@ -763,6 +756,8 @@ const char *get_relname_from_basetable(s
                //For verifying that there is 
                //only one relation name
                for (en = tmpexps->h; en; en = en->next){
+                       sql_exp *tmpexp = NULL;
+                       (void) tmpexp;
                        tmpexp = (sql_exp *) en->data; 
                        assert(tmpexp->type == e_column);
                                
@@ -2739,7 +2734,7 @@ sql_rel* transform_inner_join_subjg (mvc
                *is_contain_mv = 0; 
        }
        
-       printf("Number of mv_col: %d\n", num_mv_col); 
+       //printf("Number of mv_col: %d\n", num_mv_col); 
        if (num_mv_col > 0){    //missingcol == 0
                *is_contain_mv = 1; 
                rel = connect_sp_select_and_mv_prop(c, rel_wo_mv, mvPropRels, 
tblname, atblname, asubjcolname, nnode); 
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -54,6 +54,7 @@
 #include "opt_mitosis.h"
 #include <unistd.h>
 #include "sql_upgrades.h"
+#include "sql_rdf_env.h"
 
 static int SQLinitialized = 0;
 static int SQLnewcatalog = 0;
@@ -61,6 +62,8 @@ int SQLdebug = 0;
 static char *sqlinit = NULL;
 MT_Lock sql_contextLock MT_LOCK_INITIALIZER("sql_contextLock");
 
+int rdf_opt_simply_crp = 1;    /*RDF only*/
+
 static void
 monet5_freestack(int clientid, backend_stack stk)
 {
@@ -294,6 +297,7 @@ global_variables(mvc *sql, char *user, c
        bit F = FALSE;
        ValRecord src;
        str opt;
+       str need_crp_opt;       /*Need optimize cross product by simplifying 
predicates (For RDF only) */
 
        typename = "int";
        sql_find_subtype(&ctype, typename, 0, 0);
@@ -324,6 +328,15 @@ global_variables(mvc *sql, char *user, c
        sql_find_subtype(&ctype, typename, 0, 0);
        SQLglobal("last_id", &sql->last_id);
        SQLglobal("rowcnt", &sql->rowcnt);
+
+       need_crp_opt = GDKgetenv("crp_optimizer");
+       if (!need_crp_opt || strcmp (need_crp_opt, "yes") == 0)
+               rdf_opt_simply_crp = 1; 
+       else 
+               rdf_opt_simply_crp = 0; 
+       
+       printf("need_crp_opt = %s and rdf_opt_simply_crp = 
%d\n",need_crp_opt,rdf_opt_simply_crp);
+
        return 0;
 }
 
diff --git a/sql/server/Makefile.ag b/sql/server/Makefile.ag
--- a/sql/server/Makefile.ag
+++ b/sql/server/Makefile.ag
@@ -12,7 +12,8 @@ INCLUDES = ../include ../common ../stora
                   ../../clients/mapilib \
                   ../../common/options \
                   ../../common/stream \
-                  ../../gdk
+                  ../../gdk \
+                  ../backends/monet5
 
 AM_YFLAGS = -d -p sql
 
diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -21,6 +21,7 @@
 #ifdef HAVE_HGE
 #include "mal.h"               /* for have_hge */
 #endif
+#include "sql_rdf_env.h"
 
 #define new_func_list(sa) sa_list(sa)
 #define new_col_list(sa) sa_list(sa)
@@ -5948,6 +5949,54 @@ rel_simplify_like_select(int *changes, m
        return rel;
 }
 
+/*
+static
+int rdf_is_select_on_s(sql_rel *rel){
+       
+       if (rel->op == op_project)
+               if (rel->l) return rdf_is_select_on_s(rel->l); 
+
+       if (is_select(rel->op) && rel->exps){
+               node *n; 
+               for (n = rel->exps->h; n; n = n->next) {
+                       sql_exp *e = n->data;
+                       if (e->type == e_cmp){
+                               sql_exp *le = e->l; 
+                               if (le->type == e_convert){
+                                       sql_exp *cole = le->l; 
+                                       if (cole->type == e_column){
+                                               if (strcmp(cole->name, "s") == 
0){
+                                                       return 1; 
+                                               }
+                                       }
+                               } else continue; 
+                                       
+                       } else continue; 
+               }
+
+       } 
+
+       return 0; 
+
+}
+*/
+/* 
+ * A cross product will not cost much
+ * if there is selection on the subject 
+ * predicate
+ * */
+/*
+static 
+int rdf_is_good_crossproduct(sql_rel *rel){
+       if (rel->exps || rel->op != op_join) return 0; 
+       if (rdf_is_select_on_s(rel->l) || 
+           rdf_is_select_on_s(rel->r)){
+               return 1; 
+       } else 
+               return 0; 
+}
+*/
+
 static sql_rel *
 rel_simplify_predicates(int *changes, mvc *sql, sql_rel *rel) 
 {
@@ -5967,16 +6016,19 @@ rel_simplify_predicates(int *changes, mv
                                        break;
                        }
                        //if (0)
+                       if (rdf_opt_simply_crp)
                        if (is_atom(e->type) && !e->l && !e->r) { /* numbered 
variable */
                                atom *a = sql->args[e->flag];
                                int flag = a->data.val.bval;
-
-                               /* remove simple select true expressions */
+                               
+                               /* if (!(rel->l && 
rdf_is_good_crossproduct(rel->l)) && 
+                                       !(rel->r && 
rdf_is_good_crossproduct(rel->r)) )   */
+                                       /* remove simple select true 
expressions */
                                if (flag) {
                                        sql->caching = 0;
                                        break;
                                }
-                       }
+               }
                        if (e->type == e_cmp && get_cmp(e) == cmp_equal) {
                                sql_exp *l = e->l;
                                sql_exp *r = e->r;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to