Changeset: 85514f6b55a0 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/85514f6b55a0
Modified Files:
        sql/server/rel_optimize_sel.c
Branch: default
Log Message:

create single disjunctive expression for selects over a shared referenced 
relation


diffs (77 lines):

diff --git a/sql/server/rel_optimize_sel.c b/sql/server/rel_optimize_sel.c
--- a/sql/server/rel_optimize_sel.c
+++ b/sql/server/rel_optimize_sel.c
@@ -4193,41 +4193,49 @@ rel_push_func_and_select_down(visitor *v
                if (!list_empty(refs)) {
                        list *urefs = sa_list(v->sql->sa);
                        for(node *n = refs->h; n; n = n->next->next) {
-                               //sql_rel *r = n->data;
                                sql_rel *ref = n->next->data;
                                if (!list_find(urefs, ref, NULL))
                                        append(urefs, ref);
                        }
                        for (node *m = urefs->h; m; m = m->next) {
+                               int select_cnt = 0;
                                sql_rel *cref = m->data;
                                list *users = sa_list(v->sql->sa);
                                for(node *n = refs->h; n; n = n->next->next) {
-                                       if (n->next->data == cref)
-                                               append(users, n->data);
+                                       if (n->next->data == cref) {
+                                               sql_rel *user = n->data;
+                                               append(users, user);
+                                               select_cnt += 
(is_select(user->op));
+                                       }
                                }
                                if (cref->ref.refcnt == list_length(users)) {
-                                       /* if all users are a set of selects 
and referenced is a union, try to split the union over the
-                                        * selects, based on the select 
expressions
-                                        * similar too merge table push down?
-                                        *
-                                        * or handle like or expression lists, 
and run the rse
-                                        */
-                                       /* if all users are a set of 
projects/groupby's, try to reduced the result columns (or improve the
-                                        * dce)
-                                        */
-                                       /* if all are groupby ?? */
-                                       /* all found */
-                                       sql_rel *b = cref;
-                                       while (is_simple_project(b->op) && b->l)
-                                               b = b->l;
-                                       (void)b;
-                                       /*
-                                       printf ("all found %d\n", (int)b->op);
-                                       for(node *n = users->h; n; n = n->next) 
{
-                                               printf ("exps\n");
-                                               _exps_print(v->sql, 
((sql_rel*)n->data)->exps);
+                                       /* if all users are selects, try to 
copy/merge the expressions, and push one select */
+                                       if (select_cnt == list_length(users)) {
+                                               /* create cmp_dis lists */
+                                               sql_exp *e = NULL;
+                                               for(node *n = users->h; n; n = 
n->next) {
+                                                       sql_rel *u = n->data;
+                                                       list *nexps = 
exps_copy(v->sql, u->exps);
+                                                       sql_exp *con = 
exp_conjunctive(v->sql->sa, nexps);
+                                                       if (e) {
+                                                               e = 
exp_disjunctive2(v->sql->sa, e, con);
+                                                       } else {
+                                                               e = con;
+                                                       }
+                                               }
+                                               sql_rel *nrel = 
rel_select(v->sql->sa, rel_dup(cref), e);
+                                               for(node *n = users->h; n; n = 
n->next) {
+                                                       sql_rel *u = n->data;
+                                                       rel_destroy(v->sql, 
cref);
+                                                       nrel = rel_dup(nrel);
+                                                       if (u->l == cref) {
+                                                               u->l = nrel;
+                                                       } else {
+                                                               u->r = nrel;
+                                                       }
+                                               }
+                                               rel_destroy(v->sql, nrel);
                                        }
-                                       */
                                }
                        }
                }
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to