Changeset: 171bad5b5846 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=171bad5b5846
Modified Files:
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_rdf.c
        sql/backends/monet5/sql_rdf_jgraph.c
        sql/server/rel_select.c
Branch: rdf
Log Message:

Apply patch of rel_select

- This patch is for fixing the issue with anti-join


diffs (212 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
@@ -112,7 +112,6 @@ rel_need_distinct_query(sql_rel *rel)
 }
 
 
-
 sql_rel *
 sql_symbol2relation(mvc *c, symbol *sym)
 {
@@ -147,7 +146,9 @@ sql_symbol2relation(mvc *c, symbol *sym)
                        if (0) c->emod = mod_explain;
 
                        eT = clock(); 
-                       printf("----- Transformation time: %f seconds.\n", 
((float)(eT - sT))/CLOCKS_PER_SEC);
+                       printf("----- Transformation time: %f mseconds.\n", 
1000*((float)(eT - sT))/CLOCKS_PER_SEC);
+                       //mnstr_printf(c->scanner.ws, "#----- Transformation 
time: %f seconds.\n", ((float)(eT - sT))/CLOCKS_PER_SEC);
+
                }
 
                #if PRINT_FOR_DEBUG
@@ -175,7 +176,7 @@ sql_symbol2relation(mvc *c, symbol *sym)
                _rel_print(c,r);
                #endif
                eT = clock(); 
-               printf("----- Optimization time: %f seconds.\n", ((float)(eT - 
sT))/CLOCKS_PER_SEC);
+               printf("----- Optimization time: %f mseconds.\n", 
1000*((float)(eT - sT))/CLOCKS_PER_SEC);
                
                }
        }
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
@@ -1673,7 +1673,7 @@ void get_full_outerjoin_p_slices(oid *ls
        RDFmultiway_merge_outerjoins(np, sbats, obats, r_sbat, (*r_obats));
        end = clock(); 
 
-       printf("Mutliway outer join result: ("BUNFMT" rows)  [Took %f 
seconds]\n", BATcount(*r_sbat), ((float)(end - start))/CLOCKS_PER_SEC);
+       printf("# Multiway outer join result: ("BUNFMT" rows)  [Took %f 
seconds]\n", BATcount(*r_sbat), ((float)(end - start))/CLOCKS_PER_SEC);
        //BATprint(*r_sbat); 
        /*
        for (i = 0; i < np; i++){
@@ -2175,7 +2175,7 @@ SQLrdfScan(Client cntxt, MalBlkPtr mb, M
                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);
+               printf("# Step 1 in Handling exception took  %f seconds.\n", 
((float)(eT1 - sT1))/CLOCKS_PER_SEC);
                
                /* {
                BUN testbun = BUN_NONE; 
@@ -2225,7 +2225,7 @@ SQLrdfScan(Client cntxt, MalBlkPtr mb, M
                }
                
                eT1 = clock(); 
-               printf("Step 2 in Handling exception took  %f seconds.\n", 
((float)(eT1 - sT1))/CLOCKS_PER_SEC);
+               printf("# Step 2 in Handling exception took  %f seconds.\n", 
((float)(eT1 - sT1))/CLOCKS_PER_SEC);
 
        }
        #if PRINT_FOR_DEBUG
@@ -2238,7 +2238,7 @@ SQLrdfScan(Client cntxt, MalBlkPtr mb, M
        GDKfree(b);
 
        eT = clock(); 
-       printf("RDFscan for handling exception took  %f seconds.\n", 
((float)(eT - sT))/CLOCKS_PER_SEC);
+       printf("# RDFscan for handling exception took  %f seconds.\n", 
((float)(eT - sT))/CLOCKS_PER_SEC);
 
        return MAL_SUCCEED; 
 }
@@ -2421,7 +2421,7 @@ void getOffsets(PsoPropStat *pso_pstat, 
 
        pos = BUNfnd(pso_pstat->pBat, p);
        if (pos == BUN_NONE){
-               printf("The prop "BUNFMT " is not in PSO!\n", *p);
+               printf("# The prop "BUNFMT " is not in PSO!\n", *p);
                *start = BUN_NONE; 
                *end = BUN_NONE; 
        }
@@ -2640,8 +2640,11 @@ str SQLrdfprepare(Client cntxt, MalBlkPt
                if (BATcount(pso_fullSbat) == 0) {
                        need_handling_exception = 0; 
                        printf("Do not need to handle exception\n"); 
+               } else {
+                       printf("Need to handle exception\n"); 
                }
                
+               
        }
        
 
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
@@ -3271,18 +3271,18 @@ void build_all_rels_from_cross_edges(mvc
                spId2 = n2->patternId; 
 
                if (sp_sp_rel[spId1][spId2] == edge->r_id){
-                       printf("This rel was applied to connect sp %d and sp 
%d\n", spId1, spId2); 
+                       //printf("This rel was applied to connect sp %d and sp 
%d\n", spId1, spId2); 
                        continue; 
                }
 
                if (gr_rep_id[spId1] == gr_rep_id[spId2]){
                        int cre_id = sp_cre_map[spId1];
                        if (edge->need_add_exps == 1){ //Handling special case 
for q5 bsbm
-                               printf("Apply for adding exps 
[%d,%d]\n",edge->from,edge->to);
+                               //printf("Apply for adding exps 
[%d,%d]\n",edge->from,edge->to);
                                assert(sp_cre_map[spId1] == sp_cre_map[spId2]); 
                                tranforms_join_exps(c, edge->data, 
lst_cross_edge_rels[cre_id]->exps, 0, 1, NULL, -1, NULL, -1, NULL);
                        } else if (sp_sp_rel[spId1][spId2] == -1) {     //This 
rel is not considered as connecting sp1, sp2 yet
-                               printf("Consider the rel experessions from 
cross edges [%d,%d]\n",edge->from,edge->to);
+                               //printf("Consider the rel experessions from 
cross edges [%d,%d]\n",edge->from,edge->to);
                                if (((sql_rel *) edge->data)->exps){
                                        tranforms_join_exps(c, edge->data, 
lst_cross_edge_rels[cre_id]->exps, 0, 0, NULL, -1, NULL, -1, NULL);
                                        sp_sp_rel[spId1][spId2] = edge->r_id; 
@@ -3322,7 +3322,7 @@ void build_all_rels_from_cross_edges(mvc
                        int cre_id2 =  sp_cre_map[spId2];
 
                        if (cre_id1 == cre_id2) {
-                               printf("Already connected. Do not apply cross 
edges [%d,%d]\n",edge->from,edge->to);
+                               //printf("Already connected. Do not apply cross 
edges [%d,%d]\n",edge->from,edge->to);
                                continue;  //These patterns are connected 
already
                        }
                        else
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -2120,7 +2120,7 @@ rel_logical_exp(mvc *sql, sql_rel *rel, 
                symbol *lo = NULL;
                dnode *n = dl->h->next, *dn = NULL;
                sql_rel *left = NULL, *right = NULL, *outer = rel;
-               sql_exp *l = NULL, *e, *r = NULL;
+               sql_exp *l = NULL, *e, *r = NULL, *ident = NULL;
                list *vals = NULL, *ll = sa_list(sql->sa);
                int correlated = 0;
                int l_is_value = 1, r_is_rel = 0;
@@ -2223,14 +2223,17 @@ rel_logical_exp(mvc *sql, sql_rel *rel, 
                                                sql->session->status = 0;
                                                sql->errstr[0] = 0;
 
-                                               if (l_is_value) 
-                                                       rel = rel_dup(outer);
-                                               else
+                                               if (l_is_value) {
+                                                       outer = rel = 
rel_add_identity(sql, rel_dup(outer), &ident);
+                                                       ident = 
exp_column(sql->sa, exp_relname(ident), exp_name(ident), exp_subtype(ident), 
ident->card, has_nil(ident), is_intern(ident));
+                                               } else
                                                        rel = left = 
rel_dup(left);
                                                r = rel_value_exp(sql, &rel, 
sval, f, ek);
                                                if (r && !is_project(rel->op)) {
                                                        rel = 
rel_project(sql->sa, rel, NULL);
                                                        
rel_project_add_exp(sql, rel, r);
+                                                       if (ident)
+                                                               
rel_project_add_exp(sql, rel, ident);
                                                }
                                                z = rel;
                                                correlated = 1;
@@ -2272,13 +2275,12 @@ rel_logical_exp(mvc *sql, sql_rel *rel, 
 
                if (right) {
                        node *n, *m;
-                       list *rexps;
-
-                       rel = rel_crossproduct(sql->sa, left, right, op_join);
+                       list *rexps, *jexps = sa_list(sql->sa);
+
 
                        /* list through all left/right expressions */
                        rexps = right->exps;
-                       if (!is_project(right->op) || list_length(ll) != 
list_length(rexps)) {
+                       if (!is_project(right->op) || 
(list_length(ll)+((ident)?1:0)) != list_length(rexps)) {
                                if (list_length(ll) == 1)
                                        return sql_error(sql, 02, "IN: inner 
query should return a single column");
                                return NULL;
@@ -2294,7 +2296,26 @@ rel_logical_exp(mvc *sql, sql_rel *rel, 
                                if (rel_convert_types(sql, &l, &r, 1, 
type_equal) < 0) 
                                        return NULL;
                                e = exp_compare(sql->sa, l, r, cmp_equal );
-                               rel_join_add_exp(sql->sa, rel, e);
+                               //rel_join_add_exp(sql->sa, rel, e);
+                               append(jexps, e);
+                       }
+                       if (correlated && l_is_value) {
+                               sql_exp *le;
+
+                               le = exps_bind_column2(right->exps, 
exp_relname(ident), exp_name(ident));
+                               exp_label(sql->sa, le, ++sql->label);
+                               le = exp_column(sql->sa, exp_relname(le), 
exp_name(le), exp_subtype(le), le->card, has_nil(le), is_intern(le));
+
+                               right = rel_select(sql->sa, right, NULL);
+                               right->exps = jexps;
+
+                               rel = rel_crossproduct(sql->sa, outer, right, 
op_join);
+                               rel->exps = sa_list(sql->sa);
+                               le = exp_compare(sql->sa, ident, le, cmp_equal);
+                               append(rel->exps, le);
+                       } else {
+                               rel = rel_crossproduct(sql->sa, left, right, 
op_join);
+                               rel->exps = jexps;
                        }
                        if (correlated || l_is_value || r_is_rel) {
                                rel->op = (sc->token == SQL_IN)?op_semi:op_anti;
@@ -2306,7 +2327,7 @@ rel_logical_exp(mvc *sql, sql_rel *rel, 
                                e = exp_compare(sql->sa,  e, r, cmp_equal);
                                rel = rel_select(sql->sa, rel, e);
                        }
-                       if (l_is_value && outer)
+                       if (!correlated && l_is_value && outer)
                                rel = rel_crossproduct(sql->sa, outer, rel, 
op_join);
                        rel = rel_project(sql->sa, rel, rel_projections(sql, 
outer, NULL, 1, 1));
                        set_processed(rel);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to