Changeset: 2fa2e53945be for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2fa2e53945be
Modified Files:
        gdk/gdk_join.c
        monetdb5/modules/mal/batcalc.c
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql_statement.c
        sql/backends/monet5/sql_statement.h
        sql/include/sql_catalog.h
        sql/server/rel_dump.c
        sql/server/rel_optimizer.c
        sql/server/rel_rel.c
        sql/server/rel_rel.h
        sql/server/rel_unnest.c
        sql/server/sql_mvc.c
        sql/server/sql_mvc.h
        sql/storage/bat/bat_storage.c
        sql/storage/sql_storage.h
        sql/storage/store.c
Branch: oscar
Log Message:

Merge with Jun2020 branch.


diffs (truncated from 977 to 300 lines):

diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -3063,7 +3063,6 @@ bitmaskjoin(BAT *l, BAT *r,
            const char *reason, lng t0)
 {
        BAT *r1;
-       const oid *rp = BATtdense(r) ? NULL : Tloc(r, 0);
        size_t nmsk = (lci->ncand + 31) / 32;
        uint32_t *mask = GDKzalloc(nmsk * sizeof(uint32_t));
        BUN cnt = 0;
@@ -3073,13 +3072,9 @@ bitmaskjoin(BAT *l, BAT *r,
 
        for (BUN n = 0; n < rci->ncand; n++) {
                oid o = canditer_next(rci) - r->hseqbase;
-               if (rp) {
-                       o = rp[o];
-                       if (is_oid_nil(o))
-                               continue;
-               } else {
-                       o = o - r->hseqbase + r->tseqbase;
-               }
+               o = BUNtoid(r, o);
+               if (is_oid_nil(o))
+                       continue;
                o += l->hseqbase;
                if (o < lci->seq + l->tseqbase)
                        continue;
@@ -3362,39 +3357,58 @@ leftjoin(BAT **r1p, BAT **r2p, BAT *l, B
                                BBPunfix(sr->batCacheid);
                        if (rc != GDK_SUCCEED)
                                return rc;
+                       if (r2p == NULL) {
+                               BBPunfix(r2->batCacheid);
+                               r2 = NULL;
+                       }
                        if (semi)
                                r1->tkey = true;
-                       BAT *ob;
-                       rc = BATsort(&tmp, r2p ? &ob : NULL, NULL,
-                                    r1, NULL, NULL, false, false, false);
-                       BBPunfix(r1->batCacheid);
-                       if (rc != GDK_SUCCEED) {
-                               BBPunfix(r2->batCacheid);
-                               return rc;
+                       if (!VIEWtparent(r1) &&
+                           r1->ttype == TYPE_oid &&
+                           BBP_refs(r1->batCacheid) == 1 &&
+                           (r2 == NULL ||
+                            (!VIEWtparent(r2) &&
+                             BBP_refs(r2->batCacheid) == 1 &&
+                             r2->ttype == TYPE_oid))) {
+                               /* in-place sort if we can */
+                               if (r2) {
+                                       GDKqsort(r1->theap.base, r2->theap.base,
+                                                NULL, r1->batCount, r1->twidth,
+                                                r2->twidth, TYPE_oid, false,
+                                                false);
+                                       r2->tsorted = false;
+                                       r2->trevsorted = false;
+                                       *r2p = r2;
+                               } else {
+                                       GDKqsort(r1->theap.base, NULL, NULL,
+                                                r1->batCount, r1->twidth, 0,
+                                                TYPE_oid, false, false);
+                               }
+                               r1->tsorted = true;
+                               r1->trevsorted = false;
+                               *r1p = r1;
+                       } else {
+                               BAT *ob;
+                               rc = BATsort(&tmp, r2p ? &ob : NULL, NULL,
+                                            r1, NULL, NULL, false, false, 
false);
+                               BBPunfix(r1->batCacheid);
+                               if (rc != GDK_SUCCEED) {
+                                       if (r2)
+                                               BBPunfix(r2->batCacheid);
+                                       return rc;
+                               }
+                               *r1p = r1 = tmp;
+                               if (r2p) {
+                                       tmp = BATproject(ob, r2);
+                                       BBPunfix(r2->batCacheid);
+                                       BBPunfix(ob->batCacheid);
+                                       if (tmp == NULL) {
+                                               BBPunfix(r1->batCacheid);
+                                               return GDK_FAIL;
+                                       }
+                                       *r2p = tmp;
+                               }
                        }
-                       *r1p = r1 = tmp;
-                       if (r2p) {
-                               tmp = BATproject(ob, r2);
-                               BBPunfix(r2->batCacheid);
-                               BBPunfix(ob->batCacheid);
-                               if (tmp == NULL) {
-                                       BBPunfix(r1->batCacheid);
-                                       return GDK_FAIL;
-                               }
-                               *r2p = tmp;
-                       }
-#if 0
-#ifndef NDEBUG
-                       BAT *x1;
-                       canditer_reset(&lci);
-                       canditer_reset(&rci);
-                       hashjoin(&x1, NULL, l, r, &lci, &rci, nil_matches, 
false, false, false, false, false, estimate, t0, false, rhash, prhash, func);
-                       assert(x1->batCount == r1->batCount);
-                       for (BUN x = 0; x < x1->batCount; x++)
-                               assert(BUNtoid(r1, x) == BUNtoid(x1, x));
-                       BBPunfix(x1->batCacheid);
-#endif
-#endif
                        return GDK_SUCCEED;
                }
        }
diff --git a/monetdb5/modules/mal/batcalc.c b/monetdb5/modules/mal/batcalc.c
--- a/monetdb5/modules/mal/batcalc.c
+++ b/monetdb5/modules/mal/batcalc.c
@@ -73,6 +73,8 @@ CMDbatUNARY(MalStkPtr stk, InstrPtr pci,
        BBPunfix(b->batCacheid);
        if (s)
                BBPunfix(s->batCacheid);
+       if (r)
+               BBPunfix(r->batCacheid);
        if (bn == NULL) {
                return mythrow(MAL, malfunc, OPERATION_FAILED);
        }
@@ -121,6 +123,8 @@ CMDbatUNARY1(MalStkPtr stk, InstrPtr pci
        BBPunfix(b->batCacheid);
        if (s)
                BBPunfix(s->batCacheid);
+       if (r)
+               BBPunfix(r->batCacheid);
        if (bn == NULL) {
                return mythrow(MAL, malfunc, OPERATION_FAILED);
        }
@@ -1224,6 +1228,8 @@ CMDconvertbat(MalStkPtr stk, InstrPtr pc
        BBPunfix(b->batCacheid);
        if (s)
                BBPunfix(s->batCacheid);
+       if (r)
+               BBPunfix(r->batCacheid);
        if (bn == NULL) {
                char buf[20];
                snprintf(buf, sizeof(buf), "batcalc.%s", ATOMname(tp));
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -432,7 +432,7 @@ handle_in_exps(backend *be, sql_exp *ce,
                        s = stmt_project(be, stmt_selectnonil(be, s, NULL), s);
                }
 
-               s = stmt_join(be, c, s, in, cmp_left, 0, false);
+               s = stmt_join(be, c, s, in, cmp_equal, 1, 0, false);
                s = stmt_result(be, s, 0);
 
                if (!in) {
@@ -1060,9 +1060,9 @@ exp_bin(backend *be, sql_exp *e, stmt *l
                        if (r2) {
                                s = stmt_join2(be, l, r, r2, 
(comp_type)e->flag, is_anti(e), swapped);
                        } else if (swapped) {
-                               s = stmt_join(be, r, l, is_anti(e), 
swap_compare((comp_type)e->flag), is_semantics(e), false);
+                               s = stmt_join(be, r, l, is_anti(e), 
swap_compare((comp_type)e->flag), 0, is_semantics(e), false);
                        } else {
-                               s = stmt_join(be, l, r, is_anti(e), 
(comp_type)e->flag, is_semantics(e), false);
+                               s = stmt_join(be, l, r, is_anti(e), 
(comp_type)e->flag, 0, is_semantics(e), false);
                        }
                } else {
                        if (r2) {
@@ -2078,9 +2078,9 @@ rel2bin_hash_lookup(backend *be, sql_rel
        }
        if (h && h->nrcols) {
                if (!swap_rel) {
-                       return stmt_join(be, idx, h, 0, cmp_equal, semantics, 
false);
+                       return stmt_join(be, idx, h, 0, cmp_equal, 0, 
semantics, false);
                } else {
-                       return stmt_join(be, h, idx, 0, cmp_equal, semantics, 
false);
+                       return stmt_join(be, h, idx, 0, cmp_equal, 0, 
semantics, false);
                }
        } else {
                return stmt_uselect(be, idx, h, cmp_equal, NULL, 0, semantics);
@@ -2130,9 +2130,7 @@ releqjoin( backend *be, list *l1, list *
                        e = n3->data;
                        is_semantics = is_semantics(e);
                }
-               r =  stmt_join(be, l, r, 0, cmp_op, is_semantics, false);
-               if (need_left)
-                       r->flag = cmp_left;
+               r =  stmt_join(be, l, r, 0, cmp_op, need_left, is_semantics, 
false);
                return r;
        }
        if (used_hash) {
@@ -2141,14 +2139,12 @@ releqjoin( backend *be, list *l1, list *
                n1 = n1->next;
                n2 = n2->next;
                n3 = n3?n3->next:NULL;
-               res = stmt_join(be, l, r, 0, cmp_op, 1, false);
+               res = stmt_join(be, l, r, 0, cmp_op, need_left, 1, false);
        } else { /* need hash */
                l = join_hash_key(be, l1);
                r = join_hash_key(be, l2);
-               res = stmt_join(be, l, r, 0, cmp_op, 1, false);
-       }
-       if (need_left)
-               res->flag = cmp_left;
+               res = stmt_join(be, l, r, 0, cmp_op, need_left, 1, false);
+       }
        l = stmt_result(be, res, 0);
        r = stmt_result(be, res, 1);
        for (; n1 && n2; n1 = n1->next, n2 = n2->next, n3 = n3?n3->next:NULL) {
@@ -2179,7 +2175,7 @@ releqjoin( backend *be, list *l1, list *
                l = stmt_project(be, cmp, l );
                r = stmt_project(be, cmp, r );
        }
-       res = stmt_join(be, l, r, 0, cmp_joined, 0, false);
+       res = stmt_join(be, l, r, 0, cmp_joined, 0, 0, false);
        return res;
 }
 
@@ -2315,7 +2311,7 @@ rel2bin_join(backend *be, sql_rel *rel, 
                if (list_empty(jexps)) { /* cross product and continue after 
project */
                        stmt *l = bin_first_column(be, left);
                        stmt *r = bin_first_column(be, right);
-                       join = stmt_join(be, l, r, 0, cmp_all, 0, false);
+                       join = stmt_join(be, l, r, 0, cmp_all, 0, 0, false);
                }
 
                if (join) {
@@ -2371,17 +2367,15 @@ rel2bin_join(backend *be, sql_rel *rel, 
                        }
                        if (list_length(lje) > 1) {
                                join = releqjoin(be, lje, rje, exps, used_hash, 
cmp_equal, need_left, 0);
-                       } else if (!join) {
+                       } else if (!join || need_left) {
                                sql_exp *e = exps->h->data;
-                               join = stmt_join(be, lje->h->data, 
rje->h->data, 0, cmp_equal, is_semantics(e), false);
-                               if (need_left)
-                                       join->flag = cmp_left;
+                               join = stmt_join(be, lje->h->data, 
rje->h->data, 0, cmp_equal, need_left, is_semantics(e), false);
                        }
                }
        } else {
                stmt *l = bin_first_column(be, left);
                stmt *r = bin_first_column(be, right);
-               join = stmt_join(be, l, r, 0, cmp_all, 0, rel->single);
+               join = stmt_join(be, l, r, 0, cmp_all, 0, 0, rel->single);
        }
        jl = stmt_result(be, join, 0);
        jr = stmt_result(be, join, 1);
@@ -2610,7 +2604,7 @@ rel2bin_semijoin(backend *be, sql_rel *r
                        right = subrel_project(be, right, refs, rel->r);
                        stmt *l = bin_first_column(be, left);
                        stmt *r = bin_first_column(be, right);
-                       join = stmt_join(be, l, r, 0, cmp_all, 0, false);
+                       join = stmt_join(be, l, r, 0, cmp_all, 0, 0, false);
                        lcand = left->cand;
                }
 
@@ -2638,7 +2632,7 @@ rel2bin_semijoin(backend *be, sql_rel *r
                                        if (!join && !list_length(lje)) {
                                                stmt *l = bin_first_column(be, 
left);
                                                stmt *r = bin_first_column(be, 
right);
-                                               join = stmt_join(be, l, r, 0, 
cmp_all, 0, false);
+                                               join = stmt_join(be, l, r, 0, 
cmp_all, 0, 0, false);
                                        }
                                        break;
                                }
@@ -2664,7 +2658,7 @@ rel2bin_semijoin(backend *be, sql_rel *r
 
                                        if (!l || !r)
                                                return NULL;
-                                       s = stmt_join_cand(be, column(be, l), 
column(be, r), left->cand, NULL/*right->cand*/, e->anti, (comp_type) e->flag, 
is_semantics(e), false);
+                                       s = stmt_join_cand(be, column(be, l), 
column(be, r), left->cand, NULL/*right->cand*/, e->anti, (comp_type) e->flag, 
0, is_semantics(e), false);
                                        lcand = left->cand;
                                } else {
                                        s = exp_bin(be, e, left, right, NULL, 
NULL, NULL, NULL, NULL, 0, 1);
@@ -2698,18 +2692,18 @@ rel2bin_semijoin(backend *be, sql_rel *r
                                join = releqjoin(be, lje, rje, exps, 0 /* no 
hash used */, cmp_equal, 0, 0);
                        } else if (!join && list_length(lje) == 
list_length(rje) && list_length(lje)) {
                                sql_exp *e = exps->h->data;
-                               join = stmt_join(be, lje->h->data, 
rje->h->data, 0, cmp_equal, is_semantics(e), false);
+                               join = stmt_join(be, lje->h->data, 
rje->h->data, 0, cmp_equal, 0, is_semantics(e), false);
                        } else if (!join) {
                                stmt *l = bin_first_column(be, left);
                                stmt *r = bin_first_column(be, right);
-                               join = stmt_join(be, l, r, 0, cmp_all, 0, 
false);
+                               join = stmt_join(be, l, r, 0, cmp_all, 0, 0, 
false);
                        }
                }
        } else {
                right = subrel_project(be, right, refs, rel->r);
                stmt *l = bin_first_column(be, left);
                stmt *r = bin_first_column(be, right);
-               join = stmt_join(be, l, r, 0, cmp_all, 0, false);
+               join = stmt_join(be, l, r, 0, cmp_all, 0, 0, false);
                lcand = left->cand;
        }
        jl = stmt_result(be, join, 0);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to